-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add Label 22 Takeoff Report #180
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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,112 @@ | ||
import { MessageDecoder } from '../MessageDecoder'; | ||
import { Label_22_OFF } from './Label_22_OFF'; | ||
|
||
describe('Label 22 OFF', () => { | ||
let plugin: Label_22_OFF; | ||
|
||
beforeEach(() => { | ||
const decoder = new MessageDecoder(); | ||
plugin = new Label_22_OFF(decoder); | ||
}); | ||
|
||
test('matches qualifiers', () => { | ||
expect(plugin.decode).toBeDefined(); | ||
expect(plugin.name).toBe('label-22-off'); | ||
expect(plugin.qualifiers).toBeDefined(); | ||
expect(plugin.qualifiers()).toEqual({ | ||
labels: ['22'], | ||
preambles: ['OFF'], | ||
}); | ||
}); | ||
|
||
test('decodes variant 1', () => { | ||
const text = 'OFF01YX3661/25251712KIADKPWM171207 92' | ||
const decodeResult = plugin.decode({ text: text }); | ||
expect(decodeResult.decoded).toBe(true); | ||
expect(decodeResult.decoder.decodeLevel).toBe('partial'); | ||
expect(decodeResult.raw.flight_number).toBe('YX3661'); | ||
expect(decodeResult.raw.departure_day_of_month).toBe(25); | ||
expect(decodeResult.raw.arrival_day_of_month).toBe(25); | ||
expect(decodeResult.raw.time_of_day).toBe(61920); | ||
expect(decodeResult.raw.off_time).toBe(61927); | ||
expect(decodeResult.raw.departure_icao).toBe('KIAD'); | ||
expect(decodeResult.raw.arrival_icao).toBe('KPWM'); | ||
expect(decodeResult.formatted.items.length).toBe(7); | ||
expect(decodeResult.formatted.items[0].label).toBe('Flight Number'); | ||
expect(decodeResult.formatted.items[0].value).toBe('YX3661'); | ||
expect(decodeResult.formatted.items[1].label).toBe('Departure Day'); | ||
expect(decodeResult.formatted.items[1].value).toBe('25'); | ||
expect(decodeResult.formatted.items[2].label).toBe('Arrival Day'); | ||
expect(decodeResult.formatted.items[2].value).toBe('25'); | ||
expect(decodeResult.formatted.items[3].label).toBe('Message Timestamp'); | ||
expect(decodeResult.formatted.items[3].value).toBe('17:12:00'); | ||
expect(decodeResult.formatted.items[4].label).toBe('Origin'); | ||
expect(decodeResult.formatted.items[4].value).toBe('KIAD'); | ||
expect(decodeResult.formatted.items[5].label).toBe('Destination'); | ||
expect(decodeResult.formatted.items[5].value).toBe('KPWM'); | ||
expect(decodeResult.formatted.items[6].label).toBe('Takeoff Time'); | ||
expect(decodeResult.formatted.items[6].value).toBe('17:12:07'); | ||
expect(decodeResult.remaining.text).toBe(' 92'); | ||
}); | ||
|
||
test('decodes variant 2', () => { | ||
const text = 'OFF02XA0000/N38568 W077261251152KIADEPRZ1152****1958' | ||
const decodeResult = plugin.decode({ text: text }); | ||
expect(decodeResult.decoded).toBe(true); | ||
expect(decodeResult.decoder.decodeLevel).toBe('partial'); | ||
expect(decodeResult.raw.position.latitude).toBe(38.946666666666665); | ||
expect(decodeResult.raw.position.longitude).toBe(-77.435); | ||
expect(decodeResult.raw.day_of_month).toBe(25); | ||
expect(decodeResult.raw.time_of_day).toBe(42720); | ||
expect(decodeResult.raw.off_time).toBe(42720); | ||
expect(decodeResult.raw.departure_icao).toBe('KIAD'); | ||
expect(decodeResult.raw.arrival_icao).toBe('EPRZ'); | ||
expect(decodeResult.formatted.items.length).toBe(8); | ||
expect(decodeResult.formatted.items[0].label).toBe('Flight Number'); | ||
expect(decodeResult.formatted.items[0].value).toBe('XA0000'); | ||
expect(decodeResult.formatted.items[1].label).toBe('Aircraft Position'); | ||
expect(decodeResult.formatted.items[1].value).toBe('38.947 N, 77.435 W'); | ||
expect(decodeResult.formatted.items[2].label).toBe('Day of Month'); | ||
expect(decodeResult.formatted.items[2].value).toBe('25'); | ||
expect(decodeResult.formatted.items[3].label).toBe('Message Timestamp'); | ||
expect(decodeResult.formatted.items[3].value).toBe('11:52:00'); | ||
Comment on lines
+71
to
+72
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. in this variant, both the timestamp and takeoff time have minute resolution - i could be parsing backwards but it probably doesn't matter |
||
expect(decodeResult.formatted.items[4].label).toBe('Origin'); | ||
expect(decodeResult.formatted.items[4].value).toBe('KIAD'); | ||
expect(decodeResult.formatted.items[5].label).toBe('Destination'); | ||
expect(decodeResult.formatted.items[5].value).toBe('EPRZ'); | ||
expect(decodeResult.formatted.items[6].label).toBe('Takeoff Time'); | ||
expect(decodeResult.formatted.items[6].value).toBe('11:52:00'); | ||
expect(decodeResult.formatted.items[7].label).toBe('Estimated Time of Arrival'); | ||
expect(decodeResult.formatted.items[7].value).toBe('19:58:00'); | ||
expect(decodeResult.remaining.text).toBe('****'); | ||
}); | ||
|
||
test('decodes variant 3', () => { | ||
const text = 'OFF02\r\nKBWI,KIND,1237,18.4' | ||
const decodeResult = plugin.decode({ text: text }); | ||
expect(decodeResult.decoded).toBe(true); | ||
expect(decodeResult.decoder.decodeLevel).toBe('partial'); | ||
expect(decodeResult.raw.departure_icao).toBe('KBWI'); | ||
expect(decodeResult.raw.arrival_icao).toBe('KIND'); | ||
expect(decodeResult.raw.off_time).toBe(45420); | ||
expect(decodeResult.formatted.items.length).toBe(3); | ||
expect(decodeResult.formatted.items[0].label).toBe('Origin'); | ||
expect(decodeResult.formatted.items[0].value).toBe('KBWI'); | ||
expect(decodeResult.formatted.items[1].label).toBe('Destination'); | ||
expect(decodeResult.formatted.items[1].value).toBe('KIND'); | ||
expect(decodeResult.formatted.items[2].label).toBe('Takeoff Time'); | ||
expect(decodeResult.formatted.items[2].value).toBe('12:37:00'); | ||
expect(decodeResult.remaining.text).toBe('18.4'); | ||
}); | ||
|
||
test('does not decode invalid', () => { | ||
|
||
const text = 'POS Bogus message'; | ||
const decodeResult = plugin.decode({ text: text }); | ||
|
||
expect(decodeResult.decoded).toBe(false); | ||
expect(decodeResult.decoder.decodeLevel).toBe('none'); | ||
expect(decodeResult.formatted.description).toBe('Takeoff Report'); | ||
expect(decodeResult.message.text).toBe(text); | ||
}); | ||
}); |
This file contains 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,96 @@ | ||
import { DateTimeUtils } from '../DateTimeUtils'; | ||
import { DecoderPlugin } from '../DecoderPlugin'; | ||
import { DecodeResult, Message, Options } from '../DecoderPluginInterface'; | ||
import { CoordinateUtils } from '../utils/coordinate_utils'; | ||
import { ResultFormatter } from '../utils/result_formatter'; | ||
|
||
// Position Report | ||
export class Label_22_OFF extends DecoderPlugin { | ||
name = 'label-22-off'; | ||
|
||
qualifiers() { // eslint-disable-line class-methods-use-this | ||
return { | ||
labels: ['22'], | ||
preambles: ['OFF'], | ||
}; | ||
} | ||
|
||
decode(message: Message, options: Options = {}): DecodeResult { | ||
const decodeResult = this.defaultResult(); | ||
decodeResult.decoder.name = this.name; | ||
decodeResult.formatted.description = 'Takeoff Report'; | ||
decodeResult.message = message; | ||
|
||
if (message.text.startsWith('OFF01')) { // variant 1 | ||
const fields = message.text.substring(5).split('/'); | ||
|
||
if (fields.length != 2) { | ||
decodeResult.decoded = false; | ||
decodeResult.decoder.decodeLevel = 'none'; | ||
return decodeResult; | ||
} | ||
|
||
ResultFormatter.flightNumber(decodeResult, fields[0]); | ||
ResultFormatter.departureDay(decodeResult, Number(fields[1].substring(0, 2))); // departure day | ||
ResultFormatter.arrivalDay(decodeResult, Number(fields[1].substring(2,4))); // arrival day | ||
ResultFormatter.time_of_day(decodeResult, DateTimeUtils.convertHHMMSSToTod(fields[1].substring(4, 8) + '00')); //HHMM | ||
ResultFormatter.departureAirport(decodeResult, fields[1].substring(8, 12)); | ||
ResultFormatter.arrivalAirport(decodeResult, fields[1].substring(12, 16)); | ||
ResultFormatter.off(decodeResult, DateTimeUtils.convertHHMMSSToTod(fields[1].substring(16,22))); | ||
ResultFormatter.unknown(decodeResult, fields[1].substring(22)); | ||
|
||
decodeResult.decoded = true; | ||
decodeResult.decoder.decodeLevel = 'partial'; | ||
|
||
} else if (message.text.startsWith('OFF02\r\n')) { // varaint 3 | ||
const fields = message.text.substring(7).split(','); | ||
if (fields.length != 4) { | ||
decodeResult.decoded = false; | ||
decodeResult.decoder.decodeLevel = 'none'; | ||
return decodeResult; | ||
} | ||
|
||
ResultFormatter.departureAirport(decodeResult, fields[0]); | ||
ResultFormatter.arrivalAirport(decodeResult, fields[1]); | ||
ResultFormatter.off(decodeResult, DateTimeUtils.convertHHMMSSToTod(fields[2] + '00')); | ||
ResultFormatter.unknown(decodeResult, fields[3]); | ||
|
||
decodeResult.decoded = true; | ||
decodeResult.decoder.decodeLevel = 'partial'; | ||
|
||
} else if (message.text.startsWith('OFF02')) { // varaint 2 | ||
const fields = message.text.substring(5).split('/'); | ||
if (fields.length != 2) { | ||
decodeResult.decoded = false; | ||
decodeResult.decoder.decodeLevel = 'none'; | ||
return decodeResult; | ||
} | ||
|
||
ResultFormatter.flightNumber(decodeResult, fields[0]); | ||
const position = CoordinateUtils.decodeStringCoordinatesDecimalMinutes(fields[1].substring(0, 14)); | ||
if (position) { | ||
ResultFormatter.position(decodeResult, position); | ||
} | ||
ResultFormatter.day(decodeResult, Number(fields[1].substring(14, 16))); | ||
ResultFormatter.time_of_day(decodeResult, DateTimeUtils.convertHHMMSSToTod(fields[1].substring(16, 20) + '00')); | ||
ResultFormatter.departureAirport(decodeResult, fields[1].substring(20, 24)); | ||
ResultFormatter.arrivalAirport(decodeResult, fields[1].substring(24, 28)); | ||
ResultFormatter.off(decodeResult, DateTimeUtils.convertHHMMSSToTod(fields[1].substring(28, 32) + '00')); | ||
ResultFormatter.unknown(decodeResult, fields[1].substring(32, 36)); | ||
ResultFormatter.eta(decodeResult, DateTimeUtils.convertHHMMSSToTod(fields[1].substring(36,40) + '00')); | ||
decodeResult.decoded = true; | ||
decodeResult.decoder.decodeLevel = 'partial'; | ||
|
||
|
||
} else { | ||
if (options.debug) { | ||
console.log(`DEBUG: ${this.name}: Unknown variation.`); | ||
} | ||
decodeResult.decoded = false; | ||
decodeResult.decoder.decodeLevel = 'none'; | ||
} | ||
return decodeResult; | ||
} | ||
} | ||
|
||
export default {}; |
9 changes: 5 additions & 4 deletions
9
lib/plugins/Label_22.test.ts → lib/plugins/Label_22_POS.test.ts
This file contains 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 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 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 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
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.
this is a little weird, but what I'm calling the timestamp has minute resolution, but the actual takeoff time has second resolution. Open to ideas
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.
I would say that as long as the raw value is still defined with seconds, the formatted can be whatever.