New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nmea0183-signalk

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nmea0183-signalk - npm Package Compare versions

Comparing version 0.1.12 to 0.2.1

codecs/__GBS.js

52

codecs/APB.js

@@ -50,3 +50,4 @@ /*

module.exports = new Codec('APB', function(values) {
module.exports = new Codec('APB', function(multiplexer, input) {
var values = input.values;

@@ -65,35 +66,22 @@ if(values[0].toUpperCase() == 'V') {

var ts = new Date().toISOString();
var self = this;
var xte = this.transform(values[2], (values[4].toUpperCase() === 'N' ? 'nm' : 'km'), 'nm'); // value, inputFormat, outputFormat
var xte = this.transform(values[2], (values[4].toUpperCase() === 'N' ? 'nm' : 'km'), 'nm'); // value, inputFormat, outputFormat
var data = this.signal.navigation({
currentRoute: {
source: self.source(),
timestamp: ts,
steer: (values[3].toUpperCase() == 'R' ? 'right' : 'left'),
bearingActual: this.float(values[10]),
bearingDirect: this.float(values[7]),
courseRequired: this.float(values[12]),
waypoint: {
next: values[9],
xte: xte
}/*,
arrivalAlarm: {
circleEntered: (values[5].toUpperCase() == 'A' ? true : false),
perpendicularPassedAtWaypoint: (values[5].toUpperCase() == 'A' ? true : false)
},
*/
multiplexer
.self()
.group('navigation')
.set('currentRoute', {
source: this.source(),
timestamp: this.timestamp(),
steer: (values[3].toUpperCase() == 'R' ? 'right' : 'left'),
bearingActual: this.float(values[10]),
bearingDirect: this.float(values[7]),
courseRequired: this.float(values[12]),
waypoint: {
next: values[9],
xte: xte
}
})
;
// eta: ,
// route: ,
// startTime: ,
// waypointLastTime: ,
// waypointLast: ,
// waypointNextEta:
}
});
return data;
return true;
});

@@ -45,6 +45,2 @@ /*

6. Checksum
Needs a vessel object for input. Need to know:
- Distance between transducer to end of keel in M
- Distance between waterline and transducer transducer in M
*/

@@ -54,29 +50,14 @@

