Reset parser after inter-byte timeout to prevent truncated frame corruption - #32
Open
brocci wants to merge 1 commit into
Open
Reset parser after inter-byte timeout to prevent truncated frame corruption#32brocci wants to merge 1 commit into
brocci wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As reported in issue #28:
[BUG] No inter-byte timeout: a truncated frame corrupts the next frame and applies garbage to outputs
DECODE_DATA,DECODE_ESC_DATA); no timer anywhere in the library.DECODE_DATA. The next real frame'sFF FF 02 UA MTbytes are stored into_rx_bufferas if they were output data (until the buffer fills), and the next frame's ETX terminates the ghost frame and returnsSET— the sketch then drives layout outputs with0xFF 0xFF 0x02...garbage.DECODE_ESC_DATA, which unconditionally consumes the next byte (src/CMRI.cpp:226-233) — i.e., the first SYN of the next frame is eaten as "escaped data," cascading into case 1._modetoPREAMBLE_1(and discard the partial buffer) if more than a few character times elapse between bytes; or double-buffer and commit only on ETX.This PR implements the required fix and adds corresponding tests. This has not been tested on real hardware.
The default
INTER_BYTE_TIMEOUT_MShas been calculated based on serial transmission at 9600 bauds 8N2. JMRI uses 19200 bauds as default baud rate for C/MRI, but this default timeout value matches the baud rate used in all examples of this library.