Skip to content

Commit

Permalink
feature: add the option to output null values (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 authored Jul 22, 2023
1 parent 0cc83e7 commit f5f8b04
Show file tree
Hide file tree
Showing 56 changed files with 82 additions and 62 deletions.
20 changes: 18 additions & 2 deletions bin/analyzerjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
#!/usr/bin/env node

const argv = require('minimist')(process.argv.slice(2))
const argv = require('minimist')(process.argv.slice(2), {
alias: { h: 'help' },
boolean: ['n']
})

if ( argv['help'] ) {
console.error(`Usage: ${process.argv[1]} [options]
Options:
-c don't check for invalid values
-n output null values
-h, --help output usage information`)
process.exit(1)
}

const Parser = require('../index').FromPgn
var parser = new Parser()
var parser = new Parser( {
returnNulls: argv['n'] === true,
checkForInvalidFields: argv['n']
})

parser.on('error', (pgn, error) => {
console.error(`Error parsing ${pgn.pgn} ${error}`)
Expand Down
7 changes: 6 additions & 1 deletion lib/fromPgn.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class Parser extends EventEmitter {
super()
this.options = _.isUndefined(opts) ? {} : opts

if ( this.options.returnNulls === undefined ) {
this.options.returnNulls = false
}

this.name = pkg.name
this.version = pkg.version
this.author = pkg.author
Expand Down Expand Up @@ -235,7 +239,8 @@ class Parser extends EventEmitter {
}
}

if ( !_.isUndefined(value) && value != null ) {
if ( !_.isUndefined(value) && (value != null ||
this.options.returnNulls) ) {
pgn.fields[field.Name] = value
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/pgns/126208.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"prio":2,"pgn":126208,"dst":67,"src":0,"timestamp":"2020-04-19T00:35:55.571Z","fields":{"Function Code":"Command","PGN":126998,"Number of Parameters":1,"list":[{"Parameter":2,"Value":"YD:VOLUME 60"}]},"description":"NMEA - Command group function"},
"expected": {"prio":2,"pgn":126208,"dst":67,"src":0,"timestamp":"2020-04-19T00:35:55.571Z","fields":{"Function Code":"Command","PGN":126998,"Number of Parameters":1,"Priority":null,"Reserved1":null,"list":[{"Parameter":2,"Value":"YD:VOLUME 60"}]},"description":"NMEA - Command group function"},
"input": "2020-04-19T00:35:55.571Z,2,126208,0,67,21,01,16,f0,01,ff,01,02,0e,01,59,44,3a,56,4f,4c,55,4d,45,20,36,30"
}]
2 changes: 1 addition & 1 deletion test/pgns/126720.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T16:02:48.913Z","prio":7,"src":1,"dst":255,"pgn":126720,"description":"Seatalk1: Device Identification","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Proprietary ID":"0x81f0","command":"0x90","device":"S100"}},
"expected": {"timestamp":"2017-04-15T16:02:48.913Z","prio":7,"src":1,"dst":255,"pgn":126720,"description":"Seatalk1: Device Identification","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Proprietary ID":"0x81f0","command":"0x90","device":"S100","Reserved1":null,"Reserved2":null}},
"input": "2017-04-15T16:02:48.913Z,7,126720,1,255,7,3b,9f,f0,81,90,ff,03"
}]
2 changes: 1 addition & 1 deletion test/pgns/126992.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.471Z","prio":3,"src":3,"dst":255,"pgn":126992,"description":"System Time","fields":{"Date":"2017.04.15", "Time": "14:57:57"}},
"expected": {"timestamp":"2017-04-15T14:57:58.471Z","prio":3,"src":3,"dst":255,"pgn":126992,"description":"System Time","fields":{"Date":"2017.04.15", "Time": "14:57:57","Reserved1":null,"SID":null,"Source":null}},
"input": "2017-04-15T14:57:58.471Z,3,126992,3,255,8,ff,ff,77,43,50,fa,1c,20"
}]
2 changes: 1 addition & 1 deletion test/pgns/127237.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/pgns/127245.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.468Z","prio":2,"src":172,"dst":255,"pgn":127245,"description":"Rudder","fields":{"Instance":252,"Direction Order":4,"Angle Order":-0.0021,"Position":-0.0029}},
"expected": {"timestamp":"2017-04-15T14:57:58.468Z","prio":2,"src":172,"dst":255,"pgn":127245,"description":"Rudder","fields":{"Instance":252,"Direction Order":4,"Angle Order":-0.0021,"Position":-0.0029,"Reserved1":null,"Reserved2":null}},
"input": "2017-04-15T14:57:58.468Z,2,127245,172,255,8,fc,fc,eb,ff,e3,ff,ff,ff"
}]
2 changes: 1 addition & 1 deletion test/pgns/127250.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.468Z","prio":2,"src":204,"dst":255,"pgn":127250,"description":"Vessel Heading","fields":{"Heading":2.4600,"Reference":"Magnetic"}},
"expected": {"timestamp":"2017-04-15T14:57:58.468Z","prio":2,"src":204,"dst":255,"pgn":127250,"description":"Vessel Heading","fields":{"Heading":2.4600,"Reference":"Magnetic","Deviation":null,"Reserved1":null,"Variation":null,"SID":null}},
"input": "2017-04-15T14:57:58.468Z,2,127250,204,255,8,ff,18,60,ff,7f,ff,7f,fd"
}]
2 changes: 1 addition & 1 deletion test/pgns/127251.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.468Z","prio":2,"src":204,"dst":255,"pgn":127251,"description":"Rate of Turn","fields":{"Rate":0.00069103, "Reserved1": 16777215}},
"expected": {"timestamp":"2017-04-15T14:57:58.468Z","prio":2,"src":204,"dst":255,"pgn":127251,"description":"Rate of Turn","fields":{"Rate":0.00069103, "Reserved1": 16777215,"SID":null}},
"input": "2017-04-15T14:57:58.468Z,2,127251,204,255,8,ff,61,56,00,00,ff,ff,ff"
}]
2 changes: 1 addition & 1 deletion test/pgns/127257.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.468Z","prio":2,"src":204,"dst":255,"pgn":127257,"description":"Attitude","fields":{"Yaw":2.4600,"Pitch":0.0303,"Roll":0.0001}},
"expected": {"timestamp":"2017-04-15T14:57:58.468Z","prio":2,"src":204,"dst":255,"pgn":127257,"description":"Attitude","fields":{"Yaw":2.4600,"Pitch":0.0303,"Roll":0.0001,"Reserved1":null,"SID":null}},
"input": "2017-04-15T14:57:58.468Z,2,127257,204,255,8,ff,18,60,2f,01,01,00,ff"
}]
2 changes: 1 addition & 1 deletion test/pgns/127258.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.469Z","prio":6,"src":3,"dst":255,"pgn":127258,"description":"Magnetic Variation","fields":{"Source":"WMM 2015","Age of service":"2015.01.01","Variation":-0.1955}},
"expected": {"timestamp":"2017-04-15T14:57:58.469Z","prio":6,"src":3,"dst":255,"pgn":127258,"description":"Magnetic Variation","fields":{"Source":"WMM 2015","Age of service":"2015.01.01","Variation":-0.1955,"Reserved1":null,"Reserved2":null,"SID":null}},
"input": "2017-04-15T14:57:58.469Z,6,127258,3,255,8,ff,f7,34,40,5d,f8,ff,ff"
}]
2 changes: 1 addition & 1 deletion test/pgns/127488.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.468Z","prio":2,"src":17,"dst":255,"pgn":127488,"description":"Engine Parameters, Rapid Update","fields":{"Instance":"Dual Engine Starboard","Speed":0.0}},
"expected": {"timestamp":"2017-04-15T14:57:58.468Z","prio":2,"src":17,"dst":255,"pgn":127488,"description":"Engine Parameters, Rapid Update","fields":{"Instance":"Dual Engine Starboard","Speed":0.0,"Boost Pressure":null,"Reserved1":null,"Tilt/Trim":null}},
"input": "2017-04-15T14:57:58.468Z,2,127488,17,255,8,01,00,00,ff,ff,7f,ff,ff"
}]
5 changes: 2 additions & 3 deletions test/pgns/127489.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/pgns/127497.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"prio":5,"pgn":127497,"dst":255,"src":57,"timestamp":"2020-03-31T02:34:18.529Z","fields":{"Instance":224,"Trip Fuel Used":9,"Fuel Rate, Average":-3100.2,"Instantaneous Fuel Economy":-0.1},"description":"Trip Parameters, Engine"},
"expected": {"prio":5,"pgn":127497,"dst":255,"src":57,"timestamp":"2020-03-31T02:34:18.529Z","fields":{"Instance":224,"Trip Fuel Used":9,"Fuel Rate, Average":-3100.2,"Instantaneous Fuel Economy":-0.1,"Fuel Rate, Economy":null},"description":"Trip Parameters, Engine"},
"input": "2020-03-31T02:34:18.529Z,5,127497,57,255,9,e0,09,00,e6,86,ff,7f,ff,ff"
}]
2 changes: 1 addition & 1 deletion test/pgns/127501.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/pgns/127505.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.469Z","prio":6,"src":17,"dst":255,"pgn":127505,"description":"Fluid Level","fields":{"Instance":0,"Type":"Fuel","Level":56.264,"Capacity":49.0}},
"expected": {"timestamp":"2017-04-15T14:57:58.469Z","prio":6,"src":17,"dst":255,"pgn":127505,"description":"Fluid Level","fields":{"Instance":0,"Type":"Fuel","Level":56.264,"Capacity":49.0,"Reserved1":null}},
"input": "2017-04-15T14:57:58.469Z,6,127505,17,255,8,00,f2,36,ea,01,00,00,ff"
}]
2 changes: 1 addition & 1 deletion test/pgns/127506.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = [{
"expected": {"timestamp":"2023-04-01T17:28:01.128Z","prio":2,"src":60,"dst":255,"pgn":127506,"description":"DC Detailed Status","fields":{"Instance":3,"State of Charge":100, "Time Remaining": "00:20:00"}},
"expected": {"timestamp":"2023-04-01T17:28:01.128Z","prio":2,"src":60,"dst":255,"pgn":127506,"description":"DC Detailed Status","fields":{"Instance":3,"State of Charge":100, "Time Remaining": "00:20:00","DC Type":null,"Remaining capacity":null,"Ripple Voltage":null,"SID":null,"State of Health":null}},
"input": "2023-04-01T17:28:01.128Z,2,127506,60,255,11,ff,03,ff,64,ff,14,00,ff,ff,ff,ff"
//"2016-02-28T19:57:02.829Z,6,127506,60,255,11,ff,03,ff,64,ff,ff,ff,ff,ff,ff,ff"
}]
2 changes: 1 addition & 1 deletion test/pgns/127507.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2016-02-28T19:57:02.829Z","prio":6,"src":129,"dst":255,"pgn":127507,"description":"Charger Status","fields":{"Instance":114,"Battery Instance":6,"Operating State":"Disabled","Charge Mode":"Standalone","Enabled":"Off"}},
"expected": {"timestamp":"2016-02-28T19:57:02.829Z","prio":6,"src":129,"dst":255,"pgn":127507,"description":"Charger Status","fields":{"Instance":114,"Battery Instance":6,"Operating State":"Disabled","Charge Mode":"Standalone","Enabled":"Off","Reserved1":null,"Equalization Pending":null,"Equalization Time Remaining":null}},
"input": "2016-02-28T19:57:02.829Z,6,127507,129,255,6,72,06,08,fc,ff,ff"
}]
2 changes: 1 addition & 1 deletion test/pgns/127508.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.473Z","prio":6,"src":17,"dst":255,"pgn":127508,"description":"Battery Status","fields":{"Instance":1,"Voltage":14.62,"SID":0}},
"expected": {"timestamp":"2017-04-15T14:57:58.473Z","prio":6,"src":17,"dst":255,"pgn":127508,"description":"Battery Status","fields":{"Instance":1,"Voltage":14.62,"SID":0,"Current":null,"Temperature":null}},
"input": "2017-04-15T14:57:58.473Z,6,127508,17,255,8,01,b6,05,ff,7f,ff,ff,00"
}]
2 changes: 1 addition & 1 deletion test/pgns/128259.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.469Z","prio":2,"src":35,"dst":255,"pgn":128259,"description":"Speed","fields":{"SID":20,"Speed Water Referenced":0.00,"Speed Water Referenced Type":"Paddle wheel"}},
"expected": {"timestamp":"2017-04-15T14:57:58.469Z","prio":2,"src":35,"dst":255,"pgn":128259,"description":"Speed","fields":{"SID":20,"Speed Water Referenced":0.00,"Speed Water Referenced Type":"Paddle wheel","Reserved1":null,"Speed Direction":null,"Speed Ground Referenced":null}},
"input": "2017-04-15T14:57:58.469Z,2,128259,35,255,8,14,00,00,ff,ff,00,ff,ff"
}]
2 changes: 1 addition & 1 deletion test/pgns/128267.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.469Z","prio":3,"src":35,"dst":255,"pgn":128267,"description":"Water Depth","fields":{"SID":18,"Depth":4.46,"Offset":0.121}},
"expected": {"timestamp":"2017-04-15T14:57:58.469Z","prio":3,"src":35,"dst":255,"pgn":128267,"description":"Water Depth","fields":{"SID":18,"Depth":4.46,"Offset":0.121,"Range":null}},
"input": "2017-04-15T14:57:58.469Z,3,128267,35,255,8,12,be,01,00,00,79,00,ff"
}]
2 changes: 1 addition & 1 deletion test/pgns/128275.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.469Z","prio":6,"src":35,"dst":255,"pgn":128275,"description":"Distance Log","fields":{"Log":0,"Trip Log":0}},
"expected": {"timestamp":"2017-04-15T14:57:58.469Z","prio":6,"src":35,"dst":255,"pgn":128275,"description":"Distance Log","fields":{"Log":0,"Trip Log":0,"Time":null,"Date":null}},
"input": "2017-04-15T14:57:58.469Z,6,128275,35,255,14,ff,ff,ff,ff,ff,ff,00,00,00,00,00,00,00,00"
}]
2 changes: 1 addition & 1 deletion test/pgns/129026.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [{
"expected": {"timestamp":"2017-04-15T14:57:58.468Z","prio":2,"src":3,"dst":255,"pgn":129026,"description":"COG & SOG, Rapid Update","fields":{"COG Reference":"True","COG":2.0961,"SOG":2.46}},
"expected": {"timestamp":"2017-04-15T14:57:58.468Z","prio":2,"src":3,"dst":255,"pgn":129026,"description":"COG & SOG, Rapid Update","fields":{"COG Reference":"True","COG":2.0961,"SOG":2.46,"Reserved1":null,"Reserved2":null,"SID":null}},
"input": "2017-04-15T14:57:58.468Z,2,129026,3,255,8,ff,fc,e1,51,f6,00,ff,ff"
}]
4 changes: 2 additions & 2 deletions test/pgns/129029.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = [
{
"expected": {"timestamp":"2017-04-15T14:57:58.470Z","prio":3,"src":3,"dst":255,"pgn":129029,"description":"GNSS Position Data","fields":{"SID":155,"Date":"2017.04.15", "Time": "14:57:56.89500","Latitude":39.0700875,"Longitude":-76.4640319,"GNSS type":"GPS+SBAS/WAAS","Method":"DGNSS fix","Integrity":"No integrity checking","Number of SVs":18,"HDOP":0.65,"Reference Stations": 0, "list":[]}},
"expected": {"timestamp":"2017-04-15T14:57:58.470Z","prio":3,"src":3,"dst":255,"pgn":129029,"description":"GNSS Position Data","fields":{"SID":155,"Date":"2017.04.15", "Time": "14:57:56.89500","Latitude":39.0700875,"Longitude":-76.4640319,"GNSS type":"GPS+SBAS/WAAS","Method":"DGNSS fix","Integrity":"No integrity checking","Number of SVs":18,"HDOP":0.65,"Reference Stations": 0,"Reserved1":null,"Altitude":null,"Geoidal Separation":null,"PDOP":null, "list":[]}},
"input":"2017-04-15T14:57:58.470Z,3,129029,3,255,43,9b,77,43,36,f6,1c,20,00,2e,cf,33,60,0c,6c,05,ff,49,10,5d,ae,73,63,f5,ff,ff,ff,ff,ff,ff,ff,7f,23,fc,12,41,00,ff,7f,ff,ff,ff,7f,00"
},
{
"expected": {"canId":234358051,"prio":3,"src":35,"dst":255,"pgn":129029,"fields":{"SID":126,"Date":"2020.03.09","Time":"17:47:47.80000","Latitude":42.4913166,"Longitude":-70.8850733,"Altitude":41.4,"GNSS type":"GPS+SBAS/WAAS","Method":"DGNSS fix","Integrity":"No integrity checking","Number of SVs":10,"HDOP":0.9,"PDOP":1.6,"Geoidal Separation":-30.9,"Reference Stations":0,"list":[{"Reference Station ID":15}]},"description":"GNSS Position Data"},
"expected": {"canId":234358051,"prio":3,"src":35,"dst":255,"pgn":129029,"fields":{"SID":126,"Date":"2020.03.09","Time":"17:47:47.80000","Latitude":42.4913166,"Longitude":-70.8850733,"Altitude":41.4,"GNSS type":"GPS+SBAS/WAAS","Method":"DGNSS fix","Integrity":"No integrity checking","Number of SVs":10,"HDOP":0.9,"PDOP":1.6,"Geoidal Separation":-30.9,"Reference Stations":0,"Reserved1":null,"list":[{"Reference Station ID":15}]},"description":"GNSS Position Data"},
"format": 0,
"input": ['can0 0DF80523 [8] C0 2B 7E 9A 47 70 F8 2F',
'can0 0DF80523 [8] C1 26 00 0C D1 EF 45 98',
Expand Down
2 changes: 1 addition & 1 deletion test/pgns/129038.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f5f8b04

Please sign in to comment.