Skip to content

Commit e5d46e7

Browse files
authored
Consolidated parsers (#352)
- removed Label_1J_2J_FTX, Label_2P_POS, and Label_4J_POS - added check in Label 80 - added labels to Label_H1 - improved Label_H1 decoding
1 parent 670aec9 commit e5d46e7

14 files changed

Lines changed: 119 additions & 193 deletions

lib/MessageDecoder.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export class MessageDecoder {
3131
this.registerPlugin(new Plugins.Label_16_N_Space(this));
3232
this.registerPlugin(new Plugins.Label_16_POSA1(this));
3333
this.registerPlugin(new Plugins.Label_16_TOD(this));
34-
this.registerPlugin(new Plugins.Label_1J_2J_FTX(this));
3534
this.registerPlugin(new Plugins.Label_1L_3Line(this));
3635
this.registerPlugin(new Plugins.Label_1L_070(this));
3736
this.registerPlugin(new Plugins.Label_1L_660(this));
@@ -44,7 +43,6 @@ export class MessageDecoder {
4443
this.registerPlugin(new Plugins.Label_2P_FM3(this));
4544
this.registerPlugin(new Plugins.Label_2P_FM4(this));
4645
this.registerPlugin(new Plugins.Label_2P_FM5(this));
47-
this.registerPlugin(new Plugins.Label_2P_POS(this));
4846
this.registerPlugin(new Plugins.Label_30_Slash_EA(this));
4947
this.registerPlugin(new Plugins.Label_44_ETA(this));
5048
this.registerPlugin(new Plugins.Label_44_IN(this));
@@ -57,7 +55,6 @@ export class MessageDecoder {
5755
this.registerPlugin(new Plugins.Label_4A_DIS(this));
5856
this.registerPlugin(new Plugins.Label_4A_DOOR(this));
5957
this.registerPlugin(new Plugins.Label_4A_Slash_01(this));
60-
this.registerPlugin(new Plugins.Label_4J_POS(this));
6158
this.registerPlugin(new Plugins.Label_4N(this));
6259
this.registerPlugin(new Plugins.Label_4T_AGFSR(this));
6360
this.registerPlugin(new Plugins.Label_4T_ETA(this));

lib/plugins/Label_1J_2J_FTX.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { MessageDecoder } from '../MessageDecoder';
2-
import { Label_1J_2J_FTX } from './Label_1J_2J_FTX';
2+
import { Label_H1 } from './Label_H1';
33

44
describe('Label 1J/2J FTX', () => {
5-
let plugin: Label_1J_2J_FTX;
5+
let plugin: Label_H1;
66
let message = { label: '1J', text: '' };
77

88
beforeEach(() => {
99
const decoder = new MessageDecoder();
10-
plugin = new Label_1J_2J_FTX(decoder);
10+
plugin = new Label_H1(decoder);
1111
});
1212

1313
test('decodes Label 1J', () => {

lib/plugins/Label_1J_2J_FTX.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

lib/plugins/Label_2P_POS.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { MessageDecoder } from '../MessageDecoder';
2-
import { Label_2P_POS } from './Label_2P_POS';
2+
import { Label_H1 } from './Label_H1';
33

44
describe('Label_2P Preamble POS', () => {
5-
let plugin: Label_2P_POS;
5+
let plugin: Label_H1;
66
const message = { label: '2P', text: '' };
77

88
beforeEach(() => {
99
const decoder = new MessageDecoder();
10-
plugin = new Label_2P_POS(decoder);
10+
plugin = new Label_H1(decoder);
1111
});
1212

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

lib/plugins/Label_2P_POS.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

lib/plugins/Label_4J_POS.test.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
import { MessageDecoder } from '../MessageDecoder';
2-
import { Label_4J_POS } from './Label_4J_POS';
2+
import { Label_H1 } from './Label_H1';
33

44
describe('Label 4J POS', () => {
5-
let plugin: Label_4J_POS;
5+
let plugin: Label_H1;
66
const message = { label: '4J', text: '' };
77

88
beforeEach(() => {
99
const decoder = new MessageDecoder();
10-
plugin = new Label_4J_POS(decoder);
11-
});
12-
13-
test('matches qualifiers', () => {
14-
expect(plugin.decode).toBeDefined();
15-
expect(plugin.name).toBe('label-4j-pos');
16-
expect(plugin.qualifiers).toBeDefined();
17-
expect(plugin.qualifiers()).toEqual({
18-
labels: ['4J'],
19-
preambles: ['POS/'],
20-
});
10+
plugin = new Label_H1(decoder);
2111
});
2212

2313
test('decodes inmarsat', () => {

lib/plugins/Label_4J_POS.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

lib/plugins/Label_80.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ describe('Label 80', () => {
147147
expect(decodeResult.remaining.text).toBe('3701 INRANG//ERT');
148148
});
149149

150+
test('does not decode INR variant 1', () => {
151+
// decoded by another parser
152+
message.text =
153+
'INR/ID91511S,,/DC04032026,143534/MR19,/NR,,,,,,,,950,0/ET041505/FB983/VR32BF4C';
154+
const decodeResult = plugin.decode(message);
155+
156+
expect(decodeResult.decoded).toBe(false);
157+
expect(decodeResult.decoder.decodeLevel).toBe('none');
158+
});
159+
150160
test('does not decode invalid messages', () => {
151161
message.text = '3N01 POSRPT Bogus message';
152162
const decodeResult = plugin.decode(message);

lib/plugins/Label_80.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ export class Label_80 extends DecoderPlugin {
182182
}
183183
private parseCsvFormat(text: string, results: DecodeResult) {
184184
const csvParts = text.split(',');
185+
if(csvParts.length !== 9) {
186+
return;
187+
}
185188
const header = csvParts[0].trim().split(/\s+/);
186189
ResultFormatter.unknown(results, header[0], ' ');
187190
ResultFormatter.unknown(results, header[1], ' ');

lib/plugins/Label_80_INR.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { decode } from 'node:punycode';
2+
import { MessageDecoder } from '../MessageDecoder';
3+
import { Label_H1 } from './Label_H1';
4+
5+
describe('Label 80 Preamble INR', () => {
6+
let plugin: Label_H1;
7+
const message = { label: '80', text: '' };
8+
9+
beforeEach(() => {
10+
const decoder = new MessageDecoder();
11+
plugin = new Label_H1(decoder);
12+
});
13+
14+
test('decodes variant 1', () => {
15+
message.text =
16+
'INR/ID91511S,,/DC04032026,143534/MR19,/NR,,,,,,,,950,0/ET041505/FB983/VR32BF4C';
17+
const decodeResult = plugin.decode(message);
18+
19+
expect(decodeResult.decoded).toBe(true);
20+
expect(decodeResult.decoder.decodeLevel).toBe('partial');
21+
expect(decodeResult.raw.tail).toBe('91511S');
22+
expect(decodeResult.raw.message_timestamp).toBe(1772634934);
23+
expect(decodeResult.raw.day).toBe(4);
24+
expect(decodeResult.raw.eta_time).toBe(54300);
25+
expect(decodeResult.raw.fuel_on_board).toBe(983);
26+
expect(decodeResult.raw.version).toBe(3.2);
27+
expect(decodeResult.raw.checksum).toBe(0xbf4c);
28+
expect(decodeResult.formatted.description).toBe('In-Range Report');
29+
expect(decodeResult.formatted.items.length).toBe(6);
30+
expect(decodeResult.remaining.text).toBe('MR19,/NR,,,,,,,,950,0');
31+
});
32+
});

0 commit comments

Comments
 (0)