From 00b24415d084fc68f5b19426e3b671dce31f5354 Mon Sep 17 00:00:00 2001 From: Teppo Kurki Date: Sun, 25 Nov 2018 16:39:55 +0200 Subject: [PATCH] chore: format with prettier-standard --- aisShipTypeMapping.js | 6 +- n2kMapper.js | 5 +- package.json | 6 +- pgns/127488.js | 10 +- pgns/127489.js | 58 ++-- pgns/127506.js | 22 +- pgns/127508.js | 18 +- pgns/129038.js | 2 +- pgns/129039.js | 2 +- pgns/129040.js | 2 +- pgns/129041.js | 70 ++--- pgns/129285.js | 4 +- pgns/129794.js | 2 +- pgns/129809.js | 2 +- pgns/129810.js | 2 +- pgns/130306.js | 5 +- pgns/130310.js | 14 +- pgns/130312.js | 12 +- pgns/130314.js | 2 +- pgns/130842.js | 2 +- pgns/index.js | 2 +- test/127250_heading.js | 9 +- test/127488_engine_speed.js | 53 ++-- test/127489_engine_params.js | 442 +++++++++++++++++------------- test/127506_dc_detailed_status.js | 68 ++--- test/127508_battery_voltage.js | 35 ++- test/128259_speed.js | 5 +- test/129025_position.js | 11 +- test/129029_position_data.js | 9 +- test/129041_aton_report.js | 5 +- test/129283_xte.js | 2 +- test/129285_route_info.js | 1 - test/130310-2.json | 30 +- test/130314_pressure.js | 14 +- test/13031_temperature.js | 25 +- test/65285_temperature.js | 12 +- utils.js | 8 +- 37 files changed, 538 insertions(+), 439 deletions(-) diff --git a/aisShipTypeMapping.js b/aisShipTypeMapping.js index 48c2217..6e4def3 100644 --- a/aisShipTypeMapping.js +++ b/aisShipTypeMapping.js @@ -5,8 +5,8 @@ module.exports = function (type) { var name if (typeof num !== 'undefined' && (name = schema.getAISShipTypeName(num))) { return { - 'id': num, - 'name': name + id: num, + name: name } } else { return null @@ -32,7 +32,7 @@ const mapping = { 'High speed craft hazard cat D': 44, 'High speed craft (no additional information)': 49, 'Pilot vessel': 50, - 'SAR': 51, + SAR: 51, Tug: 52, 'Port tender': 53, 'Anti-pollution': 54, diff --git a/n2kMapper.js b/n2kMapper.js index 779ee06..5bd356e 100644 --- a/n2kMapper.js +++ b/n2kMapper.js @@ -92,8 +92,7 @@ var toValuesArray = function (theMappings, n2k, state) { ? theMapping.source(n2k, state) : getValue(n2k, theMapping, state) var allowNull = - typeof theMapping.allowNull !== 'undefined' && - theMapping.allowNull + typeof theMapping.allowNull !== 'undefined' && theMapping.allowNull if (!(value == null) || allowNull) { // null or undefined return { @@ -153,4 +152,4 @@ exports.toDeltaTransformer = function (options) { return through(function (data) { this.queue(exports.toDelta(data)) }) -} \ No newline at end of file +} diff --git a/package.json b/package.json index 2cf8fed..3ed5f3b 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,10 @@ "main": "n2kMapper.js", "scripts": { "test": "mocha", - "changelog": "github-changes -o signalk -r n2k-signalk -a --only-pulls --use-commit-body --data=pulls --tag-name=v$npm_package_version", - "release": "git tag -d v$npm_package_version ; npm run changelog && git add CHANGELOG.md && git commit -m 'chore: update changelog' && git tag v$npm_package_version && git push --tags && git push && npm publish", + "changelog": + "github-changes -o signalk -r n2k-signalk -a --only-pulls --use-commit-body --data=pulls --tag-name=v$npm_package_version", + "release": + "git tag -d v$npm_package_version ; npm run changelog && git add CHANGELOG.md && git commit -m 'chore: update changelog' && git tag v$npm_package_version && git push --tags && git push && npm publish", "format": "prettier-standard '*.js*' 'pgns/**/*.js' 'test/**/*.js*'" }, "keywords": [ diff --git a/pgns/127488.js b/pgns/127488.js index c75dd13..d59640d 100644 --- a/pgns/127488.js +++ b/pgns/127488.js @@ -1,11 +1,12 @@ -const {chooseField} = require('../utils.js') +const { chooseField } = require('../utils.js') module.exports = [ { node: 'propulsion.port.revolutions', filter: function (n2k) { return ( - chooseField(n2k, 'Engine Instance', 'Instance') === 'Single Engine or Dual Engine Port' + chooseField(n2k, 'Engine Instance', 'Instance') === + 'Single Engine or Dual Engine Port' ) }, value: function (n2k) { @@ -16,7 +17,10 @@ module.exports = [ { node: 'propulsion.starboard.revolutions', filter: function (n2k) { - return chooseField(n2k, 'Engine Instance', ['Instance']) === 'Dual Engine Starboard' + return ( + chooseField(n2k, 'Engine Instance', ['Instance']) === + 'Dual Engine Starboard' + ) }, value: function (n2k) { var rpm = Number(chooseField(n2k, 'Engine Speed', 'Speed')) diff --git a/pgns/127489.js b/pgns/127489.js index f8c84ba..09f7ec9 100644 --- a/pgns/127489.js +++ b/pgns/127489.js @@ -1,8 +1,11 @@ const util = require('util') -const {chooseField} = require('../utils.js') +const { chooseField } = require('../utils.js') function skEngineId (n2k) { - return chooseField(n2k, 'Engine Instance', 'Instance') === 'Single Engine or Dual Engine Port' ? 'port' : 'starboard' + return chooseField(n2k, 'Engine Instance', 'Instance') === + 'Single Engine or Dual Engine Port' + ? 'port' + : 'starboard' } function skEngineTitle (n2k) { @@ -13,21 +16,29 @@ function skEngineTitle (n2k) { module.exports = [ { source: 'Temperature', - node: function (n2k) { return 'propulsion.' + skEngineId(n2k) + '.temperature' } + node: function (n2k) { + return 'propulsion.' + skEngineId(n2k) + '.temperature' + } }, { source: 'Alternator Potential', - node: function (n2k) { return 'propulsion.' + skEngineId(n2k) + '.alternatorVoltage' } + node: function (n2k) { + return 'propulsion.' + skEngineId(n2k) + '.alternatorVoltage' + } }, { - node: function (n2k) { return 'propulsion.' + skEngineId(n2k) + '.fuel.rate' }, + node: function (n2k) { + return 'propulsion.' + skEngineId(n2k) + '.fuel.rate' + }, value: function (n2k) { var lph = Number(n2k.fields['Fuel Rate']) return isNaN(lph) ? null : lph / 3600000 } }, { - node: function (n2k) { return 'propulsion.' + skEngineId(n2k) + '.oilPressure' }, + node: function (n2k) { + return 'propulsion.' + skEngineId(n2k) + '.oilPressure' + }, value: function (n2k) { var kpa = Number(n2k.fields['Oil pressure']) return isNaN(kpa) ? null : kpa @@ -35,35 +46,47 @@ module.exports = [ }, { source: 'Total Engine hours', - node: function (n2k) { return 'propulsion.' + skEngineId(n2k) + '.runTime' } + node: function (n2k) { + return 'propulsion.' + skEngineId(n2k) + '.runTime' + } }, { source: 'Oil temperature', - node: function (n2k) { return 'propulsion.' + skEngineId(n2k) + '.oilTemperature' } + node: function (n2k) { + return 'propulsion.' + skEngineId(n2k) + '.oilTemperature' + } }, { - node: function (n2k) { return 'propulsion.' + skEngineId(n2k) + '.coolantPressure' }, + node: function (n2k) { + return 'propulsion.' + skEngineId(n2k) + '.coolantPressure' + }, value: function (n2k) { var kpa = Number(n2k.fields['Coolant Pressure']) return isNaN(kpa) ? null : kpa * 1000.0 } }, { - node: function (n2k) { return 'propulsion.' + skEngineId(n2k) + '.engineLoad' }, + node: function (n2k) { + return 'propulsion.' + skEngineId(n2k) + '.engineLoad' + }, value: function (n2k) { var percent = Number(n2k.fields['Percent Engine Load']) return isNaN(percent) ? null : percent / 100.0 } }, { - node: function (n2k) { return 'propulsion.' + skEngineId(n2k) + '.engineTorque' }, + node: function (n2k) { + return 'propulsion.' + skEngineId(n2k) + '.engineTorque' + }, value: function (n2k) { var percent = Number(n2k.fields['Percent Engine Torque']) return isNaN(percent) ? null : percent / 100.0 } }, { - node: function (n2k) { return 'propulsion.' + skEngineId(n2k) + '.fuel.pressure' }, + node: function (n2k) { + return 'propulsion.' + skEngineId(n2k) + '.fuel.pressure' + }, value: function (n2k) { var kpa = Number(n2k.fields['Fuel Pressure']) return isNaN(kpa) ? null : kpa * 1000.0 @@ -203,19 +226,22 @@ function generateMappingsForStatus (field, notifications) { node: function (n2k) { return util.format(notif.node, skEngineId(n2k)) }, - filter: function (n2k) { return typeof n2k.fields[field] !== 'undefined' }, + filter: function (n2k) { + return typeof n2k.fields[field] !== 'undefined' + }, value: function (n2k, state) { if (n2k.fields[field].indexOf(notif.analyzerText) != -1) { return { state: 'alarm', - method: [ 'visual', 'sound' ], + method: ['visual', 'sound'], message: util.format(notif.message, skEngineTitle(n2k)) } } else { return { state: 'normal', - method: [ 'visual' ], - message: util.format(notif.message, skEngineTitle(n2k)) + ' is Normal' + method: ['visual'], + message: + util.format(notif.message, skEngineTitle(n2k)) + ' is Normal' } } } diff --git a/pgns/127506.js b/pgns/127506.js index 5397102..a109e01 100644 --- a/pgns/127506.js +++ b/pgns/127506.js @@ -1,6 +1,6 @@ -const {chooseField} = require('../utils.js') +const { chooseField } = require('../utils.js') -function instance(n2k) { +function instance (n2k) { return chooseField(n2k, 'DC Instance', 'Instance') } @@ -13,21 +13,13 @@ module.exports = [ return typeof n2k.fields['State of Charge'] !== 'undefined' }, node: function (n2k) { - return ( - 'electrical.batteries.' + - instance(n2k) + - '.capacity.stateOfCharge' - ) + return 'electrical.batteries.' + instance(n2k) + '.capacity.stateOfCharge' } }, { source: 'State of Health', node: function (n2k) { - return ( - 'electrical.batteries.' + - instance(n2k) + - '.capacity.stateOfHealth' - ) + return 'electrical.batteries.' + instance(n2k) + '.capacity.stateOfHealth' } }, { @@ -43,11 +35,7 @@ module.exports = [ return res }, node: function (n2k) { - return ( - 'electrical.batteries.' + - instance(n2k) + - '.capacity.timeRemaining' - ) + return 'electrical.batteries.' + instance(n2k) + '.capacity.timeRemaining' } } /*, { source: 'Ripple Voltage', diff --git a/pgns/127508.js b/pgns/127508.js index b5bcb4c..5c079ad 100644 --- a/pgns/127508.js +++ b/pgns/127508.js @@ -1,6 +1,6 @@ -const {chooseField} = require('../utils.js') +const { chooseField } = require('../utils.js') -function instance(n2k) { +function instance (n2k) { return chooseField(n2k, 'Battery Instance', 'Instance') } @@ -8,27 +8,19 @@ module.exports = [ { source: 'Voltage', node: function (n2k) { - return ( - 'electrical.batteries.' + instance(n2k) + '.voltage' - ) + return 'electrical.batteries.' + instance(n2k) + '.voltage' } }, { source: 'Current', node: function (n2k) { - return ( - 'electrical.batteries.' + instance(n2k) + '.current' - ) + return 'electrical.batteries.' + instance(n2k) + '.current' } }, { source: 'Temperature', node: function (n2k) { - return ( - 'electrical.batteries.' + - instance(n2k) + - '.temperature' - ) + return 'electrical.batteries.' + instance(n2k) + '.temperature' } } ] diff --git a/pgns/129038.js b/pgns/129038.js index 38978ce..f42d828 100644 --- a/pgns/129038.js +++ b/pgns/129038.js @@ -39,7 +39,7 @@ module.exports = [ node: '', value: function (n2k) { return { - mmsi: n2k.fields["User ID"].toString() + mmsi: n2k.fields['User ID'].toString() } } }, diff --git a/pgns/129039.js b/pgns/129039.js index 65d213b..6dc3dad 100644 --- a/pgns/129039.js +++ b/pgns/129039.js @@ -26,7 +26,7 @@ module.exports = [ node: '', value: function (n2k) { return { - mmsi: n2k.fields["User ID"].toString() + mmsi: n2k.fields['User ID'].toString() } } }, diff --git a/pgns/129040.js b/pgns/129040.js index 1d62b3e..08da2f2 100644 --- a/pgns/129040.js +++ b/pgns/129040.js @@ -75,7 +75,7 @@ module.exports = [ node: '', value: function (n2k) { return { - mmsi: n2k.fields["User ID"].toString() + mmsi: n2k.fields['User ID'].toString() } } }, diff --git a/pgns/129041.js b/pgns/129041.js index 2639876..54897a2 100644 --- a/pgns/129041.js +++ b/pgns/129041.js @@ -31,12 +31,12 @@ module.exports = [ }, { node: 'atonType', - value: function(n2k) { + value: function (n2k) { const num = nameMapping[n2k.fields['AtoN Type']] if (typeof num !== 'undefined' && (name = schema.getAtonTypeName(num))) { return { - 'id': num, - 'name': name + id: num, + name: name } } else { return null @@ -65,7 +65,7 @@ module.exports = [ node: '', value: function (n2k) { return { - mmsi: n2k.fields["User ID"].toString() + mmsi: n2k.fields['User ID'].toString() } } }, @@ -77,35 +77,35 @@ module.exports = [ ] const nameMapping = { - "Default: Type of AtoN not specified": 0, - "Referece point": 1, - "RACON": 2, - "Fixed structure off-shore": 3, - "Reserved for future use": 4, - "Fixed light: without sectors": 5, - "Fixed light: with sectors": 6, - "Fixed leading light front": 7, - "Fixed leading light rear": 8, - "Fixed beacon: cardinal N": 9, - "Fixed beacon: cardinal E": 10, - "Fixed beacon: cardinal S": 11, - "Fixed beacon: cardinal W": 12, - "Fixed beacon: port hand": 13, - "Fixed beacon: starboard hand": 14, - "Fixed beacon: preferred channel port hand": 15, - "Fixed beacon: preferred channel starboard hand": 16, - "Fixed beacon: isolated danger": 17, - "Fixed beacon: safe water": 18, - "Floating AtoN: cardinal N": 20, - "Floating AtoN: cardinal E": 21, - "Floating AtoN: cardinal S": 22, - "Floating AtoN: cardinal W": 23, - "Floating AtoN: port hand mark": 24, - "Floating AtoN: starboard hand mark": 25, - "Floating AtoN: preferred channel port hand": 26, - "Floating AtoN: preferred channel starboard hand": 27, - "Floating AtoN: isolated danger": 28, - "Floating AtoN: safe water": 29, - "Floating AtoN: special mark": 30, - "Floating AtoN: light vessel/LANBY/rigs": 31 + 'Default: Type of AtoN not specified': 0, + 'Referece point': 1, + RACON: 2, + 'Fixed structure off-shore': 3, + 'Reserved for future use': 4, + 'Fixed light: without sectors': 5, + 'Fixed light: with sectors': 6, + 'Fixed leading light front': 7, + 'Fixed leading light rear': 8, + 'Fixed beacon: cardinal N': 9, + 'Fixed beacon: cardinal E': 10, + 'Fixed beacon: cardinal S': 11, + 'Fixed beacon: cardinal W': 12, + 'Fixed beacon: port hand': 13, + 'Fixed beacon: starboard hand': 14, + 'Fixed beacon: preferred channel port hand': 15, + 'Fixed beacon: preferred channel starboard hand': 16, + 'Fixed beacon: isolated danger': 17, + 'Fixed beacon: safe water': 18, + 'Floating AtoN: cardinal N': 20, + 'Floating AtoN: cardinal E': 21, + 'Floating AtoN: cardinal S': 22, + 'Floating AtoN: cardinal W': 23, + 'Floating AtoN: port hand mark': 24, + 'Floating AtoN: starboard hand mark': 25, + 'Floating AtoN: preferred channel port hand': 26, + 'Floating AtoN: preferred channel starboard hand': 27, + 'Floating AtoN: isolated danger': 28, + 'Floating AtoN: safe water': 29, + 'Floating AtoN: special mark': 30, + 'Floating AtoN: light vessel/LANBY/rigs': 31 } diff --git a/pgns/129285.js b/pgns/129285.js index 40d6505..6a0e38d 100644 --- a/pgns/129285.js +++ b/pgns/129285.js @@ -8,10 +8,10 @@ module.exports = [ }, { node: 'navigation.currentRoute.waypoints', - filter: (n2k) => { + filter: n2k => { return !_.isUndefined(n2k.fields.list) }, - value: (n2k) => { + value: n2k => { var idx = 0 return n2k.fields.list.map(wp => { return { diff --git a/pgns/129794.js b/pgns/129794.js index 11fefa7..c217fab 100644 --- a/pgns/129794.js +++ b/pgns/129794.js @@ -63,7 +63,7 @@ module.exports = [ node: '', value: function (n2k) { return { - mmsi: n2k.fields["User ID"].toString() + mmsi: n2k.fields['User ID'].toString() } } }, diff --git a/pgns/129809.js b/pgns/129809.js index ec3bfe2..3e11b54 100644 --- a/pgns/129809.js +++ b/pgns/129809.js @@ -13,7 +13,7 @@ module.exports = [ node: '', value: function (n2k) { return { - mmsi: n2k.fields["User ID"].toString() + mmsi: n2k.fields['User ID'].toString() } } }, diff --git a/pgns/129810.js b/pgns/129810.js index b4617fc..d3ddd32 100644 --- a/pgns/129810.js +++ b/pgns/129810.js @@ -42,7 +42,7 @@ module.exports = [ node: '', value: function (n2k) { return { - mmsi: n2k.fields["User ID"].toString() + mmsi: n2k.fields['User ID'].toString() } } }, diff --git a/pgns/130306.js b/pgns/130306.js index 31f6547..967dca0 100644 --- a/pgns/130306.js +++ b/pgns/130306.js @@ -48,7 +48,10 @@ module.exports = [ source: 'Wind Angle', node: 'environment.wind.directionMagnetic', filter: function (n2k) { - return n2k.fields['Reference'] === 'Magnetic (ground referenced to Magnetic North)' + return ( + n2k.fields['Reference'] === + 'Magnetic (ground referenced to Magnetic North)' + ) } } ] diff --git a/pgns/130310.js b/pgns/130310.js index 583efe2..c58d2eb 100644 --- a/pgns/130310.js +++ b/pgns/130310.js @@ -16,12 +16,12 @@ module.exports = [ } }, { - node: 'environment.water.temperature', - filter: function (n2k) { - return n2k.fields['Water Temperature'] - }, - value: function (n2k) { - return Number(n2k.fields['Water Temperature']) - } + node: 'environment.water.temperature', + filter: function (n2k) { + return n2k.fields['Water Temperature'] + }, + value: function (n2k) { + return Number(n2k.fields['Water Temperature']) + } } ] diff --git a/pgns/130312.js b/pgns/130312.js index bffb5db..32b1360 100644 --- a/pgns/130312.js +++ b/pgns/130312.js @@ -1,16 +1,18 @@ const temperatureMappings = require('../temperatureMappings') -const {chooseField} = require('../utils.js') +const { chooseField } = require('../utils.js') module.exports = [ { node: function (n2k) { var temperatureMapping = - temperatureMappings[chooseField(n2k, 'Temperature Source', 'Source')] + temperatureMappings[chooseField(n2k, 'Temperature Source', 'Source')] if (temperatureMapping) { if (temperatureMapping.pathWithIndex) { - return temperatureMapping.pathWithIndex.replace('', n2k.fields['Temperature Instance']) - } - else if (temperatureMapping.path) { + return temperatureMapping.pathWithIndex.replace( + '', + n2k.fields['Temperature Instance'] + ) + } else if (temperatureMapping.path) { return temperatureMapping.path } } diff --git a/pgns/130314.js b/pgns/130314.js index b1a29d8..c9f7ef7 100644 --- a/pgns/130314.js +++ b/pgns/130314.js @@ -1,4 +1,4 @@ -const {chooseField} = require('../utils.js') +const { chooseField } = require('../utils.js') module.exports = [ { diff --git a/pgns/130842.js b/pgns/130842.js index e5e7d0f..cf8559f 100644 --- a/pgns/130842.js +++ b/pgns/130842.js @@ -56,7 +56,7 @@ module.exports = [ node: '', value: function (n2k) { return { - mmsi: n2k.fields["User ID"].toString() + mmsi: n2k.fields['User ID'].toString() } } }, diff --git a/pgns/index.js b/pgns/index.js index 3982ac8..174ae09 100644 --- a/pgns/index.js +++ b/pgns/index.js @@ -34,4 +34,4 @@ module.exports = { 130314: require('./130314.js'), 130577: require('./130577.js'), 130842: require('./130842.js') -} \ No newline at end of file +} diff --git a/test/127250_heading.js b/test/127250_heading.js index a9e0d7c..3d49a61 100644 --- a/test/127250_heading.js +++ b/test/127250_heading.js @@ -46,7 +46,10 @@ describe('127250 Heading', function () { '{"timestamp":"2016-04-14T09:34:11.275Z","prio":2,"src":2,"dst":255,"pgn":127250,"description":"Vessel Heading","fields":{"Heading":14.8,"Deviation":0.1,"Variation":0.0,"Reference":"True"}}' ) ) - tree.should.have.with.nested.property('navigation.magneticDeviation.value', 0.1) - //tree.should.be.validSignalKVesselIgnoringIdentity - }) + tree.should.have.with.nested.property( + 'navigation.magneticDeviation.value', + 0.1 + ) + // tree.should.be.validSignalKVesselIgnoringIdentity + }) }) diff --git a/test/127488_engine_speed.js b/test/127488_engine_speed.js index 9d107c4..c650ea1 100644 --- a/test/127488_engine_speed.js +++ b/test/127488_engine_speed.js @@ -3,40 +3,41 @@ chai.Should() chai.use(require('chai-things')) chai.use(require('@signalk/signalk-schema').chaiModule) -function generatePGNs(json) { - return [json, json.replace('Engine Instance', 'Instance').replace('Engine Speed', 'Speed')] +function generatePGNs (json) { + return [ + json, + json.replace('Engine Instance', 'Instance').replace('Engine Speed', 'Speed') + ] } describe('127488 engine speed Port', function () { it('complete engine speed sentence converts', function () { - generatePGNs('{"timestamp":"2015-01-15-16:16:56.749Z","prio":"2","src":"17","dst":"255","pgn":"127488","description":"Engine Parameters, Rapid Update","fields":{"Engine Instance":"Single Engine or Dual Engine Port","Engine Speed":"3190"}}') - .forEach(pgn => { - var tree = require('./testMapper').toNested( - JSON.parse(pgn) - ) - tree.should.have.nested.property('propulsion.port.revolutions') - tree.should.have.nested.property( - 'propulsion.port.revolutions.value', - 53.166666666666664 - ) - tree.should.be.validSignalKVesselIgnoringIdentity - }) + generatePGNs( + '{"timestamp":"2015-01-15-16:16:56.749Z","prio":"2","src":"17","dst":"255","pgn":"127488","description":"Engine Parameters, Rapid Update","fields":{"Engine Instance":"Single Engine or Dual Engine Port","Engine Speed":"3190"}}' + ).forEach(pgn => { + var tree = require('./testMapper').toNested(JSON.parse(pgn)) + tree.should.have.nested.property('propulsion.port.revolutions') + tree.should.have.nested.property( + 'propulsion.port.revolutions.value', + 53.166666666666664 + ) + tree.should.be.validSignalKVesselIgnoringIdentity + }) }) }) describe('127488 engine speed Starboard', function () { it('complete engine speed sentence converts', function () { - generatePGNs('{"timestamp":"2015-01-15-16:16:56.749Z","prio":"2","src":"17","dst":"255","pgn":"127488","description":"Engine Parameters, Rapid Update","fields":{"Engine Instance":"Dual Engine Starboard","Engine Speed":"3190"}}') - .forEach(pgn => { - var tree = require('./testMapper').toNested( - JSON.parse(pgn) - ) - tree.should.have.nested.property('propulsion.starboard.revolutions') - tree.should.have.nested.property( - 'propulsion.starboard.revolutions.value', - 53.166666666666664 - ) - tree.should.be.validSignalKVesselIgnoringIdentity - }) + generatePGNs( + '{"timestamp":"2015-01-15-16:16:56.749Z","prio":"2","src":"17","dst":"255","pgn":"127488","description":"Engine Parameters, Rapid Update","fields":{"Engine Instance":"Dual Engine Starboard","Engine Speed":"3190"}}' + ).forEach(pgn => { + var tree = require('./testMapper').toNested(JSON.parse(pgn)) + tree.should.have.nested.property('propulsion.starboard.revolutions') + tree.should.have.nested.property( + 'propulsion.starboard.revolutions.value', + 53.166666666666664 + ) + tree.should.be.validSignalKVesselIgnoringIdentity + }) }) }) diff --git a/test/127489_engine_params.js b/test/127489_engine_params.js index 3907557..23df48b 100644 --- a/test/127489_engine_params.js +++ b/test/127489_engine_params.js @@ -3,222 +3,282 @@ chai.Should() chai.use(require('chai-things')) chai.use(require('@signalk/signalk-schema').chaiModule) -function generatePGNs(json) { - return [ json, json.replace('Engine Instance', 'Instance') ] +function generatePGNs (json) { + return [json, json.replace('Engine Instance', 'Instance')] } describe('127489 engine parameters Port', function () { it('every field in the PGN from the NMEA2000 spec converts', function () { - generatePGNs('{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489", "description":"Engine Parameters, Dynamic","fields":{"Engine Instance":"Single Engine or Dual Engine Port","Temperature":"29.85","Alternator Potential":"12.60","Fuel Rate":"0.4","Total Engine hours":"309960","Discrete Status 1":["Low Oil Pressure","Low Coolant Level"],"Discrete Status 2":[ "Warning Level 1","Maintenance Needed"],"Percent Engine Load": 20,"Percent Engine Torque":57,"Oil pressure":80,"Fuel Pressure":504,"Oil temperature":36,"Coolant Pressure":489}}') - .forEach(pgn => { - var tree = require('./testMapper').toNested( - JSON.parse(pgn) - ) - - tree.should.have.nested.property('propulsion.port.oilTemperature') - tree.should.have.nested.property('propulsion.port.oilTemperature.value', 36) - tree.should.have.nested.property('propulsion.port.coolantPressure') - tree.should.have.nested.property('propulsion.port.coolantPressure.value', 489000) - tree.should.have.nested.property('propulsion.port.fuel.pressure') - tree.should.have.nested.property('propulsion.port.fuel.pressure.value', 504000) + generatePGNs( + '{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489", "description":"Engine Parameters, Dynamic","fields":{"Engine Instance":"Single Engine or Dual Engine Port","Temperature":"29.85","Alternator Potential":"12.60","Fuel Rate":"0.4","Total Engine hours":"309960","Discrete Status 1":["Low Oil Pressure","Low Coolant Level"],"Discrete Status 2":[ "Warning Level 1","Maintenance Needed"],"Percent Engine Load": 20,"Percent Engine Torque":57,"Oil pressure":80,"Fuel Pressure":504,"Oil temperature":36,"Coolant Pressure":489}}' + ).forEach(pgn => { + var tree = require('./testMapper').toNested(JSON.parse(pgn)) - tree.should.have.nested.property('propulsion.port.temperature') - tree.should.have.nested.property('propulsion.port.temperature.value', 29.85) - tree.should.have.nested.property('propulsion.port.alternatorVoltage') - tree.should.have.nested.property( - 'propulsion.port.alternatorVoltage.value', - 12.6 - ) - tree.should.have.nested.property('propulsion.port.fuel.rate') - tree.should.have.nested.property( - 'propulsion.port.fuel.rate.value', - 1.1111111111111112e-7 - ) - tree.should.have.nested.property('propulsion.port.runTime') - tree.should.have.nested.property('propulsion.port.runTime.value', 309960) - tree.should.have.nested.property('propulsion.port.oilPressure') - tree.should.have.nested.property('propulsion.port.oilPressure.value', 80) - tree.should.have.nested.property('propulsion.port.engineLoad.value', 0.2) - tree.should.have.nested.property('propulsion.port.engineTorque.value', 0.57) - tree.should.have.nested.property( - 'notifications.propulsion.port.lowOilPressure.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.port.lowCoolantLevel.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.port.warningLevel1.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.port.maintenanceNeeded.value.state', - 'alarm') + tree.should.have.nested.property('propulsion.port.oilTemperature') + tree.should.have.nested.property( + 'propulsion.port.oilTemperature.value', + 36 + ) + tree.should.have.nested.property('propulsion.port.coolantPressure') + tree.should.have.nested.property( + 'propulsion.port.coolantPressure.value', + 489000 + ) + tree.should.have.nested.property('propulsion.port.fuel.pressure') + tree.should.have.nested.property( + 'propulsion.port.fuel.pressure.value', + 504000 + ) + + tree.should.have.nested.property('propulsion.port.temperature') + tree.should.have.nested.property( + 'propulsion.port.temperature.value', + 29.85 + ) + tree.should.have.nested.property('propulsion.port.alternatorVoltage') + tree.should.have.nested.property( + 'propulsion.port.alternatorVoltage.value', + 12.6 + ) + tree.should.have.nested.property('propulsion.port.fuel.rate') + tree.should.have.nested.property( + 'propulsion.port.fuel.rate.value', + 1.1111111111111112e-7 + ) + tree.should.have.nested.property('propulsion.port.runTime') + tree.should.have.nested.property('propulsion.port.runTime.value', 309960) + tree.should.have.nested.property('propulsion.port.oilPressure') + tree.should.have.nested.property('propulsion.port.oilPressure.value', 80) + tree.should.have.nested.property('propulsion.port.engineLoad.value', 0.2) + tree.should.have.nested.property( + 'propulsion.port.engineTorque.value', + 0.57 + ) + tree.should.have.nested.property( + 'notifications.propulsion.port.lowOilPressure.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.port.lowCoolantLevel.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.port.warningLevel1.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.port.maintenanceNeeded.value.state', + 'alarm' + ) tree.should.be.validSignalKVesselIgnoringIdentity }) }) it('complete engine params sentence converts', function () { - generatePGNs('{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489", "description":"Engine Parameters, Dynamic","fields":{"Engine Instance":"Single Engine or Dual Engine Port","Temperature":"29.85","Alternator Potential":"12.60","Fuel Rate":"0.4","Total Engine hours":"309960","Discrete Status 1":["Low Oil Pressure","Low Coolant Level"],"Discrete Status 2":[ "Warning Level 1","Maintenance Needed"],"Percent Engine Load": 20,"Percent Engine Torque":57,"Oil pressure":80}}') - .forEach(pgn => { - var tree = require('./testMapper').toNested( - JSON.parse(pgn) - ) - tree.should.have.nested.property('propulsion.port.temperature') - tree.should.have.nested.property('propulsion.port.temperature.value', 29.85) - tree.should.have.nested.property('propulsion.port.alternatorVoltage') - tree.should.have.nested.property( - 'propulsion.port.alternatorVoltage.value', - 12.6 - ) - tree.should.have.nested.property('propulsion.port.fuel.rate') - tree.should.have.nested.property( - 'propulsion.port.fuel.rate.value', - 1.1111111111111112e-7 - ) - tree.should.have.nested.property('propulsion.port.runTime') - tree.should.have.nested.property('propulsion.port.runTime.value', 309960) - tree.should.have.nested.property('propulsion.port.oilPressure') - tree.should.have.nested.property('propulsion.port.oilPressure.value', 80) - tree.should.have.nested.property('propulsion.port.engineLoad.value', 0.2) - tree.should.have.nested.property('propulsion.port.engineTorque.value', 0.57) - tree.should.have.nested.property( - 'notifications.propulsion.port.lowOilPressure.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.port.lowCoolantLevel.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.port.warningLevel1.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.port.maintenanceNeeded.value.state', - 'alarm') - tree.should.be.validSignalKVesselIgnoringIdentity + generatePGNs( + '{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489", "description":"Engine Parameters, Dynamic","fields":{"Engine Instance":"Single Engine or Dual Engine Port","Temperature":"29.85","Alternator Potential":"12.60","Fuel Rate":"0.4","Total Engine hours":"309960","Discrete Status 1":["Low Oil Pressure","Low Coolant Level"],"Discrete Status 2":[ "Warning Level 1","Maintenance Needed"],"Percent Engine Load": 20,"Percent Engine Torque":57,"Oil pressure":80}}' + ).forEach(pgn => { + var tree = require('./testMapper').toNested(JSON.parse(pgn)) + tree.should.have.nested.property('propulsion.port.temperature') + tree.should.have.nested.property( + 'propulsion.port.temperature.value', + 29.85 + ) + tree.should.have.nested.property('propulsion.port.alternatorVoltage') + tree.should.have.nested.property( + 'propulsion.port.alternatorVoltage.value', + 12.6 + ) + tree.should.have.nested.property('propulsion.port.fuel.rate') + tree.should.have.nested.property( + 'propulsion.port.fuel.rate.value', + 1.1111111111111112e-7 + ) + tree.should.have.nested.property('propulsion.port.runTime') + tree.should.have.nested.property('propulsion.port.runTime.value', 309960) + tree.should.have.nested.property('propulsion.port.oilPressure') + tree.should.have.nested.property('propulsion.port.oilPressure.value', 80) + tree.should.have.nested.property('propulsion.port.engineLoad.value', 0.2) + tree.should.have.nested.property( + 'propulsion.port.engineTorque.value', + 0.57 + ) + tree.should.have.nested.property( + 'notifications.propulsion.port.lowOilPressure.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.port.lowCoolantLevel.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.port.warningLevel1.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.port.maintenanceNeeded.value.state', + 'alarm' + ) + tree.should.be.validSignalKVesselIgnoringIdentity }) }) }) describe('127489 engine parameters Starboard', function () { it('every field in the PGN from the NMEA2000 spec converts', function () { - generatePGNs('{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489", "description":"Engine Parameters, Dynamic","fields":{"Engine Instance":"Dual Engine Starboard","Temperature":"29.85","Alternator Potential":"12.60","Fuel Rate":"0.4","Total Engine hours":"309960","Discrete Status 1":["Low Oil Pressure","Low Coolant Level"],"Discrete Status 2":[ "Warning Level 1","Maintenance Needed"],"Percent Engine Load": 20,"Percent Engine Torque":57,"Oil pressure":80,"Fuel Pressure":504,"Oil temperature":36,"Coolant Pressure":489}}') - .forEach(pgn => { - var tree = require('./testMapper').toNested( - JSON.parse(pgn) - ) - - tree.should.have.nested.property('propulsion.starboard.oilTemperature') - tree.should.have.nested.property('propulsion.starboard.oilTemperature.value', 36) - tree.should.have.nested.property('propulsion.starboard.coolantPressure') - tree.should.have.nested.property('propulsion.starboard.coolantPressure.value', 489000) - tree.should.have.nested.property('propulsion.starboard.fuel.pressure') - tree.should.have.nested.property('propulsion.starboard.fuel.pressure.value', 504000) + generatePGNs( + '{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489", "description":"Engine Parameters, Dynamic","fields":{"Engine Instance":"Dual Engine Starboard","Temperature":"29.85","Alternator Potential":"12.60","Fuel Rate":"0.4","Total Engine hours":"309960","Discrete Status 1":["Low Oil Pressure","Low Coolant Level"],"Discrete Status 2":[ "Warning Level 1","Maintenance Needed"],"Percent Engine Load": 20,"Percent Engine Torque":57,"Oil pressure":80,"Fuel Pressure":504,"Oil temperature":36,"Coolant Pressure":489}}' + ).forEach(pgn => { + var tree = require('./testMapper').toNested(JSON.parse(pgn)) + + tree.should.have.nested.property('propulsion.starboard.oilTemperature') + tree.should.have.nested.property( + 'propulsion.starboard.oilTemperature.value', + 36 + ) + tree.should.have.nested.property('propulsion.starboard.coolantPressure') + tree.should.have.nested.property( + 'propulsion.starboard.coolantPressure.value', + 489000 + ) + tree.should.have.nested.property('propulsion.starboard.fuel.pressure') + tree.should.have.nested.property( + 'propulsion.starboard.fuel.pressure.value', + 504000 + ) - tree.should.have.nested.property('propulsion.starboard.temperature') - tree.should.have.nested.property('propulsion.starboard.temperature.value', 29.85) - tree.should.have.nested.property('propulsion.starboard.alternatorVoltage') - tree.should.have.nested.property( - 'propulsion.starboard.alternatorVoltage.value', - 12.6 - ) - tree.should.have.nested.property('propulsion.starboard.fuel.rate') - tree.should.have.nested.property( - 'propulsion.starboard.fuel.rate.value', - 1.1111111111111112e-7 - ) - tree.should.have.nested.property('propulsion.starboard.runTime') - tree.should.have.nested.property('propulsion.starboard.runTime.value', 309960) - tree.should.have.nested.property('propulsion.starboard.oilPressure') - tree.should.have.nested.property('propulsion.starboard.oilPressure.value', 80) - tree.should.have.nested.property('propulsion.starboard.engineLoad.value', 0.2) - tree.should.have.nested.property('propulsion.starboard.engineTorque.value', 0.57) - tree.should.have.nested.property( - 'notifications.propulsion.starboard.lowOilPressure.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.starboard.lowCoolantLevel.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.starboard.warningLevel1.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.starboard.maintenanceNeeded.value.state', - 'alarm') - tree.should.be.validSignalKVesselIgnoringIdentity + tree.should.have.nested.property('propulsion.starboard.temperature') + tree.should.have.nested.property( + 'propulsion.starboard.temperature.value', + 29.85 + ) + tree.should.have.nested.property('propulsion.starboard.alternatorVoltage') + tree.should.have.nested.property( + 'propulsion.starboard.alternatorVoltage.value', + 12.6 + ) + tree.should.have.nested.property('propulsion.starboard.fuel.rate') + tree.should.have.nested.property( + 'propulsion.starboard.fuel.rate.value', + 1.1111111111111112e-7 + ) + tree.should.have.nested.property('propulsion.starboard.runTime') + tree.should.have.nested.property( + 'propulsion.starboard.runTime.value', + 309960 + ) + tree.should.have.nested.property('propulsion.starboard.oilPressure') + tree.should.have.nested.property( + 'propulsion.starboard.oilPressure.value', + 80 + ) + tree.should.have.nested.property( + 'propulsion.starboard.engineLoad.value', + 0.2 + ) + tree.should.have.nested.property( + 'propulsion.starboard.engineTorque.value', + 0.57 + ) + tree.should.have.nested.property( + 'notifications.propulsion.starboard.lowOilPressure.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.starboard.lowCoolantLevel.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.starboard.warningLevel1.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.starboard.maintenanceNeeded.value.state', + 'alarm' + ) + tree.should.be.validSignalKVesselIgnoringIdentity }) }) it('complete engine params sentence converts', function () { - generatePGNs('{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489","description":"Engine Parameters, Dynamic","fields":{"Engine Instance":"Dual Engine Starboard","Temperature":"29.85","Alternator Potential":"12.60","Fuel Rate":"0.1","Total Engine hours":"309960","Discrete Status 1":["Low Oil Pressure","Low Coolant Level"],"Discrete Status 2":["Warning Level 1","Maintenance Needed"],"Percent Engine Load": 20,"Percent Engine Torque": 57,"Oil pressure":80}}') - .forEach(pgn => { - var tree = require('./testMapper').toNested( - JSON.parse(pgn) - ) - tree.should.have.nested.property('propulsion.starboard.temperature') - tree.should.have.nested.property( - 'propulsion.starboard.temperature.value', - 29.85 - ) - tree.should.have.nested.property('propulsion.starboard.alternatorVoltage') - tree.should.have.nested.property( - 'propulsion.starboard.alternatorVoltage.value', - 12.6 - ) - tree.should.have.nested.property('propulsion.starboard.fuel.rate') - tree.should.have.nested.property( - 'propulsion.starboard.fuel.rate.value', - 2.777777777777778e-8 - ) - tree.should.have.nested.property('propulsion.starboard.runTime') - tree.should.have.nested.property( - 'propulsion.starboard.runTime.value', - 309960 - ) - tree.should.have.nested.property('propulsion.starboard.oilPressure') - tree.should.have.nested.property( - 'propulsion.starboard.oilPressure.value', - 80 - ) - tree.should.have.nested.property( - 'propulsion.starboard.engineLoad.value', - 0.2 - ) - tree.should.have.nested.property( - 'propulsion.starboard.engineTorque.value', - 0.57 - ) - tree.should.have.nested.property( - 'notifications.propulsion.starboard.lowOilPressure.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.starboard.lowCoolantLevel.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.starboard.warningLevel1.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.starboard.maintenanceNeeded.value.state', - 'alarm') - tree.should.be.validSignalKVesselIgnoringIdentity + generatePGNs( + '{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489","description":"Engine Parameters, Dynamic","fields":{"Engine Instance":"Dual Engine Starboard","Temperature":"29.85","Alternator Potential":"12.60","Fuel Rate":"0.1","Total Engine hours":"309960","Discrete Status 1":["Low Oil Pressure","Low Coolant Level"],"Discrete Status 2":["Warning Level 1","Maintenance Needed"],"Percent Engine Load": 20,"Percent Engine Torque": 57,"Oil pressure":80}}' + ).forEach(pgn => { + var tree = require('./testMapper').toNested(JSON.parse(pgn)) + tree.should.have.nested.property('propulsion.starboard.temperature') + tree.should.have.nested.property( + 'propulsion.starboard.temperature.value', + 29.85 + ) + tree.should.have.nested.property('propulsion.starboard.alternatorVoltage') + tree.should.have.nested.property( + 'propulsion.starboard.alternatorVoltage.value', + 12.6 + ) + tree.should.have.nested.property('propulsion.starboard.fuel.rate') + tree.should.have.nested.property( + 'propulsion.starboard.fuel.rate.value', + 2.777777777777778e-8 + ) + tree.should.have.nested.property('propulsion.starboard.runTime') + tree.should.have.nested.property( + 'propulsion.starboard.runTime.value', + 309960 + ) + tree.should.have.nested.property('propulsion.starboard.oilPressure') + tree.should.have.nested.property( + 'propulsion.starboard.oilPressure.value', + 80 + ) + tree.should.have.nested.property( + 'propulsion.starboard.engineLoad.value', + 0.2 + ) + tree.should.have.nested.property( + 'propulsion.starboard.engineTorque.value', + 0.57 + ) + tree.should.have.nested.property( + 'notifications.propulsion.starboard.lowOilPressure.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.starboard.lowCoolantLevel.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.starboard.warningLevel1.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.starboard.maintenanceNeeded.value.state', + 'alarm' + ) + tree.should.be.validSignalKVesselIgnoringIdentity }) }) it('engine notifications work', function () { - generatePGNs('{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489","description":"Engine Parameters, Dynamic","fields":{"Engine Instance":"Dual Engine Starboard","Temperature":"29.85","Alternator Potential":"12.60","Fuel Rate":"0.1","Total Engine hours":"309960","Discrete Status 1":["Low Oil Pressure"],"Discrete Status 2": [],"Percent Engine Load": 20,"Percent Engine Torque": 57,"Oil pressure":80}}') - .forEach(pgn => { - tree = require('./testMapper').toNested( - JSON.parse(pgn) - ) - tree.should.have.nested.property( - 'notifications.propulsion.starboard.lowOilPressure.value.state', - 'alarm') - tree.should.have.nested.property( - 'notifications.propulsion.starboard.lowCoolantLevel.value.state', - 'normal') - tree.should.have.nested.property( - 'notifications.propulsion.starboard.warningLevel1.value.state', - 'normal') - tree.should.have.nested.property( - 'notifications.propulsion.starboard.maintenanceNeeded.value.state', - 'normal') + generatePGNs( + '{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489","description":"Engine Parameters, Dynamic","fields":{"Engine Instance":"Dual Engine Starboard","Temperature":"29.85","Alternator Potential":"12.60","Fuel Rate":"0.1","Total Engine hours":"309960","Discrete Status 1":["Low Oil Pressure"],"Discrete Status 2": [],"Percent Engine Load": 20,"Percent Engine Torque": 57,"Oil pressure":80}}' + ).forEach(pgn => { + tree = require('./testMapper').toNested(JSON.parse(pgn)) + tree.should.have.nested.property( + 'notifications.propulsion.starboard.lowOilPressure.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.starboard.lowCoolantLevel.value.state', + 'normal' + ) + tree.should.have.nested.property( + 'notifications.propulsion.starboard.warningLevel1.value.state', + 'normal' + ) + tree.should.have.nested.property( + 'notifications.propulsion.starboard.maintenanceNeeded.value.state', + 'normal' + ) tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/127506_dc_detailed_status.js b/test/127506_dc_detailed_status.js index 205bd8f..9034304 100644 --- a/test/127506_dc_detailed_status.js +++ b/test/127506_dc_detailed_status.js @@ -3,48 +3,48 @@ chai.Should() chai.use(require('chai-things')) chai.use(require('@signalk/signalk-schema').chaiModule) -function generatePGNs(json) { - return [ json, json.replace('DC Instance', 'Instance') ] +function generatePGNs (json) { + return [json, json.replace('DC Instance', 'Instance')] } describe('127506 dc detailed status', function () { it('complete sentence converts', function () { - generatePGNs('{"timestamp":"2016-08-22T16:02:55.272Z","prio":6,"src":17,"dst":255,"pgn":127506,"description":"DC Detailed Status","fields":{"DC Instance":1,"State of Charge":60,"State of Health":99,"Time Remaining": 600, "Ripple Voltage": 10.9, "SID":0}}') - .forEach(pgn => { - var tree = require('./testMapper').toNested( - JSON.parse(pgn) - ) - tree.should.have.nested.property( - 'electrical.batteries.1.capacity.stateOfCharge.value', - 0.6 - ) - tree.should.have.nested.property( - 'electrical.batteries.1.capacity.stateOfHealth.value', - 99 - ) - tree.should.have.nested.property( - 'electrical.batteries.1.capacity.timeRemaining.value', - 36000 - ) - // tree.should.have.nested.property('electrical.batteries.1.voltage.ripple.value', 10.9); + generatePGNs( + '{"timestamp":"2016-08-22T16:02:55.272Z","prio":6,"src":17,"dst":255,"pgn":127506,"description":"DC Detailed Status","fields":{"DC Instance":1,"State of Charge":60,"State of Health":99,"Time Remaining": 600, "Ripple Voltage": 10.9, "SID":0}}' + ).forEach(pgn => { + var tree = require('./testMapper').toNested(JSON.parse(pgn)) + tree.should.have.nested.property( + 'electrical.batteries.1.capacity.stateOfCharge.value', + 0.6 + ) + tree.should.have.nested.property( + 'electrical.batteries.1.capacity.stateOfHealth.value', + 99 + ) + tree.should.have.nested.property( + 'electrical.batteries.1.capacity.timeRemaining.value', + 36000 + ) + // tree.should.have.nested.property('electrical.batteries.1.voltage.ripple.value', 10.9); tree.should.be.validSignalKVesselIgnoringIdentity }) }) it('null timeRemaining converts', function () { - generatePGNs('{"timestamp":"2016-08-22T16:02:55.272Z","prio":6,"src":17,"dst":255,"pgn":127506,"description":"DC Detailed Status","fields":{"DC Instance":1,"SID":0}}') - .forEach(pgn => { - var delta = require('./testMapper').toDelta(JSON.parse(pgn)) - tree = require('./testMapper').toNested(JSON.parse(pgn)) + generatePGNs( + '{"timestamp":"2016-08-22T16:02:55.272Z","prio":6,"src":17,"dst":255,"pgn":127506,"description":"DC Detailed Status","fields":{"DC Instance":1,"SID":0}}' + ).forEach(pgn => { + var delta = require('./testMapper').toDelta(JSON.parse(pgn)) + tree = require('./testMapper').toNested(JSON.parse(pgn)) - delta.updates[0].values[0].should.have.property( - 'path', - 'electrical.batteries.1.capacity.timeRemaining' - ) - delta.updates[0].values[0].should.have.property('value', null) - - tree.should.have.nested.property( - 'electrical.batteries.1.capacity.timeRemaining.value', - null - ) + delta.updates[0].values[0].should.have.property( + 'path', + 'electrical.batteries.1.capacity.timeRemaining' + ) + delta.updates[0].values[0].should.have.property('value', null) + + tree.should.have.nested.property( + 'electrical.batteries.1.capacity.timeRemaining.value', + null + ) }) }) }) diff --git a/test/127508_battery_voltage.js b/test/127508_battery_voltage.js index c932152..cc8f845 100644 --- a/test/127508_battery_voltage.js +++ b/test/127508_battery_voltage.js @@ -5,25 +5,24 @@ chai.use(require('@signalk/signalk-schema').chaiModule) describe('127508 battery voltage', function () { it('complete sentence converts', function () { - const json = '{"timestamp":"2016-08-22T16:02:55.272Z","prio":6,"src":17,"dst":255,"pgn":127508,"description":"Battery Status","fields":{"Battery Instance":1,"Voltage":13.11,"Current":5.6,"Temperature": 299, "SID":0}}' - const pgns = [ json, json.replace('Battery Instance', 'Instance') ] + const json = + '{"timestamp":"2016-08-22T16:02:55.272Z","prio":6,"src":17,"dst":255,"pgn":127508,"description":"Battery Status","fields":{"Battery Instance":1,"Voltage":13.11,"Current":5.6,"Temperature": 299, "SID":0}}' + const pgns = [json, json.replace('Battery Instance', 'Instance')] pgns.forEach(pgn => { - var tree = require('./testMapper').toNested( - JSON.parse(pgn) - ) - tree.should.have.nested.property( - 'electrical.batteries.1.voltage.value', - 13.11 - ) - tree.should.have.nested.property( - 'electrical.batteries.1.current.value', - 5.6 - ) - tree.should.have.nested.property( - 'electrical.batteries.1.temperature.value', - 299 - ) - tree.should.be.validSignalKVesselIgnoringIdentity + var tree = require('./testMapper').toNested(JSON.parse(pgn)) + tree.should.have.nested.property( + 'electrical.batteries.1.voltage.value', + 13.11 + ) + tree.should.have.nested.property( + 'electrical.batteries.1.current.value', + 5.6 + ) + tree.should.have.nested.property( + 'electrical.batteries.1.temperature.value', + 299 + ) + tree.should.be.validSignalKVesselIgnoringIdentity }) }) }) diff --git a/test/128259_speed.js b/test/128259_speed.js index adc24c6..4d42877 100644 --- a/test/128259_speed.js +++ b/test/128259_speed.js @@ -23,7 +23,10 @@ describe('128259 speed', function () { ) tree.should.have.nested.property('navigation.speedThroughWater') tree.should.have.nested.property('navigation.speedThroughWater.value', 3.47) - tree.should.have.nested.property('navigation.speedThroughWaterReferenceType.value', 'Paddle wheel') + tree.should.have.nested.property( + 'navigation.speedThroughWaterReferenceType.value', + 'Paddle wheel' + ) }) it('zerop speed sentence converts', function () { diff --git a/test/129025_position.js b/test/129025_position.js index 9c2cfdf..087e398 100644 --- a/test/129025_position.js +++ b/test/129025_position.js @@ -8,10 +8,13 @@ var msg = JSON.parse( // Seen in the wild - Original sentence: $PCDIN,01F801,5B26371E,01,FFFFFF7FFFFFFF7F*2C var messageWithoutPosition = { - "pgn":129025, - "timestamp":"1970-01-18T16:47:11.134Z","src":1,"dst":255,"prio":0, - "fields":{}, - "description":"Position, Rapid Update" + pgn: 129025, + timestamp: '1970-01-18T16:47:11.134Z', + src: 1, + dst: 255, + prio: 0, + fields: {}, + description: 'Position, Rapid Update' } describe('129025 Position, rapid update ', function () { diff --git a/test/129029_position_data.js b/test/129029_position_data.js index a75f66d..6e58590 100644 --- a/test/129029_position_data.js +++ b/test/129029_position_data.js @@ -6,7 +6,7 @@ var msg = JSON.parse( '{"timestamp":"2017-04-15T15:50:48.664Z","prio":3,"src":3,"dst":255,"pgn":129029,"description":"GNSS Position Data","fields":{"SID":22,"Date":"2017.04.15", "Time": "15:50:48.04950","Latitude":39.0536632,"Longitude":-76.3972731,"GNSS type":"GPS+GLONASS","Method":"GNSS Fix","Integrity":"No integrity checking","Number of SVs":18,"HDOP":0.73,"Geoidal Separation":-0.01, "Altitude": 1.0, "PDOP":1.20, "Age of DGNSS Corrections": 30, "Reference Station ID": 22, "list":[{}]}}' ) -//2017-07-01T13:02:15.120Z,3,129029,1,255,43,01,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,7f,ff,ff,ff,ff,ff,ff,ff,7f,ff,ff,ff,ff,ff,ff,ff,7f,00,fc,08,ff,7f,ff,7f,ff,ff,ff,7f,ff +// 2017-07-01T13:02:15.120Z,3,129029,1,255,43,01,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,7f,ff,ff,ff,ff,ff,ff,ff,7f,ff,ff,ff,ff,ff,ff,ff,7f,00,fc,08,ff,7f,ff,7f,ff,ff,ff,7f,ff const invalidDataMsg = JSON.parse( '{"timestamp":"2017-07-01T13:02:15.120Z","prio":3,"src":1,"dst":255,"pgn":129029,"description":"GNSS Position Data","fields":{"SID":1,"GNSS type":"GPS","Method":"no GNSS","Integrity":"No integrity checking","Number of SVs":8,"Geoidal Separation":-0.01,"list":[{}]}}' ) @@ -28,8 +28,11 @@ describe('129029 Position Data ', function () { tree.navigation.gnss.integrity.value.should.equal('no Integrity checking') tree.should.be.validSignalKVesselIgnoringIdentity }) - it('no position in input produces no position output', function() { + it('no position in input produces no position output', function () { var delta = require('./testMapper').toDelta(invalidDataMsg) - delta.updates[0].values.should.not.contain.a.thing.with.property('path', 'navigation.position') + delta.updates[0].values.should.not.contain.a.thing.with.property( + 'path', + 'navigation.position' + ) }) }) diff --git a/test/129041_aton_report.js b/test/129041_aton_report.js index e28b810..1ee33ea 100644 --- a/test/129041_aton_report.js +++ b/test/129041_aton_report.js @@ -16,10 +16,7 @@ describe('129041 AIS Aids to Navigation (AtoN) Report', function () { delta.updates[0].values[0].path.should.equal('') delta.updates[0].values[0].value.name.should.equal('SW @') var tree = mapper.toNested(msg) - tree.should.have.nested.property( - 'atonType.value.name', - 'Beacon, Port Hand' - ) + tree.should.have.nested.property('atonType.value.name', 'Beacon, Port Hand') tree.should.have.nested.property('atonType.value.id', 13) tree.navigation.position.value.latitude.should.equal(38.99384) tree.navigation.position.value.longitude.should.equal(-76.3847132) diff --git a/test/129283_xte.js b/test/129283_xte.js index 71b9313..75c14c1 100644 --- a/test/129283_xte.js +++ b/test/129283_xte.js @@ -42,7 +42,7 @@ describe('129283 cross track error', function () { tree.should.be.validSignalKVesselIgnoringIdentity }) - it('does not choke when state is null', function() { + it('does not choke when state is null', function () { var tree = mapper.toNested( JSON.parse( '{"timestamp":"2016-08-11T07:58:36.263Z","prio":3,"src":3,"dst":255,"pgn":129283,"description":"Cross Track Error","fields":{"XTE mode":"Autonomous","Navigation Terminated":"No","XTE":-5.63}}' diff --git a/test/129285_route_info.js b/test/129285_route_info.js index 4640070..1bfdb62 100644 --- a/test/129285_route_info.js +++ b/test/129285_route_info.js @@ -56,4 +56,3 @@ describe('129285 Route Information', function () { ) }) }) - diff --git a/test/130310-2.json b/test/130310-2.json index 4701728..1df5943 100644 --- a/test/130310-2.json +++ b/test/130310-2.json @@ -38,15 +38,15 @@ } }, "130310-water-temperature": { - "timestamp":"2018-09-20T00:33:11.411Z", - "prio":5, - "src":105, - "dst":255, - "pgn":130310, - "description":"Environmental Parameters", - "fields":{ - "SID":0, - "Water Temperature":15.50 + "timestamp": "2018-09-20T00:33:11.411Z", + "prio": 5, + "src": 105, + "dst": 255, + "pgn": 130310, + "description": "Environmental Parameters", + "fields": { + "SID": 0, + "Water Temperature": 15.5 }, "testExpectConvertedValues": {} }, @@ -83,7 +83,7 @@ "Temperature Source": "Inside Temperature", "Temperature": 13.51 }, - "testExpectConvertedValues": {"environment.inside.temperature": 13.51 } + "testExpectConvertedValues": { "environment.inside.temperature": 13.51 } }, "130311-engineroom": { "timestamp": "2015-01-15-16:25:14.120Z", @@ -150,7 +150,6 @@ } }, - "130312-heatingsystem-novalue": { "timestamp": "2015-01-15-16:25:12.126Z", "prio": 5, @@ -163,8 +162,7 @@ "Temperature Instance": 0, "Temperature Source": "Heating System Temperature" }, - "testExpectConvertedValues": { - } + "testExpectConvertedValues": {} }, "130312-heatingsystem-novalue-new": { "timestamp": "2015-01-15-16:25:12.126Z", @@ -328,8 +326,7 @@ "Temperature Instance": "5", "Temperature Source": "Engine Room Temperature" }, - "testExpectConvertedValues": { - } + "testExpectConvertedValues": {} }, "130312-engineroomtemp-novalue-new": { "timestamp": "2015-01-15-16:15:18.136Z", @@ -343,8 +340,7 @@ "Instance": "5", "Source": "Engine Room Temperature" }, - "testExpectConvertedValues": { - } + "testExpectConvertedValues": {} }, "130312-outsidetemp": { "timestamp": "2015-01-15-16:15:18.371Z", diff --git a/test/130314_pressure.js b/test/130314_pressure.js index 38db563..97c9829 100644 --- a/test/130314_pressure.js +++ b/test/130314_pressure.js @@ -5,13 +5,15 @@ chai.use(require('@signalk/signalk-schema').chaiModule) describe('130314_pressure', function () { it('complete sentence converts', function () { - const json = '{"timestamp":"2016-04-09T16:41:39.364Z","prio":5,"src":28,"dst":255,"pgn":130314,"description":"Actual Pressure","fields":{"SID":0,"Pressure Instance":0,"Pressure Source":"Atmospheric","Pressure":100578}}' - const pgns = [ json, json.replace('Pressure Instance', 'Pressure') ] + const json = + '{"timestamp":"2016-04-09T16:41:39.364Z","prio":5,"src":28,"dst":255,"pgn":130314,"description":"Actual Pressure","fields":{"SID":0,"Pressure Instance":0,"Pressure Source":"Atmospheric","Pressure":100578}}' + const pgns = [json, json.replace('Pressure Instance', 'Pressure')] pgns.forEach(pgn => { - var tree = require('./testMapper').toNested( - JSON.parse(pgn) - ) - tree.should.have.nested.property('environment.outside.pressure.value', 100578) + var tree = require('./testMapper').toNested(JSON.parse(pgn)) + tree.should.have.nested.property( + 'environment.outside.pressure.value', + 100578 + ) tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/13031_temperature.js b/test/13031_temperature.js index 3f89368..6a7752c 100644 --- a/test/13031_temperature.js +++ b/test/13031_temperature.js @@ -22,12 +22,25 @@ describe('Temperature: ', function () { full.addDelta(delta) delta.should.be.validSignalKDelta - Object.keys(testCase['testExpectConvertedValues']).forEach(expectedValuePath => { - const expectedValueFound = delta.updates[0].values.filter(value => value.path === expectedValuePath) - expectedValueFound.length.should.equal(1, `Expected value ${expectedValuePath} not found.`) - expectedValueFound[0].value.should.equal(testCase['testExpectConvertedValues'][expectedValuePath], - `Value ${expectedValuePath} incorrectly converted to ${ expectedValueFound[0].value} - expected ${testCase['testExpectConvertedValues'][expectedValuePath]}`) - }) + Object.keys(testCase['testExpectConvertedValues']).forEach( + expectedValuePath => { + const expectedValueFound = delta.updates[0].values.filter( + value => value.path === expectedValuePath + ) + expectedValueFound.length.should.equal( + 1, + `Expected value ${expectedValuePath} not found.` + ) + expectedValueFound[0].value.should.equal( + testCase['testExpectConvertedValues'][expectedValuePath], + `Value ${expectedValuePath} incorrectly converted to ${ + expectedValueFound[0].value + } - expected ${ + testCase['testExpectConvertedValues'][expectedValuePath] + }` + ) + } + ) var fullDoc = full.retrieve() fullDoc.vessels['urn:mrn:imo:mmsi:230099999'].mmsi = '230099999' diff --git a/test/65285_temperature.js b/test/65285_temperature.js index a40b8de..1509d23 100644 --- a/test/65285_temperature.js +++ b/test/65285_temperature.js @@ -6,29 +6,31 @@ describe('65285 Lowrance Temperature ', function () { it('complete sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp": "2015-01-15-16:25:14.120Z","prio": 0,"src": 5,"dst": 255,"pgn": 65285,"description": "Lowrance: Temperature","fields": {"Manufacturer Code":"Lowrance","Industry Code":"Marine Industry","Temperature Source":"Engine Room Temperature", "Actual Temperature": 25.60}}' + '{"timestamp": "2015-01-15-16:25:14.120Z","prio": 0,"src": 5,"dst": 255,"pgn": 65285,"description": "Lowrance: Temperature","fields": {"Manufacturer Code":"Lowrance","Industry Code":"Marine Industry","Temperature Source":"Engine Room Temperature", "Actual Temperature": 25.60}}' ) ) tree.environment.inside.engineRoom.temperature.should.have.property( 'timestamp', '2015-01-15T16:25:14.120Z' ) - tree.environment.inside.engineRoom.temperature.should.have.property('value', 25.60) + tree.environment.inside.engineRoom.temperature.should.have.property( + 'value', + 25.6 + ) tree.should.be.validSignalKVesselIgnoringIdentity }) it('converts livewell to a tank temperature', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp": "2015-01-15-16:25:14.120Z","prio": 0,"src": 5,"dst": 255,"pgn": 65285,"description": "Lowrance: Temperature","fields": {"Manufacturer Code":"Lowrance","Industry Code":"Marine Industry","Temperature Source":"Live Well Temperature", "Actual Temperature": 15.60}}' + '{"timestamp": "2015-01-15-16:25:14.120Z","prio": 0,"src": 5,"dst": 255,"pgn": 65285,"description": "Lowrance: Temperature","fields": {"Manufacturer Code":"Lowrance","Industry Code":"Marine Industry","Temperature Source":"Live Well Temperature", "Actual Temperature": 15.60}}' ) ) tree.tanks.liveWell.default.temperature.should.have.property( 'timestamp', '2015-01-15T16:25:14.120Z' ) - tree.tanks.liveWell.default.temperature.should.have.property('value', 15.60) + tree.tanks.liveWell.default.temperature.should.have.property('value', 15.6) tree.should.be.validSignalKVesselIgnoringIdentity }) - }) diff --git a/utils.js b/utils.js index dcb9089..5cd3334 100644 --- a/utils.js +++ b/utils.js @@ -1,8 +1,10 @@ - module.exports = { chooseField: (n2k, field1, field2) => { - let res = typeof n2k.fields[field1] === 'undefined' ? n2k.fields[field2] : n2k.fields[field1] - //console.log(`chooseField ${typeof n2k.fields[field1]} '${field1}' '${field2}' ${res} ${JSON.stringify(n2k.fields)}`) + let res = + typeof n2k.fields[field1] === 'undefined' + ? n2k.fields[field2] + : n2k.fields[field1] + // console.log(`chooseField ${typeof n2k.fields[field1]} '${field1}' '${field2}' ${res} ${JSON.stringify(n2k.fields)}`) return res } }