Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Label 4t eta decoding
Browse files Browse the repository at this point in the history
makrsmark committed Nov 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent be59d3c commit d0fdf25
Showing 5 changed files with 110 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/MessageDecoder.ts
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ export class MessageDecoder {
this.registerPlugin(new Plugins.Label_4J_POS(this));
this.registerPlugin(new Plugins.Label_4N(this));
this.registerPlugin(new Plugins.Label_4T_AGFSR(this));
this.registerPlugin(new Plugins.Label_4T_ETA(this));
this.registerPlugin(new Plugins.Label_B6_Forwardslash(this));
this.registerPlugin(new Plugins.Label_H1_FLR(this));
this.registerPlugin(new Plugins.Label_H1_OHMA(this));
2 changes: 1 addition & 1 deletion lib/plugins/Label_4T_AGFSR.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MessageDecoder } from '../MessageDecoder';
import { Label_4T_AGFSR } from './Label_4T_AGFSR';

describe('Label 4T ', () => {
describe('Label 4T ETA', () => {

let plugin: Label_4T_AGFSR;

57 changes: 57 additions & 0 deletions lib/plugins/Label_4T_ETA.test.ts
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);
});
});
50 changes: 50 additions & 0 deletions lib/plugins/Label_4T_ETA.ts
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 {};
1 change: 1 addition & 0 deletions lib/plugins/official.ts
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ export * from './Label_4A_Slash_01';
export * from './Label_4J_POS';
export * from './Label_4N';
export * from './Label_4T_AGFSR';
export * from './Label_4T_ETA';
export * from './Label_80';
export * from './Label_83';
export * from './Label_8E';

0 comments on commit d0fdf25

Please sign in to comment.