From a3fa4dd537609de95a2b65405c6e611b2c139075 Mon Sep 17 00:00:00 2001 From: Mathieu Mirmont Date: Mon, 13 Mar 2023 16:15:46 +0100 Subject: [PATCH] PlanManager: drop spurious items for unexpected mission types (#10509) * PlanManager: drop spurious items for unexpected mission types * PlanManager: drive-by bug fix --- src/MissionManager/PlanManager.cc | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/MissionManager/PlanManager.cc b/src/MissionManager/PlanManager.cc index cddd777..38da071 100644 --- a/src/MissionManager/PlanManager.cc +++ b/src/MissionManager/PlanManager.cc @@ -373,25 +373,27 @@ void PlanManager::_requestNextMissionItem(void) void PlanManager::_handleMissionItem(const mavlink_message_t& message) { - MAV_CMD command; - MAV_FRAME frame; - double param1; - double param2; - double param3; - double param4; - double param5; - double param6; - double param7; - bool autoContinue; - bool isCurrentItem; - int seq; + MAV_CMD command; + MAV_FRAME frame; + MAV_MISSION_TYPE missionType; + double param1; + double param2; + double param3; + double param4; + double param5; + double param6; + double param7; + bool autoContinue; + bool isCurrentItem; + int seq; mavlink_mission_item_int_t missionItem; mavlink_msg_mission_item_int_decode(&message, &missionItem); - command = (MAV_CMD)missionItem.command, - frame = (MAV_FRAME)missionItem.frame, - param1 = missionItem.param1; + command = (MAV_CMD)missionItem.command; + frame = (MAV_FRAME)missionItem.frame; + missionType = (MAV_MISSION_TYPE)missionItem.mission_type; + param1 = missionItem.param1; param2 = missionItem.param2; param3 = missionItem.param3; param4 = missionItem.param4; @@ -402,6 +404,13 @@ void PlanManager::_handleMissionItem(const mavlink_message_t& message) isCurrentItem = missionItem.current; seq = missionItem.seq; + // Check the mission_type field. It can happen that we receive a late duplicate message for a + // different mission_type request. + if (missionType != _planType) { + qCDebug(PlanManagerLog) << QStringLiteral("_handleMissionItem %1 dropping spurious item seq:command:missionType").arg(_planTypeString()) << seq << command << missionType; + return; + } + // We don't support editing ALT_INT frames so change on the way in. if (frame == MAV_FRAME_GLOBAL_INT) { frame = MAV_FRAME_GLOBAL;