fixed TTN decoder for gps altitude

This commit is contained in:
cyberman54 2019-07-27 15:23:17 +02:00
parent 1f9e93cf39
commit 9be1d36166
2 changed files with 12 additions and 2 deletions

View File

@ -151,7 +151,13 @@ var altitude = function (bytes) {
if (bytes.length !== altitude.BYTES) { if (bytes.length !== altitude.BYTES) {
throw new Error('Altitude must have exactly 2 bytes'); throw new Error('Altitude must have exactly 2 bytes');
} }
return +(bytesToInt(bytes) / 4 - 1000).toFixed(1);
var alt = bytesToInt(bytes);
if (alt > 32767) {
alt -= 65536;
}
return +(alt / 4 - 1000).toFixed(1);
}; };
altitude.BYTES = 2; altitude.BYTES = 2;

View File

@ -41,7 +41,11 @@ function Decoder(bytes, port) {
decoded.longitude = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]); decoded.longitude = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]);
decoded.sats = bytes[i++]; decoded.sats = bytes[i++];
decoded.hdop = (bytes[i++] << 8) | (bytes[i++]); decoded.hdop = (bytes[i++] << 8) | (bytes[i++]);
decoded.altitude = ((bytes[i++] << 8) | (bytes[i++])) / 4 - 1000; var alt = ((bytes[i++] << 8) | (bytes[i++]));
if (alt > 32767) {
alt -= 65536;
}
decoded.altitude = alt / 4 - 1000;
} }
if (port === 5) { if (port === 5) {