From 3564e658f1cef678d908bc14c2dcd8a2e4f514dd Mon Sep 17 00:00:00 2001 From: AdrianP <38519157+panaaj@users.noreply.github.com> Date: Sat, 16 Nov 2024 18:15:20 +1030 Subject: [PATCH] Fix: not sending delta when next point position values are missing. (#255) --- hooks/BWC.js | 5 +++++ hooks/BWR.js | 44 ++++++++++++++++++++++++-------------------- hooks/RMB.js | 15 +++++++++------ test/BWC.js | 12 +++++++++++- test/BWR.js | 16 +++++++++++++++- test/RMB.js | 10 +++++++++- 6 files changed, 73 insertions(+), 29 deletions(-) diff --git a/hooks/BWC.js b/hooks/BWC.js index b4ee813f..5d431f30 100644 --- a/hooks/BWC.js +++ b/hooks/BWC.js @@ -66,6 +66,11 @@ module.exports = function BWCHook(input) { latitude, }, }) + } else { + values.push({ + path: 'navigation.courseGreatCircle.nextPoint.position', + value: null, + }) } if (parts[9] !== '' && parts[10] !== '') { diff --git a/hooks/BWR.js b/hooks/BWR.js index 1b755451..06932bb9 100644 --- a/hooks/BWR.js +++ b/hooks/BWR.js @@ -37,6 +37,11 @@ module.exports = function BWRHook(input) { debug(`[BWRHook] decoding sentence ${id} => ${sentence}`) + let timestamp + let position + let distance + const bearingToWaypoint = {} + if ( upper(parts[0]) === '' || upper(parts[1]) === '' || @@ -44,24 +49,26 @@ module.exports = function BWRHook(input) { upper(parts[3]) === '' || upper(parts[4]) === '' ) { - return null + timestamp = tags.timestamp + position = null + distance = null + } else { + timestamp = utils.timestamp(parts[0]) + position = { + latitude: utils.coordinate(parts[1], parts[2]), + longitude: utils.coordinate(parts[3], parts[4]), + } + distance = utils.transform( + parts[9], + upper(parts[10]) === 'N' ? 'nm' : 'km', + 'm' + ) + bearingToWaypoint[upper(parts[6]) === 'T' ? 'True' : 'Magnetic'] = + utils.transform(parts[5], 'deg', 'rad') + bearingToWaypoint[upper(parts[8]) === 'T' ? 'True' : 'Magnetic'] = + utils.transform(parts[7], 'deg', 'rad') } - const timestamp = utils.timestamp(parts[0]) - const latitude = utils.coordinate(parts[1], parts[2]) - const longitude = utils.coordinate(parts[3], parts[4]) - const distance = utils.transform( - parts[9], - upper(parts[10]) === 'N' ? 'nm' : 'km', - 'm' - ) - - const bearingToWaypoint = {} - bearingToWaypoint[upper(parts[6]) === 'T' ? 'True' : 'Magnetic'] = - utils.transform(parts[5], 'deg', 'rad') - bearingToWaypoint[upper(parts[8]) === 'T' ? 'True' : 'Magnetic'] = - utils.transform(parts[7], 'deg', 'rad') - return { updates: [ { @@ -82,10 +89,7 @@ module.exports = function BWRHook(input) { }, { path: 'navigation.courseRhumbline.nextPoint.position', - value: { - longitude, - latitude, - }, + value: position, }, ], }, diff --git a/hooks/RMB.js b/hooks/RMB.js index ac1868f0..89289c9f 100644 --- a/hooks/RMB.js +++ b/hooks/RMB.js @@ -20,7 +20,7 @@ const utils = require('@signalk/nmea0183-utilities') const moment = require('moment-timezone') /* -RMC Sentence +RMB Sentence $GPRMB,A,0.66,L,003,004,4917.24,N,12309.57,W,001.3,052.5,000.5,V*20 values: @@ -49,11 +49,17 @@ module.exports = function (input) { let vmg = 0.0 let distance = 0.0 let crossTrackError = 0.0 + let position = null latitude = utils.coordinate(parts[5], parts[6]) longitude = utils.coordinate(parts[7], parts[8]) if (isNaN(latitude) || isNaN(longitude)) { - return null + position = null + } else { + position = { + longitude, + latitude + } } bearing = utils.float(parts[10]) @@ -78,10 +84,7 @@ module.exports = function (input) { values: [ { path: 'navigation.courseRhumbline.nextPoint.position', - value: { - longitude, - latitude, - }, + value: position, }, { diff --git a/test/BWC.js b/test/BWC.js index e1f53494..0a86f0c7 100644 --- a/test/BWC.js +++ b/test/BWC.js @@ -63,6 +63,10 @@ describe('BWC', () => { delta.should.be.an('object') delta.updates[0].values.should.deep.equal([ + { + path: 'navigation.courseGreatCircle.nextPoint.position', + value: null, + }, { path: 'navigation.courseGreatCircle.nextPoint.distance', value: 40929.20003454424, @@ -80,6 +84,12 @@ describe('BWC', () => { it("Doesn't choke on an empty sentence", () => { const delta = new Parser().parse('$GPBWC,,,,,,,,,,,,*41') - should.equal(delta, undefined) + + delta.updates[0].values.should.deep.equal([ + { + path: 'navigation.courseGreatCircle.nextPoint.position', + value: null, + }, + ]) }) }) diff --git a/test/BWR.js b/test/BWR.js index 3df82fff..061c68d9 100644 --- a/test/BWR.js +++ b/test/BWR.js @@ -56,6 +56,20 @@ describe('BWR', () => { it("Doesn't choke on an empty sentence", () => { const delta = new Parser().parse('$GPBWR,,,,,,,,,,,,*50') - should.equal(delta, null) + delta.updates[0].values.should.deep.equal([ + { path: 'navigation.courseRhumbline.bearingTrackTrue', value: null }, + { + path: 'navigation.courseRhumbline.bearingTrackMagnetic', + value: null, + }, + { + path: 'navigation.courseRhumbline.nextPoint.distance', + value: null, + }, + { + path: 'navigation.courseRhumbline.nextPoint.position', + value: null, + }, + ]) }) }) diff --git a/test/RMB.js b/test/RMB.js index c853ca23..a3d143c1 100644 --- a/test/RMB.js +++ b/test/RMB.js @@ -75,6 +75,14 @@ describe('RMB', () => { it("Doesn't choke on empty sentences", () => { const delta = new Parser().parse('$ECRMB,,,,,,,,,,,,,*77') - should.equal(delta, null) + delta.updates[0].values.should.contain.an.item.with.property( + 'path', + 'navigation.courseRhumbline.nextPoint.position' + ) + delta.updates[0].values.should.contain.an.item({ + path: 'navigation.courseRhumbline.nextPoint.position', + value: null + }) }) + })