Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix message framing (backtracking parser) #225

Merged
merged 4 commits into from Mar 4, 2024

Conversation

tjrmarques
Copy link

This PR fixes an issue where the parser can detect a STX byte that's not really a start of frame marker, but a random byte in the middle of a message, and then consume the next (few) real start-of-frame marker(s) as part of the incorrectly identified frame.

This situation can happen upon (re)connection or over lossy connections (e.g. radio) where some bytes are occasionally lost.
Although the parser will most likely resynchronise at some point (not guaranteed), this issue will still cause the loss of messages that have otherwise been correctly received in full.

The solution implemented is to use a buffered/peekable reader that can backtrack once the CRC is found to be incorrect.

In addition, this PR moves the CRC check to read_vX_message_raw, which ensures that a call to this function will always produce a valid Mavlink frame (raw message).

fixes #222

Tiago Marques added 4 commits February 27, 2024 22:03
This allows the parser to backtrack in case a STX byte in the middle of a message is mistaken for the start-of-frame (checked via CRC)
@patrickelectric patrickelectric merged commit ad39b28 into mavlink:master Mar 4, 2024
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect message frame detection
2 participants