Skip to content

Commit

Permalink
LAD / LOD extensions for B records
Browse files Browse the repository at this point in the history
example :
  I013637LAD
  B1526594446200N00547906EA013770137247
  • Loading branch information
spasutto committed Feb 21, 2023
1 parent 4856ff8 commit 8ed52e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
21 changes: 12 additions & 9 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const RE_K = /^K(\d{2})(\d{2})(\d{2})/;
const RE_IJ = /^[IJ](\d{2})(?:\d{2}\d{2}[A-Z]{3})+/;
const RE_TASK = /^C(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{4})([-\d]{2})(.*)/;
const RE_TASKPOINT = /^C(\d{2})(\d{2})(\d{3})([NS])(\d{3})(\d{2})(\d{3})([EW])(.*)/;
const RE_INT = /^\d*$/;
/* tslint:enable:max-line-length */

const VALID_DATA_SOURCES = ['F', 'O', 'P'];
Expand Down Expand Up @@ -430,24 +431,26 @@ class IGCParser {
throw new Error(`Invalid B record at line ${this.lineNumber}: ${line}`);
}

let extensions: IGCParser.RecordExtensions = {};
if (this.fixExtensions) {
for (let { code, start, length } of this.fixExtensions) {
extensions[code] = line.slice(start, start + length);
}
}

let time = `${match[1]}:${match[2]}:${match[3]}`;
let timestamp = this.calcTimestamp(time);

let latitude = IGCParser.parseLatitude(match[4], match[5], match[6], match[7]);
let longitude = IGCParser.parseLongitude(match[8], match[9], match[10], match[11]);
let mmmext = (RE_INT.test(extensions['LAD'])) ? extensions['LAD'] : '';
let latitude = IGCParser.parseLatitude(match[4], match[5], match[6] + mmmext, match[7]);
mmmext = (RE_INT.test(extensions['LOD'])) ? extensions['LOD'] : '';
let longitude = IGCParser.parseLongitude(match[8], match[9], match[10] + mmmext, match[11]);

let valid = match[12] === 'A';

let pressureAltitude = match[13] === '00000' ? null : parseInt(match[13], 10);
let gpsAltitude = match[14] === '00000' ? null : parseInt(match[14], 10);

let extensions: IGCParser.RecordExtensions = {};
if (this.fixExtensions) {
for (let { code, start, length } of this.fixExtensions) {
extensions[code] = line.slice(start, start + length);
}
}

let enl = null;
if (extensions['ENL']) {
let enlLength = this.fixExtensions.filter(it => it.code === 'ENL')[0].length;
Expand Down
17 changes: 17 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ describe('IGCParser', () => {
expect(result.errors).toMatchSnapshot();
});

test('lad_lod_extensions.igc', () => {
let content = fs.readFileSync(`${__dirname}/fixtures/lad_lod_extensions.igc`, 'utf8');
let result = IGCParser.parse(content, { lenient: true });

expect(result.fixes.length).toEqual(424);

expect(result.fixes[0].latitude).toEqual(44.968046666666666);
expect(result.fixes[0].longitude).toEqual(5.833138333333333);

expect(result.errors).toMatchSnapshot();
});

it('throws if HFDTE is missing', () => {
let lines = [
'ALXV6M7FLIGHT:1',
Expand Down Expand Up @@ -354,6 +366,11 @@ describe('IGCParser', () => {
{ code: 'ACZ', start: 63, length: 4 },
]);

test.pass('I023636LAD3737LOD', [
{ code: 'LAD', start: 35, length: 1 },
{ code: 'LOD', start: 36, length: 1 },
]);

test.fail('');
test.fail('I023638FXA');
test.fail('I0136FXA38');
Expand Down

0 comments on commit 8ed52e5

Please sign in to comment.