Skip to content

Add Label BA FANS 1/A CPDLC Downlink decoder plugin#415

Open
thepacket wants to merge 1 commit intoairframesio:masterfrom
thepacket:plugin/label-ba
Open

Add Label BA FANS 1/A CPDLC Downlink decoder plugin#415
thepacket wants to merge 1 commit intoairframesio:masterfrom
thepacket:plugin/label-ba

Conversation

@thepacket
Copy link
Copy Markdown

Adds a decoder for FANS 1/A CPDLC downlinks (the companion to label AA uplinks).

Wire format

/USADCXA.DR1.N887QS0CAF

Surfaces ground address, service qualifier (DR1/CC1/etc.), tail (registration-pattern cascade for all-hex tails), ASN.1 PER payload hex, and trailing 4-char CRC. Short payloads (≤8 hex) flagged as likely contract/keep-alive messages.

npm run build passes.

New plugin registered in official.ts and MessageDecoder.ts.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

Warning

Rate limit exceeded

@thepacket has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 55 minutes and 18 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 55 minutes and 18 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 75917637-ad1d-414b-a90c-d42250260b18

📥 Commits

Reviewing files that changed from the base of the PR and between 10f9f69 and 3eb93b9.

📒 Files selected for processing (3)
  • lib/MessageDecoder.ts
  • lib/plugins/Label_BA_CPDLC.ts
  • lib/plugins/official.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@kevinelliott kevinelliott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Adds Label_BA_CPDLC for FANS-1/A CPDLC downlinks (/GROUND.QUAL.TAILPAYLOADCRC). Registered last in MessageDecoder.ts/official.ts. No companion test file.

Verdict

Comment-only review — the tail/payload split heuristic has a real correctness bug that will mis-decode a wide range of non-US tails. Please address before merge.

Must Fix

  • Tail-split heuristic is broken for hyphenated registrations. The window is rest.substring(0, Math.min(8, rest.length)) and the search is /[G-Zg-z]/ (non-hex letters). For real samples this misfires:

    input current output (tail / payload+CRC) likely correct
    B-2345A0CAF B-2345 / A0CAF B-2345A / 0CAF
    C-FRSE0CAF C-FRS / E0CAF C-FRSE / 0CAF
    D-ABYA0CAF D-ABY / A0CAF D-ABYA / 0CAF
    F-GZNT0CAF F-G / ZNT0CAF F-GZNT / 0CAF

    The heuristic treats any non-hex letter as a tail terminator, but real tails routinely contain non-hex letters internally (G/Z/N/Y/...). The hyphen also defeats the "≥2 chars" guard for one-letter prefix codes. Two reasonable fixes:

    1. Anchor on the trailing CRC instead of leading-tail length. The CRC is always exactly 4 hex chars at the very end. Strip those, then everything between .QUAL. and the CRC is tail||payload. Tails are typically 5–7 chars; if the next chunk after tail||payload is empty, treat the whole thing as the tail (keep-alive case). If it has structure (length divisible by 2, hex), treat the leading 5–7 as tail.
    2. Use a positive tail regex. ICAO tails follow a small set of country-prefix patterns ([A-Z]-[A-Z0-9]{3,5}, N\d{1,5}[A-Z]{0,2}, JA\d{4}, B-\d{4}[A-Z]?, etc.). Match-then-fallback is more accurate than non-hex sniffing.

    Either way, please add explicit tests for at least one US tail, one hyphenated European tail, one Asian tail (JA / B-), and the keep-alive (empty payload) case.

  • Add a Label_BA_CPDLC.test.ts. No tests at all today. Please cover: qualifiers(), multiple tail formats per the table above, the malformed/short branch, and a non-matching string.

Should Fix

  • Add a preambles qualifier. Every observed example begins with /, so preambles: ['/'] lets the dispatcher skip this plugin for non-CPDLC BA traffic and keeps meetsStateRequirements/short-circuit semantics consistent with siblings.
  • raw.crc is a string ("0CAF") and raw.checksum is typed number. You're using crc, which sidesteps the typed field, but consider also pushing parseInt(crc, 16) into raw.checksum or document the new field. Same comment as #414.
  • decodeResult.formatted.items.unshift(...) is fine but the malformed branch unshifts onto an empty array — consider .push for consistency, since order doesn't matter when there's nothing else there yet.
  • The malformed-payload branch (payloadAndCrc.length < 4) silently exposes the truncated payload but still flags decoded: true, decodeLevel: 'partial'. Reasonable, but the formatted items in that branch never include a CRC field at all — downstream consumers may want a sentinel like { code: 'CRC', value: '(missing)' } to know it was tried.

Nits

  • The doc-comment ASCII art is great, thanks.
  • decodeResult.raw.direction = 'aircraft-to-ground (downlink)' is duplicated in both raw and formatted.items; that's fine but the value is constant — a const would express the intent better.
  • The doc says "tail (typ. 6 chars)" but the heuristic also accepts shorter; align the doc with whatever fix you settle on.

Tests

None added. Please add Label_BA_CPDLC.test.ts covering at minimum:

  • qualifiers() (after adding the / preamble)
  • Happy path with N-tail (/USADCXA.DR1.N887QSDEADBEEF0CAF)
  • Hyphenated tail (C-FRSE..., D-ABYA...)
  • Keep-alive / short payload (/USADCXA.DR1.N887QS0CAF)
  • Malformed (length < 4 after tail) returns partial
  • Non-matching returns decoded: false

Notes — Registration & Coexistence

  • Registered at the tail of pluginClasses and exported from official.ts. No other plugin claims label BA, so order is irrelevant.
  • No coexistence concerns.

Thanks @thepacket!

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.

2 participants