mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-13 21:41:35 +08:00
mavlink: add a shell using SERIAL_CONTROL MAVLink message
This commit is contained in:
@@ -263,6 +263,10 @@ MavlinkReceiver::handle_message(mavlink_message_t *msg)
|
||||
handle_message_battery_status(msg);
|
||||
break;
|
||||
|
||||
case MAVLINK_MSG_ID_SERIAL_CONTROL:
|
||||
handle_message_serial_control(msg);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1191,6 +1195,32 @@ MavlinkReceiver::handle_message_battery_status(mavlink_message_t *msg)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MavlinkReceiver::handle_message_serial_control(mavlink_message_t *msg)
|
||||
{
|
||||
mavlink_serial_control_t serial_control_mavlink;
|
||||
mavlink_msg_serial_control_decode(msg, &serial_control_mavlink);
|
||||
|
||||
// we only support shell commands
|
||||
if (serial_control_mavlink.device != SERIAL_CONTROL_DEV_SHELL
|
||||
|| (serial_control_mavlink.flags & SERIAL_CONTROL_FLAG_REPLY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MavlinkShell* shell = _mavlink->get_shell();
|
||||
if (shell) {
|
||||
// we ignore the timeout, EXCLUSIVE & BLOCKING flags of the SERIAL_CONTROL message
|
||||
if (serial_control_mavlink.count > 0) {
|
||||
shell->write(serial_control_mavlink.data, serial_control_mavlink.count);
|
||||
}
|
||||
|
||||
// if no response requested, assume the shell is no longer used
|
||||
if ((serial_control_mavlink.flags & SERIAL_CONTROL_FLAG_RESPOND) == 0) {
|
||||
_mavlink->close_shell();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch_pos_t
|
||||
MavlinkReceiver::decode_switch_pos(uint16_t buttons, unsigned sw)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user