Skip to content

Commit

Permalink
Increased GPS altitude resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberman54 committed Jul 27, 2019
1 parent 7ab96b6 commit a3f036c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/TTN/packed_decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/TTN/plain_decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/gpsread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a3f036c

Please sign in to comment.