Skip to content

Commit f7b82d3

Browse files
committed
Fix 0x85 distance field byte order (ZZZ nibble assembly)
The ZZZ distance value was assembled as (Z_high << 8) | ZZ, treating Z_high as a full byte shift. Per the SeaTalk spec, ZZZ is a 12-bit value where ZZ provides the high 8 bits and Z_high the low nibble: ZZZ = (ZZ << 4) | Z_high. Updated test vectors to match the corrected byte order.
1 parent 95adc21 commit f7b82d3

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

hooks/seatalk/0x85.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ module.exports = function (input) {
102102
}
103103

104104
// Distance to destination
105-
// ZZZ is formed from Z_high (high nibble of byte 4) and ZZ (byte 5)
105+
// ZZZ is formed from ZZ (byte 5) and Z_high (high nibble of byte 4)
106+
// Byte order is low-nibble-last: ZZZ = (ZZ << 4) | Z_high
106107
const rangePresent = (F & 0x4) === 0x4
107108
if (rangePresent) {
108-
const ZZZ = (Z_high << 8) | ZZ
109+
const ZZZ = (ZZ << 4) | Z_high
109110
// If Y & 1 = 1: ZZZ / 100 nm (0-9.99nm)
110111
// If Y & 1 = 0: ZZZ / 10 nm (≥10nm)
111112
const distanceNm = (Y & 0x1) === 0x1 ? ZZZ / 100 : ZZZ / 10

test/seatalk.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ const heading_nineCData = '9C,51,1E,00'
5050
const empty_nineCData = '9C,,,'
5151
const empty_eightFourData = '84,,,,,,,,'
5252
// 0x85 Navigation to waypoint: XTE=1.00nm steer left, bearing=45° magnetic, distance=5.50nm
53-
const navToWaypointData = '85,06,64,02,05,96,17,00,00'
53+
const navToWaypointData = '85,06,64,A0,65,22,17,00,00'
5454
// 0x85 Navigation to waypoint with true bearing: XTE=0.50nm steer right, bearing=180° true, distance=12.0nm
5555
// F=0x07 means XTE present (bit 0), bearing present (bit 1), range present (bit 2)
5656
// U=0xA means (A & 0x3)*90 = 2*90 = 180° base, and (A & 0x8) = 0x8 so True bearing
57-
const navToWaypointTrueData = '85,06,32,0A,07,78,07,00,00'
57+
const navToWaypointTrueData = '85,06,32,0A,80,07,47,00,00'
5858
// 0x82 Waypoint name: "WPT1" (6-bit encoded, little-endian)
5959
const waypointNameData = '82,05,27,D8,48,B7,06,F9'
6060
// 0x82 Waypoint name: "AB" (6-bit encoded, padded with zeros)

0 commit comments

Comments
 (0)