Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@signalk/nmea0183-signalk

Package Overview
Dependencies
Maintainers
4
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@signalk/nmea0183-signalk - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

package-lock.json

26

hooks/HDG.js

@@ -42,3 +42,16 @@ 'use strict'

if (isEmpty(parts[0]) || isEmpty(parts[3]) || isEmpty(parts[4])) {
const values = []
if (!isEmpty(parts[0])) {
values.push({
path: 'navigation.headingMagnetic',
value: utils.transform(utils.float(parts[0]), 'deg', 'rad')
})
}
if (!(isEmpty(parts[3]) || isEmpty(parts[4]))) {
values.push({
path: 'navigation.magneticVariation',
value: utils.transform(utils.float(parts[3]), 'deg', 'rad') * (parts[4] === 'E' ? 1 : -1)
})
}
if (!values.length) {
return Promise.resolve(null)

@@ -52,12 +65,3 @@ }

timestamp: tags.timestamp,
values: [
{
path: 'navigation.headingMagnetic',
value: utils.transform(utils.float(parts[0]), 'deg', 'rad')
},
{
path: 'navigation.magneticVariation',
value: utils.transform(utils.float(parts[3]), 'deg', 'rad') * (parts[4] === 'E' ? 1 : -1)
}
]
values
}

@@ -64,0 +68,0 @@ ],

@@ -22,3 +22,19 @@ 'use strict'

