diff --git a/libraries/GCS_MAVLink/GCS_Common.cpp b/libraries/GCS_MAVLink/GCS_Common.cpp index 93b2f53c0b..19b33b06c5 100644 --- a/libraries/GCS_MAVLink/GCS_Common.cpp +++ b/libraries/GCS_MAVLink/GCS_Common.cpp @@ -4460,9 +4460,24 @@ MAV_RESULT GCS_MAVLINK::handle_command_do_set_mission_current(const mavlink_comm } const uint32_t seq = (uint32_t)packet.param1; + if (!mission->is_valid_index(seq)) { + return MAV_RESULT_DENIED; + } + + // From https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_MISSION_CURRENT: + // Param 2: Reset Mission + // - Resets mission. 1: true, 0: false. Resets jump counters to initial values + // and changes mission state "completed" to be "active" or "paused". + const bool reset_and_restart = is_equal(packet.param2, 1.0f); + if (reset_and_restart) { + mission->reset(); + } if (!mission->set_current_cmd(seq)) { return MAV_RESULT_FAILED; } + if (reset_and_restart) { + mission->resume(); + } // volunteer the new current waypoint for all listeners send_message(MSG_CURRENT_WAYPOINT);