Skip to content

Commit

Permalink
fix: handle "not available" values in VDM messages (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 authored and tkurki committed Jun 14, 2019
1 parent 6bf467f commit 226135b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions hooks/VDM.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
11 changes: 11 additions & 0 deletions test/VDM.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?w<ovH0kOqP>4?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')
Expand Down

0 comments on commit 226135b

Please sign in to comment.