Skip to content

adding label 15 takeoff decoding #194

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

Merged
merged 1 commit into from
Nov 14, 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
40 changes: 36 additions & 4 deletions lib/plugins/Label_15.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Label_15', () => {
});
});

test('decodes short variant missing ???', () => {
test('decodes short variant missing unkown', () => {
const text = '(2N38448W 77216--- 28 20 7(Z'
const decodeResult = plugin.decode({ text: text });

Expand Down Expand Up @@ -65,16 +65,48 @@ describe('Label_15', () => {
expect(decodeResult.remaining.text).toBe('--- 42');
});

test('decodes long variant', () => {
test('decodes off variant no unkown', () => {
const text = '(2N39018W 77284OFF11112418101313--------(Z'
const decodeResult = plugin.decode({ text: text });

expect(decodeResult.decoded).toBe(true);
expect(decodeResult.decoder.decodeLevel).toBe('partial');
expect(decodeResult.formatted.items.length).toBe(1);
expect(decodeResult.formatted.items.length).toBe(2);
expect(decodeResult.formatted.items[0].label).toBe('Aircraft Position');
expect(decodeResult.formatted.items[0].value).toBe('39.030 N, 77.473 W');
expect(decodeResult.remaining.text).toBe('OFF11112418101313--------');
expect(decodeResult.formatted.items[1].label).toBe('Takeoff Time');
expect(decodeResult.formatted.items[1].value).toBe('2024-11-11T18:10:00Z');
expect(decodeResult.remaining.text).toBe('1313--------');
});

test('decodes off variant no date and unknown', () => {
// https://app.airframes.io/messages/3593342701
const text = '(2N42589W 83520OFF------13280606--------(Z'
const decodeResult = plugin.decode({ text: text });

expect(decodeResult.decoded).toBe(true);
expect(decodeResult.decoder.decodeLevel).toBe('partial');
expect(decodeResult.formatted.items.length).toBe(2);
expect(decodeResult.formatted.items[0].label).toBe('Aircraft Position');
expect(decodeResult.formatted.items[0].value).toBe('42.982 N, 83.867 W');
expect(decodeResult.formatted.items[1].label).toBe('Takeoff Time');
expect(decodeResult.formatted.items[1].value).toBe('13:28:00');
expect(decodeResult.remaining.text).toBe('0606--------');
});

test('decodes off variant all fields', () => {
// https://app.airframes.io/messages/3603048708
const text = '(2N39042W 77308OFF1311240327B1818 015(Z'
const decodeResult = plugin.decode({ text: text });

expect(decodeResult.decoded).toBe(true);
expect(decodeResult.decoder.decodeLevel).toBe('partial');
expect(decodeResult.formatted.items.length).toBe(2);
expect(decodeResult.formatted.items[0].label).toBe('Aircraft Position');
expect(decodeResult.formatted.items[0].value).toBe('39.070 N, 77.513 W');
expect(decodeResult.formatted.items[1].label).toBe('Takeoff Time');
expect(decodeResult.formatted.items[1].value).toBe('2024-11-13T03:27:00Z');
expect(decodeResult.remaining.text).toBe('B1818 015');
});

test('does not decode Label 15 <invalid>', () => {
Expand Down
16 changes: 14 additions & 2 deletions lib/plugins/Label_15.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DateTimeUtils } from '../DateTimeUtils';
import { DecoderPlugin } from '../DecoderPlugin';
import { DecodeResult, Message, Options } from '../DecoderPluginInterface';
import { CoordinateUtils } from '../utils/coordinate_utils';
Expand Down Expand Up @@ -30,8 +31,19 @@ export class Label_15 extends DecoderPlugin {
ResultFormatter.altitude(decodeResult, 100 * Number(alt));
}
ResultFormatter.temperature(decodeResult, between.substring(22).replaceAll(" ", "0"));
} else { // long variant
ResultFormatter.unknown(decodeResult, between.substring(13));
} else if(between.substring(13,16) === 'OFF') { // off variant
const ddmmyy = between.substring(16, 22);
const hhmm = between.substring(22, 26);
if(ddmmyy != '------') {
const mmddyy = ddmmyy.substring(2, 4) + ddmmyy.substring(0, 2) + ddmmyy.substring(4);
console.log(`Decoder: mmddyy: ${mmddyy}, hhmm: ${hhmm}`);
ResultFormatter.off(decodeResult, DateTimeUtils.convertDateTimeToEpoch(hhmm+'00', mmddyy), 'epoch');
} else {
ResultFormatter.off(decodeResult, DateTimeUtils.convertHHMMSSToTod(hhmm), 'tod');
}
ResultFormatter.unknown(decodeResult, between.substring(26));
} else {
ResultFormatter.unknown(decodeResult, between.substring(26));
}
} else {
if (options.debug) {
Expand Down
26 changes: 18 additions & 8 deletions lib/utils/result_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,24 @@ export class ResultFormatter {
});
}

static off(decodeResult: DecodeResult, time: number) {
decodeResult.raw.off_time = time;
decodeResult.formatted.items.push({
type: 'time_of_day',
code: 'OFF',
label: 'Takeoff Time',
value: DateTimeUtils.timestampToString(time, 'tod'),
});
static off(decodeResult: DecodeResult, time: number, type: 'tod' | 'epoch' = 'tod') {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i already do the _date and _time in eta - is this something we want to keep doing, or is there a better way?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, good question.

Copy link
Contributor

Choose a reason for hiding this comment

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

After some thought, I think notating the type is helpful.

if (type === 'tod') {
decodeResult.raw.off_time = time;
decodeResult.formatted.items.push({
type: 'time_of_day',
code: 'OFF',
label: 'Takeoff Time',
value: DateTimeUtils.timestampToString(time, 'tod'),
});
} else {
decodeResult.raw.off_date = time;
decodeResult.formatted.items.push({
type: 'epoch',
code: 'OFF',
label: 'Takeoff Time',
value: DateTimeUtils.timestampToString(time, 'epoch'),
});
}
}

static on(decodeResult: DecodeResult, time: number) {
Expand Down