payload.cpp fixes
This commit is contained in:
parent
f3ca06fa31
commit
d2739426e5
@ -18,12 +18,12 @@ function Decoder(bytes, port) {
|
|||||||
|
|
||||||
if (port === 2) {
|
if (port === 2) {
|
||||||
// device status data
|
// device status data
|
||||||
if (bytes.length == 10) {
|
if (bytes.length == 12) {
|
||||||
return decode(bytes, [uint16, unixtime, temperature], ['voltage', 'uptime', 'cputemp']);
|
return decode(bytes, [uint16, uptime, temperature], ['voltage', 'uptime', 'cputemp']);
|
||||||
}
|
}
|
||||||
// device config data
|
// device config data
|
||||||
if (bytes.length == 8) {
|
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;
|
return i;
|
||||||
};
|
};
|
||||||
|
|
||||||
var unixtime = function (bytes) {
|
var uptime = function (bytes) {
|
||||||
if (bytes.length !== unixtime.BYTES) {
|
if (bytes.length !== uptime.BYTES) {
|
||||||
throw new Error('Unix time must have exactly 4 bytes');
|
throw new Error('uptime must have exactly 8 bytes');
|
||||||
}
|
}
|
||||||
return bytesToInt(bytes);
|
return bytesToInt(bytes);
|
||||||
};
|
};
|
||||||
unixtime.BYTES = 4;
|
uptime.BYTES = 4;
|
||||||
|
|
||||||
var uint8 = function (bytes) {
|
var uint8 = function (bytes) {
|
||||||
if (bytes.length !== uint8.BYTES) {
|
if (bytes.length !== uint8.BYTES) {
|
||||||
@ -150,7 +150,7 @@ var decode = function (bytes, mask, names) {
|
|||||||
|
|
||||||
if (typeof module === 'object' && typeof module.exports !== 'undefined') {
|
if (typeof module === 'object' && typeof module.exports !== 'undefined') {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
unixtime: unixtime,
|
uptime: uptime,
|
||||||
uint8: uint8,
|
uint8: uint8,
|
||||||
uint16: uint16,
|
uint16: uint16,
|
||||||
temperature: temperature,
|
temperature: temperature,
|
||||||
|
@ -8,8 +8,8 @@ static const char TAG[] = "main";
|
|||||||
|
|
||||||
// read GPS data and cast to global struct
|
// read GPS data and cast to global struct
|
||||||
void gps_read() {
|
void gps_read() {
|
||||||
gps_status.latitude = (uint32_t)(gps.location.lat() * 1000000);
|
gps_status.latitude = (uint32_t)(gps.location.lat() * 1e6);
|
||||||
gps_status.longitude = (uint32_t)(gps.location.lng() * 1000000);
|
gps_status.longitude = (uint32_t)(gps.location.lng() * 1e6);
|
||||||
gps_status.satellites = (uint8_t)gps.satellites.value();
|
gps_status.satellites = (uint8_t)gps.satellites.value();
|
||||||
gps_status.hdop = (uint16_t)gps.hdop.value();
|
gps_status.hdop = (uint16_t)gps.hdop.value();
|
||||||
gps_status.altitude = (uint16_t)gps.altitude.meters();
|
gps_status.altitude = (uint16_t)gps.altitude.meters();
|
||||||
|
@ -125,39 +125,33 @@ void TTNpacked::addConfig(configData_t value) {
|
|||||||
|
|
||||||
void TTNpacked::addStatus(uint16_t voltage, uint64_t uptime, float cputemp) {
|
void TTNpacked::addStatus(uint16_t voltage, uint64_t uptime, float cputemp) {
|
||||||
writeUint16(voltage);
|
writeUint16(voltage);
|
||||||
writeUnixtime(uptime);
|
writeUptime(uptime);
|
||||||
writeTemperature(cputemp);
|
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++) {
|
for (uint8_t x = 0; x < byteSize; x++) {
|
||||||
buffer[x + pos] = (byte)(i >> (x * 8));
|
buffer[x + pos] = (byte)(i >> (x * 8));
|
||||||
}
|
}
|
||||||
cursor += byteSize;
|
cursor += byteSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TTNpacked::writeUnixtime(uint32_t unixtime) {
|
void TTNpacked::writeUptime(uint64_t uptime) {
|
||||||
_intToBytes(cursor, unixtime, 4);
|
intToBytes(cursor, uptime, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TTNpacked::writeLatLng(double latitude, double longitude) {
|
void TTNpacked::writeLatLng(double latitude, double longitude) {
|
||||||
int32_t lat = latitude * 1e6;
|
intToBytes(cursor, latitude, 4);
|
||||||
int32_t lng = longitude * 1e6;
|
intToBytes(cursor, longitude, 4);
|
||||||
_intToBytes(cursor, lat, 4);
|
|
||||||
_intToBytes(cursor, lng, 4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TTNpacked::writeUint16(uint16_t i) {
|
void TTNpacked::writeUint16(uint16_t i) { intToBytes(cursor, i, 2); }
|
||||||
_intToBytes(cursor, i, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TTNpacked::writeUint8(uint8_t i) {
|
void TTNpacked::writeUint8(uint8_t i) { intToBytes(cursor, i, 1); }
|
||||||
_intToBytes(cursor, i, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TTNpacked::writeHumidity(float humidity) {
|
void TTNpacked::writeHumidity(float humidity) {
|
||||||
int16_t h = (int16_t)(humidity * 100);
|
int16_t h = (int16_t)(humidity * 100);
|
||||||
_intToBytes(cursor, h, 2);
|
intToBytes(cursor, h, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,8 +59,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
uint8_t cursor;
|
uint8_t cursor;
|
||||||
void _intToBytes(uint8_t pos, int32_t i, uint8_t byteSize);
|
void intToBytes(uint8_t pos, int32_t i, uint8_t byteSize);
|
||||||
void writeUnixtime(uint32_t unixtime);
|
void writeUptime(uint64_t unixtime);
|
||||||
void writeLatLng(double latitude, double longitude);
|
void writeLatLng(double latitude, double longitude);
|
||||||
void writeUint16(uint16_t i);
|
void writeUint16(uint16_t i);
|
||||||
void writeUint8(uint8_t i);
|
void writeUint8(uint8_t i);
|
||||||
|
Loading…
Reference in New Issue
Block a user