From 226135be90496eb83155be573cfa4df052709a08 Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Fri, 14 Jun 2019 02:00:29 -0400 Subject: [PATCH] fix: handle "not available" values in VDM messages (#148) --- hooks/VDM.js | 6 +++--- test/VDM.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/hooks/VDM.js b/hooks/VDM.js index 130551cb..1e8bf4ac 100644 --- a/hooks/VDM.js +++ b/hooks/VDM.js @@ -75,21 +75,21 @@ module.exports = function (input, session) { }) } - if (typeof data.sog != 'undefined') { + if (typeof data.sog != 'undefined' && data.sog != 102.3 ) { values.push({ path: 'navigation.speedOverGround', value: utils.transform(data.sog, 'knots', 'ms') }) } - if (typeof data.cog != 'undefined') { + if (typeof data.cog != 'undefined' && data.cog != 360 ) { values.push({ path: 'navigation.courseOverGroundTrue', value: utils.transform(data.cog, 'deg', 'rad') }) } - if (typeof data.hdg != 'undefined') { + if (typeof data.hdg != 'undefined' && data.hdg != 511) { values.push({ path: 'navigation.headingTrue', value: utils.transform(data.hdg, 'deg', 'rad') diff --git a/test/VDM.js b/test/VDM.js index d3c5f5f8..88cc41db 100644 --- a/test/VDM.js +++ b/test/VDM.js @@ -54,6 +54,17 @@ describe('VDM', function() { delta.context.should.equal('vessels.urn:mrn:imo:mmsi:244670316') }) + it('Unavailable values don\'t convert', () => { + const delta = new Parser().parse('!AIVDM,1,1,,A,33@nwqwP?w4?wp0000,0*0B\n') + delta.context.should.equal('vessels.urn:mrn:imo:mmsi:219004903') + + let findPath = + should.not.exist(delta.updates[0].values.find((pv) => { return pv.path === 'navigation.headingTrue'})) + should.not.exist(delta.updates[0].values.find((pv) => { return pv.path === 'navigation.courseOverGroundTrue'})) + should.not.exist(delta.updates[0].values.find((pv) => { return pv.path === 'navigation.speedOverGround'})) + should.not.exist(delta.updates[0].values.find((pv) => { return pv.path === 'navigation.state'})) + }) + it('AtoN converts ok', () => { const delta = new Parser().parse('!AIVDM,1,1,,A,E>k`sUoJK@@@@@@@@@@@@@@@@@@MAhJS;@neP00000N000,0*0D\n') delta.context.should.equal('atons.urn:mrn:imo:mmsi:993672087')