mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 00:30:50 +08:00
fix(mavlink): NACK MAV_CMD DO_FIGURE_EIGHT and NAV_VTOL_TAKEOFF (#28235)
* fix(commander): NACK DO_FIGUREEIGHT/NAV_VTOL_TAKEOFF without double-ACKing others handle_command() decided whether the post-switch answer_command() call was needed by checking cmd_result != UNSUPPORTED, on the assumption that UNSUPPORTED only ever came from the shared default: case (which already self-acks). DO_FIGUREEIGHT and NAV_VTOL_TAKEOFF also legitimately resolve to UNSUPPORTED from within their own case (module not compiled, or wrong vehicle type), so the guard mistook them for already-handled and silently dropped the ACK - the vehicle command timed out on the GCS instead of being NACKed. A prior fix for this addressed it with a separate `already_answered` flag, but only set it in the two places that already matched the old proxy (default: and the ignore-list), so ~8 other cases that answer_command() themselves inline (PREFLIGHT_CALIBRATION, PREFLIGHT_REBOOT_SHUTDOWN, PREFLIGHT_STORAGE, FIXED_MAG_CAL_YAW, DO_SET_STANDARD_MODE, RUN_PREARM_CHECKS, DO_SET_ACTUATOR, DO_SET_SAFETY_SWITCH_STATE) would now fall through to the shared call too and get ACKed a second time, with the wrong (UNSUPPORTED) result. Replace the flag with a structural rule instead: every case that sends its own ACK returns immediately rather than breaking, so the single answer_command(cmd, cmd_result) after the switch is unconditional and only ever reached by cases that rely on it. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Hamish Willee <hamishwillee@gmail.com> * fix(commander): move GUIDED_CHANGE_HEADING into navigator-acked ignore list Its case body was empty, relying on cmd_result staying UNSUPPORTED to skip the old conditional answer_command() call. Now that the shared answer_command() runs unconditionally, this fell through into a bogus UNSUPPORTED NACK on top of navigator's own ACK/DENIED for the command. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Hamish Willee <hamishwillee@gmail.com> * Apply suggestion from @hamishwillee --------- Signed-off-by: Hamish Willee <hamishwillee@gmail.com>
This commit is contained in:
1 parent
881bce35ae
commit
b1056f653b
1 file changed
+21
-25
@@ -859,7 +859,10 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* result of the command */
|
||||
/* result of the command, sent via answer_command() once after the switch below.
|
||||
* Cases that answer_command() themselves (e.g. because they must reply before an
|
||||
* irreversible action, or because another module owns the reply) must `return true;`
|
||||
* instead of `break;`, so they are not answered a second time here. */
|
||||
unsigned cmd_result = vehicle_command_ack_s::VEHICLE_CMD_RESULT_UNSUPPORTED;
|
||||
|
||||
/* request to set different system mode */
|
||||
@@ -916,12 +919,6 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
}
|
||||
break;
|
||||
|
||||
case vehicle_command_s::VEHICLE_CMD_GUIDED_CHANGE_HEADING: {
|
||||
// Navigator handles this command: it acks ACCEPTED when
|
||||
// the vehicle is in course mode with a valid position, DENIED otherwise.
|
||||
}
|
||||
break;
|
||||
|
||||
case vehicle_command_s::VEHICLE_CMD_DO_SET_MODE: {
|
||||
uint8_t base_mode = (uint8_t)cmd.param1;
|
||||
uint8_t custom_main_mode = (uint8_t)cmd.param2;
|
||||
@@ -1425,7 +1422,7 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
return true;
|
||||
|
||||
case vehicle_command_s::VEHICLE_CMD_PREFLIGHT_CALIBRATION: {
|
||||
|
||||
@@ -1453,7 +1450,7 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
(int)(cmd.param5) == vehicle_command_s::PREFLIGHT_CALIBRATION_TEMPERATURE_CALIBRATION ||
|
||||
(int)(cmd.param7) == vehicle_command_s::PREFLIGHT_CALIBRATION_TEMPERATURE_CALIBRATION) {
|
||||
/* temperature calibration: handled in events module */
|
||||
break;
|
||||
return true;
|
||||
|
||||
} else if ((int)(cmd.param2) == 1) {
|
||||
/* magnetometer calibration */
|
||||
@@ -1544,7 +1541,7 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
case vehicle_command_s::VEHICLE_CMD_FIXED_MAG_CAL_YAW: {
|
||||
@@ -1586,7 +1583,7 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
_worker_thread.startTask(WorkerThread::Request::MagCalibrationQuick);
|
||||
}
|
||||
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
case vehicle_command_s::VEHICLE_CMD_PREFLIGHT_STORAGE: {
|
||||
@@ -1620,7 +1617,7 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
case vehicle_command_s::VEHICLE_CMD_DO_SET_STANDARD_MODE: {
|
||||
@@ -1640,16 +1637,17 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
return true;
|
||||
|
||||
case vehicle_command_s::VEHICLE_CMD_RUN_PREARM_CHECKS:
|
||||
_health_and_arming_checks.update(true);
|
||||
answer_command(cmd, vehicle_command_ack_s::VEHICLE_CMD_RESULT_ACCEPTED);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case vehicle_command_s::VEHICLE_CMD_DO_SET_ACTUATOR:
|
||||
answer_command(cmd, vehicle_command_ack_s::VEHICLE_CMD_RESULT_ACCEPTED);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case vehicle_command_s::VEHICLE_CMD_DO_SET_SAFETY_SWITCH_STATE: {
|
||||
// reject if armed, only allow pre or post flight for safety
|
||||
@@ -1672,8 +1670,10 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
return true;
|
||||
|
||||
case vehicle_command_s::VEHICLE_CMD_GUIDED_CHANGE_HEADING: // Handled by navigator
|
||||
case vehicle_command_s::VEHICLE_CMD_START_RX_PAIR:
|
||||
case vehicle_command_s::VEHICLE_CMD_CUSTOM_0:
|
||||
case vehicle_command_s::VEHICLE_CMD_CUSTOM_1:
|
||||
@@ -1722,21 +1722,17 @@ Commander::handle_command(const vehicle_command_s &cmd)
|
||||
case vehicle_command_s::VEHICLE_CMD_DO_AUTOTUNE_ENABLE:
|
||||
case vehicle_command_s::VEHICLE_CMD_ESTIMATOR_SENSOR_ENABLE:
|
||||
case vehicle_command_s::VEHICLE_CMD_ACTUATOR_GROUP_TEST:
|
||||
/* ignore commands that are handled by other parts of the system */
|
||||
break;
|
||||
/* ignore commands that are handled by other parts of the system: no reply from here */
|
||||
return true;
|
||||
|
||||
default:
|
||||
/* Warn about unsupported commands, this makes sense because only commands
|
||||
/* Command not handled above: reply UNSUPPORTED. This makes sense because only commands
|
||||
* to this component ID (or all) are passed by mavlink. */
|
||||
answer_command(cmd, vehicle_command_ack_s::VEHICLE_CMD_RESULT_UNSUPPORTED);
|
||||
cmd_result = vehicle_command_ack_s::VEHICLE_CMD_RESULT_UNSUPPORTED;
|
||||
break;
|
||||
}
|
||||
|
||||
if (cmd_result != vehicle_command_ack_s::VEHICLE_CMD_RESULT_UNSUPPORTED) {
|
||||
/* already warned about unsupported commands in "default" case */
|
||||
answer_command(cmd, cmd_result);
|
||||
}
|
||||
|
||||
answer_command(cmd, cmd_result);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user