Fix PTA/PRA parsing: truncated system names and rejected short messages - #2
Open
ragu81ca wants to merge 1 commit into
Open
Fix PTA/PRA parsing: truncated system names and rejected short messages#2ragu81ca wants to merge 1 commit into
ragu81ca 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.
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.
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.
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).
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.