From f2105d148b13ed6cc86bd6730fddf018748251d2 Mon Sep 17 00:00:00 2001 From: Teppo Kurki Date: Sat, 4 Nov 2017 21:55:16 +0200 Subject: [PATCH] feature: object valued properties under value in full model (#103) Adjust code to match changes in https://github.com/SignalK/specification/pull/315. Update @signalk/signalk-schema to version 0.0.1-12 --- aisShipTypeMapping.js | 6 ++---- package.json | 2 +- pgns/129041.js | 6 ++---- pgns/129284.js | 12 +++++++----- test/127257_attitude.js | 6 +++--- test/127489_engine_params.js | 24 ++++++++++++------------ test/129025_position.js | 4 ++-- test/129029_position_data.js | 4 ++-- test/129038_ais_class_a.js | 4 ++-- test/129039_ais_class_b.js | 4 ++-- test/129040_class_b_extended.js | 6 +++--- test/129041_aton_report.js | 4 ++-- test/129284_navigation_data.js | 4 ++-- test/129291_set_drift_rapid_update.js | 8 ++++---- test/129794_ais_class_a_static_data.js | 4 ++-- test/130577_direction_data.js | 4 ++-- test/130820_fusion.js | 6 +++--- test/130842_simnet_class_b_extended.js | 2 +- test/65288_seatalk_alarm.js | 10 +++++----- 19 files changed, 59 insertions(+), 61 deletions(-) diff --git a/aisShipTypeMapping.js b/aisShipTypeMapping.js index 61d7209..48c2217 100644 --- a/aisShipTypeMapping.js +++ b/aisShipTypeMapping.js @@ -5,10 +5,8 @@ module.exports = function (type) { var name if (typeof num !== 'undefined' && (name = schema.getAISShipTypeName(num))) { return { - value: { - 'id': num, - 'name': name - } + 'id': num, + 'name': name } } else { return null diff --git a/package.json b/package.json index 0fc08f8..e538730 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "through": ">=2.2.7 <3" }, "devDependencies": { - "@signalk/signalk-schema": "0.0.1-11", + "@signalk/signalk-schema": "0.0.1-12", "chai": "~4.1.0", "chai-things": "0.2", "github-changes": "^1.0.4", diff --git a/pgns/129041.js b/pgns/129041.js index 0e31e93..78ab084 100644 --- a/pgns/129041.js +++ b/pgns/129041.js @@ -35,10 +35,8 @@ module.exports = [ const num = nameMapping[n2k.fields['AtoN Type']] if (typeof num !== 'undefined' && (name = schema.getAtonTypeName(num))) { return { - value: { - 'id': num, - 'name': name - } + 'id': num, + 'name': name } } else { return null diff --git a/pgns/129284.js b/pgns/129284.js index 9f96555..b73b005 100644 --- a/pgns/129284.js +++ b/pgns/129284.js @@ -57,14 +57,16 @@ module.exports = [ }, { node: function (n2k, state) { - return 'navigation.course' + calculationType(n2k, state) + '.nextPoint' + return ( + 'navigation.course' + + calculationType(n2k, state) + + '.nextPoint.position' + ) }, value: function (n2k) { return { - position: { - longitude: Number(n2k.fields['Destination Longitude']), - latitude: Number(n2k.fields['Destination Latitude']) - } + longitude: Number(n2k.fields['Destination Longitude']), + latitude: Number(n2k.fields['Destination Latitude']) } } }, diff --git a/test/127257_attitude.js b/test/127257_attitude.js index 055da17..899d46c 100644 --- a/test/127257_attitude.js +++ b/test/127257_attitude.js @@ -10,9 +10,9 @@ describe('127257_attitude', function () { '{"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"}}' ) ) - tree.should.have.nested.property('navigation.attitude.yaw', 37.19) - tree.should.have.nested.property('navigation.attitude.pitch', 0.464) - tree.should.have.nested.property('navigation.attitude.roll', -2.496) + 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.be.validSignalKVesselIgnoringIdentity }) }) diff --git a/test/127489_engine_params.js b/test/127489_engine_params.js index 9089996..0855c7c 100644 --- a/test/127489_engine_params.js +++ b/test/127489_engine_params.js @@ -29,16 +29,16 @@ describe('127489 engine parameters Port', function () { 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.state', + 'notifications.propulsion.port.lowOilPressure.value.state', 'alarm') tree.should.have.nested.property( - 'notifications.propulsion.port.lowCoolantLevel.state', + 'notifications.propulsion.port.lowCoolantLevel.value.state', 'alarm') tree.should.have.nested.property( - 'notifications.propulsion.port.warningLevel1.state', + 'notifications.propulsion.port.warningLevel1.value.state', 'alarm') tree.should.have.nested.property( - 'notifications.propulsion.port.maintenanceNeeded.state', + 'notifications.propulsion.port.maintenanceNeeded.value.state', 'alarm') tree.should.be.validSignalKVesselIgnoringIdentity }) @@ -85,16 +85,16 @@ describe('127489 engine parameters Starboard', function () { 0.57 ) tree.should.have.nested.property( - 'notifications.propulsion.starboard.lowOilPressure.state', + 'notifications.propulsion.starboard.lowOilPressure.value.state', 'alarm') tree.should.have.nested.property( - 'notifications.propulsion.starboard.lowCoolantLevel.state', + 'notifications.propulsion.starboard.lowCoolantLevel.value.state', 'alarm') tree.should.have.nested.property( - 'notifications.propulsion.starboard.warningLevel1.state', + 'notifications.propulsion.starboard.warningLevel1.value.state', 'alarm') tree.should.have.nested.property( - 'notifications.propulsion.starboard.maintenanceNeeded.state', + 'notifications.propulsion.starboard.maintenanceNeeded.value.state', 'alarm') tree.should.be.validSignalKVesselIgnoringIdentity @@ -104,16 +104,16 @@ describe('127489 engine parameters Starboard', function () { ) ) tree.should.have.nested.property( - 'notifications.propulsion.starboard.lowOilPressure.state', + 'notifications.propulsion.starboard.lowOilPressure.value.state', 'alarm') tree.should.have.nested.property( - 'notifications.propulsion.starboard.lowCoolantLevel.state', + 'notifications.propulsion.starboard.lowCoolantLevel.value.state', 'normal') tree.should.have.nested.property( - 'notifications.propulsion.starboard.warningLevel1.state', + 'notifications.propulsion.starboard.warningLevel1.value.state', 'normal') tree.should.have.nested.property( - 'notifications.propulsion.starboard.maintenanceNeeded.state', + 'notifications.propulsion.starboard.maintenanceNeeded.value.state', 'normal') tree.should.be.validSignalKVesselIgnoringIdentity }) diff --git a/test/129025_position.js b/test/129025_position.js index 28fbfc2..8de23fa 100644 --- a/test/129025_position.js +++ b/test/129025_position.js @@ -9,8 +9,8 @@ var msg = JSON.parse( describe('129025 Position, rapid update ', function () { it('complete sentence converts to tree', function () { var tree = require('./testMapper').toNested(msg) - tree.navigation.position.longitude.should.equal(24.7921348) - tree.navigation.position.latitude.should.equal(60.144554) + tree.navigation.position.value.longitude.should.equal(24.7921348) + tree.navigation.position.value.latitude.should.equal(60.144554) tree.should.be.validSignalKVesselIgnoringIdentity }) diff --git a/test/129029_position_data.js b/test/129029_position_data.js index e3992d4..a75f66d 100644 --- a/test/129029_position_data.js +++ b/test/129029_position_data.js @@ -14,8 +14,8 @@ const invalidDataMsg = JSON.parse( describe('129029 Position Data ', function () { it('complete sentence converts', function () { var tree = require('./testMapper').toNested(msg) - tree.navigation.position.longitude.should.equal(-76.3972731) - tree.navigation.position.latitude.should.equal(39.0536632) + tree.navigation.position.value.longitude.should.equal(-76.3972731) + tree.navigation.position.value.latitude.should.equal(39.0536632) 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) diff --git a/test/129038_ais_class_a.js b/test/129038_ais_class_a.js index 08b2535..b19c268 100644 --- a/test/129038_ais_class_a.js +++ b/test/129038_ais_class_a.js @@ -18,8 +18,8 @@ describe('129038 Class A Update', function () { ) tree.should.have.nested.property('navigation.speedOverGround') tree.should.have.nested.property('navigation.speedOverGround.value', 2.26) - tree.navigation.position.longitude.should.equal(25.2026083) - tree.navigation.position.latitude.should.equal(60.217615) + tree.navigation.position.value.longitude.should.equal(25.2026083) + tree.navigation.position.value.latitude.should.equal(60.217615) tree.should.have.nested.property('navigation.rateOfTurn') tree.should.have.nested.property('navigation.rateOfTurn.value', 0.047) tree.should.have.nested.property('navigation.headingTrue') diff --git a/test/129039_ais_class_b.js b/test/129039_ais_class_b.js index de4c9be..e62e9b3 100644 --- a/test/129039_ais_class_b.js +++ b/test/129039_ais_class_b.js @@ -18,8 +18,8 @@ describe('129039 Class B Update', function () { ) tree.should.have.nested.property('navigation.speedOverGround') tree.should.have.nested.property('navigation.speedOverGround.value', 3.75) - tree.navigation.position.longitude.should.equal(24.9024733) - tree.navigation.position.latitude.should.equal(60.03951) + 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.be.validSignalKVesselIgnoringIdentity diff --git a/test/129040_class_b_extended.js b/test/129040_class_b_extended.js index 7b086da..0febb4b 100644 --- a/test/129040_class_b_extended.js +++ b/test/129040_class_b_extended.js @@ -16,7 +16,7 @@ describe('129040 AIS Class B Extended Position Repeat', function () { delta.updates[0].values[0].path.should.equal('') delta.updates[0].values[0].value.name.should.equal('RESCUE RAUTAUOMA') var tree = mapper.toNested(msg) - tree.should.have.nested.property('design.length.overall', 16.0) + tree.should.have.nested.property('design.length.value.overall', 16.0) 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) @@ -24,8 +24,8 @@ describe('129040 AIS Class B Extended Position Repeat', function () { 'navigation.destination.commonName.value', 'HELSINKI LIFEBOAT' ) - tree.navigation.position.longitude.should.equal(25.2026083) - tree.navigation.position.latitude.should.equal(60.217615) + 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', diff --git a/test/129041_aton_report.js b/test/129041_aton_report.js index e6866d6..e28b810 100644 --- a/test/129041_aton_report.js +++ b/test/129041_aton_report.js @@ -21,8 +21,8 @@ describe('129041 AIS Aids to Navigation (AtoN) Report', function () { 'Beacon, Port Hand' ) tree.should.have.nested.property('atonType.value.id', 13) - tree.navigation.position.latitude.should.equal(38.99384) - tree.navigation.position.longitude.should.equal(-76.3847132) + tree.navigation.position.value.latitude.should.equal(38.99384) + tree.navigation.position.value.longitude.should.equal(-76.3847132) // tree.should.be.validSignalKAtoNIgnoringIdentity; }) }) diff --git a/test/129284_navigation_data.js b/test/129284_navigation_data.js index c6cb94f..56b2f31 100644 --- a/test/129284_navigation_data.js +++ b/test/129284_navigation_data.js @@ -28,11 +28,11 @@ describe('129284 Navigation Data', function () { 2.7651 ) tree.should.have.nested.property( - 'navigation.courseGreatCircle.nextPoint.position.latitude', + 'navigation.courseGreatCircle.nextPoint.position.value.latitude', 60.1366607 ) tree.should.have.nested.property( - 'navigation.courseGreatCircle.nextPoint.position.longitude', + 'navigation.courseGreatCircle.nextPoint.position.value.longitude', 24.9068518 ) tree.should.have.nested.property( diff --git a/test/129291_set_drift_rapid_update.js b/test/129291_set_drift_rapid_update.js index dcce8e9..707666f 100644 --- a/test/129291_set_drift_rapid_update.js +++ b/test/129291_set_drift_rapid_update.js @@ -10,10 +10,10 @@ describe('129291 set & drift rapid update complete sentence', function () { ) ) it('result has correct values', function () { - tree.should.have.nested.property('environment.current.setTrue') - tree.should.have.nested.property('environment.current.setTrue', 212.6) - tree.should.have.nested.property('environment.current.drift') - tree.should.have.nested.property('environment.current.drift', 0.24) + 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.drift') + tree.should.have.nested.property('environment.current.value.drift', 0.24) }) it('result is valid SignalK', function () { tree.should.be.validSignalKVesselIgnoringIdentity diff --git a/test/129794_ais_class_a_static_data.js b/test/129794_ais_class_a_static_data.js index 6684ce5..9f0e32c 100644 --- a/test/129794_ais_class_a_static_data.js +++ b/test/129794_ais_class_a_static_data.js @@ -50,8 +50,8 @@ describe('129794 AIS Class A Static and Voyage Related Data', function () { delta.updates[0].values[0].value.name.should.equal('SILVER GWEN') // console.log(JSON.stringify(delta, null, 2)) var tree = mapper.toNested(msg) - tree.should.have.nested.property('design.draft.maximum', 10.6) - tree.should.have.nested.property('design.length.overall', 183.0) + tree.should.have.nested.property('design.draft.value.maximum', 10.6) + tree.should.have.nested.property('design.length.value.overall', 183.0) tree.should.have.nested.property('design.aisShipType.value.id', 83) tree.should.have.nested.property( 'design.aisShipType.value.name', diff --git a/test/130577_direction_data.js b/test/130577_direction_data.js index 88a90a3..1dd5b41 100644 --- a/test/130577_direction_data.js +++ b/test/130577_direction_data.js @@ -40,8 +40,8 @@ describe('130577 direction_data sentence with drift', function () { 'navigation.courseOverGroundTrue.value', 206.9 ) - tree.should.have.nested.property('environment.current.setTrue', 58.9) - tree.should.have.nested.property('environment.current.drift', 0.28) + tree.should.have.nested.property('environment.current.value.setTrue', 58.9) + tree.should.have.nested.property('environment.current.value.drift', 0.28) }) it('is valid SignalK', function () { tree.should.be.validSignalKVesselIgnoringIdentity diff --git a/test/130820_fusion.js b/test/130820_fusion.js index 88a7e21..4b35393 100644 --- a/test/130820_fusion.js +++ b/test/130820_fusion.js @@ -102,15 +102,15 @@ describe('130820 Fusion Stereo', function () { ) ) tree.should.have.nested.property( - 'entertainment.device.fusion1.output.zone1.equalizer.bass', + 'entertainment.device.fusion1.output.zone1.equalizer.value.bass', 1 ) tree.should.have.nested.property( - 'entertainment.device.fusion1.output.zone1.equalizer.mid', + 'entertainment.device.fusion1.output.zone1.equalizer.value.mid', 2 ) tree.should.have.nested.property( - 'entertainment.device.fusion1.output.zone1.equalizer.treble', + 'entertainment.device.fusion1.output.zone1.equalizer.value.treble', 3 ) // tree.should.be.validSignalKVesselIgnoringIdentity; diff --git a/test/130842_simnet_class_b_extended.js b/test/130842_simnet_class_b_extended.js index fbaed1c..026233f 100644 --- a/test/130842_simnet_class_b_extended.js +++ b/test/130842_simnet_class_b_extended.js @@ -28,7 +28,7 @@ describe('130842 Simnet AIS Class B static data', function () { delta.context.should.equal('vessels.urn:mrn:imo:mmsi:338184313') var tree = mapper.toNested(msg) tree.should.have.nested.property('mmsi', '338184313') - tree.should.have.nested.property('design.length.overall', 9.0) + tree.should.have.nested.property('design.length.value.overall', 9.0) tree.should.have.nested.property('design.aisShipType.value.id', 36) tree.should.have.nested.property('design.aisShipType.value.name', 'Sailing') tree.should.have.nested.property('design.beam.value', 4.0) diff --git a/test/65288_seatalk_alarm.js b/test/65288_seatalk_alarm.js index a9b25c2..012f692 100644 --- a/test/65288_seatalk_alarm.js +++ b/test/65288_seatalk_alarm.js @@ -11,10 +11,10 @@ describe('65288 Seatalk Alarm', function () { ) ) tree.should.have.nested.property( - 'notifications.autopilot.PilotWayPointAdvance.state', + 'notifications.autopilot.PilotWayPointAdvance.value.state', 'alarm' ) - tree.notifications.autopilot.PilotWayPointAdvance.method.should.eql([ + tree.notifications.autopilot.PilotWayPointAdvance.value.method.should.eql([ 'visual', 'sound' ]) @@ -29,7 +29,7 @@ describe('65288 Seatalk Alarm', function () { ) ) tree.should.have.nested.property( - 'notifications.autopilot.PilotWayPointAdvance.state', + 'notifications.autopilot.PilotWayPointAdvance.value.state', 'normal' ) // https://github.com/SignalK/specification/issues/281 @@ -43,10 +43,10 @@ describe('65288 Seatalk Alarm', function () { ) ) tree.should.have.nested.property( - 'notifications.autopilot.PilotWayPointAdvance.state', + 'notifications.autopilot.PilotWayPointAdvance.value.state', 'alarm' ) - tree.notifications.autopilot.PilotWayPointAdvance.method.should.eql([ + tree.notifications.autopilot.PilotWayPointAdvance.value.method.should.eql([ 'visual' ]) // https://github.com/SignalK/specification/issues/281