mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-10-06 09:02:52 +08:00
fix(mavlink): don't count forwarded unknown messages as lost
Unknown messages didn't advance the sender's sequence, so the next message from it counted them as lost. Track their sequence as well, but only for components we have already seen: the header of an unknown message isn't CRC checked, and garbage IDs would fill the component table, which is also used for routing. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Julian Oes <julian@oes.ch>
This commit is contained in:
@@ -4010,7 +4010,7 @@ MavlinkReceiver::run()
|
||||
}
|
||||
|
||||
_mavlink.set_has_received_messages(true); // Received first message, unlock wait to transmit '-w' command-line flag
|
||||
update_rx_stats(msg);
|
||||
update_rx_stats(msg, true);
|
||||
|
||||
if (_message_statistics_enabled) {
|
||||
update_message_statistics(msg);
|
||||
@@ -4019,6 +4019,10 @@ MavlinkReceiver::run()
|
||||
} else if (frame_check == FrameCheck::ForwardOnly) {
|
||||
_unknown_message_counter++;
|
||||
|
||||
// The header of an unknown message isn't CRC checked, so only
|
||||
// track the sequence of components we have already seen.
|
||||
update_rx_stats(msg, false);
|
||||
|
||||
} else if (frame_check == FrameCheck::BadSignature) {
|
||||
_bad_signature_counter++;
|
||||
}
|
||||
@@ -4172,9 +4176,9 @@ bool MavlinkReceiver::component_was_seen(int system_id, int component_id)
|
||||
return false;
|
||||
}
|
||||
|
||||
void MavlinkReceiver::update_rx_stats(const mavlink_message_t &message)
|
||||
void MavlinkReceiver::update_rx_stats(const mavlink_message_t &message, bool add_component)
|
||||
{
|
||||
const bool component_states_has_still_space = [this, &message]() {
|
||||
const bool component_states_has_still_space = [this, &message, add_component]() {
|
||||
for (unsigned i = 0; i < MAX_REMOTE_COMPONENTS; ++i) {
|
||||
if (_component_states[i].system_id == message.sysid && _component_states[i].component_id == message.compid) {
|
||||
|
||||
@@ -4196,6 +4200,10 @@ void MavlinkReceiver::update_rx_stats(const mavlink_message_t &message)
|
||||
return true;
|
||||
|
||||
} else if (_component_states[i].system_id == 0 && _component_states[i].component_id == 0) {
|
||||
if (!add_component) {
|
||||
return true;
|
||||
}
|
||||
|
||||
_component_states[i].system_id = message.sysid;
|
||||
_component_states[i].component_id = message.compid;
|
||||
|
||||
@@ -4214,7 +4222,7 @@ void MavlinkReceiver::update_rx_stats(const mavlink_message_t &message)
|
||||
return false;
|
||||
}();
|
||||
|
||||
if (!component_states_has_still_space && !_warned_component_states_full_once) {
|
||||
if (add_component && !component_states_has_still_space && !_warned_component_states_full_once) {
|
||||
PX4_WARN("Max remote components of %u used up", MAX_REMOTE_COMPONENTS);
|
||||
_warned_component_states_full_once = true;
|
||||
}
|
||||
|
||||
@@ -282,7 +282,10 @@ private:
|
||||
void schedule_tune(const char *tune);
|
||||
|
||||
void update_message_statistics(const mavlink_message_t &message);
|
||||
void update_rx_stats(const mavlink_message_t &message);
|
||||
/**
|
||||
* @param add_component false to only update components which were already seen
|
||||
*/
|
||||
void update_rx_stats(const mavlink_message_t &message, bool add_component);
|
||||
|
||||
enum class FrameCheck {
|
||||
Incomplete, ///< no complete frame yet
|
||||
|
||||
Reference in New Issue
Block a user