const Decoder = require('ggencoder').AisDecode
const schema = require('@signalk/signalk-schema')
const stateMapping = {
0: 'motoring',
1: 'anchored',
2: 'not under command',
3: 'restricted manouverability',
4: 'constrained by draft',
5: 'moored',
6: 'aground',
7: 'fishing',
8: 'sailing',
9: 'hazardous material high speed',
10: 'hazardous material wing in ground',
14: 'ais-sart'
};
module.exports = function (parser, input) {

@@ -83,2 +99,92 @@ try {

if ( data.length ) {
values.push({
path: 'design.length',
value: data.length
})
}
if ( data.width ) {
values.push({
path: 'design.beam',
value: data.width
})
}
if ( data.draught ) {
values.push({
path: 'design.draft.maximum',
value: data.draught
})
}
if ( data.dimA ) {
values.push({
path: 'sensors.ais.fromBow',
value: data.dimA
})
}
if ( data.dimD && data.width ) {
var fromCenter;
if (data.dimD > data.width / 2) {
fromCenter = (data.dimD - data.width / 2) * -1
} else {
fromCenter = data.width / 2 - data.dimD
}
values.push({
path: 'sensors.ais.fromCenter',
value: fromCenter
})
}
if ( data.navstatus ) {
var state = stateMapping[data.navstatus]
if ( typeof state !== 'undefined' ) {
values.push({
path: 'navigation.state',
value: state
})
}
}
if ( data.destination ) {
values.push({
path: 'navigation.destination.commonName',
value: data.destination
})
}
if ( data.callsign ) {
values.push({
path: 'communication.callsignVhf',
value: data.callsign
})
}
var contextPrefix = "vessels."
if ( data.aidtype ) {
contextPrefix = "atons."
var atonType = schema.getAtonTypeName(data.aidtype)
if ( typeof atonType !== 'undefined' ) {
values.push({
path: 'atonType',
value: { "id": data.aidtype, "name": atonType }
})
}
}
if ( data.cargo )
{
var typeName = schema.getAISShipTypeName(data.cargo)
if ( typeof typeName !== 'undefined' ) {
values.push({
path: 'design.aisShipType',
value: { "id": data.cargo, "name": typeName }
})
}
}
if (values.length === 0) {

@@ -89,3 +195,3 @@ return Promise.resolve(null)

const delta = {
context: `vessels.urn:mrn:imo:mmsi:${data.mmsi}`,
context: contextPrefix + `urn:mrn:imo:mmsi:${data.mmsi}`,
updates: [

@@ -92,0 +198,0 @@ {

@@ -39,2 +39,6 @@ 'use strict'

parse (sentence) {
if (typeof sentence === 'string' && sentence.trim().length > 0) {
this.emit('nmea0183', sentence.trim())
}
return parseSentence(this, sentence)

@@ -41,0 +45,0 @@ .then(result => {

@@ -43,7 +43,2 @@ 'use strict'

// The (MTK) CRC check doesn't report "invalid" if the input string contains the "<" character, even though it actually isn't valid.
if (sentence.includes('<')) {
valid = false
}
if (valid === false) {

@@ -50,0 +45,0 @@ emitter.emit('warning', { message: `Sentence "${sentence.trim()}" is invalid` })

{
"name": "@signalk/nmea0183-signalk",
"version": "2.0.2",
"version": "2.0.3",
"description": "A node.js/javascript parser for NMEA0183 sentences. Sentences are parsed to Signal K format.",

@@ -27,3 +27,3 @@ "main": "index.js",

"@signalk/nmea0183-utilities": "^0.4.0",
"@signalk/signalk-schema": "0.0.1-6",
"@signalk/signalk-schema": "0.0.1-11",
"ggencoder": "^0.1.18",

@@ -30,0 +30,0 @@ "moment": "^2.17.1",

@@ -33,11 +33,2 @@ # signalk-parser-nmea0183

### Todo
- [x] Sentence support (parity with old parser)
- [x] Tests for every sentence
- [x] Update readme
- [ ] Include parsing to full Signal K format
- [ ] Extend sentence support beyond current set (continuing)
### Usage

@@ -44,0 +35,0 @@

@@ -39,2 +39,14 @@ /**

it('Sentence with just heading works', done => {
const parser = new Parser
parser.on('signalk:delta', delta => {
delta.updates[0].values.should.contain.an.item.with.property('path', 'navigation.headingMagnetic')
delta.updates[0].values[0].value.should.be.closeTo((51.5 / 180 * Math.PI), 0.005)
done()
})
parser.parse('$HCHDG,51.5,,,,*73').catch(e => done(e))
})
it('Doesn\'t choke on empty sentences', done => {

@@ -41,0 +53,0 @@ new Parser()

@@ -23,2 +23,19 @@ 'use strict'

delta.updates[0].values[1].value.name.should.equal('UTGERDINA')
delta.updates[0].values[2].path.should.equal('design.length')
delta.updates[0].values[2].value.should.equal(641)
delta.updates[0].values[3].path.should.equal('design.beam')
delta.updates[0].values[3].value.should.equal(65)
delta.updates[0].values[4].path.should.equal('design.draft.maximum')
delta.updates[0].values[4].value.should.equal(14.1)
delta.updates[0].values[5].path.should.equal('sensors.ais.fromBow')
delta.updates[0].values[5].value.should.equal(256)
delta.updates[0].values[6].path.should.equal('sensors.ais.fromCenter')
delta.updates[0].values[6].value.should.equal(-27.5)
delta.updates[0].values[7].path.should.equal('navigation.destination.commonName')
delta.updates[0].values[7].value.should.equal('OOI SILEN')
delta.updates[0].values[8].path.should.equal('communication.callsignVhf')
delta.updates[0].values[8].value.should.equal('PH510')
delta.updates[0].values[9].path.should.equal('design.aisShipType')
delta.updates[0].values[9].value.id.should.equal(67)
delta.updates[0].values[9].value.name.should.equal('Passenger ship')
done()

@@ -44,2 +61,21 @@ })

it('AtoN converts ok', done => {
const parser = new Parser
parser.on('signalk:delta', delta => {
delta.context.should.equal('atons.urn:mrn:imo:mmsi:993672087')
delta.updates[0].values[1].value.name.should.equal('46')
delta.updates[0].values[2].path.should.equal('navigation.position')
delta.updates[0].values[2].value.longitude.should.equal(-76.128155)
delta.updates[0].values[2].value.latitude.should.equal(39.36828666666667)
delta.updates[0].values[3].path.should.equal('atonType')
delta.updates[0].values[3].value.name.should.equal('Beacon, Starboard Hand')
delta.updates[0].values[3].value.id.should.equal(14)
done()
})
parser
.parse('!AIVDM,1,1,,A,E>k`sUoJK@@@@@@@@@@@@@@@@@@MAhJS;@neP00000N000,0*0D\n')
.catch(e => { done(e) })
})
it('Doesn\'t choke on empty sentences', done => {

@@ -46,0 +82,0 @@ const parser = new Parser

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc