From 1f9e93cf39342dadf358b1109335d172c562ed25 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 27 Jul 2019 13:35:12 +0200 Subject: [PATCH] Increased GPS altitude resolution, further fixes --- include/payload.h | 10 +++++----- src/TTN/packed_decoder.js | 5 ++--- src/gpsread.cpp | 2 +- src/payload.cpp | 16 +++++++--------- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/include/payload.h b/include/payload.h index e2356764..76e74296 100644 --- a/include/payload.h +++ b/include/payload.h @@ -18,8 +18,6 @@ #define LPP_BAROMETER_CHANNEL 30 #define LPP_AIR_CHANNEL 31 -#endif - // MyDevices CayenneLPP 2.0 types for Packed Sensor Payload, not using channels, // but different FPorts #define LPP_GPS 136 // 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01m @@ -32,6 +30,8 @@ #define LPP_HUMIDITY 104 // 1 byte, 0.5 % unsigned #define LPP_BAROMETER 115 // 2 bytes, hPa unsigned MSB +#endif + class PayloadConvert { public: @@ -54,13 +54,13 @@ public: void addSensor(uint8_t[]); void addTime(time_t value); -#if PAYLOAD_ENCODER == 1 // format plain +#if (PAYLOAD_ENCODER == 1) // format plain private: uint8_t *buffer; uint8_t cursor; -#elif PAYLOAD_ENCODER == 2 // format packed +#elif (PAYLOAD_ENCODER == 2) // format packed private: uint8_t *buffer; @@ -78,7 +78,7 @@ private: void writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, bool g, bool h); -#elif (PAYLOAD_ENCODER == 3 || PAYLOAD_ENCODER == 4) // format cayenne lpp +#elif ((PAYLOAD_ENCODER == 3) || (PAYLOAD_ENCODER == 4)) // format cayenne lpp private: uint8_t *buffer; diff --git a/src/TTN/packed_decoder.js b/src/TTN/packed_decoder.js index 5b7c1811..2c5752f8 100644 --- a/src/TTN/packed_decoder.js +++ b/src/TTN/packed_decoder.js @@ -143,7 +143,7 @@ var hdop = function (bytes) { if (bytes.length !== hdop.BYTES) { throw new Error('hdop must have exactly 2 bytes'); } - return bytesToInt(bytes) / 100; + return +(bytesToInt(bytes) / 100).toFixed(1); }; hdop.BYTES = 2; @@ -151,8 +151,7 @@ var altitude = function (bytes) { if (bytes.length !== altitude.BYTES) { throw new Error('Altitude must have exactly 2 bytes'); } - var alt = bytesToInt(bytes) / 4 - 1000; - return +alt.toFixed(1); + return +(bytesToInt(bytes) / 4 - 1000).toFixed(1); }; altitude.BYTES = 2; diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 33ba301a..d99a7c46 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() + 1000) * 4); + gps_store.altitude = (int16_t)gps.altitude.meters(); } // store current GPS timedate in struct diff --git a/src/payload.cpp b/src/payload.cpp index a53cf7a1..df879467 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -16,7 +16,7 @@ uint8_t *PayloadConvert::getBuffer(void) { return buffer; } /* ---------------- plain format without special encoding ---------- */ -#if PAYLOAD_ENCODER == 1 +#if (PAYLOAD_ENCODER == 1) void PayloadConvert::addByte(uint8_t value) { buffer[cursor++] = (value); } @@ -92,8 +92,8 @@ void PayloadConvert::addGPS(gpsStatus_t value) { buffer[cursor++] = value.satellites; buffer[cursor++] = highByte(value.hdop); buffer[cursor++] = lowByte(value.hdop); - buffer[cursor++] = highByte(value.altitude); - buffer[cursor++] = lowByte(value.altitude); + buffer[cursor++] = highByte((value.altitude + 1000) * 4); + buffer[cursor++] = lowByte((value.altitude + 1000) * 4); #endif } @@ -141,7 +141,7 @@ void PayloadConvert::addTime(time_t value) { // derived from // https://github.com/thesolarnomad/lora-serialization/blob/master/src/LoraEncoder.cpp -#elif PAYLOAD_ENCODER == 2 +#elif (PAYLOAD_ENCODER == 2) void PayloadConvert::addByte(uint8_t value) { writeUint8(value); } @@ -195,7 +195,7 @@ void PayloadConvert::addGPS(gpsStatus_t value) { writeLatLng(value.latitude, value.longitude); writeUint8(value.satellites); writeUint16(value.hdop); - writeUint16(value.altitude); + writeUint16((value.altitude + 1000) * 4); #endif } @@ -301,7 +301,7 @@ void PayloadConvert::writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, // FPort 1 PAYLOAD_ENCODER == 4 -> Packed Sensor Payload, not using channels -> // FPort 2 -#elif (PAYLOAD_ENCODER == 3 || PAYLOAD_ENCODER == 4) +#elif ((PAYLOAD_ENCODER == 3) || (PAYLOAD_ENCODER == 4)) void PayloadConvert::addByte(uint8_t value) { /* @@ -412,7 +412,7 @@ void PayloadConvert::addSensor(uint8_t buf[]) { memcpy(buffer, buf+1, length); cursor += length; // length of buffer */ -#endif +#endif // HAS_SENSORS } void PayloadConvert::addBME(bmeStatus_t value) { @@ -481,6 +481,4 @@ void PayloadConvert::addTime(time_t value) { #endif } -#else -#error No valid payload converter defined! #endif \ No newline at end of file