From 67bf00c1c3c6e2fffb72dafdcfa749ead787fd84 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 12 Aug 2019 08:34:18 +1000 Subject: [PATCH] GCS_MAVLink: ensure payload space before sending message ack Also add comment about how we shouldn't be sending this message at all. --- libraries/GCS_MAVLink/GCS_Common.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libraries/GCS_MAVLink/GCS_Common.cpp b/libraries/GCS_MAVLink/GCS_Common.cpp index f17511b68c..87b1b55d34 100644 --- a/libraries/GCS_MAVLink/GCS_Common.cpp +++ b/libraries/GCS_MAVLink/GCS_Common.cpp @@ -1947,8 +1947,14 @@ void GCS_MAVLINK::handle_set_mode(const mavlink_message_t &msg) const MAV_RESULT result = _set_mode_common(_base_mode, _custom_mode); - // send ACK or NAK - mavlink_msg_command_ack_send(chan, MAVLINK_MSG_ID_SET_MODE, result); + // send ACK or NAK. Note that this is extraodinarily improper - + // we are sending a command-ack for a message which is not a + // command. The command we are acking (ID=11) doesn't actually + // exist, but if it did we'd probably be acking something + // completely unrelated to setting modes. + if (HAVE_PAYLOAD_SPACE(chan, MAVLINK_MSG_ID_COMMAND_ACK)) { + mavlink_msg_command_ack_send(chan, MAVLINK_MSG_ID_SET_MODE, result); + } } /*