Skip to content

Commit

Permalink
Add support for DTM, ALG and ALP headers (#507)
Browse files Browse the repository at this point in the history
--
GPS Datum headers HFALG and HFALP
according to FAI Sporting Code 2021 0.9.0
- 3.2.3 & 3.4
https://www.fai.org/sites/default/files/civl/documents/sporting_code_s7_h_-_civl_flight_recorder_specification_2021_v0.9.0.pdf
--
HFALGALTGPS:GEO
HFALPALTPRESSURE:ISA
  • Loading branch information
mreinart authored Jan 6, 2025
1 parent 7bba644 commit 1194b3d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
21 changes: 21 additions & 0 deletions __snapshots__/test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ exports[`IGCParser parse() 1G_77fv6m71.igc 1`] = `
"valid": true,
},
],
"geoDatum": "WGS-1984",
"geoDatumAlgorithm": null,
"geoPressureAlgorithm": null,
"gliderType": "ASW 19",
"hardwareVersion": "23",
"loggerId": "6M7",
Expand Down Expand Up @@ -270,6 +273,9 @@ exports[`IGCParser parse() 654G6NG1.IGC 1`] = `
"valid": true,
},
],
"geoDatum": "WGS84",
"geoDatumAlgorithm": null,
"geoPressureAlgorithm": null,
"gliderType": "ASG-29E (18m)",
"hardwareVersion": "Flarm-IGC06",
"loggerId": "6NG",
Expand Down Expand Up @@ -394,6 +400,9 @@ exports[`IGCParser parse() 2016-11-08-xcs-aaa-02.igc 1`] = `
"valid": true,
},
],
"geoDatum": "WGS-1984",
"geoDatumAlgorithm": null,
"geoPressureAlgorithm": null,
"gliderType": "DUO DISCUS",
"hardwareVersion": null,
"loggerId": "AAA",
Expand Down Expand Up @@ -506,6 +515,9 @@ exports[`IGCParser parse() 20180427.igc 1`] = `
"valid": true,
},
],
"geoDatum": "WGS-84",
"geoDatumAlgorithm": null,
"geoPressureAlgorithm": null,
"gliderType": "",
"hardwareVersion": null,
"loggerId": "000",
Expand Down Expand Up @@ -579,6 +591,9 @@ exports[`IGCParser parse() 20211015.igc 1`] = `
"valid": true,
},
],
"geoDatum": "WGS-84",
"geoDatumAlgorithm": null,
"geoPressureAlgorithm": null,
"gliderType": "Delta 2 S",
"hardwareVersion": null,
"loggerId": null,
Expand Down Expand Up @@ -635,6 +650,12 @@ exports[`IGCParser parseDateHeader() HFDTE1234?6 -> 💥 1`] = `"Invalid DTE he

exports[`IGCParser parseDateHeader() HFDTEXXXXXX -> 💥 1`] = `"Invalid DTE header at line 0: HFDTEXXXXXX"`;

exports[`IGCParser parseGeoDatum() [empty] -> 💥 1`] = `"Invalid FDT header at line 0: "`;

exports[`IGCParser parseGeoDatumAlgorithm() [empty] -> 💥 1`] = `"Invalid ALG header at line 0: "`;

exports[`IGCParser parseGeoPressureAlgorithm() [empty] -> 💥 1`] = `"Invalid ALP header at line 0: "`;

exports[`IGCParser parseIJRecord() [empty] -> 💥 1`] = `"Invalid undefined record at line 0: "`;

