-
-
Notifications
You must be signed in to change notification settings - Fork 20
Add decoders from jwarne #361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
makrsmark
merged 8 commits into
airframesio:master
from
makrsmark:feature/jwarne-decoders
Mar 16, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cc0b2e8
Add ICAO Flight Plan parser and OFP plugin
jwarne-aus 0b63f5e
Add easy-win plugins: M-Series position, EZF load sheet, ATIS subscri…
jwarne-aus 60ffb11
Merge branch 'master' into feature/jwarne-decoders
makrsmark 2e1f82b
fixes
makrsmark bd1e2f5
linter
makrsmark c4aeba1
fix
makrsmark 354f148
Merge branch 'master' into feature/jwarne-decoders
makrsmark 4ae1f66
merge fix
makrsmark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { MessageDecoder } from '../MessageDecoder'; | ||
| import { Label_H1_ATIS } from './Label_H1_ATIS'; | ||
|
|
||
| describe('Label H1 ATIS Subscription', () => { | ||
| let plugin: Label_H1_ATIS; | ||
| const message = { label: 'H1', text: '' }; | ||
|
|
||
| beforeEach(() => { | ||
| const decoder = new MessageDecoder(); | ||
| plugin = new Label_H1_ATIS(decoder); | ||
| }); | ||
|
|
||
| test('matches qualifiers', () => { | ||
| expect(plugin.decode).toBeDefined(); | ||
| expect(plugin.name).toBe('label-h1-atis'); | ||
| expect(plugin.qualifiers()).toEqual({ | ||
| labels: ['H1', '5Z'], | ||
| preambles: ['L'], | ||
| }); | ||
| }); | ||
|
|
||
| test('decodes KSFO ATIS subscription', () => { | ||
| message.text = 'L95AQF0073/KSFO.TI2/030KSFOAFF5C'; | ||
| const decodeResult = plugin.decode(message); | ||
|
|
||
| expect(decodeResult.decoded).toBe(true); | ||
| expect(decodeResult.decoder.decodeLevel).toBe('full'); | ||
| expect(decodeResult.decoder.name).toBe('label-h1-atis'); | ||
| expect(decodeResult.formatted.description).toBe('ATIS Subscription'); | ||
| expect(decodeResult.message).toBe(message); | ||
| expect(decodeResult.raw.flight_number).toBe('QF0073'); | ||
| expect(decodeResult.raw.arrival_icao).toBe('KSFO'); | ||
| expect(decodeResult.raw.atis_code).toBe('030'); | ||
| expect(decodeResult.raw.checksum).toBe(0xaff5c); | ||
| }); | ||
|
|
||
| test('decodes OERK ATIS subscription', () => { | ||
| message.text = 'L01AMC5477/OERK.TI2/024OERKC8781'; | ||
| const decodeResult = plugin.decode(message); | ||
|
|
||
| expect(decodeResult.decoded).toBe(true); | ||
| expect(decodeResult.decoder.decodeLevel).toBe('full'); | ||
| expect(decodeResult.raw.flight_number).toBe('MC5477'); | ||
| expect(decodeResult.raw.arrival_icao).toBe('OERK'); | ||
| expect(decodeResult.raw.atis_code).toBe('024'); | ||
| expect(decodeResult.raw.checksum).toBe(0xc8781); | ||
| }); | ||
|
|
||
| test('decodes LICC ATIS subscription', () => { | ||
| message.text = 'L11AMC5477/LICC.TI2/024LICCAFBD9'; | ||
| const decodeResult = plugin.decode(message); | ||
|
|
||
| expect(decodeResult.decoded).toBe(true); | ||
| expect(decodeResult.decoder.decodeLevel).toBe('full'); | ||
| expect(decodeResult.raw.flight_number).toBe('MC5477'); | ||
| expect(decodeResult.raw.arrival_icao).toBe('LICC'); | ||
| expect(decodeResult.raw.atis_code).toBe('024'); | ||
| expect(decodeResult.raw.checksum).toBe(0xafbd9); | ||
| }); | ||
|
|
||
| test('decodes with label 5Z', () => { | ||
| const msg5Z = { | ||
| label: '5Z', | ||
| text: 'L95AQF0073/KSFO.TI2/030KSFOAFF5C', | ||
| }; | ||
| const decodeResult = plugin.decode(msg5Z); | ||
|
|
||
| expect(decodeResult.decoded).toBe(true); | ||
| expect(decodeResult.raw.flight_number).toBe('QF0073'); | ||
| expect(decodeResult.raw.arrival_icao).toBe('KSFO'); | ||
| }); | ||
|
|
||
| test('rejects invalid message', () => { | ||
| message.text = 'LINVALID MESSAGE'; | ||
| const decodeResult = plugin.decode(message); | ||
|
|
||
| expect(decodeResult.decoded).toBe(false); | ||
| expect(decodeResult.decoder.decodeLevel).toBe('none'); | ||
| expect(decodeResult.decoder.name).toBe('label-h1-atis'); | ||
| expect(decodeResult.remaining.text).toBe(message.text); | ||
| }); | ||
|
|
||
| test('rejects non-ATIS message', () => { | ||
| message.text = 'FLR/FR24030411230034583106FWC2'; | ||
| const decodeResult = plugin.decode(message); | ||
|
|
||
| expect(decodeResult.decoded).toBe(false); | ||
| expect(decodeResult.decoder.decodeLevel).toBe('none'); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { DecoderPlugin } from '../DecoderPlugin'; | ||
| import { DecodeResult, Message, Options } from '../DecoderPluginInterface'; | ||
| import { ResultFormatter } from '../utils/result_formatter'; | ||
| import { DateTimeUtils } from '../DateTimeUtils'; | ||
|
|
||
| export class Label_H1_ATIS extends DecoderPlugin { | ||
| name = 'label-h1-atis'; | ||
|
|
||
| qualifiers() { | ||
| return { | ||
| labels: ['H1', '5Z'], | ||
| preambles: ['L'], | ||
| }; | ||
| } | ||
|
|
||
| decode(message: Message, options: Options = {}): DecodeResult { | ||
| let decodeResult = this.defaultResult(); | ||
| decodeResult.decoder.name = this.name; | ||
| decodeResult.formatted.description = 'ATIS Subscription'; | ||
| decodeResult.message = message; | ||
|
|
||
| // Pattern: L[2-digit seq]A[flight]/[facility].TI2/[code][airport][checksum] | ||
| const regex = | ||
| /^L(\d{2})A([A-Z0-9]+)\/([A-Z]{4})\.TI2\/(\d{3})([A-Z]{4})([A-F0-9]+)$/; | ||
| const match = message.text.match(regex); | ||
|
|
||
| if (!match) { | ||
| if (options.debug) { | ||
| console.log(`Decoder: Unknown H1 ATIS message: ${message.text}`); | ||
| } | ||
| ResultFormatter.unknown(decodeResult, message.text); | ||
| decodeResult.decoded = false; | ||
| decodeResult.decoder.decodeLevel = 'none'; | ||
| return decodeResult; | ||
| } | ||
|
|
||
| const seq = match[1]; | ||
| const flight = match[2]; | ||
| const facility = match[3]; | ||
| const code = match[4]; | ||
| const airport = match[5]; | ||
| const checksum = match[6]; | ||
|
|
||
| ResultFormatter.flightNumber(decodeResult, flight); | ||
| ResultFormatter.arrivalAirport(decodeResult, facility); | ||
|
|
||
| decodeResult.raw.atis_code = code; | ||
| decodeResult.formatted.items.push({ | ||
| type: 'atis', | ||
| code: 'ATIS_CODE', | ||
| label: 'ATIS Code', | ||
| value: code, | ||
| }); | ||
|
|
||
| // The airport in the TI2 section | ||
| if (airport !== facility) { | ||
| decodeResult.raw.atis_airport = airport; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't see this in tests |
||
| decodeResult.formatted.items.push({ | ||
| type: 'icao', | ||
| code: 'ATIS_ARPT', | ||
| label: 'ATIS Airport', | ||
| value: airport, | ||
| }); | ||
| } | ||
|
|
||
| // Checksum | ||
| ResultFormatter.checksum(decodeResult, parseInt(checksum, 16)); | ||
|
|
||
| decodeResult.decoded = true; | ||
| decodeResult.decoder.decodeLevel = 'full'; | ||
|
|
||
| return decodeResult; | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { MessageDecoder } from '../MessageDecoder'; | ||
| import { Label_H1_EZF } from './Label_H1_EZF'; | ||
|
|
||
| describe('Label H1 Preamble EZF Load Sheet', () => { | ||
| let plugin: Label_H1_EZF; | ||
| const message = { label: 'H1', text: '' }; | ||
|
|
||
| beforeEach(() => { | ||
| const decoder = new MessageDecoder(); | ||
| plugin = new Label_H1_EZF(decoder); | ||
| }); | ||
|
|
||
| test('matches qualifiers', () => { | ||
| expect(plugin.decode).toBeDefined(); | ||
| expect(plugin.name).toBe('label-h1-ezf'); | ||
| expect(plugin.qualifiers()).toEqual({ | ||
| labels: ['H1', '1M'], | ||
| preambles: ['EZF'], | ||
| }); | ||
| }); | ||
|
|
||
| test('decodes full load sheet', () => { | ||
| message.text = | ||
| 'EZF\nNO0246/10/EI-NEO\n/C28Y331/3/9\n-SCT/MXP-ZNZ\n-STD/2200\n-FLT STATUS/CLOSED\n-UOM/KG\n-ZFW/162075\n-PAX/305\n-PXT/122/160/19/02\n-PXW/22601\n-CGO/3573\n-BAG/4783\n-OTH/4336\n-TTL/35293\n-FWT/51063\n-TOW/213138\n-DOW/126782'; | ||
| const decodeResult = plugin.decode(message); | ||
|
|
||
| expect(decodeResult.decoded).toBe(true); | ||
| expect(decodeResult.decoder.decodeLevel).toBe('partial'); | ||
| expect(decodeResult.decoder.name).toBe('label-h1-ezf'); | ||
| expect(decodeResult.formatted.description).toBe('Load Sheet'); | ||
| expect(decodeResult.message).toBe(message); | ||
| expect(decodeResult.raw.flight_number).toBe('NO0246'); | ||
| expect(decodeResult.raw.tail).toBe('EI-NEO'); | ||
| expect(decodeResult.raw.departure_iata).toBe('MXP'); | ||
| expect(decodeResult.raw.arrival_iata).toBe('ZNZ'); | ||
| expect(decodeResult.raw.loadsheet['ZFW']).toBe('162075'); | ||
| expect(decodeResult.raw.loadsheet['PAX']).toBe('305'); | ||
| expect(decodeResult.raw.loadsheet['TOW']).toBe('213138'); | ||
| expect(decodeResult.raw.loadsheet['FLT STATUS']).toBe('CLOSED'); | ||
| expect(decodeResult.raw.loadsheet['UOM']).toBe('KG'); | ||
| }); | ||
|
|
||
| test('decodes minimal load sheet', () => { | ||
| message.text = 'EZF\nAB1234/05/D-ABCD\n-SCT/JFK-LAX\n-PAX/180\n-ZFW/55000'; | ||
| const decodeResult = plugin.decode(message); | ||
|
|
||
| expect(decodeResult.decoded).toBe(true); | ||
| expect(decodeResult.decoder.decodeLevel).toBe('partial'); | ||
| expect(decodeResult.raw.flight_number).toBe('AB1234'); | ||
| expect(decodeResult.raw.tail).toBe('D-ABCD'); | ||
| expect(decodeResult.raw.departure_iata).toBe('JFK'); | ||
| expect(decodeResult.raw.arrival_iata).toBe('LAX'); | ||
| expect(decodeResult.raw.loadsheet['PAX']).toBe('180'); | ||
| expect(decodeResult.raw.loadsheet['ZFW']).toBe('55000'); | ||
| }); | ||
|
|
||
| test('decodes with label 1M', () => { | ||
| const msg1M = { | ||
| label: '1M', | ||
| text: 'EZF\nXY5678/12/G-TEST\n-SCT/LHR-CDG\n-PAX/90', | ||
| }; | ||
| const decodeResult = plugin.decode(msg1M); | ||
|
|
||
| expect(decodeResult.decoded).toBe(true); | ||
| expect(decodeResult.raw.flight_number).toBe('XY5678'); | ||
| expect(decodeResult.raw.departure_iata).toBe('LHR'); | ||
| expect(decodeResult.raw.arrival_iata).toBe('CDG'); | ||
| }); | ||
|
|
||
| test('rejects invalid message', () => { | ||
| message.text = 'NOT_EZF data here'; | ||
| const decodeResult = plugin.decode(message); | ||
|
|
||
| expect(decodeResult.decoded).toBe(false); | ||
| expect(decodeResult.decoder.decodeLevel).toBe('none'); | ||
| expect(decodeResult.decoder.name).toBe('label-h1-ezf'); | ||
| expect(decodeResult.remaining.text).toBe(message.text); | ||
| }); | ||
|
|
||
| test('rejects message with only EZF header', () => { | ||
| message.text = 'EZF'; | ||
| const decodeResult = plugin.decode(message); | ||
|
|
||
| expect(decodeResult.decoded).toBe(false); | ||
| expect(decodeResult.decoder.decodeLevel).toBe('none'); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import { DecoderPlugin } from '../DecoderPlugin'; | ||
| import { DecodeResult, Message, Options } from '../DecoderPluginInterface'; | ||
| import { ResultFormatter } from '../utils/result_formatter'; | ||
|
|
||
| export class Label_H1_EZF extends DecoderPlugin { | ||
| name = 'label-h1-ezf'; | ||
|
|
||
| qualifiers() { | ||
| return { | ||
| labels: ['H1', '1M'], | ||
| preambles: ['EZF'], | ||
| }; | ||
| } | ||
|
|
||
| decode(message: Message, options: Options = {}): DecodeResult { | ||
| let decodeResult = this.defaultResult(); | ||
| decodeResult.decoder.name = this.name; | ||
| decodeResult.formatted.description = 'Load Sheet'; | ||
| decodeResult.message = message; | ||
|
|
||
| const lines = message.text | ||
| .split('\n') | ||
| .map((l) => l.trim()) | ||
| .filter((l) => l.length > 0); | ||
|
|
||
| if (lines.length < 2 || lines[0] !== 'EZF') { | ||
| if (options.debug) { | ||
| console.log(`Decoder: Unknown H1 EZF message: ${message.text}`); | ||
| } | ||
| ResultFormatter.unknown(decodeResult, message.text); | ||
| decodeResult.decoded = false; | ||
| decodeResult.decoder.decodeLevel = 'none'; | ||
| return decodeResult; | ||
| } | ||
|
|
||
| const loadsheet: Record<string, string> = {}; | ||
| const unknowns: string[] = []; | ||
|
|
||
| for (let i = 1; i < lines.length; i++) { | ||
| const line = lines[i]; | ||
| if (line.startsWith('-')) { | ||
| const kvMatch = line.match(/^-([^/]+)\/(.+)$/); | ||
| if (kvMatch) { | ||
| loadsheet[kvMatch[1]] = kvMatch[2]; | ||
| } else { | ||
| unknowns.push(line); | ||
| } | ||
| } else if (i === 1) { | ||
| // Second line is the flight identifier, e.g. NO0246/10/EI-NEO | ||
| const idParts = line.split('/'); | ||
| if (idParts.length >= 1) { | ||
| ResultFormatter.flightNumber(decodeResult, idParts[0]); | ||
| } | ||
| if (idParts.length >= 3) { | ||
| ResultFormatter.tail(decodeResult, idParts[2]); | ||
| } | ||
| // Remaining parts of identifier line | ||
| if (idParts.length >= 2) { | ||
| // idParts[1] is day or other info - store but don't format | ||
| } | ||
| } else if (i === 2) { | ||
| // Third line typically contains config info, e.g. /C28Y331/3/9 | ||
| unknowns.push(line); | ||
| } else { | ||
| unknowns.push(line); | ||
| } | ||
| } | ||
|
|
||
| // Extract known fields from loadsheet | ||
| if (loadsheet['SCT']) { | ||
| const route = loadsheet['SCT'].split('-'); | ||
| if (route.length === 2) { | ||
| ResultFormatter.departureAirport(decodeResult, route[0], 'IATA'); | ||
| ResultFormatter.arrivalAirport(decodeResult, route[1], 'IATA'); | ||
| } | ||
| } | ||
|
|
||
| // Store all loadsheet data in raw | ||
| decodeResult.raw.loadsheet = loadsheet; | ||
|
|
||
| // Format key loadsheet items | ||
| const formatFields: [string, string, string][] = [ | ||
| ['STD', 'Scheduled Time of Departure', 'std'], | ||
| ['FLT STATUS', 'Flight Status', 'flight_status'], | ||
| ['UOM', 'Unit of Measure', 'uom'], | ||
| ['ZFW', 'Zero Fuel Weight', 'zfw'], | ||
| ['PAX', 'Passengers', 'pax'], | ||
| ['TOW', 'Takeoff Weight', 'tow'], | ||
| ['DOW', 'Dry Operating Weight', 'dow'], | ||
| ['FWT', 'Fuel Weight', 'fuel_weight'], | ||
| ]; | ||
|
|
||
| for (const [key, label, code] of formatFields) { | ||
| if (loadsheet[key]) { | ||
| decodeResult.formatted.items.push({ | ||
| type: 'loadsheet', | ||
| code: code.toUpperCase(), | ||
| label: label, | ||
| value: loadsheet[key], | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| if (unknowns.length > 0) { | ||
| ResultFormatter.unknownArr(decodeResult, unknowns, '\n'); | ||
| } | ||
|
|
||
| decodeResult.decoded = true; | ||
| decodeResult.decoder.decodeLevel = 'partial'; | ||
|
|
||
| return decodeResult; | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we validate this? 5 nibbles seems not right