Ah, nice, so you changed:
decoded.latitude = degree(bytes.slice[6]);
decoded.longitude = degree(bytes.slice[9]);
…into:
decoded.latitude = degree(bytes.slice(6,8));
decoded.longitude = degree(bytes.slice(9,11));
The second parameter is not really needed (but surely cleaner as it’s more explicit) as the degree
function only cares for the first 3 bytes it gets passed, and ignores the rest. However, to pass 3 bytes it would then need to read (6, 9)
and (9, 12)
as the end position is not included.
But using (..)
instead of [..]
surely helps a lot.
Can you please share a GPS payload for future readers? (And any other type of payload you might get in the future? @flodenh, maybe you have some other payloads too?) I assume that the following would suffice, as JavaScript’s bitwise operators always yield signed 32 bits numbers:
function degree(bytes) {
return (bytes[0]<<24 | bytes[1]<<16 | bytes[2]<<8) / 1e7;
}