Update payload.cpp
This commit is contained in:
parent
f33494b84f
commit
d818b6ecf4
@ -80,7 +80,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PayloadConvert::addGPS(gpsStatus_t value) {
|
void PayloadConvert::addGPS(gpsStatus_t value) {
|
||||||
#if(HAS_GPS)
|
#if (HAS_GPS)
|
||||||
buffer[cursor++] = (byte)((value.latitude & 0xFF000000) >> 24);
|
buffer[cursor++] = (byte)((value.latitude & 0xFF000000) >> 24);
|
||||||
buffer[cursor++] = (byte)((value.latitude & 0x00FF0000) >> 16);
|
buffer[cursor++] = (byte)((value.latitude & 0x00FF0000) >> 16);
|
||||||
buffer[cursor++] = (byte)((value.latitude & 0x0000FF00) >> 8);
|
buffer[cursor++] = (byte)((value.latitude & 0x0000FF00) >> 8);
|
||||||
@ -100,7 +100,7 @@ void PayloadConvert::addGPS(gpsStatus_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PayloadConvert::addSensor(uint8_t buf[]) {
|
void PayloadConvert::addSensor(uint8_t buf[]) {
|
||||||
#if(HAS_SENSORS)
|
#if (HAS_SENSORS)
|
||||||
uint8_t length = buf[0];
|
uint8_t length = buf[0];
|
||||||
memcpy(buffer, buf + 1, length);
|
memcpy(buffer, buf + 1, length);
|
||||||
cursor += length; // length of buffer
|
cursor += length; // length of buffer
|
||||||
@ -108,7 +108,7 @@ void PayloadConvert::addSensor(uint8_t buf[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PayloadConvert::addBME(bmeStatus_t value) {
|
void PayloadConvert::addBME(bmeStatus_t value) {
|
||||||
#if(HAS_BME)
|
#if (HAS_BME)
|
||||||
int16_t temperature = (int16_t)(value.temperature); // float -> int
|
int16_t temperature = (int16_t)(value.temperature); // float -> int
|
||||||
uint16_t humidity = (uint16_t)(value.humidity); // float -> int
|
uint16_t humidity = (uint16_t)(value.humidity); // float -> int
|
||||||
uint16_t pressure = (uint16_t)(value.pressure); // float -> int
|
uint16_t pressure = (uint16_t)(value.pressure); // float -> int
|
||||||
@ -124,6 +124,16 @@ void PayloadConvert::addBME(bmeStatus_t value) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PayloadConvert::addSDS(sdsStatus_t sds) {
|
||||||
|
#if (HAS_SDS011)
|
||||||
|
char tempBuffer[10 + 1];
|
||||||
|
sprintf(tempBuffer, ",%5.1f", sds.pm10);
|
||||||
|
addChars(tempBuffer, strlen(tempBuffer));
|
||||||
|
sprintf(tempBuffer, ",%5.1f", sds.pm25);
|
||||||
|
addChars(tempBuffer, strlen(tempBuffer));
|
||||||
|
#endif // HAS_SDS011
|
||||||
|
}
|
||||||
|
|
||||||
void PayloadConvert::addButton(uint8_t value) {
|
void PayloadConvert::addButton(uint8_t value) {
|
||||||
#ifdef HAS_BUTTON
|
#ifdef HAS_BUTTON
|
||||||
buffer[cursor++] = value;
|
buffer[cursor++] = value;
|
||||||
@ -193,7 +203,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PayloadConvert::addGPS(gpsStatus_t value) {
|
void PayloadConvert::addGPS(gpsStatus_t value) {
|
||||||
#if(HAS_GPS)
|
#if (HAS_GPS)
|
||||||
writeLatLng(value.latitude, value.longitude);
|
writeLatLng(value.latitude, value.longitude);
|
||||||
#if (!PAYLOAD_OPENSENSEBOX)
|
#if (!PAYLOAD_OPENSENSEBOX)
|
||||||
writeUint8(value.satellites);
|
writeUint8(value.satellites);
|
||||||
@ -204,7 +214,7 @@ void PayloadConvert::addGPS(gpsStatus_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PayloadConvert::addSensor(uint8_t buf[]) {
|
void PayloadConvert::addSensor(uint8_t buf[]) {
|
||||||
#if(HAS_SENSORS)
|
#if (HAS_SENSORS)
|
||||||
uint8_t length = buf[0];
|
uint8_t length = buf[0];
|
||||||
memcpy(buffer, buf + 1, length);
|
memcpy(buffer, buf + 1, length);
|
||||||
cursor += length; // length of buffer
|
cursor += length; // length of buffer
|
||||||
@ -212,7 +222,7 @@ void PayloadConvert::addSensor(uint8_t buf[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PayloadConvert::addBME(bmeStatus_t value) {
|
void PayloadConvert::addBME(bmeStatus_t value) {
|
||||||
#if(HAS_BME)
|
#if (HAS_BME)
|
||||||
writeFloat(value.temperature);
|
writeFloat(value.temperature);
|
||||||
writePressure(value.pressure);
|
writePressure(value.pressure);
|
||||||
writeUFloat(value.humidity);
|
writeUFloat(value.humidity);
|
||||||
@ -220,6 +230,13 @@ void PayloadConvert::addBME(bmeStatus_t value) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PayloadConvert::addSDS(sdsStatus_t sds) {
|
||||||
|
#if (HAS_SDS011)
|
||||||
|
writeUint16((uint16_t)(sds.pm10 * 10));
|
||||||
|
writeUint16((uint16_t)(sds.pm25 * 10));
|
||||||
|
#endif // HAS_SDS011
|
||||||
|
}
|
||||||
|
|
||||||
void PayloadConvert::addButton(uint8_t value) {
|
void PayloadConvert::addButton(uint8_t value) {
|
||||||
#ifdef HAS_BUTTON
|
#ifdef HAS_BUTTON
|
||||||
writeUint8(value);
|
writeUint8(value);
|
||||||
@ -242,9 +259,7 @@ void PayloadConvert::uintToBytes(uint64_t value, uint8_t byteSize) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PayloadConvert::writeUptime(uint64_t uptime) {
|
void PayloadConvert::writeUptime(uint64_t uptime) { writeUint64(uptime); }
|
||||||
writeUint64(uptime);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PayloadConvert::writeVersion(char *version) {
|
void PayloadConvert::writeVersion(char *version) {
|
||||||
memcpy(buffer + cursor, version, 10);
|
memcpy(buffer + cursor, version, 10);
|
||||||
@ -265,13 +280,9 @@ void PayloadConvert::writeUint16(uint16_t i) { uintToBytes(i, 2); }
|
|||||||
|
|
||||||
void PayloadConvert::writeUint8(uint8_t i) { uintToBytes(i, 1); }
|
void PayloadConvert::writeUint8(uint8_t i) { uintToBytes(i, 1); }
|
||||||
|
|
||||||
void PayloadConvert::writeUFloat(float value) {
|
void PayloadConvert::writeUFloat(float value) { writeUint16(value * 100); }
|
||||||
writeUint16(value * 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PayloadConvert::writePressure(float value) {
|
void PayloadConvert::writePressure(float value) { writeUint16(value * 10); }
|
||||||
writeUint16(value * 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses a 16bit two's complement with two decimals, so the range is
|
* Uses a 16bit two's complement with two decimals, so the range is
|
||||||
@ -315,7 +326,8 @@ void PayloadConvert::writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f,
|
|||||||
void PayloadConvert::addByte(uint8_t value) {
|
void PayloadConvert::addByte(uint8_t value) {
|
||||||
/*
|
/*
|
||||||
not implemented
|
not implemented
|
||||||
*/ }
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
void PayloadConvert::addSDS(sdsStatus_t sds) {
|
void PayloadConvert::addSDS(sdsStatus_t sds) {
|
||||||
#if (HAS_SDS011)
|
#if (HAS_SDS011)
|
||||||
@ -412,7 +424,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PayloadConvert::addGPS(gpsStatus_t value) {
|
void PayloadConvert::addGPS(gpsStatus_t value) {
|
||||||
#if(HAS_GPS)
|
#if (HAS_GPS)
|
||||||
int32_t lat = value.latitude / 100;
|
int32_t lat = value.latitude / 100;
|
||||||
int32_t lon = value.longitude / 100;
|
int32_t lon = value.longitude / 100;
|
||||||
int32_t alt = value.altitude * 100;
|
int32_t alt = value.altitude * 100;
|
||||||
@ -433,18 +445,18 @@ void PayloadConvert::addGPS(gpsStatus_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PayloadConvert::addSensor(uint8_t buf[]) {
|
void PayloadConvert::addSensor(uint8_t buf[]) {
|
||||||
#if(HAS_SENSORS)
|
#if (HAS_SENSORS)
|
||||||
// to come
|
// to come
|
||||||
/*
|
/*
|
||||||
uint8_t length = buf[0];
|
uint8_t length = buf[0];
|
||||||
memcpy(buffer, buf+1, length);
|
memcpy(buffer, buf+1, length);
|
||||||
cursor += length; // length of buffer
|
cursor += length; // length of buffer
|
||||||
*/
|
*/
|
||||||
#endif // HAS_SENSORS
|
#endif // HAS_SENSORS
|
||||||
}
|
}
|
||||||
|
|
||||||
void PayloadConvert::addBME(bmeStatus_t value) {
|
void PayloadConvert::addBME(bmeStatus_t value) {
|
||||||
#if(HAS_BME)
|
#if (HAS_BME)
|
||||||
|
|
||||||
// data value conversions to meet cayenne data type definition
|
// data value conversions to meet cayenne data type definition
|
||||||
// 0.1°C per bit => -3276,7 .. +3276,7 °C
|
// 0.1°C per bit => -3276,7 .. +3276,7 °C
|
||||||
@ -510,7 +522,7 @@ void PayloadConvert::addTime(time_t value) {
|
|||||||
}
|
}
|
||||||
#endif // PAYLOAD_ENCODER
|
#endif // PAYLOAD_ENCODER
|
||||||
|
|
||||||
void PayloadConvert::addChars( char * string, int len) {
|
void PayloadConvert::addChars(char *string, int len) {
|
||||||
for (int i=0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
addByte(string[i]);
|
addByte(string[i]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user