diff --git a/src/TTN/packed_decoder.js b/src/TTN/packed_decoder.js index af28fab4..8c469b9b 100644 --- a/src/TTN/packed_decoder.js +++ b/src/TTN/packed_decoder.js @@ -18,12 +18,12 @@ function Decoder(bytes, port) { if (port === 2) { // device status data - if (bytes.length == 10) { - return decode(bytes, [uint16, unixtime, temperature], ['voltage', 'uptime', 'cputemp']); + if (bytes.length == 12) { + return decode(bytes, [uint16, uptime, temperature], ['voltage', 'uptime', 'cputemp']); } // device config data if (bytes.length == 8) { - return decode(bytes, [uint8, uint16, uint8, uint8, uint8, bitmap], ['lorasf', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags']); + return decode(bytes, [uint8, uint16, uint8, uint8, uint8, uint8, bitmap], ['lorasf', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags']); } } @@ -41,13 +41,13 @@ var bytesToInt = function (bytes) { return i; }; -var unixtime = function (bytes) { - if (bytes.length !== unixtime.BYTES) { - throw new Error('Unix time must have exactly 4 bytes'); +var uptime = function (bytes) { + if (bytes.length !== uptime.BYTES) { + throw new Error('uptime must have exactly 8 bytes'); } return bytesToInt(bytes); }; -unixtime.BYTES = 4; +uptime.BYTES = 4; var uint8 = function (bytes) { if (bytes.length !== uint8.BYTES) { @@ -150,7 +150,7 @@ var decode = function (bytes, mask, names) { if (typeof module === 'object' && typeof module.exports !== 'undefined') { module.exports = { - unixtime: unixtime, + uptime: uptime, uint8: uint8, uint16: uint16, temperature: temperature, diff --git a/src/gpsread.cpp b/src/gpsread.cpp index d0cab92c..11a8cf92 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -8,8 +8,8 @@ static const char TAG[] = "main"; // read GPS data and cast to global struct void gps_read() { - gps_status.latitude = (uint32_t)(gps.location.lat() * 1000000); - gps_status.longitude = (uint32_t)(gps.location.lng() * 1000000); + gps_status.latitude = (uint32_t)(gps.location.lat() * 1e6); + gps_status.longitude = (uint32_t)(gps.location.lng() * 1e6); gps_status.satellites = (uint8_t)gps.satellites.value(); gps_status.hdop = (uint16_t)gps.hdop.value(); gps_status.altitude = (uint16_t)gps.altitude.meters(); diff --git a/src/payload.cpp b/src/payload.cpp index b3b73e18..dce09224 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -125,39 +125,33 @@ void TTNpacked::addConfig(configData_t value) { void TTNpacked::addStatus(uint16_t voltage, uint64_t uptime, float cputemp) { writeUint16(voltage); - writeUnixtime(uptime); + writeUptime(uptime); writeTemperature(cputemp); } -void TTNpacked::_intToBytes(uint8_t pos, int32_t i, uint8_t byteSize) { +void TTNpacked::intToBytes(uint8_t pos, int32_t i, uint8_t byteSize) { for (uint8_t x = 0; x < byteSize; x++) { buffer[x + pos] = (byte)(i >> (x * 8)); } cursor += byteSize; } -void TTNpacked::writeUnixtime(uint32_t unixtime) { - _intToBytes(cursor, unixtime, 4); +void TTNpacked::writeUptime(uint64_t uptime) { + intToBytes(cursor, uptime, 8); } void TTNpacked::writeLatLng(double latitude, double longitude) { - int32_t lat = latitude * 1e6; - int32_t lng = longitude * 1e6; - _intToBytes(cursor, lat, 4); - _intToBytes(cursor, lng, 4); + intToBytes(cursor, latitude, 4); + intToBytes(cursor, longitude, 4); } -void TTNpacked::writeUint16(uint16_t i) { - _intToBytes(cursor, i, 2); -} +void TTNpacked::writeUint16(uint16_t i) { intToBytes(cursor, i, 2); } -void TTNpacked::writeUint8(uint8_t i) { - _intToBytes(cursor, i, 1); -} +void TTNpacked::writeUint8(uint8_t i) { intToBytes(cursor, i, 1); } void TTNpacked::writeHumidity(float humidity) { int16_t h = (int16_t)(humidity * 100); - _intToBytes(cursor, h, 2); + intToBytes(cursor, h, 2); } /** diff --git a/src/payload.h b/src/payload.h index a828b818..53cda054 100644 --- a/src/payload.h +++ b/src/payload.h @@ -59,8 +59,8 @@ public: private: uint8_t *buffer; uint8_t cursor; - void _intToBytes(uint8_t pos, int32_t i, uint8_t byteSize); - void writeUnixtime(uint32_t unixtime); + void intToBytes(uint8_t pos, int32_t i, uint8_t byteSize); + void writeUptime(uint64_t unixtime); void writeLatLng(double latitude, double longitude); void writeUint16(uint16_t i); void writeUint8(uint8_t i);