Skip to content

Fix PTA/PRA parsing: truncated system names and rejected short messages - #2

Open
ragu81ca wants to merge 1 commit into
flash62au:masterfrom
ragu81ca:master
Open

Fix PTA/PRA parsing: truncated system names and rejected short messages#2
ragu81ca wants to merge 1 commit into
flash62au:masterfrom
ragu81ca:master

Conversation

@ragu81ca

Copy link
Copy Markdown

Fix turnout/route action parsing dropping or rejecting system names

Three defects on the PTA/PRA receive path, all of which corrupt or discard the system name reported to the delegate.

  1. processCommand() required len > 5 to dispatch a PTA message. The shortest valid PTA is "PTA" + 1 state char + a 1-character system name = 5 chars, so turnouts with single-character system names were never dispatched and fell through to processUnknownCommand(). This affects DCC-EX, whose turnout system names are bare numbers with no prefix ("PTA22" for turnout 2). The PRA branch immediately below already used the correct len > 4. Relaxed to len > 4 to match.

  2. processTurnoutAction() computed the system name as s.substring(1, s.length()-1). String::substring() takes an exclusive end index, so this dropped the final character of every system name: "PTA2LT92" yielded "LT9" instead of "LT92". For the shortest messages it yielded an empty string. The command is already null-terminated at CR/LF in check(), so there is no trailing delimiter to strip. Changed to s.substring(1).

  3. processRouteAction() had the identical off-by-one; same fix.

These went unnoticed because receivedTurnoutAction() and receivedRouteAction() are optional delegate methods with empty default bodies, so consumers that do not override them never observe the corrupted name.

Verified against DCC-EX: turnout state broadcasts now resolve to the correct system name and repeated toggles alternate as expected.

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