module.exports = new Codec('DBT', function(values, vessel) {
var ts = this.timestamp();
var data = {
depthBelowTransducer: {
source: this.source(),
timestamp: ts,
value: this.float(values[2])
}
};
module.exports = new Codec('DBT', function(multiplexer, input) {
var values = input.values;
if(typeof vessel === 'object' && vessel !== null && vessel.dimensions !== null && typeof vessel.dimensions === 'object' && typeof vessel.dimensions.depthTransducer === 'number') {
data.depth = {
source: this.source(),
timestamp: ts,
value: (this.float(values[2]) + vessel.dimensions.depthTransducer)
};
multiplexer
.self()
.group('environment')
.timestamp(this.timestamp())
.source(this.source())
.value('depthBelowTransducer', this.float(values[2]))
;
if(typeof vessel.dimensions.keel === 'number') {
data.depthBelowKeel = {
source: this.source(),
timestamp: ts,
value: (this.float(values[2]) - (vessel.dimensions.keel - vessel.dimensions.depthTransducer))
};
}
}
return this.signal.environmental(data);
return true;
});

@@ -73,27 +73,38 @@ /*

module.exports = new Codec('GGA', function(values, vessel) {
var ts = this.timestamp();
var data = this.signal.navigation({
gnss: {
source: this.source(),
timestamp: this.timestamp(values[0]),
quality: this.int(values[5]),
satellites: this.int(values[6]),
antennaAltitude: this.int(values[8]),
horizontalDilution: this.int(values[7]),
geoidalSeparation: this.int(values[10]),
differentialAge: this.int(values[12]),
differentialReference: this.int(values[13])
},
module.exports = new Codec('GGA', function(multiplexer, input) {
var values = input.values;
var ts = this.timestamp(values[0]);
var src = this.source();
var self = this;
position: {
source: this.source(),
timestamp: this.timestamp(values[0]),
latitude: this.coordinate(values[1], values[2]),
longitude: this.coordinate(values[3], values[4]),
altitude: 0.0
}
});
// Position
multiplexer
.self()
.group('navigation')
.set('position', {
source: this.source(),
timestamp: ts,
longitude: this.coordinate(values[3], values[4]),
latitude: this.coordinate(values[1], values[2])
})
;
return data;
// GNSS
multiplexer
.self()
.group('navigation')
.set('gnss', {
source: this.source(),
timestamp: ts,
quality: this.int(values[5]),
satellites: this.int(values[6]),
antennaAltitude: this.int(values[8]),
horizontalDilution: this.int(values[7]),
geoidalSeparation: this.int(values[10]),
differentialAge: this.int(values[12]),
differentialReference: this.int(values[13])
})
;
return true;
});

@@ -49,3 +49,4 @@ /*

module.exports = new Codec('GLL', function(values) {
module.exports = new Codec('GLL', function(multiplexer, input) {
var values = input.values;

@@ -75,15 +76,17 @@ if(values[5].toUpperCase() == 'V') {

var ts = this.timestamp(time);
var self = this;
var self = this;
var data = this.signal.navigation({
position: {
latitude: self.coordinate(values[0], values[1]),
longitude: self.coordinate(values[2], values[3]),
altitude: 0.0,
source: self.source(),
timestamp: ts
}
});
// Position
multiplexer
.self()
.group('navigation')
.set('position', {
source: this.source(),
timestamp: ts,
longitude: self.coordinate(values[2], values[3]),
latitude: self.coordinate(values[0], values[1])
})
;
return data;
return true;
});

@@ -90,0 +93,0 @@

@@ -48,4 +48,5 @@ /*

module.exports = new Codec('MWV', function(values, vessel) {
module.exports = new Codec('MWV', function(multiplexer, input) {
var values = input.values;
if(values[4].toUpperCase() != 'A') {

@@ -57,6 +58,6 @@ // Don't parse this sentence as it's void, but report the exception to the main Codec.

var data = {};
var ts = this.timestamp();
var data = {};
var ts = this.timestamp();
var source = this.source();
var wsu = values[3].toUpperCase();
var wsu = values[3].toUpperCase();

@@ -79,4 +80,22 @@ if(wsu == 'K') {

return this.signal.environmental({ wind: data });
multiplexer
.self()
.group('environment')
.timestamp(ts)
.source(source)
;
if(values[1].toUpperCase() == "R") {
multiplexer.values([
{ path: 'directionApparent', value: this.float(values[0]) },
{ path: 'speedApparent', value: this.transform(values[2], wsu, 'ms') }
]);
} else {
multiplexer.values([
{ path: 'directionTrue', value: this.float(values[0]) },
{ path: 'speedTrue', value: this.transform(values[2], wsu, 'ms') }
]);
}
return true;
});

@@ -48,4 +48,5 @@ /*

module.exports = new Codec('RMC', function(values) {
module.exports = new Codec('RMC', function(multiplexer, input, line) {
var values = input.values;
if(values[1].toUpperCase() == 'V') {

@@ -67,17 +68,28 @@ // Don't parse this sentence as it's void, but report the exception to the main Codec.

var data = {
position: {
latitude: self.coordinate(values[2], String(values[3]).toUpperCase()),
longitude: self.coordinate(values[4], String(values[5]).toUpperCase()),
altitude: 0.0,
source: self.source(),
timestamp: ts
},
// Position
multiplexer
.self()
.group('navigation')
.set('position', {
source: this.source(),
timestamp: ts,
longitude: self.coordinate(values[4], String(values[5]).toUpperCase()),
latitude: self.coordinate(values[2], String(values[3]).toUpperCase())
})
;
magneticVariaton: this.magneticVariaton(values[9], values[10]),
courseOverGroundTrue: self.float(values[7]),
speedOverGround: self.transform(values[6], 'knots', 'ms')
};
// Other
multiplexer
.self()
.group('navigation')
.source(this.source())
.timestamp(ts)
.values([
{ path: 'magneticVariation', value: this.magneticVariaton(values[9], values[10]) },
{ path: 'courseOverGroundTrue', value: self.float(values[7]) },
{ path: 'speedOverGround', value: self.transform(values[6], 'knots', 'ms') }
])
;
return this.signal.navigation(data);
return true;
});

@@ -84,0 +96,0 @@

@@ -52,23 +52,27 @@ /*

module.exports = new Codec('VTG', function(values) {
module.exports = new Codec('VTG', function(multiplexer, input) {
var values = input.values;
var speed = 0.0;
var speed = 0.0;
if(this.float(values[6]) > 0 && String(values[7]).toUpperCase() === 'K') {
speed = this.transform(values[6], 'kph', 'ms');
}
if(this.float(values[6]) > 0 && String(values[7]).toUpperCase() === 'K') {
speed = this.transform(values[6], 'kph', 'ms');
}
if(this.float(values[4]) > 0 && String(values[5]).toUpperCase() === 'N') {
speed = this.transform(values[4], 'knots', 'ms');
}
if(this.float(values[4]) > 0 && String(values[5]).toUpperCase() === 'N') {
speed = this.transform(values[4], 'knots', 'ms');
}
multiplexer
.self()
.group('navigation')
.timestamp(this.timestamp())
.source(this.source())
.values([
{ path: 'courseOverGroundMagnetic', value: this.float(values[2]) },
{ path: 'courseOverGroundTrue', value: this.float(values[0]) },
{ path: 'speedOverGround', value: speed }
]);
;
var data = {
courseOverGroundMagnetic: this.float(values[2]),
courseOverGroundTrue: this.float(values[0]),
speedOverGround: speed,
timestamp: this.timestamp(),
source: this.source()
};
return this.signal.navigation(data);
return true;
});

@@ -1,27 +0,1 @@

/*
* index.js
*
* @repository https://github.com/signalk/nmea-signalk
* @author Fabian Tollenaar <fabian@starting-point.nl>
*
*
*
* Copyright 2014, Fabian Tollenaar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
"use strict";
module.exports = require('./lib');

@@ -1,42 +0,15 @@

/*
* index.js - Transform Stream
*
* @description This file contains the Transform Stream that acts upon incoming data. It serves as the central
* controller of the parser. ATM it still makes a line out of a sentence, validates it, and decodes it.
* That functionality should however be abstracted away and moved to NMEA0183.js.
*
* @repository https://github.com/signalk/nmea-signalk
* @author Fabian Tollenaar <fabian@starting-point.nl>
*
* @todo Move _validSentence, _lineData etc methods to NMEA0183.js
* @todo Make this Transform stream more abstract, so it can easily be used in different parsers.
*
*
*
* Copyright 2014, Fabian Tollenaar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var Transform = require('stream').Transform;
var util = require('util');
var _ = require('lodash');
var codecs = require('../codecs');
var debug = require('debug')('signalk-parser-nmea0183');
var uuid = require('node-uuid').v4;
var Multiplexer = require('signalk-multiplexer');
var Transform = require('stream').Transform;
var util = require('util');
var _ = require('lodash');
var codecs = require('../codecs');
var error = require('./errors');
function Parser(opts) {
// Allow the parser to be used as a function.
if(!(this instanceof Parser)) return new Parser(opts);
if(!(this instanceof Parser)) {
return new Parser(opts);
}
var self = this;
var options = opts || {};

@@ -48,19 +21,27 @@

if(!options.vessel) {
options.vessel = {};
}
if(!options.debug) {
options.debug = false;
}
options.stream.objectMode = true;
Transform.call(this, options.stream);
this._codecs = options.codecs || require('../codecs');
this._linesParsed = 0;
this._linesProcessed = 0;
this._options = options;
this._lineBuffer = "";
this._options = options;
this._lineBuffer = "";
this.self = {};
this.self.id = this._options.selfId || String(uuid().split('-')[0]).toUpperCase();
this.self.type = this._options.selfType || 'uuid';
this._multiplexer = new Multiplexer(this.self.id, this.self.type);
this._codecs = require('../codecs');
this._multiplexer.on('change', function() {
var data = self._multiplexer.retrieve();
self.emit('sentence', data, self._linesParsed, self._linesProcessed);
self.emit('signalk', data, self._linesParsed, self._linesProcessed);
self.push(data);
});
this._multiplexer.on('change:delta', function(delta) {
self.emit('delta', delta, self._linesParsed, self._linesProcessed);
});
}

@@ -71,14 +52,17 @@

Parser.prototype._validSentence = function(sentence) {
sentence = sentence.trim();
if(sentence === "") return false;
sentence = String(sentence).trim();
if(sentence.charAt(0) == '$' && sentence.charAt(sentence.length - 3) == '*') {
var check = 0;
var split = sentence.split('*');
if(sentence === "") {
return false;
}
for (var i = 1; i < split[0].length; i++) {
check = check ^ split[0].charCodeAt(i);
};
if((sentence.charAt(0) == '$' || sentence.charAt(0) == '!') && sentence.charAt(sentence.length - 3) == '*') {
var check = 0;
var split = sentence.split('*');
return (parseInt(split[1], 16) == check);
for (var i = 1; i < split[0].length; i++) {
check = check ^ split[0].charCodeAt(i);
};
return (parseInt(split[1], 16) == check);
} else {

@@ -91,6 +75,11 @@ return false;

var split = sentence.split('*');
var raw = split[0].replace('$', '');
var raw = split[0].slice(1, (split[0].length - 1));
var values = raw.split(',');
var data = { instrument: values[0].slice(0, 2), type: values[0].slice(-3), values: [] };
var data = {
instrument: values[0].slice(0, 2),
type: values[0].slice(-3),
values: []
};
for(var i = 1; i < values.length; i++) {

@@ -103,11 +92,12 @@ data.values.push(values[i]);

Parser.prototype._decode = function(data) {
Parser.prototype._decode = function(data, line) {
if(typeof codecs[data.type.toUpperCase()] !== 'undefined') {
var codec = codecs[data.type.toUpperCase()];
return codec.decode(data.values, this._options.vessel);
};
return codecs[data.type.toUpperCase()].decode(this._multiplexer, data, line);
}
}
Parser.prototype._transform = function(chunk, encoding, done) {
if(Buffer.isBuffer(chunk)) chunk = chunk.toString();
if(Buffer.isBuffer(chunk)) {
chunk = chunk.toString();
}

@@ -119,5 +109,5 @@ var self = this;

if(this._lineBuffer.indexOf('\r\n') !== -1 || (this._lineBuffer.indexOf('\r\n') === -1 && this._lineBuffer.indexOf('$') !== -1 && this._lineBuffer.indexOf('*') !== -1)) {
var split = this._lineBuffer.split('\r\n');
var split = this._lineBuffer.split('\r\n');
var unfinished = "";
var lines = [];
var lines = [];

@@ -128,3 +118,3 @@ _.each(split, function(line) {

if(line !== '') {
if(line.charAt(0) == '$') {
if(line.charAt(0) == '$' || line.charAt(0) == '!') {
if(line.charAt(line.length - 3) == '*') {

@@ -141,3 +131,3 @@ // we have a full line

if(unfinished.trim() != '' && unfinished.charAt(0) == '$' && unfinished.charAt(unfinished.length - 3) == '*') {
if(unfinished.trim() != '' && (unfinished.charAt(0) == '$' || unfinished.charAt(0) == '!') && unfinished.charAt(unfinished.length - 3) == '*') {
// Unfinished is a full line

@@ -151,3 +141,3 @@ lines.push(unfinished);

var data = self._lineData(line);
var signal = self._decode(data);
var valid = self._decode(data, line);

@@ -157,8 +147,6 @@ // Internal counter counting lines that were processed

if(signal) {
if(valid) {
// Internal counter counting lines that were actually parsed.
// Lines that weren't parsed are either of an unsupported type (see codecs) or VOID.
self._linesParsed++;
self.emit.call(self, 'sentence', signal, self._linesParsed, self._linesProcessed);
self.push.call(self, signal);
}

@@ -182,11 +170,9 @@ }

function parseLine(line, cb, _vessel, _debug) {
var parser = new Parser({
vessel: _vessel || {},
debug: _debug || false
});
function parseLine(line, cb) {
var parser = new Parser();
parser.on('sentence', function(signal) {
cb(signal);
return parser.end();
cb(null, signal);
parser.end();
parser = undefined;
});

@@ -193,0 +179,0 @@

@@ -1,46 +0,10 @@

/*
* NMEA0183.js
*
* @description This file contains contains the basic structure of a codec. It contains a set of helper functions
* to normalise/decode certain data types etc. Any and all format-specific (e.g. NMEA 0183, N2K) stuff
* should be in a file like this, abstracted away from index. For now, that's not yet the case. See
* index.js for more info.
*
* @repository https://github.com/signalk/nmea-signalk
* @author Fabian Tollenaar <fabian@starting-point.nl>
*
* @todo Move standard-specific stuff from index.js to this file.
*
*
*
* Copyright 2014, Fabian Tollenaar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var error = require('./errors');
!function() {
"use strict";
var NMEA0183;
NMEA0183 = function(name, decoder) {
var NMEA0183 = function(name, decoder) {
if(!(this instanceof NMEA0183)) return new NMEA0183();
this.name = name;
this._decoder = decoder;
this.exceptions = [];
this.error = error;
this.name = name;
this._decoder = decoder;
this.exceptions = [];

@@ -82,3 +46,3 @@ this.errors = {

sentence: this.name,
device: 'nmea0183-signalk'
device: 'signalk-parser-nmea0183'
};

@@ -88,5 +52,2 @@ };

NMEA0183.prototype.transform = function(value, inputFormat, outputFormat) {
// console.log('-- TRANSFORM --', inputFormat, ' --> ', outputFormat);
// console.log('-- VALUE 01 --', value);
value = this.float(value);

@@ -101,4 +62,2 @@

// console.log('-- VALUE 02 --', value);
// KM

@@ -149,4 +108,2 @@ if(inputFormat == 'km') {

* @TODO
* - Do something more with errors than reporting
* - Also report validation errors
*/

@@ -266,18 +223,4 @@

NMEA0183.prototype.log = function() {
var date = new Date();
var zero = function(n) { if(parseInt(n, 10) > 9) { return "" + n; } else { return "0" + n; } }
var args = ["[" + zero(date.getHours()) + ":" + zero(date.getMinutes()) + ":" + zero(date.getSeconds()) + "][" + this.name + "]"];
for(var i in arguments) {
args.push(arguments[i]);
}
console.log.apply(console, args);
};
NMEA0183.prototype.decode = function(values, vessel) {
// console.log('NMEA0183.prototype.decode', vessel);
this.signal = require('./signalk')(vessel);
return this._decoder.call(this, values, vessel);
NMEA0183.prototype.decode = function() {
return this._decoder.apply(this, Array.prototype.slice.call(arguments));
}

@@ -284,0 +227,0 @@

{
"name": "nmea0183-signalk",
"version": "0.1.12",
"version": "0.2.1",
"description": "NMEA0183 to Signal K parser",

@@ -10,15 +10,14 @@ "main": "index.js",

},
"directories": {
"test": "test"
"scripts": {
"start": "node ./index",
"test": "node ./test/index"
},
"dependencies": {
"debug": "^2.1.0",
"ggencoder": "^0.1.5",
"lodash": "~2.4.1",
"nomnom": "~1.6.2",
"serialport": "~1.3.1",
"signalk-merge": "^0.1.9"
"node-uuid": "^1.4.1",
"signalk-multiplexer": "^0.1.7"
},
"devDependencies": {},
"scripts": {
"test": "node test/test.js"
},
"repository": {

@@ -37,3 +36,3 @@ "type": "git",

"author": "Fabian Tollenaar <fabian@starting-point.nl>",
"license": "Apache 2",
"license": "MIT",
"bugs": {

@@ -40,0 +39,0 @@ "url": "https://github.com/signalk/nmea0183-signalk/issues"

Sorry, the diff of this file is not supported yet

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