From a78f42f7e77588e8157560cf78c7474f49ce36b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3bal=20Contreras=20Rubio?= Date: Tue, 23 Jul 2024 12:04:01 +0200 Subject: [PATCH 1/4] NORSUB-eMRU: Added build in the testing phase --- .github/workflows/norsub-emru.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/norsub-emru.yml b/.github/workflows/norsub-emru.yml index 462a3bd..a86d087 100644 --- a/.github/workflows/norsub-emru.yml +++ b/.github/workflows/norsub-emru.yml @@ -33,6 +33,9 @@ jobs: - name: 🧑‍🔬 Tests run: "npm run norsub-emru:test" + + - name: 🛠️ Build + run: "npm run norsub-emru:build" publish: name: 🚀 Publish From 876628144ae62980a3df83ecc57a10fe2b384ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3bal=20Contreras=20Rubio?= Date: Tue, 23 Jul 2024 14:13:22 +0200 Subject: [PATCH 2/4] removing unnecesary blank lines --- packages/nmea-parser/protocols/norsub.yaml | 3 - packages/norsub-emru/protocols/norsub.yaml | 375 ++++++++++----------- 2 files changed, 186 insertions(+), 192 deletions(-) diff --git a/packages/nmea-parser/protocols/norsub.yaml b/packages/nmea-parser/protocols/norsub.yaml index 0e4a0e0..3bb9e40 100644 --- a/packages/nmea-parser/protocols/norsub.yaml +++ b/packages/nmea-parser/protocols/norsub.yaml @@ -55,7 +55,6 @@ protocols: - name: status type: uint32 description: "0 - Error\n - 1 - No Error" - protocol: NORSUB2 standard: false @@ -89,7 +88,6 @@ protocols: - name: status type: uint32 description: "0 - Error\n - 1 - No Error" - protocol: NORSUB6 standard: false @@ -153,7 +151,6 @@ protocols: - name: status type: uint32 description: "0 - Error\n - 1 - No Error" - protocol: NORSUB7 standard: false diff --git a/packages/norsub-emru/protocols/norsub.yaml b/packages/norsub-emru/protocols/norsub.yaml index c833bb2..3bb9e40 100644 --- a/packages/norsub-emru/protocols/norsub.yaml +++ b/packages/norsub-emru/protocols/norsub.yaml @@ -2,36 +2,36 @@ protocols: - protocol: GYROCOMPAS1 standard: false sentences: - - sentence: HEHDT - fields: + - id: HEHDT + payload: - name: heading - type: float + type: float32 units: deg - name: symbol type: string - - sentence: PHTRO - fields: + - id: PHTRO + payload: - name: pitch - type: float + type: float32 units: deg - name: pitch_direction type: string - note: M bow up, P bow down + description: M bow up, P bow down - name: roll - type: float + type: float32 units: deg - name: roll_direction type: string - note: M bow up, P bow down - - sentence: PHINF - fields: + description: M bow up, P bow down + - id: PHINF + payload: - name: status type: string - protocol: NORSUB standard: false sentences: - - sentence: PNORSUB - fields: + - id: PNORSUB + payload: - name: time type: uint32 units: ms @@ -39,29 +39,28 @@ protocols: type: uint32 units: ms - name: roll - type: double + type: float64 units: deg - name: pitch - type: double + type: float64 units: deg - name: heading - type: double + type: float64 units: deg - note: 0 - 360 + description: 0 - 360 - name: heave - type: double + type: float64 units: m - note: z-down + description: z-down - name: status type: uint32 - note: "0 - Error\n - + description: "0 - Error\n 1 - No Error" - protocol: NORSUB2 standard: false sentences: - - sentence: PNORSUB2 - fields: + - id: PNORSUB2 + payload: - name: time type: uint32 units: ms @@ -69,33 +68,32 @@ protocols: type: uint32 units: ms - name: roll - type: double + type: float64 units: deg - name: pitch - type: double + type: float64 units: deg - name: heading - type: double + type: float64 units: deg - note: 0 - 360 + description: 0 - 360 - name: heave - type: double + type: float64 units: m - note: z-down + description: z-down - name: heave_velocity - type: double + type: float64 units: m/s - note: z-down + description: z-down - name: status type: uint32 - note: "0 - Error\n - + description: "0 - Error\n 1 - No Error" - protocol: NORSUB6 standard: false sentences: - - sentence: PNORSUB6 - fields: + - id: PNORSUB6 + payload: - name: time type: uint32 units: ms @@ -103,63 +101,62 @@ protocols: type: uint32 units: ms - name: roll - type: double + type: float64 units: deg - name: pitch - type: double + type: float64 units: deg - name: heading - type: double + type: float64 units: deg - note: 0 - 360 + description: 0 - 360 - name: surge - type: double + type: float64 units: m - name: sway - type: double + type: float64 units: m - name: heave - type: double + type: float64 units: m - note: z-down + description: z-down - name: roll_rate - type: double + type: float64 units: deg/s - name: pitch_rate - type: double + type: float64 units: deg/s - name: yaw_rate - type: double + type: float64 units: deg/s - name: surge_velocity - type: double + type: float64 units: m/s - name: sway_velocity - type: double + type: float64 units: m/s - name: heave_velocity - type: double + type: float64 units: m/s - note: z-down + description: z-down - name: acceleration_x - type: double + type: float64 units: m/s2 - name: acceleration_y - type: double + type: float64 units: m/s2 - name: acceleration_z - type: double + type: float64 units: m/s2 - name: status type: uint32 - note: "0 - Error\n - + description: "0 - Error\n 1 - No Error" - protocol: NORSUB7 standard: false sentences: - - sentence: PNORSUB7 - fields: + - id: PNORSUB7 + payload: - name: time type: uint32 units: ms @@ -167,78 +164,78 @@ protocols: type: uint32 units: ms - name: roll - type: double + type: float64 units: deg - name: pitch - type: double + type: float64 units: deg - name: heading - type: double + type: float64 units: deg - note: 0 - 360 + description: 0 - 360 - name: surge - type: double + type: float64 units: m - name: sway - type: double + type: float64 units: m - name: heave - type: double + type: float64 units: m - note: z-down + description: z-down - name: roll_rate - type: double + type: float64 units: deg/s - name: pitch_rate - type: double + type: float64 units: deg/s - name: yaw_rate - type: double + type: float64 units: deg/s - name: surge_velocity - type: double + type: float64 units: m/s - name: sway_velocity - type: double + type: float64 units: m/s - name: heave_velocity - type: double + type: float64 units: m/s - note: z-down + description: z-down - name: acceleration_x - type: double + type: float64 units: m/s2 - name: acceleration_y - type: double + type: float64 units: m/s2 - name: acceleration_z - type: double + type: float64 units: m/s2 - name: period_x - type: double + type: float64 units: s - name: period_y - type: double + type: float64 units: s - name: period_z - type: double + type: float64 units: s - name: amplitude_x - type: double + type: float64 units: m - name: amplitude_y - type: double + type: float64 units: m - name: amplitude_z - type: double + type: float64 units: m - name: status type: uint32 - protocol: NORSUB7b standard: false sentences: - - sentence: PNORSUB7b - fields: + - id: PNORSUB7b + payload: - name: time type: uint32 units: ms @@ -246,70 +243,70 @@ protocols: type: uint32 units: ms - name: roll - type: double + type: float64 units: deg - name: pitch - type: double + type: float64 units: deg - name: heading - type: double + type: float64 units: deg - note: 0 - 360 + description: 0 - 360 - name: surge - type: double + type: float64 units: m - name: sway - type: double + type: float64 units: m - name: heave - type: double + type: float64 units: m - note: z-down + description: z-down - name: roll_rate - type: double + type: float64 units: deg/s - name: pitch_rate - type: double + type: float64 units: deg/s - name: yaw_rate - type: double + type: float64 units: deg/s - name: surge_velocity - type: double + type: float64 units: m/s - name: sway_velocity - type: double + type: float64 units: m/s - name: heave_velocity - type: double + type: float64 units: m/s - note: z-down + description: z-down - name: acceleration_x - type: double + type: float64 units: m/s2 - name: acceleration_y - type: double + type: float64 units: m/s2 - name: acceleration_z - type: double + type: float64 units: m/s2 - name: period_x - type: double + type: float64 units: s - name: period_y - type: double + type: float64 units: s - name: period_z - type: double + type: float64 units: s - name: amplitude_x - type: double + type: float64 units: m - name: amplitude_y - type: double + type: float64 units: m - name: amplitude_z - type: double + type: float64 units: m - name: status_a type: uint16 @@ -318,9 +315,9 @@ protocols: - protocol: NORSUB8 standard: false sentences: - - sentence: PNORSUB8 + - id: PNORSUB8 description: The whole regular attitude information from the MRU - fields: + payload: - name: time type: uint32 units: us @@ -328,191 +325,191 @@ protocols: type: uint32 units: us - name: roll - type: double + type: float64 units: deg - name: pitch - type: double + type: float64 units: deg - name: heading - type: double + type: float64 units: deg - note: From 0 to 360 + description: From 0 to 360 - name: surge - type: double + type: float64 units: m - name: sway - type: double + type: float64 units: m - name: heave - type: double + type: float64 units: m - note: z-down + description: z-down - name: roll_rate - type: double + type: float64 units: deg/s - name: pitch_rate - type: double + type: float64 units: deg/s - name: yaw_rate - type: double + type: float64 units: deg/s - name: surge_velocity - type: double + type: float64 units: m/s - name: sway_velocity - type: double + type: float64 units: m/s - name: heave_velocity - type: double + type: float64 units: m/s - note: z-down + description: z-down - name: acceleration_x - type: double + type: float64 units: m/s2 - name: acceleration_y - type: double + type: float64 units: m/s2 - name: acceleration_z - type: double + type: float64 units: m/s2 - name: period_x - type: double + type: float64 units: s - name: period_y - type: double + type: float64 units: s - name: period_z - type: double + type: float64 units: s - name: amplitude_x - type: double + type: float64 units: m - name: amplitude_y - type: double + type: float64 units: m - name: amplitude_z - type: double + type: float64 units: m - name: status type: uint32 - protocol: NORSUB PRDID standard: false sentences: - - sentence: PRDID - fields: + - id: PRDID + payload: - name: pitch - type: double + type: float64 units: deg - name: roll - type: double + type: float64 units: deg - protocol: Tokimek PTVG standard: false sentences: - - sentence: PTVG - fields: + - id: PTVG + payload: - name: pitch - type: number + type: float64 units: deg - note: "Multiplied by 100, a [-] bow up / a [space] bow down" + description: "Multiplied by 100, a [-] bow up / a [space] bow down" - name: roll - type: number + type: float64 units: deg - note: "Multiplied by 100, a [-] bow up / a [space] bow down" + description: "Multiplied by 100, a [-] bow up / a [space] bow down" - name: heading - type: number + type: float64 units: deg - protocol: RDI ADCP standard: false sentences: - - sentence: PRDID - fields: + - id: PRDID + payload: - name: pitch - type: double + type: float64 units: deg - note: "s if [+] is bow up / s is [-] if bow down, leading zeros" + description: "s if [+] is bow up / s is [-] if bow down, leading zeros" - name: roll - type: double + type: float64 units: deg - note: "s if [+] is bow up / s is [-] if bow down, leading zeros" + description: "s if [+] is bow up / s is [-] if bow down, leading zeros" - name: heading - type: double + type: float64 units: deg - protocol: SMCA standard: false sentences: - - sentence: PSMCA - fields: + - id: PSMCA + payload: - name: pitch - type: double + type: float64 units: deg - note: "±100 degs, resolution 0.001 degs" + description: "±100 degs, resolution 0.001 degs" - name: roll - type: double + type: float64 units: deg - note: "±100 degs, resolution 0.001 degs" + description: "±100 degs, resolution 0.001 degs" - name: heading - type: double + type: float64 units: m - note: "±10 m, resolution 0.01 m" + description: "±10 m, resolution 0.01 m" - name: surge - type: double + type: float64 units: m - note: "±10 m, resolution 0.01 m" + description: "±10 m, resolution 0.01 m" - name: sway - type: double + type: float64 units: m - note: "±10 m, resolution 0.01 m" + description: "±10 m, resolution 0.01 m" - protocol: SMCC standard: false sentences: - - sentence: PSMCC - fields: + - id: PSMCC + payload: - name: pitch - type: double + type: float64 units: deg - note: "±100 degs, resolution 0.001 degs" + description: "±100 degs, resolution 0.001 degs" - name: roll - type: double + type: float64 units: deg - note: "±100 degs, resolution 0.001 degs" + description: "±100 degs, resolution 0.001 degs" - name: yaw - type: double + type: float64 units: deg - note: "0-359.9 degs, resolution 0.1 degs" + description: "0-359.9 degs, resolution 0.1 degs" - name: surge - type: double + type: float64 units: m - note: "±10 m, resolution 0.01 m" + description: "±10 m, resolution 0.01 m" - name: sway - type: double + type: float64 units: m - note: "±10 m, resolution 0.01 m" + description: "±10 m, resolution 0.01 m" - name: heave - type: double + type: float64 units: m - note: "±10 m, resolution 0.01 m" + description: "±10 m, resolution 0.01 m" - name: surge_velocity - type: double + type: float64 units: m/s - note: "±100 m/s, resolution 0.01 m/s" + description: "±100 m/s, resolution 0.01 m/s" - name: sway_velocity - type: double + type: float64 units: m/s - note: "±100 m/s, resolution 0.01 m/s" + description: "±100 m/s, resolution 0.01 m/s" - name: heave_velocity - type: double + type: float64 units: m/s - note: "±100 m/s, resolution 0.01 m/s" + description: "±100 m/s, resolution 0.01 m/s" - name: acceleration_x - type: double + type: float64 units: m/s2 - note: "±100 m/s2, resolution 0.01 m/s2" + description: "±100 m/s2, resolution 0.01 m/s2" - name: acceleration_y - type: double + type: float64 units: m/s2 - note: "±100 m/s2, resolution 0.01 m/s2" + description: "±100 m/s2, resolution 0.01 m/s2" - name: acceleration_z - type: double + type: float64 units: m/s2 - note: "±100 m/s2, resolution 0.01 m/s2" + description: "±100 m/s2, resolution 0.01 m/s2" From 31513e2798c4bf114a352a2ec71f6840781b27e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3bal=20Contreras=20Rubio?= Date: Tue, 23 Jul 2024 14:13:55 +0200 Subject: [PATCH 3/4] update deps --- package-lock.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7e594e9..303c931 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10417,7 +10417,7 @@ }, "packages/nmea-parser": { "name": "@coremarine/nmea-parser", - "version": "1.7.0", + "version": "2.1.2", "license": "MIT", "dependencies": { "@gcornut/valibot-json-schema": "^0.31.0", @@ -10437,10 +10437,10 @@ }, "packages/nmea-parser-nodered": { "name": "@coremarine/nmea-parser-nodered", - "version": "1.0.2", + "version": "1.1.0", "license": "MIT", "dependencies": { - "@coremarine/nmea-parser": "^1.7.0" + "@coremarine/nmea-parser": "^2.1.2" }, "engines": { "node": ">=18.0.0" @@ -10451,7 +10451,7 @@ "version": "1.1.0", "license": "MIT", "dependencies": { - "@coremarine/nmea-parser": "^1.7.0", + "@coremarine/nmea-parser": "^2.1.2", "@schemasjs/valibot-numbers": "^1.0.13", "@schemasjs/validator": "^1.0.1" }, @@ -10459,7 +10459,7 @@ "node": ">= 18" }, "peerDependencies": { - "valibot": ">=0.31.0" + "valibot": ">=0.36.0" } }, "packages/norsub-emru-nodered": { From 7c199fc0d6fc5e2aca88d544e3358071e66b6c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3bal=20Contreras=20Rubio?= Date: Tue, 23 Jul 2024 14:22:15 +0200 Subject: [PATCH 4/4] NORSUB-eMRU: v2.0.0 update nmea-parser an a little refactor --- packages/norsub-emru/README.md | 39 ++- packages/norsub-emru/package.json | 10 +- packages/norsub-emru/src/constants.ts | 13 - packages/norsub-emru/src/index.ts | 1 - packages/norsub-emru/src/norsub.ts | 376 +++++++++++----------- packages/norsub-emru/src/parser.ts | 84 +---- packages/norsub-emru/src/status.ts | 116 ++++--- packages/norsub-emru/src/types.ts | 14 +- packages/norsub-emru/src/utils.ts | 2 +- packages/norsub-emru/tests/index.test.ts | 44 ++- packages/norsub-emru/tests/status.test.ts | 8 + packages/norsub-emru/vitest.config.ts | 3 +- 12 files changed, 325 insertions(+), 385 deletions(-) delete mode 100644 packages/norsub-emru/src/constants.ts diff --git a/packages/norsub-emru/README.md b/packages/norsub-emru/README.md index fef72c3..c326e78 100644 --- a/packages/norsub-emru/README.md +++ b/packages/norsub-emru/README.md @@ -1,14 +1,12 @@ # Norsub eMRU Parser -![npm (scoped)](https://img.shields.io/npm/v/%40coremarine/norsub-emru) -[![publish](https://github.com/core-marine-dev/norsub-emru/actions/workflows/publish.yml/badge.svg)](https://github.com/core-marine-dev/norsub-emru/actions/workflows/publish.yml) -![npm](https://img.shields.io/npm/dy/%40coremarine/norsub-emru) +![npm (scoped)](https://img.shields.io/npm/v/%40coremarine/norsub-emru) [![publish](https://github.com/core-marine-dev/norsub-emru/actions/workflows/publish.yml/badge.svg)](https://github.com/core-marine-dev/norsub-emru/actions/workflows/publish.yml) ![npm](https://img.shields.io/npm/dy/%40coremarine/norsub-emru) Library to read NMEA-like sentences of Norsub eMRU devices. It works same as [NMEA-Parser library](https://www.npmjs.com/package/@coremarine/nmea-parser) and it has the same API. The only nuance is it gives metadata of the device status if the sentence bring that info. To understand how it works, please look the info of [NMEA-Parser library](https://www.npmjs.com/package/@coremarine/nmea-parser). -The complete output with metadata it is shown below. +`PNORSUBx` sentences contains `status` property in the metada as ```typescript type Status = { @@ -73,20 +71,25 @@ type Status = { } } } +``` + +The complete output with metadata it is shown below. +```typescript type NMEASentence = { // Sentence ID - sentence: string, - // Array just with the data of each field (easier to just read data and not fields metadata) - data: Array, + id: string, // Array with ordered fields and their metadata - fields: Array<{ + payload: Array<{ name: string, - data: string | number | boolean | null, - metadata?: Status, + value: string | number | bigint | boolean | null, + type: 'string' | 'boolean' | 'uint8' | 'uint16' | 'uint32' | 'uint64' | 'int8' | 'int16' | 'int32' | 'int64' | 'float32' | 'float64' | 'unknown', units?: string, - note?: string, + description?: string, + metadata?: any }>, + // Metadata which can be computed fields from payload fields + metadata?: any, // Protocol information protocol: { name: string, @@ -94,12 +97,18 @@ type NMEASentence = { version: string, }, // UTC timestamp when the sentence was parsed - timestamp: number, + received: number, // Whole ASCII string sentence - raw: string, + sample: string, // Sentence checksum - checksum: number + checksum: { + sample: string, + value: number + } // Sentence talker - talker?: null | { id: string, description: string } + talker?: { + value: string, + description: string + } } ``` diff --git a/packages/norsub-emru/package.json b/packages/norsub-emru/package.json index f84b33a..9454600 100644 --- a/packages/norsub-emru/package.json +++ b/packages/norsub-emru/package.json @@ -1,6 +1,6 @@ { "name": "@coremarine/norsub-emru", - "version": "1.1.0", + "version": "2.0.0", "description": "Library to work with eMRU devices of NorSub company", "author": "Core Marine", "license": "MIT", @@ -45,19 +45,19 @@ }, "scripts": { "protocols": "node yaml-to-json.js ./protocols/norsub.yaml ./src/norsub.ts", - "build": "npm run protocols && npm run format && tsup", + "build": "npm run format && tsup", "lint": "ts-standard", "format": "ts-standard --fix", - "test": "npm run protocols && vitest", + "test": "vitest", "test:coverage": "vitest run --coverage" }, "dependencies": { - "@coremarine/nmea-parser": "^1.7.0", + "@coremarine/nmea-parser": "^2.1.2", "@schemasjs/valibot-numbers": "^1.0.13", "@schemasjs/validator": "^1.0.1" }, "peerDependencies": { - "valibot": ">=0.31.0" + "valibot": ">=0.36.0" }, "ts-standard": { "ignore": [ diff --git a/packages/norsub-emru/src/constants.ts b/packages/norsub-emru/src/constants.ts deleted file mode 100644 index 413b615..0000000 --- a/packages/norsub-emru/src/constants.ts +++ /dev/null @@ -1,13 +0,0 @@ -// GENERATE NUMBERS -export const UINT8_MAX = Uint8Array.from([0b1111_1111])[0] -export const UINT16_MAX = Uint16Array.from([0b1111_1111_1111_1111])[0] -export const UINT32_MAX = Uint32Array.from([0b1111_1111_1111_1111_1111_1111_1111_1111])[0] -// export const UINT64_MAX = Uint64Array.from([0b11111111_11111111_11111111_11111111_11111111_11111111_11111111_11111111])[0] - -export const [INT8_MIN, INT8_MAX] = Int8Array.from([0b1000_0000, 0b0111_1111]) -export const [INT16_MIN, INT16_MAX] = Int16Array.from([0b1000_0000_0000_0000, 0b0111_1111_1111_1111]) -export const [INT32_MIN, INT32_MAX] = Int32Array.from([0b1000_0000_0000_0000_0000_0000_0000_0000, 0b0111_1111_1111_1111_1111_1111_1111_1111]) -// export const [INT64_MIN, INT64_MAX] = Int64Array.from([0b10000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000, 0b01111111_11111111_11111111_11111111_11111111_11111111_11111111_11111111]) - -export const MAX_FLOAT = 999999999999999 -export const MIN_FLOAT = -999999999999999 diff --git a/packages/norsub-emru/src/index.ts b/packages/norsub-emru/src/index.ts index 506291b..bfaec11 100644 --- a/packages/norsub-emru/src/index.ts +++ b/packages/norsub-emru/src/index.ts @@ -1,4 +1,3 @@ export { NorsubParser } from './parser' -export * from './constants' export * from './schemas' export * from './types' diff --git a/packages/norsub-emru/src/norsub.ts b/packages/norsub-emru/src/norsub.ts index d73c918..8e93210 100644 --- a/packages/norsub-emru/src/norsub.ts +++ b/packages/norsub-emru/src/norsub.ts @@ -1,15 +1,17 @@ -export const PROTOCOLS = { +import type { ProtocolsFileContent } from '@coremarine/nmea-parser' + +export const NORSUB_SENTENCES: ProtocolsFileContent = { protocols: [ { protocol: 'GYROCOMPAS1', standard: false, sentences: [ { - sentence: 'HEHDT', - fields: [ + id: 'HEHDT', + payload: [ { name: 'heading', - type: 'float', + type: 'float32', units: 'deg' }, { @@ -19,33 +21,33 @@ export const PROTOCOLS = { ] }, { - sentence: 'PHTRO', - fields: [ + id: 'PHTRO', + payload: [ { name: 'pitch', - type: 'float', + type: 'float32', units: 'deg' }, { name: 'pitch_direction', type: 'string', - note: 'M bow up, P bow down' + description: 'M bow up, P bow down' }, { name: 'roll', - type: 'float', + type: 'float32', units: 'deg' }, { name: 'roll_direction', type: 'string', - note: 'M bow up, P bow down' + description: 'M bow up, P bow down' } ] }, { - sentence: 'PHINF', - fields: [ + id: 'PHINF', + payload: [ { name: 'status', type: 'string' @@ -59,8 +61,8 @@ export const PROTOCOLS = { standard: false, sentences: [ { - sentence: 'PNORSUB', - fields: [ + id: 'PNORSUB', + payload: [ { name: 'time', type: 'uint32', @@ -73,30 +75,30 @@ export const PROTOCOLS = { }, { name: 'roll', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'pitch', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'heading', - type: 'double', + type: 'float64', units: 'deg', - note: '0 - 360' + description: '0 - 360' }, { name: 'heave', - type: 'double', + type: 'float64', units: 'm', - note: 'z-down' + description: 'z-down' }, { name: 'status', type: 'uint32', - note: '0 - Error\n\n1 - No Error' + description: '0 - Error\n\n1 - No Error' } ] } @@ -107,8 +109,8 @@ export const PROTOCOLS = { standard: false, sentences: [ { - sentence: 'PNORSUB2', - fields: [ + id: 'PNORSUB2', + payload: [ { name: 'time', type: 'uint32', @@ -121,36 +123,36 @@ export const PROTOCOLS = { }, { name: 'roll', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'pitch', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'heading', - type: 'double', + type: 'float64', units: 'deg', - note: '0 - 360' + description: '0 - 360' }, { name: 'heave', - type: 'double', + type: 'float64', units: 'm', - note: 'z-down' + description: 'z-down' }, { name: 'heave_velocity', - type: 'double', + type: 'float64', units: 'm/s', - note: 'z-down' + description: 'z-down' }, { name: 'status', type: 'uint32', - note: '0 - Error\n\n1 - No Error' + description: '0 - Error\n\n1 - No Error' } ] } @@ -161,8 +163,8 @@ export const PROTOCOLS = { standard: false, sentences: [ { - sentence: 'PNORSUB6', - fields: [ + id: 'PNORSUB6', + payload: [ { name: 'time', type: 'uint32', @@ -175,86 +177,86 @@ export const PROTOCOLS = { }, { name: 'roll', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'pitch', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'heading', - type: 'double', + type: 'float64', units: 'deg', - note: '0 - 360' + description: '0 - 360' }, { name: 'surge', - type: 'double', + type: 'float64', units: 'm' }, { name: 'sway', - type: 'double', + type: 'float64', units: 'm' }, { name: 'heave', - type: 'double', + type: 'float64', units: 'm', - note: 'z-down' + description: 'z-down' }, { name: 'roll_rate', - type: 'double', + type: 'float64', units: 'deg/s' }, { name: 'pitch_rate', - type: 'double', + type: 'float64', units: 'deg/s' }, { name: 'yaw_rate', - type: 'double', + type: 'float64', units: 'deg/s' }, { name: 'surge_velocity', - type: 'double', + type: 'float64', units: 'm/s' }, { name: 'sway_velocity', - type: 'double', + type: 'float64', units: 'm/s' }, { name: 'heave_velocity', - type: 'double', + type: 'float64', units: 'm/s', - note: 'z-down' + description: 'z-down' }, { name: 'acceleration_x', - type: 'double', + type: 'float64', units: 'm/s2' }, { name: 'acceleration_y', - type: 'double', + type: 'float64', units: 'm/s2' }, { name: 'acceleration_z', - type: 'double', + type: 'float64', units: 'm/s2' }, { name: 'status', type: 'uint32', - note: '0 - Error\n\n1 - No Error' + description: '0 - Error\n\n1 - No Error' } ] } @@ -265,8 +267,8 @@ export const PROTOCOLS = { standard: false, sentences: [ { - sentence: 'PNORSUB7', - fields: [ + id: 'PNORSUB7', + payload: [ { name: 'time', type: 'uint32', @@ -279,110 +281,110 @@ export const PROTOCOLS = { }, { name: 'roll', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'pitch', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'heading', - type: 'double', + type: 'float64', units: 'deg', - note: '0 - 360' + description: '0 - 360' }, { name: 'surge', - type: 'double', + type: 'float64', units: 'm' }, { name: 'sway', - type: 'double', + type: 'float64', units: 'm' }, { name: 'heave', - type: 'double', + type: 'float64', units: 'm', - note: 'z-down' + description: 'z-down' }, { name: 'roll_rate', - type: 'double', + type: 'float64', units: 'deg/s' }, { name: 'pitch_rate', - type: 'double', + type: 'float64', units: 'deg/s' }, { name: 'yaw_rate', - type: 'double', + type: 'float64', units: 'deg/s' }, { name: 'surge_velocity', - type: 'double', + type: 'float64', units: 'm/s' }, { name: 'sway_velocity', - type: 'double', + type: 'float64', units: 'm/s' }, { name: 'heave_velocity', - type: 'double', + type: 'float64', units: 'm/s', - note: 'z-down' + description: 'z-down' }, { name: 'acceleration_x', - type: 'double', + type: 'float64', units: 'm/s2' }, { name: 'acceleration_y', - type: 'double', + type: 'float64', units: 'm/s2' }, { name: 'acceleration_z', - type: 'double', + type: 'float64', units: 'm/s2' }, { name: 'period_x', - type: 'double', + type: 'float64', units: 's' }, { name: 'period_y', - type: 'double', + type: 'float64', units: 's' }, { name: 'period_z', - type: 'double', + type: 'float64', units: 's' }, { name: 'amplitude_x', - type: 'double', + type: 'float64', units: 'm' }, { name: 'amplitude_y', - type: 'double', + type: 'float64', units: 'm' }, { name: 'amplitude_z', - type: 'double', + type: 'float64', units: 'm' }, { @@ -398,8 +400,8 @@ export const PROTOCOLS = { standard: false, sentences: [ { - sentence: 'PNORSUB7b', - fields: [ + id: 'PNORSUB7b', + payload: [ { name: 'time', type: 'uint32', @@ -412,110 +414,110 @@ export const PROTOCOLS = { }, { name: 'roll', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'pitch', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'heading', - type: 'double', + type: 'float64', units: 'deg', - note: '0 - 360' + description: '0 - 360' }, { name: 'surge', - type: 'double', + type: 'float64', units: 'm' }, { name: 'sway', - type: 'double', + type: 'float64', units: 'm' }, { name: 'heave', - type: 'double', + type: 'float64', units: 'm', - note: 'z-down' + description: 'z-down' }, { name: 'roll_rate', - type: 'double', + type: 'float64', units: 'deg/s' }, { name: 'pitch_rate', - type: 'double', + type: 'float64', units: 'deg/s' }, { name: 'yaw_rate', - type: 'double', + type: 'float64', units: 'deg/s' }, { name: 'surge_velocity', - type: 'double', + type: 'float64', units: 'm/s' }, { name: 'sway_velocity', - type: 'double', + type: 'float64', units: 'm/s' }, { name: 'heave_velocity', - type: 'double', + type: 'float64', units: 'm/s', - note: 'z-down' + description: 'z-down' }, { name: 'acceleration_x', - type: 'double', + type: 'float64', units: 'm/s2' }, { name: 'acceleration_y', - type: 'double', + type: 'float64', units: 'm/s2' }, { name: 'acceleration_z', - type: 'double', + type: 'float64', units: 'm/s2' }, { name: 'period_x', - type: 'double', + type: 'float64', units: 's' }, { name: 'period_y', - type: 'double', + type: 'float64', units: 's' }, { name: 'period_z', - type: 'double', + type: 'float64', units: 's' }, { name: 'amplitude_x', - type: 'double', + type: 'float64', units: 'm' }, { name: 'amplitude_y', - type: 'double', + type: 'float64', units: 'm' }, { name: 'amplitude_z', - type: 'double', + type: 'float64', units: 'm' }, { @@ -535,9 +537,9 @@ export const PROTOCOLS = { standard: false, sentences: [ { - sentence: 'PNORSUB8', + id: 'PNORSUB8', description: 'The whole regular attitude information from the MRU', - fields: [ + payload: [ { name: 'time', type: 'uint32', @@ -550,110 +552,110 @@ export const PROTOCOLS = { }, { name: 'roll', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'pitch', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'heading', - type: 'double', + type: 'float64', units: 'deg', - note: 'From 0 to 360' + description: 'From 0 to 360' }, { name: 'surge', - type: 'double', + type: 'float64', units: 'm' }, { name: 'sway', - type: 'double', + type: 'float64', units: 'm' }, { name: 'heave', - type: 'double', + type: 'float64', units: 'm', - note: 'z-down' + description: 'z-down' }, { name: 'roll_rate', - type: 'double', + type: 'float64', units: 'deg/s' }, { name: 'pitch_rate', - type: 'double', + type: 'float64', units: 'deg/s' }, { name: 'yaw_rate', - type: 'double', + type: 'float64', units: 'deg/s' }, { name: 'surge_velocity', - type: 'double', + type: 'float64', units: 'm/s' }, { name: 'sway_velocity', - type: 'double', + type: 'float64', units: 'm/s' }, { name: 'heave_velocity', - type: 'double', + type: 'float64', units: 'm/s', - note: 'z-down' + description: 'z-down' }, { name: 'acceleration_x', - type: 'double', + type: 'float64', units: 'm/s2' }, { name: 'acceleration_y', - type: 'double', + type: 'float64', units: 'm/s2' }, { name: 'acceleration_z', - type: 'double', + type: 'float64', units: 'm/s2' }, { name: 'period_x', - type: 'double', + type: 'float64', units: 's' }, { name: 'period_y', - type: 'double', + type: 'float64', units: 's' }, { name: 'period_z', - type: 'double', + type: 'float64', units: 's' }, { name: 'amplitude_x', - type: 'double', + type: 'float64', units: 'm' }, { name: 'amplitude_y', - type: 'double', + type: 'float64', units: 'm' }, { name: 'amplitude_z', - type: 'double', + type: 'float64', units: 'm' }, { @@ -669,16 +671,16 @@ export const PROTOCOLS = { standard: false, sentences: [ { - sentence: 'PRDID', - fields: [ + id: 'PRDID', + payload: [ { name: 'pitch', - type: 'double', + type: 'float64', units: 'deg' }, { name: 'roll', - type: 'double', + type: 'float64', units: 'deg' } ] @@ -690,23 +692,23 @@ export const PROTOCOLS = { standard: false, sentences: [ { - sentence: 'PTVG', - fields: [ + id: 'PTVG', + payload: [ { name: 'pitch', - type: 'number', + type: 'float64', units: 'deg', - note: 'Multiplied by 100, a [-] bow up / a [space] bow down' + description: 'Multiplied by 100, a [-] bow up / a [space] bow down' }, { name: 'roll', - type: 'number', + type: 'float64', units: 'deg', - note: 'Multiplied by 100, a [-] bow up / a [space] bow down' + description: 'Multiplied by 100, a [-] bow up / a [space] bow down' }, { name: 'heading', - type: 'number', + type: 'float64', units: 'deg' } ] @@ -718,23 +720,23 @@ export const PROTOCOLS = { standard: false, sentences: [ { - sentence: 'PRDID', - fields: [ + id: 'PRDID', + payload: [ { name: 'pitch', - type: 'double', + type: 'float64', units: 'deg', - note: 's if [+] is bow up / s is [-] if bow down, leading zeros' + description: 's if [+] is bow up / s is [-] if bow down, leading zeros' }, { name: 'roll', - type: 'double', + type: 'float64', units: 'deg', - note: 's if [+] is bow up / s is [-] if bow down, leading zeros' + description: 's if [+] is bow up / s is [-] if bow down, leading zeros' }, { name: 'heading', - type: 'double', + type: 'float64', units: 'deg' } ] @@ -746,37 +748,37 @@ export const PROTOCOLS = { standard: false, sentences: [ { - sentence: 'PSMCA', - fields: [ + id: 'PSMCA', + payload: [ { name: 'pitch', - type: 'double', + type: 'float64', units: 'deg', - note: '±100 degs, resolution 0.001 degs' + description: '±100 degs, resolution 0.001 degs' }, { name: 'roll', - type: 'double', + type: 'float64', units: 'deg', - note: '±100 degs, resolution 0.001 degs' + description: '±100 degs, resolution 0.001 degs' }, { name: 'heading', - type: 'double', + type: 'float64', units: 'm', - note: '±10 m, resolution 0.01 m' + description: '±10 m, resolution 0.01 m' }, { name: 'surge', - type: 'double', + type: 'float64', units: 'm', - note: '±10 m, resolution 0.01 m' + description: '±10 m, resolution 0.01 m' }, { name: 'sway', - type: 'double', + type: 'float64', units: 'm', - note: '±10 m, resolution 0.01 m' + description: '±10 m, resolution 0.01 m' } ] } @@ -787,79 +789,79 @@ export const PROTOCOLS = { standard: false, sentences: [ { - sentence: 'PSMCC', - fields: [ + id: 'PSMCC', + payload: [ { name: 'pitch', - type: 'double', + type: 'float64', units: 'deg', - note: '±100 degs, resolution 0.001 degs' + description: '±100 degs, resolution 0.001 degs' }, { name: 'roll', - type: 'double', + type: 'float64', units: 'deg', - note: '±100 degs, resolution 0.001 degs' + description: '±100 degs, resolution 0.001 degs' }, { name: 'yaw', - type: 'double', + type: 'float64', units: 'deg', - note: '0-359.9 degs, resolution 0.1 degs' + description: '0-359.9 degs, resolution 0.1 degs' }, { name: 'surge', - type: 'double', + type: 'float64', units: 'm', - note: '±10 m, resolution 0.01 m' + description: '±10 m, resolution 0.01 m' }, { name: 'sway', - type: 'double', + type: 'float64', units: 'm', - note: '±10 m, resolution 0.01 m' + description: '±10 m, resolution 0.01 m' }, { name: 'heave', - type: 'double', + type: 'float64', units: 'm', - note: '±10 m, resolution 0.01 m' + description: '±10 m, resolution 0.01 m' }, { name: 'surge_velocity', - type: 'double', + type: 'float64', units: 'm/s', - note: '±100 m/s, resolution 0.01 m/s' + description: '±100 m/s, resolution 0.01 m/s' }, { name: 'sway_velocity', - type: 'double', + type: 'float64', units: 'm/s', - note: '±100 m/s, resolution 0.01 m/s' + description: '±100 m/s, resolution 0.01 m/s' }, { name: 'heave_velocity', - type: 'double', + type: 'float64', units: 'm/s', - note: '±100 m/s, resolution 0.01 m/s' + description: '±100 m/s, resolution 0.01 m/s' }, { name: 'acceleration_x', - type: 'double', + type: 'float64', units: 'm/s2', - note: '±100 m/s2, resolution 0.01 m/s2' + description: '±100 m/s2, resolution 0.01 m/s2' }, { name: 'acceleration_y', - type: 'double', + type: 'float64', units: 'm/s2', - note: '±100 m/s2, resolution 0.01 m/s2' + description: '±100 m/s2, resolution 0.01 m/s2' }, { name: 'acceleration_z', - type: 'double', + type: 'float64', units: 'm/s2', - note: '±100 m/s2, resolution 0.01 m/s2' + description: '±100 m/s2, resolution 0.01 m/s2' } ] } diff --git a/packages/norsub-emru/src/parser.ts b/packages/norsub-emru/src/parser.ts index 612c859..c29679f 100644 --- a/packages/norsub-emru/src/parser.ts +++ b/packages/norsub-emru/src/parser.ts @@ -1,86 +1,36 @@ -import type { FieldParsed, NMEALike, NMEASentence, ProtocolOutput, ProtocolsInput, Sentence } from '@coremarine/nmea-parser' +import type { Field, NMEASentence, Uint16, Uint32 } from '@coremarine/nmea-parser' import { MAX_CHARACTERS, NMEAParser, ProtocolsInputSchema } from '@coremarine/nmea-parser' -import { PROTOCOLS } from './norsub' -import { BooleanSchema, UnsignedIntegerSchema } from './schemas' +import { NORSUB_SENTENCES } from './norsub' import { getStatus } from './status' -import { NorsubSentence } from './types' -import { getUint32 } from './utils' - -export class NorsubParser { - // Parser - protected _parser: NMEAParser = new NMEAParser() - // Memory - Buffer - get memory (): typeof this._parser.memory { return this._parser.memory } - set memory (mem: boolean) { this._parser.memory = BooleanSchema.parse(mem) } - get bufferLimit (): typeof this._parser.bufferLimit { return this._parser.bufferLimit } - set bufferLimit (limit: number) { this._parser.bufferLimit = UnsignedIntegerSchema.parse(limit) } +import { StatusInput } from './types' +export class NorsubParser extends NMEAParser { constructor (memory: boolean = true, limit: number = MAX_CHARACTERS) { - this.memory = memory - this.bufferLimit = limit - const parsed = ProtocolsInputSchema.parse(PROTOCOLS) + super(memory, limit) + const parsed = ProtocolsInputSchema.parse(NORSUB_SENTENCES) this.addProtocols(parsed) } - private getStatusIndexes (fields: FieldParsed[]): number[] { - const indexes: number[] = [] - fields.forEach((field, index) => { - if (field.name.includes('status')) { - indexes.push(index) - } - }) - return indexes - } - - private addStatus (nmea: NMEASentence): NorsubSentence { - const indexes: number[] = this.getStatusIndexes(nmea.fields) - const numberOfIndex = indexes.length - if (![1, 2].includes(numberOfIndex)) { return nmea } - const sentence: NorsubSentence = { ...nmea } - // Status - if (numberOfIndex === 1) { - const index = indexes[0] - const data = sentence.fields[index].data as number - const status = getStatus({ status: data }) - if (status !== null) { - sentence.fields[index].metadata = status - } - return sentence - } - // Status_A + Status_B - const [indexA, indexB] = indexes - const statusA = sentence.fields[indexA].data as number - const statusB = sentence.fields[indexB].data as number - const status = getStatus({ status_a: statusA, status_b: statusB }) - if (status !== null) { - const statusNumber = getUint32(statusA, statusB) - sentence.data.push(statusNumber) - sentence.fields.push({ - name: 'status', - type: 'uint32', - data: statusNumber, - metadata: status - }) + private addStatus (sentence: NMEASentence): NMEASentence { + const input: StatusInput = sentence.id.includes('b') + ? { status_a: sentence.payload.at(-2)?.value as Uint16, status_b: sentence.payload.at(-1)?.value as Uint16 } + : { status: sentence.payload.at(-1)?.value as Uint32 } + const status = getStatus(input) + sentence.metadata = { status } + if (input.status !== undefined) { + (sentence.payload.at(-1) as Field).metadata = { status } } return sentence } - parseData (data: string): NorsubSentence[] { - const sentences = this._parser.parseData(data) + parseData (data: string): NMEASentence[] { + const sentences = super.parseData(data) if (sentences.length === 0) return sentences return sentences.map(sentence => { - if (sentence.protocol.name.includes('NORSUB')) { + if (sentence.id.includes('PNORSUB')) { return this.addStatus(sentence) } return sentence }) } - - addProtocols (protocols: ProtocolsInput): void { this._parser.addProtocols(protocols) } - - getProtocols (): ProtocolOutput[] { return this._parser.getProtocols() } - - getSentence (id: string): Sentence { return this._parser.getSentence(id) } - - getFakeSentenceByID (id: string): NMEALike { return this._parser.getFakeSentenceByID(id) as NMEALike } } diff --git a/packages/norsub-emru/src/status.ts b/packages/norsub-emru/src/status.ts index d8c14a8..8390814 100644 --- a/packages/norsub-emru/src/status.ts +++ b/packages/norsub-emru/src/status.ts @@ -1,4 +1,4 @@ -import { Uint32 } from '@schemasjs/valibot-numbers' +import type { Uint32 } from '@schemasjs/valibot-numbers' import { StatusInputSchema } from './schemas' import { Status, StatusInput } from './types' import { getBit, getUint32 } from './utils' @@ -38,70 +38,68 @@ import { getBit, getUint32 } from './utils' * 30 - AID_VERTICAL_VALID - 1 = vertical position is valid and used in the observer. * 31 - AID_HORIZONTAL_VALID - 1 = horizontal position is valid and used in the observer. **/ -const _getStatus = (input: Uint32): Status => { - return { - main: { - ok: getBit(input, 0), - health: getBit(input, 1) +const _getStatus = (input: Uint32): Status => ({ + main: { + ok: getBit(input, 0), + health: getBit(input, 1) + }, + system: { + ok: getBit(input, 2), + health: getBit(input, 3), + synchronized: { + time: getBit(input, 4), + clock: getBit(input, 5) }, - system: { - ok: getBit(input, 2), - health: getBit(input, 3), - synchronized: { - time: getBit(input, 4), - clock: getBit(input, 5) - }, - cpu: getBit(input, 6) + cpu: getBit(input, 6) + }, + sensor: { + ok: getBit(input, 7), + health: getBit(input, 8), + limits: getBit(input, 9), + environmental: { + vibration: getBit(input, 10), + temperature: getBit(input, 11) + } + }, + algorithms: { + ok: getBit(input, 12), + health: getBit(input, 13), + initialization: { + observer: getBit(input, 14), + heading: getBit(input, 15) + }, + roll_pitch: { + ok: getBit(input, 16), + health: getBit(input, 17) }, - sensor: { - ok: getBit(input, 7), - health: getBit(input, 8), - limits: getBit(input, 9), - environmental: { - vibration: getBit(input, 10), - temperature: getBit(input, 11) - } + heading: { + ok: getBit(input, 18), + health: getBit(input, 19) }, - algorithms: { - ok: getBit(input, 12), - health: getBit(input, 13), - initialization: { - observer: getBit(input, 14), - heading: getBit(input, 15) - }, - roll_pitch: { - ok: getBit(input, 16), - health: getBit(input, 17) - }, - heading: { - ok: getBit(input, 18), - health: getBit(input, 19) - }, - surge_sway: { - ok: getBit(input, 20), - health: getBit(input, 21) - }, - heave: { - ok: getBit(input, 22), - health: getBit(input, 23) - } + surge_sway: { + ok: getBit(input, 20), + health: getBit(input, 21) }, - aiding: { - received: { - position: getBit(input, 24), - velocity: getBit(input, 25), - heading: getBit(input, 26) - }, - valid: { - position: getBit(input, 27), - velocity: getBit(input, 28), - heading: getBit(input, 29), - vertical: getBit(input, 30), - horizontal: getBit(input, 31) - } + heave: { + ok: getBit(input, 22), + health: getBit(input, 23) + } + }, + aiding: { + received: { + position: getBit(input, 24), + velocity: getBit(input, 25), + heading: getBit(input, 26) + }, + valid: { + position: getBit(input, 27), + velocity: getBit(input, 28), + heading: getBit(input, 29), + vertical: getBit(input, 30), + horizontal: getBit(input, 31) } } -} +}) export const getStatus = (input: StatusInput): Status | null => { if (!StatusInputSchema.is(input)) { return null } diff --git a/packages/norsub-emru/src/types.ts b/packages/norsub-emru/src/types.ts index 7c8130e..61b1dfc 100644 --- a/packages/norsub-emru/src/types.ts +++ b/packages/norsub-emru/src/types.ts @@ -1,4 +1,4 @@ -import type { Data, FieldParsed, NMEASentence } from '@coremarine/nmea-parser' +// import type { NMEASentence } from '@coremarine/nmea-parser' import { StatusInputSchema, StatusSchema } from './schemas' /** STATUS @@ -36,16 +36,6 @@ import { StatusInputSchema, StatusSchema } from './schemas' * 30 - AID_VERTICAL_VALID - 1 = vertical position is valid and used in the observer. * 31 - AID_HORIZONTAL_VALID - 1 = horizontal position is valid and used in the observer. **/ + export type Status = ReturnType export type StatusInput = ReturnType - -export type NorsubFieldData = Data | Status - -export type NorsubField = FieldParsed & { metadata?: object } - -export type NMEAWithoutFieldsData = Omit - -export type NorsubSentence = NMEAWithoutFieldsData & { - fields: NorsubField[] - data: NorsubFieldData[] -} diff --git a/packages/norsub-emru/src/utils.ts b/packages/norsub-emru/src/utils.ts index a5cf26f..9b9811d 100644 --- a/packages/norsub-emru/src/utils.ts +++ b/packages/norsub-emru/src/utils.ts @@ -1,4 +1,4 @@ -import { Uint16, Uint32 } from '@schemasjs/valibot-numbers' +import type { Uint16, Uint32 } from '@schemasjs/valibot-numbers' export const getUint32 = (lsb: Uint16, msb: Uint16): Uint32 => Uint32Array.from([(msb << 16) | lsb])[0] diff --git a/packages/norsub-emru/tests/index.test.ts b/packages/norsub-emru/tests/index.test.ts index b379e03..cf46cfd 100644 --- a/packages/norsub-emru/tests/index.test.ts +++ b/packages/norsub-emru/tests/index.test.ts @@ -1,41 +1,37 @@ import { describe, test, expect } from 'vitest' -import type { ProtocolOutput, Sentence } from '@coremarine/nmea-parser' +import type { NMEALike } from '@coremarine/nmea-parser' import { NorsubParser } from '../src' -import { StatusSchema } from '../src/schemas' -const PROTOCOLS = ['NMEA', 'GYROCOMPAS1', 'NORSUB', 'NORSUB2', 'NORSUB6', 'NORSUB7', 'NORSUB7b', 'NORSUB8', 'NORSUB PRDID', 'Tokimek PTVG', 'RDI ADCP', 'SMCA', 'SMCC'] +const PROTOCOLS = ['NMEA', 'GYROCOMPAS1', 'NORSUB', 'NORSUB2', 'NORSUB6', 'NORSUB7', 'NORSUB7b', 'NORSUB8', 'Tokimek PTVG', 'RDI ADCP', 'SMCA', 'SMCC'] +// const PROTOCOLS = ['NMEA', 'GYROCOMPAS1', 'NORSUB', 'NORSUB2', 'NORSUB6', 'NORSUB7', 'NORSUB7b', 'NORSUB8', 'NORSUB PRDID', 'Tokimek PTVG', 'RDI ADCP', 'SMCA', 'SMCC'] describe('Parser', () => { test('Default constructor', () => { const parser = new NorsubParser() + // Memory true expect(parser.memory).toBeTruthy() - const parserProtocols = parser.getProtocols() - parserProtocols.forEach(({ protocol }) => { - expect(PROTOCOLS.includes(protocol)).toBeTruthy() + // Protocols + const parserProtocols = parser.getSentencesByProtocol() + PROTOCOLS.forEach(protocol => { + expect(protocol in parserProtocols).toBeTruthy() }) }) test('Norsub Sentences', () => { const parser = new NorsubParser() - const output = parser.getProtocols() - output.forEach((element: ProtocolOutput) => { - if (!element.protocol.includes('NMEA')) { - element.sentences.forEach(sentence => { - const norsubSentence: Sentence = parser.getSentence(sentence) - expect(norsubSentence).not.toBeNull() - if (norsubSentence !== null) { - const fake = parser.getFakeSentenceByID(norsubSentence.sentence) - expect(fake).not.toBeNull() - if (fake !== null) { - const parsed = parser.parseData(fake) - expect(parsed).toHaveLength(1) - const norsub = parsed[0] - if (norsub.sentence.includes('PNORSUB')) { - const statusField = (norsub.fields.slice(-1))[0].metadata - expect(StatusSchema.is(statusField)).toBeTruthy() - } - } + const protocols = parser.getSentencesByProtocol() + Object.keys(protocols).forEach(keyProtocol => { + if (!keyProtocol.includes('NMEA')) { + protocols[keyProtocol].forEach(storedSentence => { + const fakeSentence = parser.getFakeSentenceByID(storedSentence.id) + expect(fakeSentence).not.toBeNull() + const parsedFakeSentece = parser.parseData(fakeSentence as NMEALike) + expect(parsedFakeSentece).toHaveLength(1) + const norsubSentence = parsedFakeSentece[0] + if (norsubSentence.id.includes('PNORSUB')) { + expect(norsubSentence.metadata).not.toBeUndefined() + expect(norsubSentence.metadata.status).not.toBeUndefined() } }) } diff --git a/packages/norsub-emru/tests/status.test.ts b/packages/norsub-emru/tests/status.test.ts index c5d11fc..2063955 100644 --- a/packages/norsub-emru/tests/status.test.ts +++ b/packages/norsub-emru/tests/status.test.ts @@ -127,7 +127,15 @@ test('null Status', () => { const status_a: Uint16 = Uint32Array.from([0b0_1010_1010_1010_1010])[0] const status_b: Uint16 = Uint32Array.from([0b0_1010_1010_1010_1010])[0] expect(getStatus({})).toBeNull() + // @ts-expect-error expect(getStatus({ status: 'hola '})).toBeNull() expect(getStatus({ status_a })).toBeNull() expect(getStatus({ status_b })).toBeNull() +}) + +test('nanai', () => { + // const status = 892941617 + const status = 1036236 + const parsed = getStatus({ status }) + expect(parsed).not.toBeNull() }) \ No newline at end of file diff --git a/packages/norsub-emru/vitest.config.ts b/packages/norsub-emru/vitest.config.ts index df8f570..67ea2d6 100644 --- a/packages/norsub-emru/vitest.config.ts +++ b/packages/norsub-emru/vitest.config.ts @@ -8,7 +8,8 @@ export default defineConfig({ '**/*/constants.ts', '**/*/types.ts', 'dist/*', - 'yaml-to-json.js' + 'yaml-to-json.js', + '*.config.ts' ] } }