Skip to content

Commit

Permalink
NMEA-PARSER: v1.6.14
Browse files Browse the repository at this point in the history
NMEA-PARSER: Removed __dirname and import.meta to get path
  • Loading branch information
crisconru authored May 16, 2024
2 parents 8d11e46 + 7e64fd3 commit 4795fe0
Show file tree
Hide file tree
Showing 14 changed files with 1,074 additions and 39 deletions.
10 changes: 6 additions & 4 deletions packages/nmea-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coremarine/nmea-parser",
"version": "1.6.13",
"version": "1.6.14",
"description": "Library to parse NMEA 0183 sentences",
"author": "CoreMarine",
"license": "ISC",
Expand Down Expand Up @@ -42,10 +42,11 @@
"node": ">= 18"
},
"scripts": {
"build": "tsup && cp -r ./src/protocols ./dist",
"protocols": "node yaml-to-json.js ./protocols/nmea.yaml ./src/nmea.ts && node yaml-to-json.js ./protocols/norsub.yaml ./tests/norsub.ts",
"build": "npm run protocols && npm run format && tsup",
"lint": "ts-standard",
"format": "ts-standard --fix",
"test": "vitest",
"test": "npm run protocols && vitest",
"test:coverage": "vitest run --coverage"
},
"dependencies": {
Expand All @@ -63,7 +64,8 @@
"ignore": [
"tests",
"vitest.config.ts",
"tsup.config.ts"
"tsup.config.ts",
"yaml-to-json.js"
]
},
"eslintConfig": {
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions packages/nmea-parser/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
// DIR
export const DIRNAME = ((): string => {
try {
// CJS
return __dirname
} catch (error) {
// ESM
const filename = fileURLToPath(import.meta.url)
return path.dirname(filename)
}
})()
// NMEA
export const START_FLAG = '$'
export const SEPARATOR = ','
Expand Down
2 changes: 1 addition & 1 deletion packages/nmea-parser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { Parser as NMEAParser } from './parser'
export * from './constants'
export * from './schemas'
export * from './types'
export * from './types'
169 changes: 169 additions & 0 deletions packages/nmea-parser/src/nmea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
export const PROTOCOLS = {
protocols: [
{
protocol: 'NMEA',
version: '3.1',
standard: true,
sentences: [
{
sentence: 'AAM',
description: 'Waypoint Arrival Alarm',
fields: [
{
name: 'status',
type: 'string',
note: 'BOOLEAN\n\nA = arrival circle entered\n\nV = arrival circle not passed'
},
{
name: 'status',
type: 'string',
note: 'BOOLEAN\n\nA = perpendicular passed at waypoint\n\nV = perpendicular not passed'
},
{
name: 'arrival_circle_radius',
type: 'float32'
},
{
name: 'radius_units',
type: 'string',
units: 'nautic miles'
},
{
name: 'waypoint_id',
type: 'string'
}
]
},
{
sentence: 'GGA',
description: 'Global Positioning System Fix Data',
fields: [
{
name: 'utc_position',
type: 'string',
units: 'ms'
},
{
name: 'latitude',
type: 'string',
units: 'deg'
},
{
name: 'latitude_direction',
type: 'string',
note: 'N: North\n S: South'
},
{
name: 'longitude',
type: 'string',
units: 'deg'
},
{
name: 'longitude_direction',
type: 'string',
note: 'E - East\n W - West'
},
{
name: 'gps_quality',
type: 'int8',
note: '0: Fix not valid\n 1: GPS fix\n 2: Differential GPS fix (DGNSS), SBAS, OmniSTAR VBS, Beacon, RTX in GVBS mode\n 3: Not applicable\n 4: RTK Fixed, xFill\n 5: RTK Float, OmniSTAR XP/HP, Location RTK, RTX\n 6: INS Dead reckoning\n 7: Manual Input Mode\n 8: Simulator Mode'
},
{
name: 'satellites',
type: 'uint8'
},
{
name: 'hdop',
type: 'float64'
},
{
name: 'altitude',
type: 'float64',
units: 'm',
note: 'Orthometric height Mean-Sea-Level (MSL reference)'
},
{
name: 'altitude_units',
type: 'string',
units: 'm'
},
{
name: 'geoid_separation',
type: 'float64',
units: 'm',
note: 'Geoidal Separation: the difference between the WGS-84 earth ellipsoid surface and mean-sea-level (geoid) surface, "-" = mean-sea-level surface below WGS-84 ellipsoid surface.'
},
{
name: 'geoid_separation_units',
type: 'string',
units: 'm'
},
{
name: 'age_of_differential_gps_data',
type: 'uint32',
units: 'sec',
note: 'Time in seconds since last SC104 Type 1 or 9 update, null field when DGPS is not used300'
},
{
name: 'reference_station_id',
type: 'uint16',
note: 'Reference station ID, range 0000 to 4095. A null field when any reference station ID is selected and no corrections are received. See table below for a description of the field values.\n\n0002 CenterPoint or ViewPoint RTX\n\n0005 RangePoint RTX\n\n0006 FieldPoint RTX\n\n0100 VBS\n\n1000 HP\n\n1001 HP/XP (Orbits)\n\n1002 HP/G2 (Orbits)\n\n1008 XP (GPS)\n\n1012 G2 (GPS)\n\n1013 G2 (GPS/GLONASS)\n\n1014 G2 (GLONASS)\n\n1016 HP/XP (GPS)\n\n1020 HP/G2 (GPS)\n\n1021 HP/G2 (GPS/GLONASS)'
}
]
},
{
sentence: 'HDT',
description: 'Heading - True',
fields: [
{
name: 'heading',
type: 'float32',
note: 'Heading, degrees True'
},
{
name: 'true',
type: 'string',
note: 'T = True'
}
]
},
{
sentence: 'ZDA',
description: 'Time & Date - UTC, day, month, year and local time zone',
fields: [
{
name: 'utc_time',
type: 'string',
note: 'UTC time (hours, minutes, seconds, may have fractional subseconds)'
},
{
name: 'day',
type: 'int8',
note: 'Day, 01 to 31'
},
{
name: 'month',
type: 'int8',
note: 'Month, 01 to 12'
},
{
name: 'year',
type: 'int16',
note: 'Year (4 digits)'
},
{
name: 'local_zone_hours',
type: 'int8',
note: 'Local zone description, 00 to +- 13 hours'
},
{
name: 'local_zone_minutes',
type: 'int8',
note: 'Local zone minutes description, 00 to 59, apply same sign as local hours'
}
]
}
]
}
]
}
13 changes: 4 additions & 9 deletions packages/nmea-parser/src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { readdirSync } from 'node:fs'
import Path from 'node:path'
import * as v from 'valibot'
import { DIRNAME, END_FLAG, END_FLAG_LENGTH, MAX_CHARACTERS, NMEA_ID_LENGTH, START_FLAG, START_FLAG_LENGTH } from './constants'
import { END_FLAG, END_FLAG_LENGTH, MAX_CHARACTERS, NMEA_ID_LENGTH, START_FLAG, START_FLAG_LENGTH } from './constants'
import { BooleanSchema, NMEALikeSchema, ProtocolsInputSchema, StringSchema, UnsignedIntegerSchema } from './schemas'
import type { Data, FieldType, FieldUnknown, NMEAKnownSentence, NMEALike, NMEAParser, NMEAPreParsed, NMEASentence, NMEAUknownSentence, ParserSentences, ProtocolOutput, ProtocolsFile, ProtocolsInput, Sentence, StoredSentences } from './types'
import { getSentencesByProtocol, getStoreSentences, readProtocolsFile, readProtocolsString } from './protocols'
import { generateSentenceFromModel, getFakeSentence, getNMEAUnparsedSentence } from './sentences'
import { getTalker } from './utils'
import { PROTOCOLS } from './nmea'

export class Parser implements NMEAParser {
// Memory - Buffer
Expand All @@ -29,12 +28,8 @@ export class Parser implements NMEAParser {
}

private readInternalProtocols (): void {
const folder = Path.join(DIRNAME, 'protocols')
const files = readdirSync(folder, { encoding: 'utf-8' })
files.forEach(file => {
const absoluteFile = Path.join(folder, file)
this.addProtocols({ file: absoluteFile })
})
const parsed = v.parse(ProtocolsInputSchema, PROTOCOLS)
this.addProtocols(parsed)
}

private readProtocols (input: ProtocolsInput): ProtocolsFile {
Expand Down
4 changes: 2 additions & 2 deletions packages/nmea-parser/src/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as v from 'valibot'
import { DELIMITER, DIRNAME, END_FLAG, SEPARATOR, START_FLAG } from './constants'
import { DELIMITER, END_FLAG, SEPARATOR, START_FLAG } from './constants'

// COMMONS
export const StringSchema = v.string()
Expand Down Expand Up @@ -104,7 +104,7 @@ export const StoredSentenceSchema = v.object({
export const StoredSentencesSchema = v.map(StringSchema, StoredSentenceSchema)

export const JSONSchemaInputSchema = v.object({
path: v.optional(StringSchema, DIRNAME),
path: v.optional(StringSchema),
filename: v.optional(StringSchema, 'nmea_protocols_schema.json')
})
// SENTENCES
Expand Down
4 changes: 2 additions & 2 deletions packages/nmea-parser/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import fs from 'node:fs'
import path from 'node:path'
import { describe, test, expect } from 'vitest'
import * as v from 'valibot'
import { DIRNAME, NMEAParser as Parser } from '../src'
import { NMEAParser as Parser } from '../src'
import { generateSentenceFromModel, getFakeSentence } from '../src/sentences'
import { NMEAKnownSentenceSchema, NMEALikeSchema, NMEAUknownSentenceSchema } from '../src/schemas'
import { readProtocolsFile } from '../src/protocols'
import { Protocol } from '../src/types'

const NORSUB_FILE = path.join(DIRNAME, '..', 'tests', 'norsub.yaml')
const NORSUB_FILE = path.join(__dirname, '..', 'protocols', 'norsub.yaml')

describe('Parser', () => {
test('Default constructor', () => {
Expand Down
Loading

0 comments on commit 4795fe0

Please sign in to comment.