Skip to content

Commit

Permalink
Fix BWR no position handling. Send delta with nextPoint.position valu…
Browse files Browse the repository at this point in the history
…e = null
  • Loading branch information
panaaj committed Nov 14, 2024
1 parent 818c8b2 commit 1ad7979
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
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
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,
},
])
})
})

0 comments on commit 1ad7979

Please sign in to comment.