Handle Init (I) messages instead of discarding payload#21
Closed
brocci wants to merge 1 commit into
Closed
Conversation
Author
|
Superseded by #22 which combines both changes. |
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
POSTAMBLE_OTHERand are discarded without the data payload being consumedINITfromprocess(), and allows the sketch to handle itDetails
Problem: The NMRA CMRInet specification defines the Init message as the first message sent to a node after power-up, carrying configuration data such as the node type, transmit character delay, and card configuration. The current
_decode()state machine treats the Init ('I') command byte the same as any other unrecognized command:This means:
Fix: Treat 'I' the same as 'T' in
DECODE_CMD— enterDECODE_DATAto consume the payload bytes (with DLE un-escaping) until ETX. Also track the received command type soPOSTAMBLE_SETcan return eitherSETorINITto the caller. Updateprocess_char()to returntruefor INIT messages, using the already-definedCMRI::INITenum.The existing
_rx_packet_typemember variable (declared but never written) is repurposed to store the current command type duringDECODE_CMD.Example
When JMRI sends
FF FF 02 41 49 43 00 00 00 00 02 02 03(Init for node 0, cpNode type, 2 input + 2 output bytes):POSTAMBLE_OTHERand flushes only to ETX._rx_buffermay contain43 00 00 00 00 02 02as stale data from Init.process()returnsfalse.DECODE_DATA, correctly un-escapes and consumes the payload, ETX terminates cleanly.process()returnstrueand the sketch can check forCMRI::INITviaprocess_char().Changes
CMRI.cpp— two changes in_decode()and one inprocess_char(). The comments inprocess_char()are updated to reflect that INIT is now handled.Closes #20