From 1ad79799b3f48c92d8f088f4285df4ca07aa2728 Mon Sep 17 00:00:00 2001 From: panaaj <38519157+panaaj@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:59:13 +1030 Subject: [PATCH] Fix BWR no position handling. Send delta with nextPoint.position value = null --- hooks/BWR.js | 44 ++++++++++++++++++++++++-------------------- test/BWR.js | 16 +++++++++++++++- 2 files changed, 39 insertions(+), 21 deletions(-) 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/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, + }, + ]) }) })