Skip to content
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

Adding H1 *POS parsing #183

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/MessageDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class MessageDecoder {
this.registerPlugin(new Plugins.Label_H1_OHMA(this));
this.registerPlugin(new Plugins.Label_H1_WRN(this));
this.registerPlugin(new Plugins.Label_H1(this));
this.registerPlugin(new Plugins.Label_H1_StarPOS(this));
this.registerPlugin(new Plugins.Label_HX(this));
this.registerPlugin(new Plugins.Label_80(this));
this.registerPlugin(new Plugins.Label_83(this));
Expand Down
49 changes: 49 additions & 0 deletions lib/plugins/Label_H1_StarPOS.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { MessageDecoder } from '../MessageDecoder';
import { Label_H1_StarPOS } from './Label_H1_StarPOS';

describe('Label H1 *POS', () => {

let plugin: Label_H1_StarPOS;

beforeEach(() => {
const decoder = new MessageDecoder();
plugin = new Label_H1_StarPOS(decoder);
});

test('decodes variant 1', () => {

const text = '*POS10300950N3954W07759363312045802M5230175';
const decodeResult = plugin.decode({ text: text });

expect(decodeResult.decoded).toBe(true);
expect(decodeResult.decoder.decodeLevel).toBe('partial');
expect(decodeResult.message.text).toBe(text);
expect(decodeResult.raw.day_of_month).toBe(30);
expect(decodeResult.raw.month).toBe(10);
expect(decodeResult.raw.time_of_day).toBe(35400);
expect(decodeResult.raw.position.latitude).toBe(39.900000);
expect(decodeResult.raw.position.longitude).toBe(-77.98333333333333);
expect(decodeResult.raw.altitude).toBe(36331);
expect(decodeResult.formatted.items.length).toBe(3);
expect(decodeResult.formatted.items[0].label).toBe('Message Timestamp');
expect(decodeResult.formatted.items[0].value).toBe('09:50:00');
expect(decodeResult.formatted.items[1].label).toBe('Aircraft Position');
expect(decodeResult.formatted.items[1].value).toBe('39.900 N, 77.983 W');
expect(decodeResult.formatted.items[2].label).toBe('Altitude');
expect(decodeResult.formatted.items[2].value).toBe('36331 feet');

expect(decodeResult.remaining.text).toBe('2045802M5230175');
});


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('Position Report');
expect(decodeResult.formatted.items.length).toBe(0);
});
});
49 changes: 49 additions & 0 deletions lib/plugins/Label_H1_StarPOS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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';

export class Label_H1_StarPOS extends DecoderPlugin {
name = 'label-h1-star-pos';
qualifiers() { // eslint-disable-line class-methods-use-this
return {
labels: ['H1'],
preambles: ['*POS'],
};
}

decode(message: Message, options: Options = {}) : DecodeResult {
let decodeResult = this.defaultResult();
decodeResult.decoder.name = this.name;
decodeResult.formatted.description = 'Position Report';
decodeResult.message = message;

const msg = message.text;
// assuming fixed length until other variants found
if (msg.length !== 43 || !msg.startsWith('*POS')) {
if (options.debug) {
console.log(`Decoder: Unknown H1 message: ${msg}`);
}
ResultFormatter.unknown(decodeResult, msg);
decodeResult.decoded = false;
decodeResult.decoder.decodeLevel = 'none';
return decodeResult;
}

decodeResult.raw.month = Number(msg.substring(4, 6));
decodeResult.raw.day_of_month = Number(msg.substring(6, 8));
Comment on lines +34 to +35
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

using day_of_month to be consistent - thinking of refactoring so they're all just day - do we want these as a formatted result too? or is it good as-is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

going to leave as-is - we can come back making all messages more consistent

ResultFormatter.time_of_day(decodeResult, DateTimeUtils.convertHHMMSSToTod(msg.substring(8, 12) + '00'));
ResultFormatter.position(decodeResult, { // Deg Min, no sec
latitude: CoordinateUtils.getDirection(msg.substring(12,13)) * (Number(msg.substring(13, 15)) + Number(msg.substring(15, 17))/60),
longitude: CoordinateUtils.getDirection(msg.substring(17,18)) * (Number(msg.substring(18, 21)) + Number(msg.substring(21, 23))/60)
});
ResultFormatter.altitude(decodeResult, Number(msg.substring(23, 28)));
ResultFormatter.unknown(decodeResult, msg.substring(28));
decodeResult.decoded = true;
decodeResult.decoder.decodeLevel = 'partial';
return decodeResult;
}
}

export default {};
3 changes: 2 additions & 1 deletion lib/plugins/official.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ export * from './Label_83';
export * from './Label_8E';
export * from './Label_B6';
export * from './Label_ColonComma';
export * from './Label_H1';
export * from './Label_H1_FLR';
export * from './Label_H1_OHMA';
export * from './Label_H1_StarPOS';
export * from './Label_H1_WRN';
export * from './Label_H1';
export * from './Label_HX';
export * from './Label_SQ';
export * from './Label_QR';
Expand Down