Skip to content

Commit

Permalink
Fix: not sending delta when next point position values are missing. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
panaaj authored Nov 16, 2024
1 parent 6c3351c commit 3564e65
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 29 deletions.
5 changes: 5 additions & 0 deletions hooks/BWC.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] !== '') {
Expand Down
44 changes: 24 additions & 20 deletions hooks/BWR.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,38 @@ 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]) === '' ||
upper(parts[2]) === '' ||
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: [
{
Expand All @@ -82,10 +89,7 @@ module.exports = function BWRHook(input) {
},
{
path: 'navigation.courseRhumbline.nextPoint.position',
value: {
longitude,
latitude,
},
value: position,
},
],
},
Expand Down
15 changes: 9 additions & 6 deletions hooks/RMB.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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])
Expand All @@ -78,10 +84,7 @@ module.exports = function (input) {
values: [
{
path: 'navigation.courseRhumbline.nextPoint.position',
value: {
longitude,
latitude,
},
value: position,
},

{
Expand Down
12 changes: 11 additions & 1 deletion test/BWC.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
])
})
})
16 changes: 15 additions & 1 deletion test/BWR.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
])
})
})
10 changes: 9 additions & 1 deletion test/RMB.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})

})

0 comments on commit 3564e65

Please sign in to comment.