mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-22 14:19:57 +08:00
feat(mavlink): count received messages dropped for a bad CRC (#29766)
Assisted-by: Claude:claude-opus-5-5 Signed-off-by: danielbuleandra <daniel.buleandra@auterion.com>
This commit is contained in:
1 parent
e1e1122af5
commit
f65fe36aea
4 files changed
+19
-5
No files matched your search
@@ -34,6 +34,7 @@ uint32 rx_parse_errors # number of parse errors
|
||||
uint32 rx_packet_drop_count # number of packet drops
|
||||
uint32 rx_unknown_message_count # number of messages not in the dialect, not processed
|
||||
uint32 rx_bad_signature_count # number of messages with missing or invalid signature, not processed
|
||||
uint32 rx_bad_crc_count # number of known messages dropped for a bad CRC
|
||||
float32 rx_message_lost_rate # fraction of messages lost (0 to 1)
|
||||
|
||||
|
||||
|
||||
@@ -3643,6 +3643,7 @@ Mavlink::display_status()
|
||||
printf("\t rx loss: %.1f%%\n", (double)_tstatus.rx_message_lost_rate * 100.0);
|
||||
printf("\t rx unknown messages: %" PRIu32 "\n", _tstatus.rx_unknown_message_count);
|
||||
printf("\t rx bad signatures: %" PRIu32 "\n", _tstatus.rx_bad_signature_count);
|
||||
printf("\t rx bad CRCs: %" PRIu32 "\n", _tstatus.rx_bad_crc_count);
|
||||
|
||||
#if !defined(CONSTRAINED_FLASH)
|
||||
_receiver.print_detailed_rx_stats();
|
||||
|
||||
@@ -4158,7 +4158,7 @@ MavlinkReceiver::run()
|
||||
|
||||
const FrameCheck frame_check = check_frame(framing, msg);
|
||||
|
||||
if (frame_check == FrameCheck::Invalid) {
|
||||
if (frame_check == FrameCheck::BadCrc || frame_check == FrameCheck::Invalid) {
|
||||
reset_parser_after_rejected_frame(buf[i]);
|
||||
}
|
||||
|
||||
@@ -4203,6 +4203,11 @@ MavlinkReceiver::run()
|
||||
|
||||
} else if (frame_check == FrameCheck::BadSignature) {
|
||||
_bad_signature_counter++;
|
||||
|
||||
} else if (frame_check == FrameCheck::BadCrc && msg.sysid != 0 && msg.compid != 0
|
||||
&& component_was_seen(msg.sysid, msg.compid)) {
|
||||
// Header may be corrupted too: count only known senders (0 is a wildcard)
|
||||
_bad_crc_counter++;
|
||||
}
|
||||
|
||||
if (frame_check == FrameCheck::Ok || frame_check == FrameCheck::ForwardOnly) {
|
||||
@@ -4222,6 +4227,7 @@ MavlinkReceiver::run()
|
||||
tstatus.rx_message_lost_count = _total_lost_counter;
|
||||
tstatus.rx_unknown_message_count = _unknown_message_counter;
|
||||
tstatus.rx_bad_signature_count = _bad_signature_counter;
|
||||
tstatus.rx_bad_crc_count = _bad_crc_counter;
|
||||
const uint64_t total_messages = _total_received_counter + _total_lost_counter;
|
||||
tstatus.rx_message_lost_rate = (total_messages > 0)
|
||||
? static_cast<float>(_total_lost_counter) / static_cast<float>(total_messages) : 0.f;
|
||||
@@ -4306,9 +4312,13 @@ MavlinkReceiver::FrameCheck MavlinkReceiver::check_frame(uint8_t framing, const
|
||||
return FrameCheck::Incomplete;
|
||||
}
|
||||
|
||||
// Messages which are not in our dialect can't have their CRC checked and
|
||||
// are reported as bad CRC by the parser. They can still be forwarded.
|
||||
if ((mavlink_get_msg_entry(message.msgid) != nullptr) || (_status.flags & MAVLINK_STATUS_FLAG_IN_MAVLINK1)) {
|
||||
// Known message: corrupted frame or different message definition on the sender
|
||||
if (mavlink_get_msg_entry(message.msgid) != nullptr) {
|
||||
return FrameCheck::BadCrc;
|
||||
}
|
||||
|
||||
// Unknown MAVLink 1 message
|
||||
if (_status.flags & MAVLINK_STATUS_FLAG_IN_MAVLINK1) {
|
||||
return FrameCheck::Invalid;
|
||||
}
|
||||
|
||||
|
||||
@@ -296,7 +296,8 @@ private:
|
||||
Ok, ///< valid, handle and forward
|
||||
ForwardOnly, ///< not in our dialect, can't be handled but can be forwarded
|
||||
BadSignature, ///< signature missing or not valid with our key, drop
|
||||
Invalid, ///< bad CRC, drop
|
||||
BadCrc, ///< known message with a bad CRC, drop
|
||||
Invalid, ///< unknown MAVLink 1 message, drop
|
||||
};
|
||||
|
||||
FrameCheck check_frame(uint8_t framing, const mavlink_message_t &message);
|
||||
@@ -360,6 +361,7 @@ private:
|
||||
uint64_t _total_lost_counter{0}; ///< Total messages lost during transmission.
|
||||
uint32_t _unknown_message_counter{0}; ///< Messages not in our dialect
|
||||
uint32_t _bad_signature_counter{0}; ///< Messages with missing or invalid signature
|
||||
uint32_t _bad_crc_counter{0}; ///< Known messages dropped for a bad CRC
|
||||
|
||||
uint8_t _mavlink_status_last_buffer_overrun{0};
|
||||
uint8_t _mavlink_status_last_parse_error{0};
|
||||
|
||||
Reference in new issue
Block a user