Skip to content

Return packet type processed in process() - #27

Open
madleech wants to merge 1 commit into
masterfrom
return-packet-type-from-process
Open

Return packet type processed in process()#27
madleech wants to merge 1 commit into
masterfrom
return-packet-type-from-process

Conversation

@madleech

Copy link
Copy Markdown
Owner

The readme specifically says for process():

Return value is NULL for no valid packet received, or one of CMRI::INIT, CMRI::SET, CMRI::POLL depending on the packet type received.

However in reality it's just returning true / false. For some users, having it return the processed packet type is a useful enhancement. Lets update it to match the documentation.

Note: although this is a behaviour change, anyone doing if (cmri.process()) will see unchanged behaviour, as false and NOOP are both 0 and so equivalent.

brocci added a commit to brocci/ArduinoCMRI that referenced this pull request Aug 16, 2026
brocci added a commit to brocci/ArduinoCMRI that referenced this pull request Sep 11, 2026
PR madleech#30 consumes the POLL body to ETX before replying to avoid RS-485 bus
contention. But POSTAMBLE_IGNORE is also reached when ignoring frames
addressed to other nodes, and it decided to reply by checking
_rx_packet_type. Since that field is only refreshed in DECODE_CMD, a node
that had recently been polled (type == 'P') spuriously transmitted a GET
reply every time it finished ignoring another node's frame. On a
multi-node bus this ping-ponged between nodes, colliding with the
addressed node's response and JMRI's polls.

Fix the regression without changing PR madleech#30's design: clear _rx_packet_type
when entering IGNORE_CMD, so finishing an ignored (foreign) frame can
never look like a pending poll. Also initialize _rx_packet_type in the
constructor.

Tests: regression tests for hearing another node's POLL/GET and still
replying to one's own POLL, plus tests pinning process()'s returned packet
type (PR madleech#27 semantics: POLL/SET reported, NOOP for ignored frames and
INIT).
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.

1 participant