Skip to content

Commit

Permalink
commander: prevent potential disarms in-air
Browse files Browse the repository at this point in the history
This fixes the terrifying case where the drone disarms in-air just
because it receives a MAVLink disarm command. We now check param2 for a
magic number which enforces arming/disarming.

This is added to the mavlink protocol in:
mavlink/mavlink#1162
  • Loading branch information
julianoes committed Jul 26, 2019
1 parent 71613ac commit 308d91e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/modules/commander/Commander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,21 @@ Commander::handle_command(vehicle_status_s *status_local, const vehicle_command_

bool cmd_arms = (static_cast<int>(cmd.param1 + 0.5f) == 1);

// Arm/disarm is enforced only when param2 is set to a magic number.
const bool enforce_in_air = (static_cast<int>(std::round(cmd.param2)) == 21196);

if (!enforce_in_air && !land_detector.landed) {
if (cmd_arms) {
mavlink_log_critical(&mavlink_log_pub, "Arming denied! Not landed");

} else {
mavlink_log_critical(&mavlink_log_pub, "Disarming denied! Not landed");
}

cmd_result = vehicle_command_s::VEHICLE_CMD_RESULT_DENIED;
break;
}

// Flick to inair restore first if this comes from an onboard system
if (cmd.source_system == status_local->system_id && cmd.source_component == status_local->component_id) {
status.arming_state = vehicle_status_s::ARMING_STATE_IN_AIR_RESTORE;
Expand Down

0 comments on commit 308d91e

Please sign in to comment.