@signalk/nmea0183-signalk
Advanced tools
Comparing version 3.7.0 to 3.9.0
@@ -17,3 +17,3 @@ /** | ||
const debug = require('debug')('signalk-parser-nmea0183/APB') | ||
const debug = require('debug')('signalk-parser-nmea0183/BOD') | ||
const utils = require('@signalk/nmea0183-utilities') | ||
@@ -20,0 +20,0 @@ |
@@ -17,3 +17,3 @@ /** | ||
const debug = require('debug')('signalk-parser-nmea0183/APB') | ||
const debug = require('debug')('signalk-parser-nmea0183/BWC') | ||
const utils = require('@signalk/nmea0183-utilities') | ||
@@ -20,0 +20,0 @@ |
@@ -17,3 +17,3 @@ /** | ||
const debug = require('debug')('signalk-parser-nmea0183/APB') | ||
const debug = require('debug')('signalk-parser-nmea0183/BWR') | ||
const utils = require('@signalk/nmea0183-utilities') | ||
@@ -20,0 +20,0 @@ |
@@ -19,3 +19,3 @@ 'use strict' | ||
const debug = require('debug')('signalk-parser-nmea0183/DBT') | ||
const debug = require('debug')('signalk-parser-nmea0183/HDM') | ||
const utils = require('@signalk/nmea0183-utilities') | ||
@@ -59,2 +59,2 @@ | ||
return delta | ||
} | ||
} |
@@ -17,3 +17,3 @@ /** | ||
const debug = require('debug')('signalk-parser-nmea0183/APB') | ||
const debug = require('debug')('signalk-parser-nmea0183/HSC') | ||
const utils = require('@signalk/nmea0183-utilities') | ||
@@ -20,0 +20,0 @@ |
@@ -16,4 +16,7 @@ module.exports = { | ||
'PNKEP': require('./proprietary/PNKEP.js'), | ||
'PSMDST': require('./proprietary/PSMDST.js'), | ||
'MDA': require('./MDA.js'), | ||
'MTA': require('./MTA.js'), | ||
'MTW': require('./MTW.js'), | ||
'MWD': require('./MWD.js'), | ||
'MWV': require('./MWV.js'), | ||
@@ -33,2 +36,3 @@ 'RMB': require('./RMB.js'), | ||
'VWR': require('./VWR.js'), | ||
'VWT': require('./VWT.js'), | ||
'ZDA': require('./ZDA.js'), | ||
@@ -35,0 +39,0 @@ 'XTE': require('./XTE.js'), |
@@ -17,3 +17,3 @@ /** | ||
const debug = require('debug')('signalk-parser-nmea0183/APB') | ||
const debug = require('debug')('signalk-parser-nmea0183/XTE') | ||
const utils = require('@signalk/nmea0183-utilities') | ||
@@ -20,0 +20,0 @@ |
@@ -22,7 +22,11 @@ 'use strict' | ||
const utils = require('@signalk/nmea0183-utilities') | ||
const hooks = require('../hooks') | ||
const defaultHooks = require('../hooks') | ||
const pkg = require('../package.json') | ||
const debug = require('debug')('signalk-parser-nmea0183') | ||
class Parser { | ||
constructor (opts) { | ||
constructor(opts = { | ||
emitPropertyValue: () => undefined, | ||
onPropertyValues: () => undefined | ||
}) { | ||
this.options = (typeof opts === 'object' && opts !== null) ? opts : {} | ||
@@ -38,5 +42,18 @@ if (!Object.keys(this.options).includes('validateChecksum')) { | ||
this.license = pkg.license | ||
this.hooks = { ...defaultHooks } | ||
opts.onPropertyValues && opts.onPropertyValues('nmea0183sentenceParser', propertyValues_ => { | ||
if (propertyValues_ === undefined) { | ||
return | ||
} | ||
const propValues = propertyValues_.filter(v => v) | ||
.map(propValue => propValue.value) | ||
.filter(isValidSentenceParserEntry) | ||
.map(({ sentence, parser }) => { | ||
debug(`setting custom parser ${sentence}`) | ||
this.hooks[sentence] = parser }) | ||
}) | ||
} | ||
parse (sentence) { | ||
parse(sentence) { | ||
let tags = getTagBlock(sentence) | ||
@@ -56,3 +73,3 @@ | ||
let valid = utils.valid(sentence, this.options.validateChecksum) | ||
if (valid === false) { | ||
@@ -90,4 +107,4 @@ throw new Error(`Sentence "${sentence.trim()}" is invalid`) | ||
if (typeof hooks[internalId] === 'function') { | ||
const result = hooks[internalId]({ | ||
if (typeof this.hooks[internalId] === 'function') { | ||
const result = this.hooks[internalId]({ | ||
id, | ||
@@ -105,2 +122,10 @@ sentence, | ||
function isValidSentenceParserEntry(entry) { | ||
const isValid = typeof entry.sentence === 'string' && typeof entry.parser === 'function' | ||
if (!isValid) { | ||
console.error(`Invalid sentence parser entry:${JSON.stringify(entry)}`) | ||
} | ||
return isValid | ||
} | ||
module.exports = Parser |
@@ -25,3 +25,3 @@ 'use strict' | ||
const _source = update.source | ||
const _source = update.source || '' | ||
const tagSentence = _source.split(':')[1] | ||
@@ -28,0 +28,0 @@ let tagTalker = _source.split(':')[0] |
{ | ||
"name": "@signalk/nmea0183-signalk", | ||
"version": "3.7.0", | ||
"version": "3.9.0", | ||
"description": "A node.js/javascript parser for NMEA0183 sentences. Sentences are parsed to Signal K format.", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"deploy": "npm test && npm run release && npm publish --access public --scope @signalk .", | ||
"create-release": "github-create-release --owner signalk --repository signalk-parser-nmea0183", | ||
"create-release": "github-create-release --owner signalk --repository nmea0183-signalk", | ||
"release": "git tag -d v$npm_package_version && git tag v$npm_package_version && git push --tags && git push && npm run create-release" | ||
@@ -29,4 +29,4 @@ }, | ||
"dependencies": { | ||
"@signalk/nmea0183-utilities": "^0.7.0", | ||
"@signalk/signalk-schema": "^1.1.1", | ||
"@signalk/nmea0183-utilities": "^0.8.0", | ||
"@signalk/signalk-schema": "1.6.0", | ||
"ggencoder": "^1.0.4", | ||
@@ -41,3 +41,3 @@ "moment-timezone": "^0.5.21", | ||
"debug": "^4.0.1", | ||
"mocha": "^6.1.3" | ||
"mocha": "^8.1.3" | ||
}, | ||
@@ -44,0 +44,0 @@ "repository": { |
@@ -1,9 +0,5 @@ | ||
# signalk-parser-nmea0183 | ||
# @signalk/nmea0183-signalk | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/SignalK/signalk-parser-nmea0183.svg)](https://greenkeeper.io/) | ||
> A node.js/JavaScript parser of NMEA0183 sentences. Sentences are parsed to [Signal K delta](http://signalk.org/specification/master/data_model.html#delta-format) format. | ||
[![Build Status](https://travis-ci.org/SignalK/signalk-parser-nmea0183.svg?branch=development)](https://travis-ci.org/SignalK/signalk-parser-nmea0183) | ||
> A node.js/javascript parser of NMEA0183 sentences. Sentences are parsed to [Signal K delta](http://signalk.org/specification/master/data_model.html#delta-format) format. | ||
## Supported sentences | ||
@@ -30,3 +26,5 @@ | ||
- [MDA - Meteorological Composite](https://gpsd.gitlab.io/gpsd/NMEA.html#_mda_meteorilogical_composite) | ||
- [MTA - Mean Temperature of Air](https://www.nmea.org/Assets/100108_nmea_0183_sentences_not_recommended_for_new_designs.pdf) | ||
- [MTW - Mean Temperature of Water](https://gpsd.gitlab.io/gpsd/NMEA.html#_mtw_mean_temperature_of_water) | ||
- [MWD - Wind Speed and Direction](https://lists.nongnu.org/archive/html/gpsd-dev/2012-04/msg00048.html) | ||
- [MWV - Wind Speed and Angle](https://gpsd.gitlab.io/gpsd/NMEA.html#_mwv_wind_speed_and_angle) | ||
@@ -46,8 +44,18 @@ - [RMB - Recommended Minimum Navigation Information](https://gpsd.gitlab.io/gpsd/NMEA.html#_rmb_recommended_minimum_navigation_information) | ||
- [VWR - Relative Wind Speed and Angle](https://gpsd.gitlab.io/gpsd/NMEA.html#_vwr_relative_wind_speed_and_angle) | ||
- [VWT - True Wind Angle and Speed](https://lists.nongnu.org/archive/html/gpsd-dev/2012-04/msg00048.html) | ||
- [ZDA - UTC day, month, and year, and local time zone offset](https://gpsd.gitlab.io/gpsd/NMEA.html#_zda_time_amp_date_utc_day_month_year_and_local_time_zone) | ||
- [XTE - Cross-track Error](https://www.tronico.fi/OH6NT/docs/NMEA0183.pdf) | ||
- [ZDA - UTC day, month, and year, and local time zone offset](http://www.trimble.com/oem_receiverhelp/v4.44/en/NMEA-0183messages_ZDA.html) | ||
- [Custom Sentences](#custom-sentences) | ||
**Note:** *at this time, unknown sentences will be silently discarded.* | ||
### Custom Sentences | ||
You can add custom sentence parsers via the [Signal K Server plugin mechanism](https://github.com/SignalK/signalk-server/blob/master/SERVERPLUGINS.md). A plugin can register custom parsers by emitting `nmea0183sentenceParser` PropertyValues with a value that has the properties | ||
- sentence: the three letter id of the sentence | ||
- parser: a function with the signature `({ id, sentence, parts, tags }, session) => delta` | ||
See [custom-sentence-plugin](./custom-sentence-plugin) for an example. | ||
## Usage | ||
@@ -83,4 +91,2 @@ | ||
This parser has (limited) support of [NMEA0183v4 tag blocks](http://www.nmea.org/Assets/may%2009%20rtcm%200183_v400.pdf) (e.g. `\s:airmar dst800,c:1438489697*13\$SDDBT,17.0,f,5.1,M,2.8,F*3E`). | ||
Keep in mind that, since NMEA uses the backslash `\` as the start and end character of the tag block, you need to escape these characters *before* parsing them. | ||
This is necessary because javascript treats the backslash as the escape character causing it not to be included in the resulting string (unless escaped). | ||
@@ -94,2 +100,3 @@ Example: | ||
try { | ||
// backslash starts an escape sequence in JavaScript code, so they need to be double in string literals | ||
const delta = parser.parse('\\s:airmar dst800,c:1438489697*13\\$SDDBT,17.0,f,5.1,M,2.8,F*3E') | ||
@@ -96,0 +103,0 @@ if (delta !== null) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
256883
119
6674
149
0
+ Added@apidevtools/json-schema-ref-parser@9.0.9(transitive)
+ Added@signalk/nmea0183-utilities@0.8.1(transitive)
+ Added@signalk/signalk-schema@1.6.0(transitive)
+ Addedjson-schema-ref-parser@9.0.9(transitive)
- Removed@apidevtools/json-schema-ref-parser@9.1.2(transitive)
- Removed@signalk/nmea0183-utilities@0.7.0(transitive)
- Removed@signalk/signalk-schema@1.7.2(transitive)