From 20d054408c5552c37c6a0e14351a5e5e66eca7cd Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Sun, 1 Oct 2023 02:46:35 -0400 Subject: [PATCH] feature: use canboat v4 or canboatjs v2 (#263) Use canboatjs v2 so that we can use the latest PGN definitions from upstream https://github.com/canboat/canboat --- aisShipTypeMapping.js | 53 +- fusion/130820.js | 26 +- package.json | 6 +- pgns/126983.js | 4 +- pgns/127489.js | 15 +- pgns/127506.js | 11 +- pgns/130306.js | 6 +- raymarine/126720.js | 10 +- test/126720_seatalk_STNG_pilot_mode.js | 8 +- test/126983_alert.js | 24 +- test/127245_rudder.js | 4 +- test/127250_heading.js | 12 +- test/127257_attitude.js | 8 +- test/127258_variation.js | 4 +- test/127488_engine_boost.js | 64 ++- test/127488_engine_speed.js | 67 ++- test/127488_engine_trim.js | 2 +- test/127489_engine_params.js | 681 ++++++++++++------------- test/127493_transmission.js | 13 +- test/127505_fluid_level.js | 10 +- test/127506_dc_detailed_status.js | 6 +- test/127508_battery_voltage.js | 6 +- test/127750_converter_status.js | 12 +- test/128259_speed.js | 4 +- test/128267_water_depth.js | 4 +- test/129025_position.js | 2 +- test/129026_cog_sog_rapid_update.js | 4 +- test/129029_position_data.js | 29 +- test/129038_ais_class_a.js | 6 +- test/129039_ais_class_b.js | 6 +- test/129040_class_b_extended.js | 10 +- test/129291_set_drift_rapid_update.js | 4 +- test/129794_ais_class_a_static_data.js | 2 +- test/129798_sar.js | 4 +- test/130306_wind_data.js | 24 +- test/130577_direction_data.js | 14 +- test/130820_fusion.js | 22 +- test/65285_temperature.js | 8 - test/65288_seatalk_alarm.js | 8 +- test/maretron.js | 10 +- test/meta.js | 8 +- test/testMapper.js | 37 ++ utils.js | 13 +- 43 files changed, 619 insertions(+), 652 deletions(-) diff --git a/aisShipTypeMapping.js b/aisShipTypeMapping.js index 6e4def31..80b0613a 100644 --- a/aisShipTypeMapping.js +++ b/aisShipTypeMapping.js @@ -1,7 +1,8 @@ const schema = require('@signalk/signalk-schema') +const { lookupEnumerationValue } = require('@canboat/canboatjs') module.exports = function (type) { - const num = mapping[type] + const num = lookupEnumerationValue('SHIP_TYPE', type) var name if (typeof num !== 'undefined' && (name = schema.getAISShipTypeName(num))) { return { @@ -12,53 +13,3 @@ module.exports = function (type) { return null } } - -const mapping = { - unavailable: 0, - 'Wing In Ground': 20, - 'Wing In Ground (no other information)': 29, - Fishing: 30, - Towing: 31, - 'Towing exceeds 200m or wider than 25m': 32, - 'Engaged in dredging or underwater operations': 33, - 'Engaged in diving operations': 34, - 'Engaged in military operations': 35, - Sailing: 36, - Pleasure: 37, - 'High speed craft': 40, - 'High speed craft carrying dangerous goods': 41, - 'High speed craft hazard cat B': 42, - 'High speed craft hazard cat C': 43, - 'High speed craft hazard cat D': 44, - 'High speed craft (no additional information)': 49, - 'Pilot vessel': 50, - SAR: 51, - Tug: 52, - 'Port tender': 53, - 'Anti-pollution': 54, - 'Law enforcement': 55, - Spare: 56, - 'Spare #2': 57, - Medical: 58, - 'RR Resolution No.1': 59, - 'Passenger ship': 60, - 'Passenger ship (no additional information)': 69, - 'Cargo ship': 70, - 'Cargo ship carrying dangerous goods': 71, - 'Cargo ship hazard cat B': 72, - 'Cargo ship hazard cat C': 73, - 'Cargo ship hazard cat D': 74, - 'Cargo ship (no additional information)': 79, - Tanker: 80, - 'Tanker carrying dangerous goods': 81, - 'Tanker hazard cat B': 82, - 'Tanker hazard cat C': 83, - 'Tanker hazard cat D': 84, - 'Tanker (no additional information)': 89, - Other: 90, - 'Other carrying dangerous goods': 91, - 'Other hazard cat B': 92, - 'Other hazard cat C': 93, - 'Other hazard cat D': 94, - 'Other (no additional information)': 99 -} diff --git a/fusion/130820.js b/fusion/130820.js index 0174019b..bc48a485 100644 --- a/fusion/130820.js +++ b/fusion/130820.js @@ -1,4 +1,4 @@ - +const { timeToSeconds } = require('../utils.js') var currentFusionSource = null var fusionSources = {} @@ -26,13 +26,19 @@ module.exports = [ node: function(n2k) { return 'entertainment.device.fusion1.avsource.source' + currentFusionSource + '.track.name'} , filter: function(n2k) { return n2k.fields['Message ID'] == 'Track Title' && n2k.fields.Track != 0 && currentFusionSource != null } }, { - source: 'Progress', + //source: 'Progress', node: function(n2k) { return 'entertainment.device.fusion1.avsource.source' + currentFusionSource + '.track.elapsedTime'} , - filter: function(n2k) { return n2k.fields['Message ID'] == 'Track Progress' && currentFusionSource != null } + filter: function(n2k) { return n2k.fields['Message ID'] == 'Track Progress' && currentFusionSource != null }, + value: function(n2k) { + return timeToSeconds(n2k.fields['Progress']) + } }, { - source: 'Track Length', + //source: 'Length', node: function(n2k) { return 'entertainment.device.fusion1.avsource.source' + currentFusionSource + '.track.length'} , - filter: function(n2k) { return n2k.fields['Message ID'] == 'Track Info' && currentFusionSource != null } + filter: function(n2k) { return n2k.fields['Message ID'] == 'Track Info' && currentFusionSource != null }, + value: function(n2k) { + return timeToSeconds(n2k.fields['Length']) + } }, { source: 'Artist', node: function(n2k) { return 'entertainment.device.fusion1.avsource.source' + currentFusionSource + '.track.artistName'} , @@ -125,35 +131,35 @@ module.exports = [ node: function(n2k) { return 'entertainment.device.fusion1.avsource.source' + currentFusionSource + '.playbackState'} , value: function(n2k) { var val = n2k.fields['Transport'] - return val == 'Paused' ? 'Paused' : 'Playing' + return val == 'Paused' || val == 'Stop' ? 'Paused' : 'Playing' }, filter: function(n2k) { return n2k.fields['Message ID'] == 'Track Info' } }, { node: 'entertainment.device.fusion1.output.zone1.isMuted', value: function(n2k) { var val = n2k.fields['Mute'] - return val == 'Muted' ? true : false + return val == 'Mute On' ? true : false }, filter: function(n2k) { return n2k.fields['Message ID'] == 'Mute' } }, { node: 'entertainment.device.fusion1.output.zone2.isMuted', value: function(n2k) { var val = n2k.fields['Mute'] - return val == 'Muted' ? true : false + return val == 'Mute On' ? true : false }, filter: function(n2k) { return n2k.fields['Message ID'] == 'Mute' } }, { node: 'entertainment.device.fusion1.output.zone3.isMuted', value: function(n2k) { var val = n2k.fields['Mute'] - return val == 'Muted' ? true : false + return val == 'Mute On' ? true : false }, filter: function(n2k) { return n2k.fields['Message ID'] == 'Mute' } }, { node: 'entertainment.device.fusion1.output.zone4.isMuted', value: function(n2k) { var val = n2k.fields['Mute'] - return val == 'Muted' ? true : false + return val == 'Mute On' ? true : false }, filter: function(n2k) { return n2k.fields['Message ID'] == 'Mute' } diff --git a/package.json b/package.json index 3c8f56fb..b97b9789 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@signalk/n2k-signalk", - "version": "2.7.0", + "version": "3.0.0-beta.1", "description": "NMEA 2000 to SignalK conversion library", "main": "n2kMapper.js", "scripts": { @@ -21,10 +21,10 @@ "license": "Apache-2.0", "repository": "https://github.com/SignalK/n2k-signalk", "dependencies": { - "@canboat/canboatjs": "^1.13.1", - "JSONStream": "~1.3.0", + "@canboat/canboatjs": "^2.1.0", "debug": "^4.0.0", "int64-buffer": "^0.99.1007", + "JSONStream": "~1.3.0", "lodash": "^4.17.11", "through": ">=2.2.7 <3" }, diff --git a/pgns/126983.js b/pgns/126983.js index 3071c0de..f2eb0987 100644 --- a/pgns/126983.js +++ b/pgns/126983.js @@ -78,8 +78,8 @@ module.exports = [ //if the alert is silenced or acknowledged then dont alert in SK if ( - n2k.fields['Temporary Silence Status'] == 'Temporary Silence' || - n2k.fields['Acknowledge Status'] == 'Acknowledged' + n2k.fields['Temporary Silence Status'] == 'Yes' || + n2k.fields['Acknowledge Status'] == 'Yes' ) { value.method = [] } diff --git a/pgns/127489.js b/pgns/127489.js index 2c983ed9..b3bf5f57 100644 --- a/pgns/127489.js +++ b/pgns/127489.js @@ -1,5 +1,10 @@ const util = require('util') -const { chooseField, skEngineId, skEngineTitle } = require('../utils.js') +const { + chooseField, + skEngineId, + skEngineTitle, + timeToSeconds +} = require('../utils.js') module.exports = [ { @@ -33,9 +38,11 @@ module.exports = [ } }, { - source: 'Total Engine hours', node: function (n2k) { return 'propulsion.' + skEngineId(n2k) + '.runTime' + }, + value: function (n2k) { + return timeToSeconds(n2k.fields['Total Engine hours']) } }, { @@ -58,7 +65,7 @@ module.exports = [ return 'propulsion.' + skEngineId(n2k) + '.engineLoad' }, value: function (n2k) { - var percent = Number(n2k.fields['Percent Engine Load']) + var percent = Number(n2k.fields['Engine Load']) return isNaN(percent) ? null : percent / 100.0 } }, @@ -67,7 +74,7 @@ module.exports = [ return 'propulsion.' + skEngineId(n2k) + '.engineTorque' }, value: function (n2k) { - var percent = Number(n2k.fields['Percent Engine Torque']) + var percent = Number(n2k.fields['Engine Torque']) return isNaN(percent) ? null : percent / 100.0 } }, diff --git a/pgns/127506.js b/pgns/127506.js index a109e012..9067ccda 100644 --- a/pgns/127506.js +++ b/pgns/127506.js @@ -1,4 +1,4 @@ -const { chooseField } = require('../utils.js') +const { chooseField, timeToSeconds } = require('../utils.js') function instance (n2k) { return chooseField(n2k, 'DC Instance', 'Instance') @@ -25,14 +25,7 @@ module.exports = [ { allowNull: true, value: function (n2k) { - var val = n2k.fields['Time Remaining'] - var res - if (typeof val !== 'undefined') { - res = val * 60 // convert to seconds - } else { - res = null - } - return res + return timeToSeconds(n2k.fields['Time Remaining']) }, node: function (n2k) { return 'electrical.batteries.' + instance(n2k) + '.capacity.timeRemaining' diff --git a/pgns/130306.js b/pgns/130306.js index b09db53b..44513e8d 100644 --- a/pgns/130306.js +++ b/pgns/130306.js @@ -5,7 +5,8 @@ module.exports = [ filter: function (n2k) { return ( n2k.fields['Reference'] === 'Apparent' || - n2k.fields['Reference'] === undefined + n2k.fields['Reference'] === undefined || + n2k.fields['Reference'] === null ) } }, @@ -28,7 +29,8 @@ module.exports = [ filter: function (n2k) { return ( n2k.fields['Reference'] === 'Apparent' || - n2k.fields['Reference'] === undefined + n2k.fields['Reference'] === undefined || + n2k.fields['Reference'] === null ) }, value: function (n2k) { diff --git a/raymarine/126720.js b/raymarine/126720.js index efae8c63..c42859dd 100644 --- a/raymarine/126720.js +++ b/raymarine/126720.js @@ -13,22 +13,22 @@ module.exports = [ }, node: 'steering.autopilot.state', value: function (n2k) { - var mode = Number(n2k.fields['Pilot Mode']) + var mode = n2k.fields['Pilot Mode'] var subMode = Number(n2k.fields['Sub Mode']) if ( - (mode == 0 || mode == 64 || mode == 68 || mode == 72) && + (mode == 0 || mode == 'Standby' || mode == 68 || mode == 72) && subMode == 0 ) { return 'standby' } else if ( - mode == 70 && + mode == 'Wind' && (subMode == 0 || subMode == 4 || subMode == 8 || subMode == 12) ) { // submodes: 0=on course, 4=off course pt/stb, 8=wind shift, submode 12 tbd return 'wind' - } else if (mode == 74 && subMode == 0) { + } else if (mode == 'Track' && subMode == 0) { return 'route' - } else if (mode == 66 && (subMode == 0 || subMode == 4)) { + } else if (mode == 'Auto' && (subMode == 0 || subMode == 4)) { //subMode 4 means offcourse return 'auto' } else { diff --git a/test/126720_seatalk_STNG_pilot_mode.js b/test/126720_seatalk_STNG_pilot_mode.js index 298753e2..d9b4fa81 100644 --- a/test/126720_seatalk_STNG_pilot_mode.js +++ b/test/126720_seatalk_STNG_pilot_mode.js @@ -7,7 +7,7 @@ describe('126720 Seatalk-STNG-Converter Pilot Mode', function () { it('complet pilot mode sentence converts track', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-10-18T15:52:49.048Z","prio":7,"src":115,"dst":255,"pgn":126720,"description":"Seatalk1: Pilot Mode","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Pilot Mode":"74","Sub Mode":"0","Pilot Mode Data":"0"}}' + '{"timestamp":"2016-10-18T15:52:49.048Z","prio":7,"src":115,"dst":255,"pgn":126720,"description":"Seatalk1: Pilot Mode","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Pilot Mode":74,"Sub Mode":0,"Pilot Mode Data":"0","Proprietary ID":33264,"command":132}}' ) ) tree.should.have.nested.property('steering.autopilot.state.value', 'route') @@ -17,7 +17,7 @@ describe('126720 Seatalk-STNG-Converter Pilot Mode', function () { it('complet pilot mode sentence converts auto', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-09-06T22:56:27.719Z","prio":7,"src":115,"dst":255,"pgn":126720,"description":"Seatalk1: Pilot Mode","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Pilot Mode":"66","Sub Mode":"0","Pilot Mode Data":"0"}}' + '{"timestamp":"2016-09-06T22:56:27.719Z","prio":7,"src":115,"dst":255,"pgn":126720,"description":"Seatalk1: Pilot Mode","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Pilot Mode":"66","Sub Mode":"0","Pilot Mode Data":"0","Proprietary ID":33264,"command":132}}' ) ) tree.should.have.nested.property('steering.autopilot.state.value', 'auto') @@ -27,7 +27,7 @@ describe('126720 Seatalk-STNG-Converter Pilot Mode', function () { it('complet pilot mode sentence converts wind', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-09-06T23:01:38.822Z","prio":7,"src":115,"dst":255,"pgn":126720,"description":"Seatalk1: Pilot Mode","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Pilot Mode":"70","Sub Mode":"0","Pilot Mode Data":"0"}}' + '{"timestamp":"2016-09-06T23:01:38.822Z","prio":7,"src":115,"dst":255,"pgn":126720,"description":"Seatalk1: Pilot Mode","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Pilot Mode":"70","Sub Mode":"0","Pilot Mode Data":"0", "Proprietary ID":33264,"command":132}}' ) ) tree.should.have.nested.property('steering.autopilot.state.value', 'wind') @@ -37,7 +37,7 @@ describe('126720 Seatalk-STNG-Converter Pilot Mode', function () { it('complet pilot mode sentence converts standby', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-10-18T15:52:00.751Z","prio":7,"src":115,"dst":255,"pgn":126720,"description":"Seatalk1: Pilot Mode","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Pilot Mode":"0","Sub Mode":"0","Pilot Mode Data":"0"}}' + '{"timestamp":"2016-10-18T15:52:00.751Z","prio":7,"src":115,"dst":255,"pgn":126720,"description":"Seatalk1: Pilot Mode","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Pilot Mode":"0","Sub Mode":"0","Pilot Mode Data":"0","Proprietary ID":33264,"command":132}}' ) ) tree.should.have.nested.property( diff --git a/test/126983_alert.js b/test/126983_alert.js index 8ff51425..24edd1e9 100644 --- a/test/126983_alert.js +++ b/test/126983_alert.js @@ -31,12 +31,12 @@ var value = { dataSourceInstance: 0, 'dataSourceIndex-Source': 0, occurrence: 1, - temporarySilenceStatus: 'Not Temporary Silence', - acknowledgeStatus: 'Not Acknowledged', - escalationStatus: 'Not Escalated', - temporarySilenceSupport: 'Supported', - acknowledgeSupport: 'Supported', - escalationSupport: 'Not Supported', + temporarySilenceStatus: 'No', + acknowledgeStatus: 'No', + escalationStatus: 'No', + temporarySilenceSupport: 'Yes', + acknowledgeSupport: 'Yes', + escalationSupport: 'No', acknowledgeSourceNetworkIDNAME: 1233993542451364400, triggerCondition: 'Auto', thresholdStatus: 'Threshold Exceeded', @@ -47,7 +47,7 @@ var value = { describe('126983 Alert', function () { it('alert without silence or ackknowledgement', function () { var msg = JSON.parse( - '{"canId":166725416,"prio":2,"src":40,"dst":255,"pgn":126983,"direction":"R","time":"15:48:36.090","fields":{"Alert Type":"Warning","Alert Category":"Navigational","Alert System":20,"Alert ID":23480,"Data Source Network ID NAME":6458553273545042000,"Data Source Instance":0,"Data Source Index-Source":0,"Alert Occurrence Number":1,"Temporary Silence Status":"Not Temporary Silence","Acknowledge Status":"Not Acknowledged","Escalation Status":"Not Escalated","Temporary Silence Support":"Supported","Acknowledge Support":"Supported","Escalation Support":"Not Supported","Acknowledge Source Network ID NAME":1233993542451364400,"Trigger Condition":"Auto","Threshold Status":"Threshold Exceeded","Alert Priority":187,"Alert State":"Active"},"description":"Alert","timestamp":"2020-03-03T15:48:36.494Z"}' + '{"canId":166725416,"prio":2,"src":40,"dst":255,"pgn":126983,"direction":"R","time":"15:48:36.090","fields":{"Alert Type":"Warning","Alert Category":"Navigational","Alert System":20,"Alert ID":23480,"Data Source Network ID NAME":6458553273545042000,"Data Source Instance":0,"Data Source Index-Source":0,"Alert Occurrence Number":1,"Temporary Silence Status":"Not Temporary Silence","Acknowledge Status":"Not Acknowledged","Escalation Status":"Not Escalated","Temporary Silence Support":"Yes","Acknowledge Support":"Yes","Escalation Support":"Not Supported","Acknowledge Source Network ID NAME":1233993542451364400,"Trigger Condition":"Auto","Threshold Status":"Threshold Exceeded","Alert Priority":187,"Alert State":"Active"},"description":"Alert","timestamp":"2020-03-03T15:48:36.494Z"}' ) var tree = mapper.toNested(msg, state) tree.should.have.nested.property( @@ -65,10 +65,10 @@ describe('126983 Alert', function () { it('alert with temporary silence', function () { //method should be empty for this test value.method = [] - value.temporarySilenceStatus = 'Temporary Silence' + value.temporarySilenceStatus = 'Yes' var msg = JSON.parse( - '{"canId":166725416,"prio":2,"src":40,"dst":255,"pgn":126983,"direction":"R","time":"15:48:36.090","fields":{"Alert Type":"Warning","Alert Category":"Navigational","Alert System":20,"Alert ID":23480,"Data Source Network ID NAME":6458553273545042000,"Data Source Instance":0,"Data Source Index-Source":0,"Alert Occurrence Number":1,"Temporary Silence Status":"Temporary Silence","Acknowledge Status":"Not Acknowledged","Escalation Status":"Not Escalated","Temporary Silence Support":"Supported","Acknowledge Support":"Supported","Escalation Support":"Not Supported","Acknowledge Source Network ID NAME":1233993542451364400,"Trigger Condition":"Auto","Threshold Status":"Threshold Exceeded","Alert Priority":187,"Alert State":"Active"},"description":"Alert","timestamp":"2020-03-03T15:48:36.494Z"}' + '{"canId":166725416,"prio":2,"src":40,"dst":255,"pgn":126983,"direction":"R","time":"15:48:36.090","fields":{"Alert Type":"Warning","Alert Category":"Navigational","Alert System":20,"Alert ID":23480,"Data Source Network ID NAME":6458553273545042000,"Data Source Instance":0,"Data Source Index-Source":0,"Alert Occurrence Number":1,"Temporary Silence Status":"Yes","Acknowledge Status":"Not Acknowledged","Escalation Status":"Not Escalated","Temporary Silence Support":"Yes","Acknowledge Support":"Yes","Escalation Support":"Not Supported","Acknowledge Source Network ID NAME":1233993542451364400,"Trigger Condition":"Auto","Threshold Status":"Threshold Exceeded","Alert Priority":187,"Alert State":"Active"},"description":"Alert","timestamp":"2020-03-03T15:48:36.494Z"}' ) var tree = mapper.toNested(msg, state) tree.should.have.nested.property( @@ -84,11 +84,11 @@ describe('126983 Alert', function () { }) it('alert with acknowledgement', function () { - value.temporarySilenceStatus = 'Not Temporary Silence' - value.acknowledgeStatus = 'Acknowledged' + value.temporarySilenceStatus = 'No' + value.acknowledgeStatus = 'Yes' var msg = JSON.parse( - '{"canId":166725416,"prio":2,"src":40,"dst":255,"pgn":126983,"direction":"R","time":"15:48:36.090","fields":{"Alert Type":"Warning","Alert Category":"Navigational","Alert System":20,"Alert ID":23480,"Data Source Network ID NAME":6458553273545042000,"Data Source Instance":0,"Data Source Index-Source":0,"Alert Occurrence Number":1,"Temporary Silence Status":"Not Temporary Silence","Acknowledge Status":"Acknowledged","Escalation Status":"Not Escalated","Temporary Silence Support":"Supported","Acknowledge Support":"Supported","Escalation Support":"Not Supported","Acknowledge Source Network ID NAME":1233993542451364400,"Trigger Condition":"Auto","Threshold Status":"Threshold Exceeded","Alert Priority":187,"Alert State":"Active"},"description":"Alert","timestamp":"2020-03-03T15:48:36.494Z"}' + '{"canId":166725416,"prio":2,"src":40,"dst":255,"pgn":126983,"direction":"R","time":"15:48:36.090","fields":{"Alert Type":"Warning","Alert Category":"Navigational","Alert System":20,"Alert ID":23480,"Data Source Network ID NAME":6458553273545042000,"Data Source Instance":0,"Data Source Index-Source":0,"Alert Occurrence Number":1,"Temporary Silence Status":"No","Acknowledge Status":"Yes","Escalation Status":"Not Escalated","Temporary Silence Support":"Yes","Acknowledge Support":"Yes","Escalation Support":"Not Supported","Acknowledge Source Network ID NAME":1233993542451364400,"Trigger Condition":"Auto","Threshold Status":"Threshold Exceeded","Alert Priority":187,"Alert State":"Active"},"description":"Alert","timestamp":"2020-03-03T15:48:36.494Z"}' ) var tree = mapper.toNested(msg, state) tree.should.have.nested.property( diff --git a/test/127245_rudder.js b/test/127245_rudder.js index 76d7f6ad..8d56a713 100644 --- a/test/127245_rudder.js +++ b/test/127245_rudder.js @@ -6,14 +6,14 @@ describe('127245_rudder ', function () { it('complete sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2013-10-08T15:47:28.263Z","prio":"2","src":"204","dst":"255","pgn":"127245","description":"Rudder","fields":{"Instance":"0","Position":"-0.7"}}' + '{"timestamp":"2013-10-08T15:47:28.263Z","prio":"2","src":"204","dst":"255","pgn":"127245","description":"Rudder","fields":{"Instance":"0","Position":-0.0026}}' ) ) tree.steering.rudderAngle.should.have.property( 'timestamp', '2013-10-08T15:47:28.263Z' ) - tree.steering.rudderAngle.should.have.property('value', -0.7) + tree.steering.rudderAngle.should.have.property('value', -0.0026) tree.should.be.validSignalKVesselIgnoringIdentity }) diff --git a/test/127250_heading.js b/test/127250_heading.js index 3d49a61a..f2c14141 100644 --- a/test/127250_heading.js +++ b/test/127250_heading.js @@ -7,12 +7,12 @@ describe('127250 Heading', function () { it('Magnetic sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2013-10-08-15:47:28.263Z","prio":"2","src":"204","dst":"255","pgn":"127250","description":"Vessel Heading","fields":{"Heading":"129.7","Reference":"Magnetic"}}' + '{"timestamp":"2013-10-08-15:47:28.263Z","prio":"2","src":"204","dst":"255","pgn":"127250","description":"Vessel Heading","fields":{"Heading":1.7447,"Reference":"Magnetic"}}' ) ) tree.should.have.with.nested.property( 'navigation.headingMagnetic.value', - 129.7 + 1.7447 ) tree.should.be.validSignalKVesselIgnoringIdentity }) @@ -20,12 +20,12 @@ describe('127250 Heading', function () { it('Variation sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2013-10-08-15:47:28.264Z","prio":"2","src":"1","dst":"255","pgn":"127250","description":"Vessel Heading","fields":{"SID":"68","Variation":"8.0","Reference":"True"}}' + '{"timestamp":"2013-10-08-15:47:28.264Z","prio":"2","src":"1","dst":"255","pgn":"127250","description":"Vessel Heading","fields":{"SID":"68","Variation":-0.1956, "Reference":"True"}}' ) ) tree.should.have.with.nested.property( 'navigation.magneticVariation.value', - 8 + -0.1956 ) tree.should.be.validSignalKVesselIgnoringIdentity }) @@ -33,10 +33,10 @@ describe('127250 Heading', function () { it('True heading sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-04-14T09:34:11.275Z","prio":2,"src":2,"dst":255,"pgn":127250,"description":"Vessel Heading","fields":{"Heading":14.8,"Variation":0.0,"Reference":"True"}}' + '{"timestamp":"2016-04-14T09:34:11.275Z","prio":2,"src":2,"dst":255,"pgn":127250,"description":"Vessel Heading","fields":{"Heading":1.871,"Variation":0.0,"Reference":"True"}}' ) ) - tree.should.have.with.nested.property('navigation.headingTrue.value', 14.8) + tree.should.have.with.nested.property('navigation.headingTrue.value', 1.871) tree.should.be.validSignalKVesselIgnoringIdentity }) diff --git a/test/127257_attitude.js b/test/127257_attitude.js index 899d46c1..906b7e15 100644 --- a/test/127257_attitude.js +++ b/test/127257_attitude.js @@ -7,12 +7,12 @@ describe('127257_attitude', function () { it('complete sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2013-10-08-15:47:28.263Z","prio":"2","src":"204","dst":"255","pgn":"127257","description":"Attitude","fields":{"Yaw":"37.190","Pitch":"0.464","Roll":"-2.496"}}' + '{"timestamp":"2013-10-08-15:47:28.263Z","prio":"2","src":"204","dst":"255","pgn":"127257","description":"Attitude","fields":{"Yaw":1.9594,"Pitch":0.0267,"Roll":-0.0155}}' ) ) - tree.should.have.nested.property('navigation.attitude.value.yaw', 37.19) - tree.should.have.nested.property('navigation.attitude.value.pitch', 0.464) - tree.should.have.nested.property('navigation.attitude.value.roll', -2.496) + tree.should.have.nested.property('navigation.attitude.value.yaw', 1.9594) + tree.should.have.nested.property('navigation.attitude.value.pitch', 0.0267) + tree.should.have.nested.property('navigation.attitude.value.roll', -0.0155) tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/127258_variation.js b/test/127258_variation.js index 2fbf41fb..b0c7dc95 100644 --- a/test/127258_variation.js +++ b/test/127258_variation.js @@ -6,10 +6,10 @@ describe('127258_variation ', function () { it('complete sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2015-01-15-16:25:11.333Z","prio":7,"src":4,"dst":255,"pgn":127258,"description":"Magnetic Variation","fields":{"SID":247,"Variation":16.1}}' + '{"timestamp":"2015-01-15-16:25:11.333Z","prio":7,"src":4,"dst":255,"pgn":127258,"description":"Magnetic Variation","fields":{"SID":247,"Variation":1.1}}' ) ) - tree.navigation.magneticVariation.should.have.property('value', 16.1) + tree.navigation.magneticVariation.should.have.property('value', 1.1) tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/127488_engine_boost.js b/test/127488_engine_boost.js index 84cdda6e..4ca7e275 100644 --- a/test/127488_engine_boost.js +++ b/test/127488_engine_boost.js @@ -3,54 +3,48 @@ 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') - ] -} - describe('127488 engine boost Port', function () { it('complete engine boost 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", "Boost Pressure": 127}}' - ).forEach(pgn => { - var tree = require('./testMapper').toNested(JSON.parse(pgn)) - tree.should.have.nested.property('propulsion.port.boostPressure') - tree.should.have.nested.property( - 'propulsion.port.boostPressure.value', - 127 + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:16:56.749Z","prio":"2","src":"17","dst":"255","pgn":"127488","description":"Engine Parameters, Rapid Update","fields":{"Instance":"Single Engine or Dual Engine Port","Speed":3190, "Boost Pressure": 393000}}' ) - tree.should.be.validSignalKVesselIgnoringIdentity - }) + ) + tree.should.have.nested.property('propulsion.port.boostPressure') + tree.should.have.nested.property( + 'propulsion.port.boostPressure.value', + 393000 + ) + tree.should.be.validSignalKVesselIgnoringIdentity }) }) describe('127488 engine boost 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","Boost Pressure": 128}}' - ).forEach(pgn => { - var tree = require('./testMapper').toNested(JSON.parse(pgn)) - tree.should.have.nested.property('propulsion.starboard.boostPressure') - tree.should.have.nested.property( - 'propulsion.starboard.boostPressure.value', - 128 + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:16:56.749Z","prio":"2","src":"17","dst":"255","pgn":"127488","description":"Engine Parameters, Rapid Update","fields":{"Instance":"Dual Engine Starboard","Speed":"3190","Boost Pressure": 393000}}' ) - tree.should.be.validSignalKVesselIgnoringIdentity - }) + ) + tree.should.have.nested.property('propulsion.starboard.boostPressure') + tree.should.have.nested.property( + 'propulsion.starboard.boostPressure.value', + 393000 + ) + tree.should.be.validSignalKVesselIgnoringIdentity }) }) describe('127488 engine boost 2', 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":2,"Engine Speed":"3190", "Boost Pressure": 129}}' - ).forEach(pgn => { - var tree = require('./testMapper').toNested(JSON.parse(pgn)) - tree.should.have.nested.property('propulsion.2.boostPressure') - tree.should.have.nested.property('propulsion.2.boostPressure.value', 129) - tree.should.be.validSignalKVesselIgnoringIdentity - }) + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:16:56.749Z","prio":"2","src":"17","dst":"255","pgn":"127488","description":"Engine Parameters, Rapid Update","fields":{"Instance":2,"Speed":3190, "Boost Pressure": 393000}}' + ) + ) + + tree.should.have.nested.property('propulsion.2.boostPressure') + tree.should.have.nested.property('propulsion.2.boostPressure.value', 393000) + tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/127488_engine_speed.js b/test/127488_engine_speed.js index 0b039e8e..2f6c6cb9 100644 --- a/test/127488_engine_speed.js +++ b/test/127488_engine_speed.js @@ -3,57 +3,50 @@ 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') - ] -} - 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 + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:16:56.749Z","prio":"2","src":"17","dst":"255","pgn":"127488","description":"Engine Parameters, Rapid Update","fields":{"Instance":"Single Engine or Dual Engine Port","Speed":3190}}' ) - tree.should.be.validSignalKVesselIgnoringIdentity - }) + ) + 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 + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:16:56.749Z","prio":"2","src":"17","dst":"255","pgn":"127488","description":"Engine Parameters, Rapid Update","fields":{"Instance":"Dual Engine Starboard","Speed":3190}}' ) - tree.should.be.validSignalKVesselIgnoringIdentity - }) + ) + tree.should.have.nested.property('propulsion.starboard.revolutions') + tree.should.have.nested.property( + 'propulsion.starboard.revolutions.value', + 53.166666666666664 + ) + tree.should.be.validSignalKVesselIgnoringIdentity }) }) describe('127488 engine speed 2', 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":2,"Engine Speed":"3190"}}' - ).forEach(pgn => { - var tree = require('./testMapper').toNested(JSON.parse(pgn)) - tree.should.have.nested.property('propulsion.2.revolutions') - tree.should.have.nested.property( - 'propulsion.2.revolutions.value', - 53.166666666666664 + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:16:56.749Z","prio":"2","src":"17","dst":"255","pgn":"127488","description":"Engine Parameters, Rapid Update","fields":{"Instance":2,"Speed":3190}}' ) - tree.should.be.validSignalKVesselIgnoringIdentity - }) + ) + tree.should.have.nested.property('propulsion.2.revolutions') + tree.should.have.nested.property( + 'propulsion.2.revolutions.value', + 53.166666666666664 + ) + tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/127488_engine_trim.js b/test/127488_engine_trim.js index 34f1732d..dc77bd25 100644 --- a/test/127488_engine_trim.js +++ b/test/127488_engine_trim.js @@ -4,7 +4,7 @@ chai.use(require('chai-things')) chai.use(require('@signalk/signalk-schema').chaiModule) function generatePGNs (json) { - return [json, json.replace('Engine Instance', 'Instance')] + return [json.replace('Engine Instance', 'Instance')] } describe('127488 engine trim Port', function () { diff --git a/test/127489_engine_params.js b/test/127489_engine_params.js index dd1d0cc5..0ce6e3fe 100644 --- a/test/127489_engine_params.js +++ b/test/127489_engine_params.js @@ -3,385 +3,366 @@ chai.Should() chai.use(require('chai-things')) chai.use(require('@signalk/signalk-schema').chaiModule) -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 + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489", "description":"Engine Parameters, Dynamic","fields":{"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"],"Engine Load": 20,"Engine Torque":57,"Oil pressure":80000,"Fuel Pressure":504000,"Oil temperature":36,"Coolant Pressure":38900}}' ) + ) - 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 - }) + 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', + 38900000 + ) + tree.should.have.nested.property('propulsion.port.fuel.pressure') + tree.should.have.nested.property( + 'propulsion.port.fuel.pressure.value', + 504000000 + ) + + 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', 80000) + 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 - }) + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489", "description":"Engine Parameters, Dynamic","fields":{"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"],"Engine Load": 20,"Engine Torque":57,"Oil pressure":80000}}' + ) + ) + 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', 80000) + 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 + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489", "description":"Engine Parameters, Dynamic","fields":{"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"],"Engine Load": 20,"Engine Torque":57,"Oil pressure":80000,"Fuel Pressure":504000,"Oil temperature":36,"Coolant Pressure":38900}}' ) + ) - 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.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', + 38900000 + ) + tree.should.have.nested.property('propulsion.starboard.fuel.pressure') + tree.should.have.nested.property( + 'propulsion.starboard.fuel.pressure.value', + 504000000 + ) + + 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', + 80000 + ) + 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 - }) + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489","description":"Engine Parameters, Dynamic","fields":{"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"],"Engine Load": 20,"Engine Torque": 57,"Oil pressure":80000}}' + ) + ) + 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', + 80000 + ) + 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' - ) - tree.should.be.validSignalKVesselIgnoringIdentity - }) + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489","description":"Engine Parameters, Dynamic","fields":{"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": [],"Engine Load": 20,"Engine Torque": 57,"Oil pressure":80000}}' + ) + ) + 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 }) }) describe('127489 engine parameters 2', 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":2,"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.2.oilTemperature') - tree.should.have.nested.property('propulsion.2.oilTemperature.value', 36) - tree.should.have.nested.property('propulsion.2.coolantPressure') - tree.should.have.nested.property( - 'propulsion.2.coolantPressure.value', - 489000 - ) - tree.should.have.nested.property('propulsion.2.fuel.pressure') - tree.should.have.nested.property( - 'propulsion.2.fuel.pressure.value', - 504000 + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489", "description":"Engine Parameters, Dynamic","fields":{"Instance":2,"Temperature":29.85,"Alternator Potential":12.60,"Fuel Rate":0.4,"Total Engine hours":"52:20:22","Discrete Status 1":["Low Oil Pressure","Low Coolant Level"],"Discrete Status 2":[ "Warning Level 1","Maintenance Needed"],"Engine Load": 20,"Engine Torque":57,"Oil pressure":80000,"Fuel Pressure": 28000,"Oil temperature":36,"Coolant Pressure":38900}}' ) + ) - tree.should.have.nested.property('propulsion.2.temperature') - tree.should.have.nested.property('propulsion.2.temperature.value', 29.85) - tree.should.have.nested.property('propulsion.2.alternatorVoltage') - tree.should.have.nested.property( - 'propulsion.2.alternatorVoltage.value', - 12.6 - ) - tree.should.have.nested.property('propulsion.2.fuel.rate') - tree.should.have.nested.property( - 'propulsion.2.fuel.rate.value', - 1.1111111111111112e-7 - ) - tree.should.have.nested.property('propulsion.2.runTime') - tree.should.have.nested.property('propulsion.2.runTime.value', 309960) - tree.should.have.nested.property('propulsion.2.oilPressure') - tree.should.have.nested.property('propulsion.2.oilPressure.value', 80) - tree.should.have.nested.property('propulsion.2.engineLoad.value', 0.2) - tree.should.have.nested.property('propulsion.2.engineTorque.value', 0.57) - tree.should.have.nested.property( - 'notifications.propulsion.2.lowOilPressure.value.state', - 'alarm' - ) - tree.should.have.nested.property( - 'notifications.propulsion.2.lowCoolantLevel.value.state', - 'alarm' - ) - tree.should.have.nested.property( - 'notifications.propulsion.2.warningLevel1.value.state', - 'alarm' - ) - tree.should.have.nested.property( - 'notifications.propulsion.2.maintenanceNeeded.value.state', - 'alarm' - ) - tree.should.be.validSignalKVesselIgnoringIdentity - }) + tree.should.have.nested.property('propulsion.2.oilTemperature') + tree.should.have.nested.property('propulsion.2.oilTemperature.value', 36) + tree.should.have.nested.property('propulsion.2.coolantPressure') + tree.should.have.nested.property( + 'propulsion.2.coolantPressure.value', + 38900000 + ) + tree.should.have.nested.property('propulsion.2.fuel.pressure') + tree.should.have.nested.property( + 'propulsion.2.fuel.pressure.value', + 28000000 + ) + + tree.should.have.nested.property('propulsion.2.temperature') + tree.should.have.nested.property('propulsion.2.temperature.value', 29.85) + tree.should.have.nested.property('propulsion.2.alternatorVoltage') + tree.should.have.nested.property( + 'propulsion.2.alternatorVoltage.value', + 12.6 + ) + tree.should.have.nested.property('propulsion.2.fuel.rate') + tree.should.have.nested.property( + 'propulsion.2.fuel.rate.value', + 1.1111111111111112e-7 + ) + tree.should.have.nested.property('propulsion.2.runTime') + tree.should.have.nested.property('propulsion.2.runTime.value', 188422) + tree.should.have.nested.property('propulsion.2.oilPressure') + tree.should.have.nested.property('propulsion.2.oilPressure.value', 80000) + tree.should.have.nested.property('propulsion.2.engineLoad.value', 0.2) + tree.should.have.nested.property('propulsion.2.engineTorque.value', 0.57) + tree.should.have.nested.property( + 'notifications.propulsion.2.lowOilPressure.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.2.lowCoolantLevel.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.2.warningLevel1.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.2.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":2,"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.2.temperature') - tree.should.have.nested.property('propulsion.2.temperature.value', 29.85) - tree.should.have.nested.property('propulsion.2.alternatorVoltage') - tree.should.have.nested.property( - 'propulsion.2.alternatorVoltage.value', - 12.6 - ) - tree.should.have.nested.property('propulsion.2.fuel.rate') - tree.should.have.nested.property( - 'propulsion.2.fuel.rate.value', - 1.1111111111111112e-7 - ) - tree.should.have.nested.property('propulsion.2.runTime') - tree.should.have.nested.property('propulsion.2.runTime.value', 309960) - tree.should.have.nested.property('propulsion.2.oilPressure') - tree.should.have.nested.property('propulsion.2.oilPressure.value', 80) - tree.should.have.nested.property('propulsion.2.engineLoad.value', 0.2) - tree.should.have.nested.property('propulsion.2.engineTorque.value', 0.57) - tree.should.have.nested.property( - 'notifications.propulsion.2.lowOilPressure.value.state', - 'alarm' - ) - tree.should.have.nested.property( - 'notifications.propulsion.2.lowCoolantLevel.value.state', - 'alarm' - ) - tree.should.have.nested.property( - 'notifications.propulsion.2.warningLevel1.value.state', - 'alarm' - ) - tree.should.have.nested.property( - 'notifications.propulsion.2.maintenanceNeeded.value.state', - 'alarm' - ) - tree.should.be.validSignalKVesselIgnoringIdentity - }) + var tree = require('./testMapper').toNested( + JSON.parse( + '{"timestamp":"2015-01-15-16:25:14.952Z","prio":"2","src":"17","dst":"255","pgn":"127489", "description":"Engine Parameters, Dynamic","fields":{"Instance":2,"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"],"Engine Load": 20,"Engine Torque":57,"Oil pressure":80000}}' + ) + ) + tree.should.have.nested.property('propulsion.2.temperature') + tree.should.have.nested.property('propulsion.2.temperature.value', 29.85) + tree.should.have.nested.property('propulsion.2.alternatorVoltage') + tree.should.have.nested.property( + 'propulsion.2.alternatorVoltage.value', + 12.6 + ) + tree.should.have.nested.property('propulsion.2.fuel.rate') + tree.should.have.nested.property( + 'propulsion.2.fuel.rate.value', + 1.1111111111111112e-7 + ) + tree.should.have.nested.property('propulsion.2.runTime') + tree.should.have.nested.property('propulsion.2.runTime.value', 309960) + tree.should.have.nested.property('propulsion.2.oilPressure') + tree.should.have.nested.property('propulsion.2.oilPressure.value', 80000) + tree.should.have.nested.property('propulsion.2.engineLoad.value', 0.2) + tree.should.have.nested.property('propulsion.2.engineTorque.value', 0.57) + tree.should.have.nested.property( + 'notifications.propulsion.2.lowOilPressure.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.2.lowCoolantLevel.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.2.warningLevel1.value.state', + 'alarm' + ) + tree.should.have.nested.property( + 'notifications.propulsion.2.maintenanceNeeded.value.state', + 'alarm' + ) + tree.should.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/127493_transmission.js b/test/127493_transmission.js index df2cafe8..46c09ac1 100644 --- a/test/127493_transmission.js +++ b/test/127493_transmission.js @@ -4,13 +4,13 @@ chai.use(require('chai-things')) chai.use(require('@signalk/signalk-schema').chaiModule) function generatePGNs (json) { - return [json, json.replace('Engine Instance', 'Instance')] + return [json.replace('Engine Instance', 'Instance')] } describe('127493 transmission parameters Port', function () { it('every field in the PGN from the NMEA2000 spec converts', function () { generatePGNs( - '{ "prio": 2, "pgn": 127493, "dst": 255, "src": 40, "timestamp": "2020-03-07T18:49:14.471Z", "fields": { "Instance": "Single Engine or Dual Engine Port", "Transmission Gear": "Forward", "Oil pressure": 20, "Oil temperature": 15, "Discrete Status 1": 34 } }' + '{ "prio": 2, "pgn": 127493, "dst": 255, "src": 40, "timestamp": "2020-03-07T18:49:14.471Z", "fields": { "Instance": "Single Engine or Dual Engine Port", "Transmission Gear": "Forward", "Oil pressure": 2000, "Oil temperature": 15, "Discrete Status 1": 34 } }' ).forEach(pgn => { var tree = require('./testMapper').toNested(JSON.parse(pgn)) @@ -24,7 +24,7 @@ describe('127493 transmission parameters Port', function () { ) tree.should.have.nested.property( 'propulsion.port.transmission.oilPressure.value', - 20 + 2000 ) tree.should.have.nested.property( 'notifications.propulsion.port.transmission.checkTransmission.value.state', @@ -56,7 +56,7 @@ describe('127493 transmission parameters Port', function () { it('every field in the PGN from the NMEA2000 spec converts with discrete text', function () { generatePGNs( - '{ "prio": 2, "pgn": 127493, "dst": 255, "src": 40, "timestamp": "2020-03-07T18:49:14.471Z", "fields": { "Instance": "Single Engine or Dual Engine Port", "Transmission Gear": "Forward", "Oil pressure": 20, "Oil temperature": 15, "Discrete Status 1": [ "Sail Drive" ] } }' + '{ "prio": 2, "pgn": 127493, "dst": 255, "src": 40, "timestamp": "2020-03-07T18:49:14.471Z", "fields": { "Instance": "Single Engine or Dual Engine Port", "Transmission Gear": "Forward", "Oil pressure": 2000, "Oil temperature": 15, "Discrete Status 1": [ "Check Engine" ] } }' ).forEach(pgn => { var tree = require('./testMapper').toNested(JSON.parse(pgn)) @@ -70,7 +70,7 @@ describe('127493 transmission parameters Port', function () { ) tree.should.have.nested.property( 'propulsion.port.transmission.oilPressure.value', - 20 + 2000 ) tree.should.have.nested.property( 'notifications.propulsion.port.transmission.checkTransmission.value.state', @@ -88,10 +88,13 @@ describe('127493 transmission parameters Port', function () { 'notifications.propulsion.port.transmission.lowOilLevel.value.state', 'normal' ) + /* + //canboat does not currently suoport decoding/encoding this tree.should.have.nested.property( 'notifications.propulsion.port.transmission.sailDrive.value.state', 'alarm' ) + */ //temporarily until the specification is fixed delete tree.propulsion.port.transmission.gear diff --git a/test/127505_fluid_level.js b/test/127505_fluid_level.js index 94675702..0be9e4ec 100644 --- a/test/127505_fluid_level.js +++ b/test/127505_fluid_level.js @@ -7,16 +7,16 @@ describe('127505 fuel', function () { it('just level, no capacity', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2015-01-15-16:15:30.984Z","prio":"6","src":"17","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"0","Type":"Fuel","Level":"131.068"}}' + '{"timestamp":"2015-01-15-16:15:30.984Z","prio":"6","src":"17","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"0","Type":"Fuel","Level":99}}' ) ) - tree.should.have.nested.property('tanks.fuel.0.currentLevel.value', 1.31068) + tree.should.have.nested.property('tanks.fuel.0.currentLevel.value', 0.99) tree.should.be.validSignalKVesselIgnoringIdentity }) it('level and capacity', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2015-01-15-16:15:33.341Z","prio":"6","src":"112","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"1","Type":"Fuel","Level":"64.284","Capacity":"41.6"}}' + '{"timestamp":"2015-01-15-16:15:33.341Z","prio":"6","src":"112","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"1","Type":"Fuel","Level":64.284,"Capacity":41.6}}' ) ) tree.tanks.fuel['1'].currentLevel.value.should.be.closeTo(0.64284, 0.000005) @@ -29,7 +29,7 @@ describe('127505 water', function () { it('level and capacity', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2015-01-15-16:15:33.366Z","prio":"6","src":"114","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"0","Type":"Water","Level":"88.596","Capacity":"71.9"}}' + '{"timestamp":"2015-01-15-16:15:33.366Z","prio":"6","src":"114","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"0","Type":"Water","Level":88.596,"Capacity":71.9}}' ) ) tree.tanks.freshWater['0'].currentLevel.value.should.be.closeTo( @@ -48,7 +48,7 @@ describe('127505 grayWater', function () { it('level and capacity', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2015-01-15-16:15:33.369Z","prio":"6","src":"113","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"0","Type":"Gray water","Level":"90.240","Capacity":"37.9"}}' + '{"timestamp":"2015-01-15-16:15:33.369Z","prio":"6","src":"113","dst":"255","pgn":"127505","description":"Fluid Level","fields":{"Instance":"0","Type":"Gray water","Level":90.240,"Capacity":37.9}}' ) ) tree.should.have.nested.property( diff --git a/test/127506_dc_detailed_status.js b/test/127506_dc_detailed_status.js index 90343049..d995c90a 100644 --- a/test/127506_dc_detailed_status.js +++ b/test/127506_dc_detailed_status.js @@ -4,12 +4,12 @@ chai.use(require('chai-things')) chai.use(require('@signalk/signalk-schema').chaiModule) function generatePGNs (json) { - return [json, json.replace('DC Instance', 'Instance')] + return [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}}' + '{"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": "00:30:00", "Ripple Voltage": 10.9, "SID":0}}' ).forEach(pgn => { var tree = require('./testMapper').toNested(JSON.parse(pgn)) tree.should.have.nested.property( @@ -22,7 +22,7 @@ describe('127506 dc detailed status', function () { ) tree.should.have.nested.property( 'electrical.batteries.1.capacity.timeRemaining.value', - 36000 + 1800 ) // tree.should.have.nested.property('electrical.batteries.1.voltage.ripple.value', 10.9); tree.should.be.validSignalKVesselIgnoringIdentity diff --git a/test/127508_battery_voltage.js b/test/127508_battery_voltage.js index cc8f845f..e4415af1 100644 --- a/test/127508_battery_voltage.js +++ b/test/127508_battery_voltage.js @@ -5,9 +5,9 @@ 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 pgns = [ + '{"timestamp":"2016-08-22T16:02:55.272Z","prio":6,"src":17,"dst":255,"pgn":127508,"description":"Battery Status","fields":{"Instance":1,"Voltage":13.11,"Current":5.6,"Temperature": 299, "SID":0}}' + ] pgns.forEach(pgn => { var tree = require('./testMapper').toNested(JSON.parse(pgn)) tree.should.have.nested.property( diff --git a/test/127750_converter_status.js b/test/127750_converter_status.js index a8c65610..7ce7cc71 100644 --- a/test/127750_converter_status.js +++ b/test/127750_converter_status.js @@ -15,9 +15,9 @@ describe('127750 converter status', function () { 'Connection Number': 1, 'Operating State': 'Absorption', 'Temperature State': 'Warning', - 'Overload State': 'Overload', - 'Low DC Voltage State': 'DC voltage too low', - 'Ripple State': 'Ripple Too High' + 'Overload State': 'Error', + 'Low DC Voltage State': 'Error', + 'Ripple State': 'Error' } }) tree.should.have.nested.property( @@ -30,15 +30,15 @@ describe('127750 converter status', function () { ) tree.should.have.nested.property( 'electrical.converter.10.1.overloadState.value', - 'overload' + 'error' ) tree.should.have.nested.property( 'electrical.converter.10.1.lowDCVoltageState.value', - 'dc voltage too low' + 'error' ) tree.should.have.nested.property( 'electrical.converter.10.1.rippleState.value', - 'ripple too high' + 'error' ) }) diff --git a/test/128259_speed.js b/test/128259_speed.js index 4d428773..fd9c2eda 100644 --- a/test/128259_speed.js +++ b/test/128259_speed.js @@ -7,7 +7,7 @@ describe('128259 speed', function () { it('complete sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2014-08-15-18:00:30.175Z","prio":"2","src":"115","dst":"255","pgn":"128259","description":"Speed","fields":{"SID":"0","Speed Water Referenced":"3.47"}}' + '{"timestamp":"2014-08-15-18:00:30.175Z","prio":"2","src":"115","dst":"255","pgn":"128259","description":"Speed","fields":{"SID":"0","Speed Water Referenced":3.47}}' ) ) tree.should.have.nested.property('navigation.speedThroughWater') @@ -18,7 +18,7 @@ describe('128259 speed', function () { it('speed water reference type converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2014-08-15-18:00:30.175Z","prio":"2","src":"115","dst":"255","pgn":"128259","description":"Speed","fields":{"SID":"0","Speed Water Referenced":"3.47", "Speed Water Referenced Type":"Paddle wheel"}}' + '{"timestamp":"2014-08-15-18:00:30.175Z","prio":"2","src":"115","dst":"255","pgn":"128259","description":"Speed","fields":{"SID":"0","Speed Water Referenced":3.47, "Speed Water Referenced Type":"Paddle wheel"}}' ) ) tree.should.have.nested.property('navigation.speedThroughWater') diff --git a/test/128267_water_depth.js b/test/128267_water_depth.js index f3ed02db..78c7daef 100644 --- a/test/128267_water_depth.js +++ b/test/128267_water_depth.js @@ -7,7 +7,7 @@ describe('128267_water_depth', function () { it('complete positive offset sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2013-10-08-15:47:28.280Z","prio":"3","src":"1","dst":"255","pgn":"128267","description":"Water Depth","fields":{"SID":"91","Depth":"8.20", "Offset":0.304}}' + '{"timestamp":"2013-10-08-15:47:28.280Z","prio":"3","src":"1","dst":"255","pgn":"128267","description":"Water Depth","fields":{"SID":"91","Depth":8.20, "Offset":0.304}}' ) ) tree.should.have.nested.property( @@ -28,7 +28,7 @@ describe('128267_water_depth', function () { it('complete negative offset sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2013-10-08-15:47:28.280Z","prio":"3","src":"1","dst":"255","pgn":"128267","description":"Water Depth","fields":{"SID":"91","Depth":"8.20", "Offset":-0.304}}' + '{"timestamp":"2013-10-08-15:47:28.280Z","prio":"3","src":"1","dst":"255","pgn":"128267","description":"Water Depth","fields":{"SID":"91","Depth":8.20, "Offset":-0.304}}' ) ) tree.should.have.nested.property( diff --git a/test/129025_position.js b/test/129025_position.js index 087e398e..8aac0092 100644 --- a/test/129025_position.js +++ b/test/129025_position.js @@ -3,7 +3,7 @@ chai.Should() chai.use(require('@signalk/signalk-schema').chaiModule) var msg = JSON.parse( - '{"timestamp":"2013-10-08-15:47:28.264Z","prio":"2","src":"2","dst":"255","pgn":"129025","description":"Position, Rapid Update","fields":{"Latitude":"60.1445540","Longitude":"24.7921348"}}' + '{"timestamp":"2013-10-08-15:47:28.264Z","prio":"2","src":"2","dst":"255","pgn":"129025","description":"Position, Rapid Update","fields":{"Latitude":60.1445540,"Longitude":24.7921348}}' ) // Seen in the wild - Original sentence: $PCDIN,01F801,5B26371E,01,FFFFFF7FFFFFFF7F*2C diff --git a/test/129026_cog_sog_rapid_update.js b/test/129026_cog_sog_rapid_update.js index 67125bf5..01dc2a47 100644 --- a/test/129026_cog_sog_rapid_update.js +++ b/test/129026_cog_sog_rapid_update.js @@ -7,13 +7,13 @@ describe('129026 COG & SOG, Rapid Update', function () { it('complete sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2014-08-15-18:00:10.005Z","prio":"2","src":"160","dst":"255","pgn":"129026","description":"COG & SOG, Rapid Update","fields":{"COG Reference":"True","COG":"206.1","SOG":"3.65"}}' + '{"timestamp":"2014-08-15-18:00:10.005Z","prio":"2","src":"160","dst":"255","pgn":"129026","description":"COG & SOG, Rapid Update","fields":{"COG Reference":"True","COG":2.9384,"SOG":3.65}}' ) ) tree.should.have.nested.property('navigation.courseOverGroundTrue') tree.should.have.nested.property( 'navigation.courseOverGroundTrue.value', - 206.1 + 2.9384 ) tree.should.have.nested.property('navigation.speedOverGround') tree.should.have.nested.property('navigation.speedOverGround.value', 3.65) diff --git a/test/129029_position_data.js b/test/129029_position_data.js index 90a61a0d..db297562 100644 --- a/test/129029_position_data.js +++ b/test/129029_position_data.js @@ -1,9 +1,10 @@ var chai = require('chai') chai.Should() +chai.use(require('chai-things')) chai.use(require('@signalk/signalk-schema').chaiModule) 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":[{}]}}' + '{"timestamp":"2017-04-15T15:50:48.664Z","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","Method":"DGNSS fix","Integrity":"No integrity checking","Number of SVs":10,"HDOP":0.9,"PDOP":1.6,"Geoidal Separation":-30.9,"Reference Stations":1,"list":[{"Reference Station ID":15,"Age of DGNSS Corrections": 30}]},"description":"GNSS Position Data"}' ) // 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 @@ -14,19 +15,21 @@ const invalidDataMsg = JSON.parse( describe('129029 Position Data ', function () { it('complete sentence converts', function () { var tree = require('./testMapper').toNested(msg) - tree.navigation.position.value.longitude.should.equal(-76.3972731) - tree.navigation.position.value.latitude.should.equal(39.0536632) - tree.navigation.datetime.value.should.equal('2017-04-15T15:50:48.04950Z') - tree.navigation.gnss.antennaAltitude.value.should.equal(1.0) - tree.navigation.gnss.satellites.value.should.equal(18) - tree.navigation.gnss.horizontalDilution.value.should.equal(0.73) - tree.navigation.gnss.positionDilution.value.should.equal(1.2) - tree.navigation.gnss.geoidalSeparation.value.should.equal(-0.01) - tree.navigation.gnss.differentialAge.value.should.equal(30) - tree.navigation.gnss.differentialReference.value.should.equal(22) - tree.navigation.gnss.type.value.should.equal('Combined GPS/GLONASS') - tree.navigation.gnss.methodQuality.value.should.equal('GNSS Fix') + tree.navigation.position.value.longitude.should.equal(-70.8850733) + tree.navigation.position.value.latitude.should.equal(42.4913166) + tree.navigation.datetime.value.should.equal('2020-03-09T17:47:47.80000Z') + tree.navigation.gnss.antennaAltitude.value.should.equal(41.4) + tree.navigation.gnss.satellites.value.should.equal(10) + tree.navigation.gnss.horizontalDilution.value.should.equal(0.9) + tree.navigation.gnss.positionDilution.value.should.equal(1.6) + tree.navigation.gnss.geoidalSeparation.value.should.equal(-30.9) + tree.navigation.gnss.type.value.should.equal('GPS') + tree.navigation.gnss.methodQuality.value.should.equal('DGNSS fix') tree.navigation.gnss.integrity.value.should.equal('no Integrity checking') + + //tree.navigation.gnss.differentialAge.value.should.equal(30) + //tree.navigation.gnss.differentialReference.value.should.equal(22) + tree.should.be.validSignalKVesselIgnoringIdentity }) it('no position in input produces no position output', function () { diff --git a/test/129038_ais_class_a.js b/test/129038_ais_class_a.js index df419be5..418dd1f6 100644 --- a/test/129038_ais_class_a.js +++ b/test/129038_ais_class_a.js @@ -9,13 +9,13 @@ var mapper = require('./testMapper') describe('129038 Class A Update', function () { it('complete sentence converts', function () { var msg = JSON.parse( - '{"timestamp":"2014-08-15-15:00:01.665Z","prio":"4","src":"43","dst":"255","pgn":"129038","description":"AIS Class A Position Report","fields":{"Message ID":"1","Repeat Indicator":"Initial","User ID":"230982000","Longitude":"25.2026083","Latitude":"60.2176150","Position Accuracy":"High","RAIM":"not in use","Time Stamp":"0","COG":"154.0","SOG":"2.26","Communication State":"2286","AIS Transceiver information":"Channel B VDL reception","Heading":"153.0","Rate of Turn":"0.047","Nav Status":"Under way using engine"}}' + '{"timestamp":"2014-08-15-15:00:01.665Z","prio":"4","src":"43","dst":"255","pgn":"129038","description":"AIS Class A Position Report","fields":{"Message ID":"1","Repeat Indicator":"Initial","User ID":"230982000","Longitude":25.2026083,"Latitude":60.2176150,"Position Accuracy":"High","RAIM":"not in use","Time Stamp":"0","COG":1.54,"SOG":2.26,"Communication State":"2286","AIS Transceiver information":"Channel B VDL reception","Heading":2.2672,"Rate of Turn":0.047,"Nav Status":"Under way using engine"}}' ) var tree = mapper.toNested(msg) tree.should.have.nested.property('navigation.courseOverGroundTrue') tree.should.have.nested.property( 'navigation.courseOverGroundTrue.value', - 154.0 + 1.54 ) tree.should.have.nested.property('navigation.speedOverGround') tree.should.have.nested.property('navigation.speedOverGround.value', 2.26) @@ -24,7 +24,7 @@ describe('129038 Class A Update', function () { tree.should.have.nested.property('navigation.rateOfTurn') tree.should.have.nested.property('navigation.rateOfTurn.value', 0.047) tree.should.have.nested.property('navigation.headingTrue') - tree.should.have.nested.property('navigation.headingTrue.value', 153.0) + tree.should.have.nested.property('navigation.headingTrue.value', 2.2672) tree.should.have.nested.property('navigation.state') tree.should.have.nested.property('navigation.state.value', 'motoring') diff --git a/test/129039_ais_class_b.js b/test/129039_ais_class_b.js index 0cb4fdcc..abbc681f 100644 --- a/test/129039_ais_class_b.js +++ b/test/129039_ais_class_b.js @@ -10,20 +10,20 @@ const { assertSensorClass } = require('./ais_utils') describe('129039 Class B Update', function () { it('complete self sentence converts', function () { var msg = JSON.parse( - '{"timestamp":"2014-08-15-16:00:00.257Z","prio":"4","src":"43","dst":"255","pgn":"129039","description":"AIS Class B Position Report","fields":{"Message ID":"18","Repeat Indicator":"Initial","User ID":"230035780","Longitude":"24.9024733","Latitude":"60.0395100","Position Accuracy":"High","RAIM":"in use","Time Stamp":"0","COG":"167.7","SOG":"3.75","Communication State":"393222","AIS Transceiver information":"Own information not broadcast","Regional Application":"0","Regional Application":"0","Unit type":"CS","Integrated Display":"No","DSC":"Yes","Band":"entire marine band","Can handle Msg 22":"Yes","AIS mode":"Autonomous","AIS communication state":"ITDMA","Heading": "153.0"}}' + '{"timestamp":"2014-08-15-16:00:00.257Z","prio":"4","src":"43","dst":"255","pgn":"129039","description":"AIS Class B Position Report","fields":{"Message ID":"18","Repeat Indicator":"Initial","User ID":"230035780","Longitude":24.9024733,"Latitude":60.0395100,"Position Accuracy":"High","RAIM":"in use","Time Stamp":"0","COG":1.2,"SOG":3.75,"Communication State":"393222","AIS Transceiver information":"Own information not broadcast","Regional Application":"0","Regional Application":"0","Unit type":"CS","Integrated Display":"No","DSC":"Yes","Band":"entire marine band","Can handle Msg 22":"Yes","AIS mode":"Autonomous","AIS communication state":"ITDMA","Heading": 0.23}}' ) var tree = mapper.toNested(msg) tree.should.have.nested.property('navigation.courseOverGroundTrue') tree.should.have.nested.property( 'navigation.courseOverGroundTrue.value', - 167.7 + 1.2 ) tree.should.have.nested.property('navigation.speedOverGround') tree.should.have.nested.property('navigation.speedOverGround.value', 3.75) tree.navigation.position.value.longitude.should.equal(24.9024733) tree.navigation.position.value.latitude.should.equal(60.03951) tree.should.have.nested.property('navigation.headingTrue') - tree.should.have.nested.property('navigation.headingTrue.value', 153.0) + tree.should.have.nested.property('navigation.headingTrue.value', 0.23) //TODO remove when sensors.ais.class is in schema delete tree.sensors.ais diff --git a/test/129040_class_b_extended.js b/test/129040_class_b_extended.js index efa12bd8..fd6080a0 100644 --- a/test/129040_class_b_extended.js +++ b/test/129040_class_b_extended.js @@ -9,7 +9,7 @@ var mapper = require('./testMapper') describe('129040 AIS Class B Extended Position Repeat', function () { it('complete sentence converts', function () { var msg = JSON.parse( - '{"timestamp":"2014-08-15-15:01:01.881Z","prio":"6","src":"43","dst":"255","pgn":"129040","description":"AIS Class B Extended Position Report","fields":{"Message ID":"5","Repeat indicator":"Initial","User ID":"230939100","Name":"RESCUE RAUTAUOMA","Type of ship":"SAR","Length":"16.0","Beam":"4.0","Position reference from Starboard":"2.0","Position reference from Bow":"9.0","ETA Date":"2014.11.30", "ETA Time": "25:00:00","Draft":"1.00","Destination":"HELSINKI LIFEBOAT","AIS version indicator":"ITU-R M.1371-1","GNSS type":"GPS","DTE":"available","Reserved":"0","AIS Transceiver information":"Channel B VDL reception", "True Heading": "158.0","Longitude":"25.2026083","Latitude":"60.2176150","COG":"154.0","SOG":"2.26"}}' + '{"timestamp":"2014-08-15-15:01:01.881Z","prio":"6","src":"43","dst":"255","pgn":"129040","description":"AIS Class B Extended Position Report","fields":{"Message ID":"5","Repeat indicator":"Initial","User ID":"230939100","Name":"RESCUE RAUTAUOMA","Type of ship":"SAR","Length":16.0,"Beam":4.0,"Position reference from Starboard":2.0,"Position reference from Bow":9.0,"ETA Date":"2014.11.30", "ETA Time": "25:00:00","Draft":"1.00","AIS version indicator":"ITU-R M.1371-1","GNSS type":"GPS","DTE":"available","Reserved":"0","AIS Transceiver information":"Channel B VDL reception", "True Heading": 1.58,"Longitude":25.2026083,"Latitude":60.2176150,"COG":1.54,"SOG":2.26}}' ) var delta = mapper.toDelta(msg) delta.updates.length.should.equal(1) @@ -23,20 +23,16 @@ describe('129040 AIS Class B Extended Position Repeat', function () { tree.should.have.nested.property('design.aisShipType.value.id', 51) tree.should.have.nested.property('design.aisShipType.value.name', 'SAR') tree.should.have.nested.property('design.beam.value', 4.0) - tree.should.have.nested.property( - 'navigation.destination.commonName.value', - 'HELSINKI LIFEBOAT' - ) tree.navigation.position.value.longitude.should.equal(25.2026083) tree.navigation.position.value.latitude.should.equal(60.217615) tree.should.have.nested.property('navigation.courseOverGroundTrue') tree.should.have.nested.property( 'navigation.courseOverGroundTrue.value', - 154.0 + 1.54 ) tree.should.have.nested.property('navigation.speedOverGround') tree.should.have.nested.property('navigation.speedOverGround.value', 2.26) - tree.should.have.nested.property('navigation.headingTrue.value', 158.0) + tree.should.have.nested.property('navigation.headingTrue.value', 1.58) tree.should.have.nested.property('sensors.ais.fromBow.value', 9.0) tree.should.have.nested.property('sensors.ais.fromCenter.value', 0) delete tree.design.aisShipType diff --git a/test/129291_set_drift_rapid_update.js b/test/129291_set_drift_rapid_update.js index 707666fd..28aab1fc 100644 --- a/test/129291_set_drift_rapid_update.js +++ b/test/129291_set_drift_rapid_update.js @@ -6,12 +6,12 @@ chai.use(require('@signalk/signalk-schema').chaiModule) describe('129291 set & drift rapid update complete sentence', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2014-08-15-18:00:06.573Z","prio":"3","src":"160","dst":"255","pgn":"129291","description":"Set & Drift, Rapid Update","fields":{"Set Reference":"True","Set":"212.6","Drift":"0.24"}}' + '{"timestamp":"2014-08-15-18:00:06.573Z","prio":"3","src":"160","dst":"255","pgn":"129291","description":"Set & Drift, Rapid Update","fields":{"Set Reference":"True","Set":2.126,"Drift":0.24}}' ) ) it('result has correct values', function () { tree.should.have.nested.property('environment.current.value.setTrue') - tree.should.have.nested.property('environment.current.value.setTrue', 212.6) + tree.should.have.nested.property('environment.current.value.setTrue', 2.126) tree.should.have.nested.property('environment.current.value.drift') tree.should.have.nested.property('environment.current.value.drift', 0.24) }) diff --git a/test/129794_ais_class_a_static_data.js b/test/129794_ais_class_a_static_data.js index 80b94985..5273f490 100644 --- a/test/129794_ais_class_a_static_data.js +++ b/test/129794_ais_class_a_static_data.js @@ -43,7 +43,7 @@ var mapper = require('./testMapper') describe('129794 AIS Class A Static and Voyage Related Data', function () { it('complete sentence converts', function () { var msg = JSON.parse( - '{"timestamp":"2017-03-13T18:30:56.945Z","prio":6,"src":43,"dst":255,"pgn":129794,"description":"AIS Class A Static and Voyage Related Data","fields":{"Message ID":5,"Repeat indicator":"Initial","User ID":356307000,"IMO number":9683362,"Callsign":"3FJJ4","Name":"SILVER GWEN","Type of ship":"Tanker hazard cat C","Length":183.0,"Beam":32.0,"Position reference from Starboard":8.0,"Position reference from Bow":147.0,"ETA Date":"2018.03.11", "ETA Time": "07:00:00","Draft":10.60,"Destination":"USA (BALTIMORE)","AIS version indicator":"ITU-R M.1371-3","GNSS type":"GPS","DTE":"available","AIS Transceiver information":"Channel A VDL reception"}}' + '{"timestamp":"2017-03-13T18:30:56.945Z","prio":6,"src":43,"dst":255,"pgn":129794,"description":"AIS Class A Static and Voyage Related Data","fields":{"Message ID":5,"Repeat indicator":"Initial","User ID":356307000,"IMO number":9683362,"Callsign":"3FJJ4","Name":"SILVER GWEN","Type of ship":"Tanker (hazard cat Z)","Length":183.0,"Beam":32.0,"Position reference from Starboard":8.0,"Position reference from Bow":147.0,"ETA Date":"2018.03.11", "ETA Time": "07:00:00","Draft":10.60,"Destination":"USA (BALTIMORE)","AIS version indicator":"ITU-R M.1371-3","GNSS type":"GPS","DTE":"available","AIS Transceiver information":"Channel A VDL reception"}}' ) var delta = mapper.toDelta(msg) delta.updates.length.should.equal(1) diff --git a/test/129798_sar.js b/test/129798_sar.js index 055804b4..4e5140ca 100644 --- a/test/129798_sar.js +++ b/test/129798_sar.js @@ -9,11 +9,11 @@ var mapper = require('./testMapper') describe('129798 AIS SAR Aircraft Position Report', function () { it('complete sentence converts', function () { var msg = JSON.parse( - '{"prio":4,"pgn":129798,"dst":255,"src":43,"timestamp":"2017-07-20T16:50:11.352Z", "fields":{"Message ID":9,"Repeat indicator":"Initial","User ID":100046,"Longitude":-75.8338099,"Latitude":39.6475617,"Position Accuracy":"High","RAIM":"in use","Time Stamp":"10","COG":2.227,"SOG":694.4,"Communication State":"33188","AIS Transceiver information":"Channel A VDL reception"},"description":"AIS SAR Aircraft Position Report"}' + '{"prio":4,"pgn":129798,"dst":255,"src":43,"timestamp":"2017-07-20T16:50:11.352Z", "fields":{"Message ID":9,"Repeat indicator":"Initial","User ID":338254261,"Longitude":-75.8338099,"Latitude":39.6475617,"Position Accuracy":"High","RAIM":"in use","Time Stamp":"10","COG":2.227,"SOG":694.4,"Communication State":"33188","AIS Transceiver information":"Channel A VDL reception"},"description":"AIS SAR Aircraft Position Report"}' ) var delta = mapper.toDelta(msg) delta.updates.length.should.equal(1) - delta.context.should.equal('sar.urn:mrn:imo:mmsi:000100046') + delta.context.should.equal('sar.urn:mrn:imo:mmsi:338254261') assertSensorClass(delta, 'SAR') var tree = mapper.toNested(msg) tree.navigation.position.value.longitude.should.equal(-75.8338099) diff --git a/test/130306_wind_data.js b/test/130306_wind_data.js index 92359ec3..5a7fca97 100644 --- a/test/130306_wind_data.js +++ b/test/130306_wind_data.js @@ -7,7 +7,7 @@ describe('130306 Wind Data', function () { it('Apparent sentence converts positive', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2013-10-08-15:47:28.263Z","prio":"2","src":"1","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"67","Wind Speed":"6.22","Wind Angle":"0.872665","Reference":"Apparent"}}' + '{"timestamp":"2013-10-08-15:47:28.263Z","prio":"2","src":"1","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"67","Wind Speed":6.22,"Wind Angle":0.8727,"Reference":"Apparent"}}' ) ) tree.should.have.nested.property( @@ -16,7 +16,7 @@ describe('130306 Wind Data', function () { ) tree.should.have.nested.property( 'environment.wind.angleApparent.value', - 0.872665 + 0.8727 ) tree.should.be.validSignalKVesselIgnoringIdentity }) @@ -24,7 +24,7 @@ describe('130306 Wind Data', function () { it('Apparent sentence converts positive gt 180', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2013-10-08-15:47:28.263Z","prio":"2","src":"1","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"67","Wind Speed":"6.22","Wind Angle":"3.31613","Reference":"Apparent"}}' + '{"timestamp":"2013-10-08-15:47:28.263Z","prio":"2","src":"1","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"67","Wind Speed":6.22,"Wind Angle":3.3,"Reference":"Apparent"}}' ) ) tree.should.have.nested.property( @@ -33,7 +33,7 @@ describe('130306 Wind Data', function () { ) tree.should.have.nested.property( 'environment.wind.angleApparent.value', - -2.9670553071795864 + -2.9831853071795864 ) tree.should.be.validSignalKVesselIgnoringIdentity }) @@ -41,7 +41,7 @@ describe('130306 Wind Data', function () { it('Apparent sentence converts negative', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2013-10-08-15:47:28.263Z","prio":"2","src":"1","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"67","Wind Speed":"6.22","Wind Angle":"-0.872665","Reference":"Apparent"}}' + '{"timestamp":"2013-10-08-15:47:28.263Z","prio":"2","src":"1","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"67","Wind Speed":6.22,"Wind Angle":4.8726,"Reference":"Apparent"}}' ) ) tree.should.have.nested.property( @@ -50,7 +50,7 @@ describe('130306 Wind Data', function () { ) tree.should.have.nested.property( 'environment.wind.angleApparent.value', - -0.872665 + -1.410585307179586 ) tree.should.be.validSignalKVesselIgnoringIdentity }) @@ -58,13 +58,13 @@ describe('130306 Wind Data', function () { it('True Boat sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2013-10-08-15:47:28.264Z","prio":"2","src":"1","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"68","Wind Speed":"4.89","Wind Angle":"86.0","Reference":"True (boat referenced)"}}' + '{"timestamp":"2013-10-08-15:47:28.264Z","prio":"2","src":"1","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"68","Wind Speed":4.89,"Wind Angle":0.9948,"Reference":"True (boat referenced)"}}' ) ) tree.should.have.nested.property('environment.wind.speedTrue.value', 4.89) tree.should.have.nested.property( 'environment.wind.angleTrueWater.value', - 86 + 0.9948 ) tree.should.be.validSignalKVesselIgnoringIdentity }) @@ -72,7 +72,7 @@ describe('130306 Wind Data', function () { it('True Ground sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2013-10-08-15:47:28.264Z","prio":"2","src":"3","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"94","Wind Speed":"4.82","Wind Angle":"218.6","Reference":"True (ground referenced to North)"}}' + '{"timestamp":"2013-10-08-15:47:28.264Z","prio":"2","src":"3","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"94","Wind Speed":4.82,"Wind Angle":0.9948,"Reference":"True (ground referenced to North)"}}' ) ) tree.should.have.nested.property( @@ -81,7 +81,7 @@ describe('130306 Wind Data', function () { ) tree.should.have.nested.property( 'environment.wind.directionTrue.value', - 218.6 + 0.9948 ) tree.should.be.validSignalKVesselIgnoringIdentity }) @@ -89,12 +89,12 @@ describe('130306 Wind Data', function () { it('Magnetic Ground sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2013-10-08-15:47:28.264Z","prio":"2","src":"3","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"94","Wind Speed":"4.82","Wind Angle":"218.6","Reference":"Magnetic (ground referenced to Magnetic North)"}}' + '{"timestamp":"2013-10-08-15:47:28.264Z","prio":"2","src":"3","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"94","Wind Speed":4.82,"Wind Angle":0.9948,"Reference":"Magnetic (ground referenced to Magnetic North)"}}' ) ) tree.should.have.nested.property( 'environment.wind.directionMagnetic.value', - 218.6 + 0.9948 ) tree.should.be.validSignalKVesselIgnoringIdentity }) diff --git a/test/130577_direction_data.js b/test/130577_direction_data.js index 1dd5b414..a9b1a7bb 100644 --- a/test/130577_direction_data.js +++ b/test/130577_direction_data.js @@ -6,7 +6,7 @@ chai.use(require('@signalk/signalk-schema').chaiModule) describe('130577 direction_data sentence without drift', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2014-08-15-10:01:35.236Z","prio":"3","src":"160","dst":"255","pgn":"130577","description":"Direction Data","fields":{"Data Mode":"Autonomous","COG Reference":"True","SID":"21","COG":"70.1","SOG":"0.01"}}' + '{"timestamp":"2014-08-15-10:01:35.236Z","prio":"3","src":"160","dst":"255","pgn":"130577","description":"Direction Data","fields":{"Data Mode":"Autonomous","COG Reference":"True","SID":"21","COG":0.9948,"SOG":0.01}}' ) ) it('has correct values', function () { @@ -14,11 +14,7 @@ describe('130577 direction_data sentence without drift', function () { tree.should.have.nested.property('navigation.speedOverGround.value', 0.01) tree.should.have.nested.property( 'navigation.courseOverGroundTrue.value', - 70.1 - ) - tree.should.have.nested.property( - 'navigation.courseOverGroundTrue.value', - 70.1 + 0.9948 ) }) it('is valid SignalK', function () { @@ -29,7 +25,7 @@ describe('130577 direction_data sentence without drift', function () { describe('130577 direction_data sentence with drift', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2014-08-15-18:00:00.755Z","prio":"3","src":"160","dst":"255","pgn":"130577","description":"Direction Data","fields":{"Data Mode":"Autonomous","COG Reference":"True","SID":"84","COG":"206.9","SOG":"3.51","Set":"58.9","Drift":"0.28"}}' + '{"timestamp":"2014-08-15-18:00:00.755Z","prio":"3","src":"160","dst":"255","pgn":"130577","description":"Direction Data","fields":{"Data Mode":"Autonomous","COG Reference":"True","SID":"84","COG":0.9948,"SOG":3.51,"Set":1.9,"Drift":0.28}}' ) ) it('has correct values', function () { @@ -38,9 +34,9 @@ describe('130577 direction_data sentence with drift', function () { tree.should.have.nested.property('navigation.courseOverGroundTrue') tree.should.have.nested.property( 'navigation.courseOverGroundTrue.value', - 206.9 + 0.9948 ) - tree.should.have.nested.property('environment.current.value.setTrue', 58.9) + tree.should.have.nested.property('environment.current.value.setTrue', 1.9) tree.should.have.nested.property('environment.current.value.drift', 0.28) }) it('is valid SignalK', function () { diff --git a/test/130820_fusion.js b/test/130820_fusion.js index 4b353931..4c6a813f 100644 --- a/test/130820_fusion.js +++ b/test/130820_fusion.js @@ -7,7 +7,7 @@ describe('130820 Fusion Stereo', function () { it('complet device name sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-11-26T20:40:00.895Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Unit Name","fields":{"Manufacturer Code":"Fusion","Industry Code":"Marine Industry","Message ID":"Unit Name","A":128,"Name":"Fusion"}}' + '{"timestamp":"2016-11-26T20:40:00.895Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Unit Name","fields":{"Manufacturer Code":"Fusion Electronics","Industry Code":"Marine Industry","Message ID":"Unit Name","A":128,"Name":"Fusion"}}' ) ) // tree.should.be.validSignalKVesselIgnoringIdentity; @@ -16,7 +16,7 @@ describe('130820 Fusion Stereo', function () { it('complet current source sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-11-26T20:40:00.901Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Source Name","fields":{"Manufacturer Code":"Fusion","Industry Code":"Marine Industry","Message ID":"Source","A":128,"Source ID":4,"Current Source ID":4,"D":3,"E":5,"Source":"SiriusXM"}}' + '{"timestamp":"2016-11-26T20:40:00.901Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Source Name","fields":{"Manufacturer Code":"Fusion Electronics","Industry Code":"Marine Industry","Message ID":"Source","A":128,"Source ID":4,"Current Source ID":4,"D":3,"E":5,"Source":"SiriusXM"}}' ) ) tree.should.have.nested.property( @@ -33,7 +33,7 @@ describe('130820 Fusion Stereo', function () { it('complet SiriusXM channel sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-11-26T20:40:00.906Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: SiriusXM Channel","fields":{"Manufacturer Code":"Fusion","Industry Code":"Marine Industry","Message ID":"SiriusXM Channel","A":6554752,"Channel":"xL Howard 100"}}' + '{"timestamp":"2016-11-26T20:40:00.906Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: SiriusXM Channel","fields":{"Manufacturer Code":"Fusion Electronics","Industry Code":"Marine Industry","Message ID":"SiriusXM Channel","A":6554752,"Channel":"xL Howard 100"}}' ) ) tree.should.have.nested.property( @@ -46,7 +46,7 @@ describe('130820 Fusion Stereo', function () { it('complet SiriusXM Genre sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-11-26T20:40:00.911Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: SiriusXM Genre","fields":{"Manufacturer Code":"Fusion","Industry Code":"Marine Industry","Message ID":"SiriusXM Genre","A":6554752,"Genre":"Howard Stern"}}' + '{"timestamp":"2016-11-26T20:40:00.911Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: SiriusXM Genre","fields":{"Manufacturer Code":"Fusion Electronics","Industry Code":"Marine Industry","Message ID":"SiriusXM Genre","A":6554752,"Genre":"Howard Stern"}}' ) ) tree.should.have.nested.property( @@ -59,7 +59,7 @@ describe('130820 Fusion Stereo', function () { it('complet SiriusXM title sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-11-26T20:40:00.915Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: SiriusXM Title","fields":{"Manufacturer Code":"Fusion","Industry Code":"Marine Industry","Message ID":"SiriusXM Title","A":6554752,"Title":"A title"}}' + '{"timestamp":"2016-11-26T20:40:00.915Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: SiriusXM Title","fields":{"Manufacturer Code":"Fusion Electronics","Industry Code":"Marine Industry","Message ID":"SiriusXM Title","A":6554752,"Title":"A title"}}' ) ) tree.should.have.nested.property( @@ -72,7 +72,7 @@ describe('130820 Fusion Stereo', function () { it('complet SiriusXM Artist sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-11-26T20:40:00.918Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: SiriusXM Artist","fields":{"Manufacturer Code":"Fusion","Industry Code":"Marine Industry","Message ID":"SiriusXM Artist","A":6554752,"Artist":"Howard Stern"}}' + '{"timestamp":"2016-11-26T20:40:00.918Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: SiriusXM Artist","fields":{"Manufacturer Code":"Fusion Electronics","Industry Code":"Marine Industry","Message ID":"SiriusXM Artist","A":6554752,"Artist":"Howard Stern"}}' ) ) tree.should.have.nested.property( @@ -85,7 +85,7 @@ describe('130820 Fusion Stereo', function () { it('complet mute sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-11-26T20:40:00.973Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Mute","fields":{"Manufacturer Code":"Fusion","Industry Code":"Marine Industry","Message ID":"Mute","A":128,"Mute":"Not Muted"}}' + '{"timestamp":"2016-11-26T20:40:00.973Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Mute","fields":{"Manufacturer Code":"Fusion Electronics","Industry Code":"Marine Industry","Message ID":"Mute","A":128,"Mute":"Not Muted"}}' ) ) tree.should.have.nested.property( @@ -98,7 +98,7 @@ describe('130820 Fusion Stereo', function () { it('complete equalizer sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-11-26T20:40:00.986Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Tone","fields":{"Manufacturer Code":"Fusion","Industry Code":"Marine Industry","Message ID":"Tone","A":128,"B":3,"Bass":1,"Mid":2,"Treble":3}}' + '{"timestamp":"2016-11-26T20:40:00.986Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Tone","fields":{"Manufacturer Code":"Fusion Electronics","Industry Code":"Marine Industry","Message ID":"Tone","A":128,"B":3,"Bass":1,"Mid":2,"Treble":3}}' ) ) tree.should.have.nested.property( @@ -119,7 +119,7 @@ describe('130820 Fusion Stereo', function () { it('complet volume sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-11-26T20:40:00.991Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Volume","fields":{"Manufacturer Code":"Fusion","Industry Code":"Marine Industry","Message ID":"Volume","A":128,"Zone 1":10,"Zone 2":11,"Zone 3":12,"Zone 4":13}}' + '{"timestamp":"2016-11-26T20:40:00.991Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Volume","fields":{"Manufacturer Code":"Fusion Electronics","Industry Code":"Marine Industry","Message ID":"Volume","A":128,"Zone 1":10,"Zone 2":11,"Zone 3":12,"Zone 4":13}}' ) ) tree.should.have.nested.property( @@ -144,7 +144,7 @@ describe('130820 Fusion Stereo', function () { it('complet zone name sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-11-26T20:40:00.996Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Zone Name","fields":{"Manufacturer Code":"Fusion","Industry Code":"Marine Industry","Message ID":"Zone Name","A":128,"Number":0,"Name":"Cockpit"}}' + '{"timestamp":"2016-11-26T20:40:00.996Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Zone Name","fields":{"Manufacturer Code":"Fusion Electronics","Industry Code":"Marine Industry","Message ID":"Zone Name","A":128,"Number":0,"Name":"Cockpit"}}' ) ) tree.should.have.nested.property( @@ -157,7 +157,7 @@ describe('130820 Fusion Stereo', function () { it('complet track name sentence converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-11-12T20:26:52.150Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Track","fields":{"Manufacturer Code":"Fusion","Industry Code":"Marine Industry","Message ID":"Track Title","A":128,"B":3592,"Track":"Flow"}}' + '{"timestamp":"2016-11-12T20:26:52.150Z","prio":7,"src":10,"dst":255,"pgn":130820,"description":"Fusion: Track","fields":{"Manufacturer Code":"Fusion Electronics","Industry Code":"Marine Industry","Message ID":"Track Title","A":128,"B":3592,"Track":"Flow"}}' ) ) tree.should.have.nested.property( diff --git a/test/65285_temperature.js b/test/65285_temperature.js index 1509d239..99c41c5d 100644 --- a/test/65285_temperature.js +++ b/test/65285_temperature.js @@ -9,10 +9,6 @@ describe('65285 Lowrance Temperature ', function () { '{"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.6 @@ -26,10 +22,6 @@ describe('65285 Lowrance Temperature ', function () { '{"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.6) tree.should.be.validSignalKVesselIgnoringIdentity }) diff --git a/test/65288_seatalk_alarm.js b/test/65288_seatalk_alarm.js index e7ab5319..157f4433 100644 --- a/test/65288_seatalk_alarm.js +++ b/test/65288_seatalk_alarm.js @@ -56,15 +56,15 @@ describe('65288 Seatalk Alarm', function () { it('unkown alarm type converts', function () { var tree = require('./testMapper').toNested( JSON.parse( - '{"timestamp":"2016-10-18T15:54:16.750Z","prio":7,"src":204,"dst":255,"pgn":65288,"description":"Seatalk: Alarm","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Alarm Status":"Alarm condition met and not silenced","Alarm ID":999,"Alarm Group":"Autopilot","Alarm Priority":"0"}}' + '{"timestamp":"2016-10-18T15:54:16.750Z","prio":7,"src":204,"dst":255,"pgn":65288,"description":"Seatalk: Alarm","fields":{"Manufacturer Code":"Raymarine","Industry Code":"Marine Industry","Alarm Status":"Alarm condition met and not silenced","Alarm ID":199,"Alarm Group":"Autopilot","Alarm Priority":"0"}}' ) ) tree.should.have.nested.property( - 'notifications.autopilot.unknown999.value.state', + 'notifications.autopilot.unknown199.value.state', 'alarm' ) - tree.notifications.autopilot.unknown999.value.message.should.eql( - 'Unknown Seatalk Alarm 999' + tree.notifications.autopilot.unknown199.value.message.should.eql( + 'Unknown Seatalk Alarm 199' ) // https://github.com/SignalK/specification/issues/281 // tree.should.be.validSignalKVesselIgnoringIdentity; diff --git a/test/maretron.js b/test/maretron.js index 677dbe95..c9c1718d 100644 --- a/test/maretron.js +++ b/test/maretron.js @@ -87,7 +87,7 @@ describe('Maretron AC PGNs work', function () { it('65012 Utility Phase A AC Reactive Power', function () { var tree = toNested( JSON.parse( - '{"canId":217969856,"prio":3,"src":192,"dst":255,"pgn":65012,"direction":"R","time":"18:58:11.989","fields":{"Reactive Power":859,"Power Factor":30400,"Power Factor Lagging":"Lagging"},"description":"Utility Phase A AC Reactive Power","timestamp":"2020-03-28T18:58:12.480Z"}' + '{"canId":217969856,"prio":3,"src":192,"dst":255,"pgn":65012,"direction":"R","time":"18:58:11.989","fields":{"Reactive Power":859,"Power Factor Lagging":"Lagging"},"description":"Utility Phase A AC Reactive Power","timestamp":"2020-03-28T18:58:12.480Z"}' ), n2kMapper.state ) @@ -96,10 +96,12 @@ describe('Maretron AC PGNs work', function () { 'electrical.ac.8.phase.A.reactivePower.value', 859 ) + /* tree.should.have.nested.property( 'electrical.ac.8.phase.A.powerFactor.value', 0.927734375 - ) + ) + */ tree.should.have.nested.property( 'electrical.ac.8.phase.A.powerFactorLagging.value', 'lagging' @@ -147,7 +149,7 @@ describe('Maretron AC PGNs work', function () { it('65030 Generator Average Basic AC Quantities', function () { var tree = toNested( JSON.parse( - '{"canId":217974465,"prio":3,"src":193,"dst":255,"pgn":65030,"direction":"R","time":"18:58:11.835","fields":{"Line-Line AC RMS Voltage":1,"Line-Neutral AC RMS Voltage":1,"AC Frequency":60.0078125,"AC RMS Current":0},"description":"Generator Average Basic AC Quantities","timestamp":"2020-03-28T18:58:12.477Z"}' + '{"canId":217974465,"prio":3,"src":193,"dst":255,"pgn":65030,"direction":"R","time":"18:58:11.835","fields":{"Line-Line AC RMS Voltage":1,"Line-Neutral AC RMS Voltage":1,"AC Frequency":60.008,"AC RMS Current":0},"description":"Generator Average Basic AC Quantities","timestamp":"2020-03-28T18:58:12.477Z"}' ), n2kMapper.state ) @@ -161,7 +163,7 @@ describe('Maretron AC PGNs work', function () { ) tree.should.have.nested.property( 'electrical.generators.16.average.frequency.value', - 60.0078125 + 60.008 ) tree.should.have.nested.property( 'electrical.generators.16.average.current.value', diff --git a/test/meta.js b/test/meta.js index d282d382..d1d72d8a 100644 --- a/test/meta.js +++ b/test/meta.js @@ -8,7 +8,7 @@ describe('Meta data works', function () { it('Address Claim', done => { const n2kMapper = new N2kMapper() n2kMapper.on('n2kSourceMetadata', (n2k, meta) => { - meta.should.have.property('uniqueId', '76223') + meta.should.have.property('uniqueId', 76223) meta.should.have.property('manufacturerName', 'Fusion Electronics') meta.should.have.property('deviceFunction', 130) meta.should.have.property('deviceClass', 'Entertainment') @@ -26,16 +26,16 @@ describe('Meta data works', function () { src: 12, timestamp: '2019-05-31T11:46:58.594Z', fields: { - 'Unique Number': '76223', + 'Unique Number': 76223, 'Manufacturer Code': 'Fusion Electronics', 'Device Instance Lower': 0, 'Device Instance Upper': 0, 'Device Function': 130, - Reserved1: '0', + Spare: 0, 'Device Class': 'Entertainment', 'System Instance': 0, 'Industry Group': 'Marine', - Reserved2: '1' + 'Arbitrary address capable': 1 }, description: 'ISO Address Claim' }) diff --git a/test/testMapper.js b/test/testMapper.js index a34cb3b6..2e645008 100644 --- a/test/testMapper.js +++ b/test/testMapper.js @@ -1,7 +1,43 @@ const n2kMapper = require('../n2kMapper') const signalkSchema = require('@signalk/signalk-schema') +const canboatjs = require('@canboat/canboatjs') +const { FromPgn, pgnToActisenseSerialFormat } = canboatjs +const Parser = canboatjs.FromPgn +const parser = new FromPgn() + +/* + By default we take the input canboat json and convert to actisense format, + back to conboat json and then do the n2k conversion. + This is done to expose any issues/changes with field names in canboat. + + Set the env variable NO_CANBOATJS=true to skip the back and forth conversion. +*/ + n2kMapper.toNested = function (n2k, state) { + if (!process.env.NO_CANBOATJS) { + return n2kMapper.doubleConvertWithCanboat(n2k, state) + } else { + return n2kMapper.n2kToNested(n2k, state) + } +} + +n2kMapper.doubleConvertWithCanboat = function (n2k, state) { + var actisense = pgnToActisenseSerialFormat(n2k) + var parsed = parser.parseString(actisense) + parsed.src = n2k.src + if (n2k.timestamp) { + parsed.timestamp = n2k.timestamp + } + var delta = n2kMapper.toDelta(parsed, state) + if (!delta.context) { + delta.context = 'vessels.' + signalkSchema.fakeMmsiId + } + var contextParts = delta.context.split('.') + return signalkSchema.deltaToFull(delta)[contextParts[0]][contextParts[1]] +} + +n2kMapper.n2kToNested = function (n2k, state) { var delta = n2kMapper.toDelta(n2k, state) if (!delta.context) { delta.context = 'vessels.' + signalkSchema.fakeMmsiId @@ -9,4 +45,5 @@ n2kMapper.toNested = function (n2k, state) { var contextParts = delta.context.split('.') return signalkSchema.deltaToFull(delta)[contextParts[0]][contextParts[1]] } + module.exports = n2kMapper diff --git a/utils.js b/utils.js index e0e8eb4c..45710534 100644 --- a/utils.js +++ b/utils.js @@ -43,9 +43,20 @@ function acPhase (n2k) { } } +function timeToSeconds (time) { + if (typeof time !== 'undefined' && time !== null) { + let split = time.split(':') + if (split.length === 3) { + return Number(split[0]) * 3600 + Number(split[1]) * 60 + Number(split[2]) + } + } + return null +} + module.exports = { chooseField, skEngineId, skEngineTitle, - acPhase + acPhase, + timeToSeconds }