Fix missing STX (0x02) DLE-escape in transmit()#19
Open
brocci wants to merge 1 commit into
Open
Conversation
cf1f8bc to
bf8b8db
Compare
bf8b8db to
003e127
Compare
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.
Summary
transmit()per NMRA CMRInet spec LCS-9.10.1 v1.1Details
Problem: The NMRA CMRInet specification (LCS-9.10.1, §Data Link Escape (DLE) Processing) requires:
The three values requiring DLE are STX (0x02), ETX (0x03), and DLE (0x10).
The current
transmit()only checks two of the three:STX (0x02) is not escaped. If any output data byte carries the value 0x02 (perfectly valid binary data), it is transmitted raw. A CMRInet host receiving this frame will see 0x02 in the data stream and interpret it as the start-of-text character, potentially corrupting the current frame and subsequent ones.
Fix: Combine the escape check into a single condition covering all three protocol character values (STX, ETX, DLE). The
ESCconstant in the code is already defined as 0x10 (DLE).Changes
CMRI.cpp—transmit()method:for (int i=0; i<_tx_length; i++) { if (_tx_buffer[i] == STX || _tx_buffer[i] == ETX || _tx_buffer[i] == ESC) _serial.write(ESC); _serial.write(_tx_buffer[i]); }Closes #18