exports[`IGCParser parseIJRecord() I0136FXA38 -> 💥 1`] = `"Invalid I record at line 0: I0136FXA38"`;
Expand Down
27 changes: 27 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const RE_FTY_HEADER = /^H(\w)FTY(?:.{0,}?:(.*)|(.*))$/;
const RE_RFW_HEADER = /^H(\w)RFW(?:.{0,}?:(.*)|(.*))$/;
const RE_RHW_HEADER = /^H(\w)RHW(?:.{0,}?:(.*)|(.*))$/;
const RE_TZN_HEADER = /^H(\w)TZN(?:.{0,}?:([-+]?[\d.]+))$/;
const RE_DTM_HEADER = /^H(\w)DTM(?:.{0,}?:(.*)|(.*))$/;
const RE_ALG_HEADER = /^H(\w)ALG(?:.{0,}?:(.*)|(.*))$/;
const RE_ALP_HEADER = /^H(\w)ALP(?:.{0,}?:(.*)|(.*))$/;
const RE_B = /^B(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{3})([NS])(\d{3})(\d{2})(\d{3})([EW])([AV])(-\d{4}|\d{5})(-\d{4}|\d{5})/;
const RE_K = /^K(\d{2})(\d{2})(\d{2})/;
const RE_IJ = /^[IJ](\d{2})(?:\d{2}\d{2}[A-Z]{3})+/;
Expand Down Expand Up @@ -52,6 +55,9 @@ declare namespace IGCParser {
loggerType: string | null;
firmwareVersion: string | null;
hardwareVersion: string | null;
geoDatum: string | null;
geoDatumAlgorithm: string | null;
geoPressureAlgorithm: string | null;

task: Task | null;

Expand Down Expand Up @@ -149,6 +155,9 @@ class IGCParser {
loggerType: null,
firmwareVersion: null,
hardwareVersion: null,
geoDatum: null,
geoDatumAlgorithm: null,
geoPressureAlgorithm: null,
task: null,
fixes: [],
dataRecords: [],
Expand Down Expand Up @@ -280,6 +289,12 @@ class IGCParser {
this._result.firmwareVersion = this.parseFirmwareVersion(line);
} else if (headerType === 'RHW') {
this._result.hardwareVersion = this.parseHardwareVersion(line);
} else if (headerType === 'DTM') {
this._result.geoDatum = this.parseGeoDatum(line);
} else if (headerType === 'ALG') {
this._result.geoDatumAlgorithm = this.parseGeoDatumAlgorithm(line);
} else if (headerType === 'ALP') {
this._result.geoPressureAlgorithm = this.parseGeoPressureAlgorithm(line);
}
}

Expand Down Expand Up @@ -379,6 +394,18 @@ class IGCParser {
return this.parseTextHeader('RHW', RE_RHW_HEADER, line);
}

private parseGeoDatum(line: string): string {
return this.parseTextHeader('FDT', RE_DTM_HEADER, line);
}

private parseGeoDatumAlgorithm(line: string): string {
return this.parseTextHeader('ALG', RE_ALG_HEADER, line);
}

private parseGeoPressureAlgorithm(line: string): string {
return this.parseTextHeader('ALP', RE_ALP_HEADER, line);
}

private processTaskLine(line: string) {
if (!this._result.task) {
this._result.task = this.parseTask(line);
Expand Down
50 changes: 50 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,36 @@ describe('IGCParser', () => {
'2017-07-17T01:00:00.000Z',
]);
});

it('handles GPS Datum FAI Sporting Code 2021 0.9.0 - 3.2.3 & 3.4', () => {
// Example data as of 3.4 - see fai.org
let result = IGCParser.parse([
'AVXX00026',
'HFDTEDATE:160816',
'HFPLTPILOTINCHARGE:Bloggs Bill',
'HFCM2CREW2:NIL',
'HFGTYGLIDERTYPE:NKN',
'HFGIDGLIDERID:NKN',
'HFDTMGPSDATUM:WGS84',
'HFRFWFIRMWAREVERSION:0.2-alpha',
'HFRHWHARDWAREVERSION:1.0',
'HFFTYFRTYPE:Zebra Instruments,Proto 1',
'HFGPSRECEIVER:UBLOX,NEO7,56,50000',
'HFPRSPRESSALTSENSOR:MEAS,MS5611,25907',
'HFALGALTGPS:GEO',
'HFALPALTPRESSURE:ISA',
'B1153555536248N00339528WA0050200475',
'B1154005536249N00339528WA0050300476',
'B1154105536249N00339528WA0050300477',
'B1154155536248N00339528WA0050300476',
'G5734B6437B7796F96460F5D8AAC8FD4F',
'G0B6401B0E19216179A25DAE23CD0487F',
].join('\n'));

expect(result.geoDatum).toEqual('WGS84');
expect(result.geoDatumAlgorithm).toEqual('GEO');
expect(result.geoPressureAlgorithm).toEqual('ISA');
});
});

describeMethod('parseARecord', (test) => {
Expand Down Expand Up @@ -384,6 +414,26 @@ describe('IGCParser', () => {
test.fail('I0136FXA38');
});

describeMethod('parseGeoDatum', (test) => {
test.pass('HFDTMGPSDATUM:WGS84', 'WGS84');
test.pass('HFDTM100GPSDATUM:WGS-1984', 'WGS-1984');
test.pass('HFDTM100GPSDATUM:WGS-84', 'WGS-84');

test.fail('');
});

describeMethod('parseGeoDatumAlgorithm', (test) => {
test.pass('HFALGALTGPS:GEO', 'GEO');

test.fail('');
});

describeMethod('parseGeoPressureAlgorithm', (test) => {
test.pass('HFALPALTPRESSURE:ISA', 'ISA');

test.fail('');
});

// Test Suite Generator

function describeMethod(methodName: string, cb: (test: any) => void) {
Expand Down

0 comments on commit 1194b3d

Please sign in to comment.