diff --git a/src/TTN/packed_decoder.js b/src/TTN/packed_decoder.js index 6db312a4..5b7c1811 100644 --- a/src/TTN/packed_decoder.js +++ b/src/TTN/packed_decoder.js @@ -151,11 +151,8 @@ var altitude = function (bytes) { if (bytes.length !== altitude.BYTES) { throw new Error('Altitude must have exactly 2 bytes'); } - var alt = bytesToInt(bytes); - if (alt > 32767) { - alt -= 65536; - } - return alt; + var alt = bytesToInt(bytes) / 4 - 1000; + return +alt.toFixed(1); }; altitude.BYTES = 2; diff --git a/src/TTN/plain_decoder.js b/src/TTN/plain_decoder.js index 96655ee7..c6eba7b4 100644 --- a/src/TTN/plain_decoder.js +++ b/src/TTN/plain_decoder.js @@ -20,7 +20,7 @@ function Decoder(bytes, port) { decoded.longitude = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]); decoded.sats = bytes[i++]; decoded.hdop = (bytes[i++] << 8) | (bytes[i++]); - decoded.altitude = (bytes[i++] << 8) | (bytes[i++]); + decoded.altitude = ((bytes[i++] << 8) | (bytes[i++])) / 4 - 1000; } } @@ -41,7 +41,7 @@ function Decoder(bytes, port) { decoded.longitude = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]); decoded.sats = bytes[i++]; decoded.hdop = (bytes[i++] << 8) | (bytes[i++]); - decoded.altitude = (bytes[i++] << 8) | (bytes[i++]); + decoded.altitude = ((bytes[i++] << 8) | (bytes[i++])) / 4 - 1000; } if (port === 5) { diff --git a/src/gpsread.cpp b/src/gpsread.cpp index d99a7c46..33ba301a 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -71,7 +71,7 @@ void gps_storelocation(gpsStatus_t &gps_store) { gps_store.longitude = (int32_t)(gps.location.lng() * 1e6); gps_store.satellites = (uint8_t)gps.satellites.value(); gps_store.hdop = (uint16_t)gps.hdop.value(); - gps_store.altitude = (int16_t)gps.altitude.meters(); + gps_store.altitude = (int16_t)((gps.altitude.meters() + 1000) * 4); } // store current GPS timedate in struct