fromPgn: implement DECIMAL field type (fixes PGN 129808 DSC MMSI decode) - #452
fromPgn: implement DECIMAL field type (fixes PGN 129808 DSC MMSI decode)#452fakehec wants to merge 2 commits into
Conversation
readValue() had no branch for FieldType DECIMAL, so 40-bit DECIMAL fields fell through to the generic binary reader and were decoded as little-endian integers. Per the canboat spec, DECIMAL means each byte holds two decimal digits (00-99). This affects PGN 129808 dscMessageAddress and mmsiOfShipInDistress, causing wrong MMSIs in DSC consumers (e.g. signalk-dsc). Emit the field as a digit string to preserve leading zeros (coast-station identities); all-0xFF or any byte > 99 => null. Bitstream advance is unchanged, so downstream field alignment is preserved. Fixes canboat#451
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthrough
ChangesDECIMAL decoding
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The PR makes a localized DECIMAL decoding correction; no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
lib/fromPgn.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/fromPgn.ts`:
- Around line 1278-1285: Update the byte-validation loop in the surrounding
parser to use a boolean invalid/unavailable flag that is set when any byte
exceeds 99 and never reset by later valid bytes. Return [null, undefined]
whenever that flag is triggered, including for isolated 0xFF bytes, while
preserving normal string construction for valid bytes.
- Around line 1274-1284: Update the DECIMAL handling block around nbytes and its
byte-reading loop to resolve bitLength safely, detect insufficient bs.bitsLeft
before reading, and handle truncated input without allowing an uncaught
bitstream exception. After processing the full-byte portion, consume any
remaining bitLength remainder so downstream fields stay aligned, and update the
return logic below the loop to use the existing isValid state.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
- Latch invalid-byte detection so a valid byte after 0xFF/>99 cannot unmask it (e.g. [0xFF, 0x12] now yields null, not "25518"). - Guard against bitstream underflow on truncated packets: this block runs outside the surrounding try/catch, so an underflow would throw. - Consume non-byte-aligned remainder bits so downstream fields stay aligned when BitLength is not a multiple of 8. Addresses the CodeRabbit review comments on canboat#452.
|
Addressed the CodeRabbit review:
Thanks for the review. |
Implements the
DECIMALfield type inreadValue(), which was previously unhandled.Problem
FieldType: "DECIMAL"had no branch inreadValue(), so a 40-bit DECIMAL field fell through to the generic binary reader (bs.readBits) and was decoded as a little-endian integer. Per the canboat spec, DECIMAL means each byte holds two decimal digits (00–99).This is used by PGN 129808 (DSC Call Information) for
dscMessageAddressandmmsiOfShipInDistress, so DSC consumers such assignalk-dsclogged incorrect MMSIs for every call. Verified against a Raymarine MFD, which decodes the same on-wire PGN correctly.DECIMALis used only by PGN 129808 in the current spec, so blast radius is minimal.Fix
00MIDxxxx).0xFF(or any byte > 99) →null(not available).Verified end-to-end with a real DSC position-response frame: the MMSI now decodes correctly (matching the MFD) instead of the previous bogus integer.
Closes #451
Summary by CodeRabbit