From 40e4a896a239f353b0531f4729c0469b37fd0839 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Mon, 14 Oct 2024 10:52:37 +1300 Subject: [PATCH] core: prevent invalid duplicate acks (#2424) It turns out we respond with two acks to a MAV_REQUEST_MESSAGE when we should only respond once with the successful one. Alternatively, we could first grab all the results and then do some magic to determine which one is the best ack but that's a bit too magic and complex, so I'm not doing that yet. --- .../telemetry_server_impl.cpp | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/mavsdk/plugins/telemetry_server/telemetry_server_impl.cpp b/src/mavsdk/plugins/telemetry_server/telemetry_server_impl.cpp index a11fd8acf..9a1049590 100644 --- a/src/mavsdk/plugins/telemetry_server/telemetry_server_impl.cpp +++ b/src/mavsdk/plugins/telemetry_server/telemetry_server_impl.cpp @@ -83,20 +83,25 @@ void TelemetryServerImpl::init() case MAVLINK_MSG_ID_HOME_POSITION: if (_maybe_home) { if (_send_home()) { - return _server_component_impl->make_command_ack_message( - command, MAV_RESULT::MAV_RESULT_ACCEPTED); + return std::optional{ + _server_component_impl->make_command_ack_message( + command, MAV_RESULT::MAV_RESULT_ACCEPTED)}; } else { - return _server_component_impl->make_command_ack_message( - command, MAV_RESULT::MAV_RESULT_FAILED); + return std::optional{ + _server_component_impl->make_command_ack_message( + command, MAV_RESULT::MAV_RESULT_FAILED)}; } } else { - return _server_component_impl->make_command_ack_message( - command, MAV_RESULT::MAV_RESULT_DENIED); + return std::optional{ + _server_component_impl->make_command_ack_message( + command, MAV_RESULT::MAV_RESULT_DENIED)}; } default: - return _server_component_impl->make_command_ack_message( - command, MAV_RESULT::MAV_RESULT_DENIED); + // Let's hope someone else answers and keep silent. In an ideal world we would + // explicitly deny all the ones that we ought to answer but haven't implemented + // yet. + return std::optional{}; } }, this);