-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Label 4t eta decoding
Showing
5 changed files
with
110 additions
and
1 deletion.
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
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,57 @@ | ||
import { MessageDecoder } from '../MessageDecoder'; | ||
import { Label_4T_ETA } from './Label_4T_ETA'; | ||
|
||
describe('Label 4T ETA', () => { | ||
|
||
let plugin: Label_4T_ETA; | ||
|
||
beforeEach(() => { | ||
const decoder = new MessageDecoder(); | ||
plugin = new Label_4T_ETA(decoder); | ||
}); | ||
|
||
|
||
test('matches qualifiers', () => { | ||
expect(plugin.decode).toBeDefined(); | ||
expect(plugin.name).toBe('label-4t-eta'); | ||
expect(plugin.qualifiers).toBeDefined(); | ||
expect(plugin.qualifiers()).toEqual({ | ||
labels: ['4T'], | ||
preambles: ['ETA'], | ||
}); | ||
}); | ||
|
||
|
||
test('decodes msg 1', () => { | ||
const text = 'ETA AC7221/13/14 YYZ 0902Z'; | ||
|
||
const decodeResult = plugin.decode({ text: text }); | ||
|
||
expect(decodeResult.decoded).toBe(true); | ||
expect(decodeResult.decoder.decodeLevel).toBe('full'); | ||
expect(decodeResult.formatted.description).toBe('ETA Report'); | ||
expect(decodeResult.formatted.items.length).toBe(5); | ||
expect(decodeResult.formatted.items[0].label).toBe('Flight Number'); | ||
expect(decodeResult.formatted.items[0].value).toBe('AC7221'); | ||
expect(decodeResult.formatted.items[1].label).toBe('Departure Day'); | ||
expect(decodeResult.formatted.items[1].value).toBe('13'); | ||
expect(decodeResult.formatted.items[2].label).toBe('Arrival Day'); | ||
expect(decodeResult.formatted.items[2].value).toBe('14'); | ||
expect(decodeResult.formatted.items[3].label).toBe('Destination'); | ||
expect(decodeResult.formatted.items[3].value).toBe('YYZ'); | ||
expect(decodeResult.formatted.items[4].label).toBe('Estimated Time of Arrival'); | ||
expect(decodeResult.formatted.items[4].value).toBe('09:02:00'); | ||
}); | ||
|
||
|
||
test('decodes <invalid>', () => { | ||
|
||
const text = 'ETA Bogus message'; | ||
const decodeResult = plugin.decode({ text: text }); | ||
|
||
expect(decodeResult.decoded).toBe(false); | ||
expect(decodeResult.decoder.decodeLevel).toBe('none'); | ||
expect(decodeResult.formatted.description).toBe('ETA Report'); | ||
expect(decodeResult.formatted.items.length).toBe(0); | ||
}); | ||
}); |
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,50 @@ | ||
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'; | ||
|
||
// General Aviation Position Report | ||
export class Label_4T_ETA extends DecoderPlugin { | ||
name = 'label-4t-eta'; | ||
|
||
qualifiers() { // eslint-disable-line class-methods-use-this | ||
return { | ||
labels: ['4T'], | ||
preambles: ['ETA'], | ||
}; | ||
} | ||
|
||
decode(message: Message, options: Options = {}) : DecodeResult { | ||
const decodeResult = this.defaultResult(); | ||
decodeResult.decoder.name = this.name; | ||
decodeResult.formatted.description = 'ETA Report'; | ||
decodeResult.message = message; | ||
|
||
const data = message.text.substring(3).split('/'); | ||
|
||
if(!message.text.startsWith('ETA') || data.length !== 3) { | ||
if (options.debug) { | ||
console.log(`Decoder: Unknown 4T message: ${message.text}`); | ||
} | ||
ResultFormatter.unknown(decodeResult, message.text); | ||
decodeResult.decoded = false; | ||
decodeResult.decoder.decodeLevel = 'none'; | ||
return decodeResult; | ||
} | ||
|
||
ResultFormatter.flightNumber(decodeResult, data[0].trim()); | ||
ResultFormatter.departureDay(decodeResult, Number(data[1])); | ||
const etaData = data[2].split(' '); | ||
ResultFormatter.arrivalDay(decodeResult, Number(etaData[0])); | ||
ResultFormatter.arrivalAirport(decodeResult, etaData[1], 'IATA'); | ||
ResultFormatter.eta(decodeResult, DateTimeUtils.convertHHMMSSToTod(etaData[2].substring(0,4))); | ||
|
||
decodeResult.decoded = true; | ||
decodeResult.decoder.decodeLevel = 'full'; | ||
|
||
return decodeResult; | ||
} | ||
} | ||
|
||
export default {}; |
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