nmea0183-signalk
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -55,5 +55,9 @@ /* | ||
.group('environment') | ||
.timestamp(this.timestamp()) | ||
.source(this.source()) | ||
.value('depthBelowTransducer', this.float(values[2])) | ||
.set('depth', { | ||
belowTransducer: { | ||
source: this.source(), | ||
timestamp: this.timestamp(), | ||
value: this.float(values[2]) | ||
} | ||
}) | ||
; | ||
@@ -60,0 +64,0 @@ |
@@ -41,3 +41,3 @@ /* | ||
2. Wind Speed | ||
3. Wind Speed Units, K(nots)/M(iles/hour)/N(m/s) | ||
3. Wind Speed Units, K = km/h, M = m/s, N = knots | ||
4. Status, A = Data Valid | ||
@@ -49,2 +49,10 @@ 5. Checksum | ||
function convertToWindAngle(self, angle) { | ||
var numAngle = self.float(angle) % 360; | ||
if (numAngle > 180 && numAngle <= 360) { | ||
return numAngle - 360; | ||
} | ||
return numAngle; | ||
} | ||
module.exports = new Codec('MWV', function(multiplexer, input) { | ||
@@ -59,3 +67,2 @@ var values = input.values; | ||
var data = {}; | ||
var ts = this.timestamp(); | ||
@@ -66,16 +73,11 @@ var source = this.source(); | ||
if(wsu == 'K') { | ||
wsu = 'kph'; | ||
} else if(wsu == 'N') { | ||
wsu = 'knots'; | ||
} else if(wsu == 'M') { | ||
wsu = 'mph'; | ||
} else { | ||
} else { // M | ||
wsu = 'ms'; | ||
} | ||
if(values[1].toUpperCase() == "R") { | ||
data['directionApparent'] = this.float(values[0]); | ||
data['speedApparent'] = this.transform(values[2], wsu, 'ms'); | ||
} else { | ||
data['directionTrue'] = this.float(values[0]); | ||
data['speedTrue'] = this.transform(values[2], wsu, 'ms'); | ||
} | ||
var angle = convertToWindAngle(this, values[0]); | ||
var speed = this.transform(values[2], wsu, 'ms'); | ||
@@ -85,19 +87,34 @@ multiplexer | ||
.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') } | ||
]); | ||
multiplexer.set('wind', { | ||
angleApparent: { | ||
timestamp: ts, | ||
source: source, | ||
value: angle | ||
}, | ||
speedApparent: { | ||
timestamp: ts, | ||
source: source, | ||
value: speed | ||
} | ||
}); | ||
} else { | ||
multiplexer.values([ | ||
{ path: 'directionTrue', value: this.float(values[0]) }, | ||
{ path: 'speedTrue', value: this.transform(values[2], wsu, 'ms') } | ||
]); | ||
multiplexer.set('wind', { | ||
angleTrue: { | ||
timestamp: ts, | ||
source: source, | ||
value: angle | ||
}, | ||
speedTrue: { | ||
timestamp: ts, | ||
source: source, | ||
value: speed | ||
} | ||
}); | ||
} | ||
return true; | ||
}); | ||
}); |
@@ -79,2 +79,11 @@ /* | ||
var vals = [ | ||
{ path: 'courseOverGroundTrue', value: self.float(values[7]) }, | ||
{ path: 'speedOverGround', value: self.transform(values[6], 'knots', 'ms') } | ||
]; | ||
if(typeof values[9] !== 'undefined' && typeof values[10] === 'string') { | ||
vals.push({ path: 'magneticVariation', value: this.magneticVariaton(values[9], values[10]) }); | ||
} | ||
// Other | ||
@@ -86,7 +95,3 @@ multiplexer | ||
.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') } | ||
]) | ||
.values(vals) | ||
; | ||
@@ -93,0 +98,0 @@ |
@@ -73,3 +73,3 @@ var Transform = require('stream').Transform; | ||
var split = sentence.split('*'); | ||
var raw = split[0].slice(1, (split[0].length - 1)); | ||
var raw = split[0].slice(1); | ||
var values = raw.split(','); | ||
@@ -104,5 +104,6 @@ | ||
this._lineBuffer += chunk; | ||
this._lineBuffer = this._lineBuffer.replace(/\\r\\n/g, "\n"); | ||
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'); | ||
if(this._lineBuffer.indexOf('\n') !== -1 || (this._lineBuffer.indexOf('\n') === -1 && this._lineBuffer.indexOf('$') !== -1 && this._lineBuffer.indexOf('*') !== -1)) { | ||
var split = this._lineBuffer.split('\n'); | ||
var unfinished = ""; | ||
@@ -163,4 +164,4 @@ var lines = []; | ||
function parseLine(line, cb) { | ||
var parser = new Parser(); | ||
function parseLine(line, cb, opts) { | ||
var parser = new Parser(opts); | ||
@@ -167,0 +168,0 @@ parser.on('sentence', function(signal) { |
@@ -45,4 +45,4 @@ !function() { | ||
type: 'NMEA0183', | ||
sentence: this.name, | ||
device: 'signalk-parser-nmea0183' | ||
src: this.name, | ||
label: 'signalk-parser-nmea0183' | ||
}; | ||
@@ -117,3 +117,3 @@ }; | ||
NMEA0183.prototype.magneticVariaton = function(degrees, pole) { | ||
pole = pole.toUpperCase(); | ||
pole = pole.toUpperCase(); | ||
degrees = this.float(degrees); | ||
@@ -120,0 +120,0 @@ |
{ | ||
"name": "nmea0183-signalk", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "NMEA0183 to Signal K parser", | ||
@@ -8,4 +8,8 @@ "main": "index.js", | ||
"start": "node ./index", | ||
"test": "node ./test/index" | ||
"test": "mocha" | ||
}, | ||
"bin": { | ||
"nmea0183-signalk": "./bin/nmea0183-signalk", | ||
"nmea2signalk": "./bin/nmea0183-signalk" | ||
}, | ||
"dependencies": { | ||
@@ -15,6 +19,10 @@ "debug": "^2.1.0", | ||
"lodash": "~2.4.1", | ||
"mocha": "^2.1.0", | ||
"node-uuid": "^1.4.1", | ||
"signalk-multiplexer": "^0.1.7" | ||
}, | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"signalk-schema": "SignalK/specification", | ||
"mocha": "^2.1.0" | ||
}, | ||
"repository": { | ||
@@ -21,0 +29,0 @@ "type": "git", |
@@ -0,3 +1,6 @@ | ||
signalk-parser-nmea0183 | ||
======================= | ||
[](https://travis-ci.org/SignalK/signalk-parser-nmea0183) | ||
@@ -4,0 +7,0 @@ A parser written in node.js to parse NMEA 0183 sentences into Signal K. |
3846481
33
1407
55
6
2
+ Addedmocha@^2.1.0
+ Addedcommander@0.6.12.3.0(transitive)
+ Addeddebug@2.2.0(transitive)
+ Addeddiff@1.4.0(transitive)
+ Addedescape-string-regexp@1.0.2(transitive)
+ Addedglob@3.2.11(transitive)
+ Addedgrowl@1.9.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjade@0.26.3(transitive)
+ Addedlru-cache@2.7.3(transitive)
+ Addedminimatch@0.3.0(transitive)
+ Addedminimist@0.0.8(transitive)
+ Addedmkdirp@0.3.00.5.1(transitive)
+ Addedmocha@2.5.3(transitive)
+ Addedms@0.7.1(transitive)
+ Addedsigmund@1.0.1(transitive)
+ Addedsupports-color@1.2.0(transitive)
+ Addedto-iso-string@0.0.2(transitive)