commander: check for stale arming_check_reply messages

based on the message timestamp.

Previously it was possible to run into the following case:
- 2 external modes are registered (running inside the same ROS node)
- they time out due to the micro xrce agent being blocked for some reason
- PX4 removes them
- the latest arming check replies still arrive to PX4
- the application restarts
- the first mode gets registered
- PX4 handles the previous arming check reply, and clears
  waiting_for_first_response, which reduces the timeout
- the second mode registers and as part of that checks for message
  compatibility. This takes ~1s, triggering a timeout of the first mode
This commit is contained in:
Beat Küng
2025-08-19 15:48:25 +02:00
parent a1ee9eb2c4
commit edfcdaa008
@@ -229,8 +229,10 @@ void ExternalChecks::update()
int max_num_updates = arming_check_reply_s::ORB_QUEUE_LENGTH;
while (_arming_check_reply_sub.update(&reply) && --max_num_updates >= 0) {
if (reply.registration_id < MAX_NUM_REGISTRATIONS && registrationValid(reply.registration_id)
&& _current_request_id == reply.request_id) {
const bool valid = reply.registration_id < MAX_NUM_REGISTRATIONS && registrationValid(reply.registration_id);
const bool timed_out = now > reply.timestamp + 300_ms;
if (!timed_out && valid && _current_request_id == reply.request_id) {
_reply_received_mask |= 1u << reply.registration_id;
_registrations[reply.registration_id].num_no_response = 0;
_registrations[reply.registration_id].waiting_for_first_response = false;