From d818b6ecf4781f161b4282f3d1f06dfeedeb1a65 Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Fri, 13 Mar 2020 15:41:07 +0100 Subject: [PATCH] Update payload.cpp --- src/payload.cpp | 72 ++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/src/payload.cpp b/src/payload.cpp index ceb971fa..8ab9f91c 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -80,7 +80,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, } void PayloadConvert::addGPS(gpsStatus_t value) { -#if(HAS_GPS) +#if (HAS_GPS) buffer[cursor++] = (byte)((value.latitude & 0xFF000000) >> 24); buffer[cursor++] = (byte)((value.latitude & 0x00FF0000) >> 16); buffer[cursor++] = (byte)((value.latitude & 0x0000FF00) >> 8); @@ -100,7 +100,7 @@ void PayloadConvert::addGPS(gpsStatus_t value) { } void PayloadConvert::addSensor(uint8_t buf[]) { -#if(HAS_SENSORS) +#if (HAS_SENSORS) uint8_t length = buf[0]; memcpy(buffer, buf + 1, length); cursor += length; // length of buffer @@ -108,7 +108,7 @@ void PayloadConvert::addSensor(uint8_t buf[]) { } void PayloadConvert::addBME(bmeStatus_t value) { -#if(HAS_BME) +#if (HAS_BME) int16_t temperature = (int16_t)(value.temperature); // float -> int uint16_t humidity = (uint16_t)(value.humidity); // float -> int uint16_t pressure = (uint16_t)(value.pressure); // float -> int @@ -124,6 +124,16 @@ void PayloadConvert::addBME(bmeStatus_t value) { #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) { #ifdef HAS_BUTTON buffer[cursor++] = value; @@ -193,7 +203,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, } void PayloadConvert::addGPS(gpsStatus_t value) { -#if(HAS_GPS) +#if (HAS_GPS) writeLatLng(value.latitude, value.longitude); #if (!PAYLOAD_OPENSENSEBOX) writeUint8(value.satellites); @@ -204,7 +214,7 @@ void PayloadConvert::addGPS(gpsStatus_t value) { } void PayloadConvert::addSensor(uint8_t buf[]) { -#if(HAS_SENSORS) +#if (HAS_SENSORS) uint8_t length = buf[0]; memcpy(buffer, buf + 1, length); cursor += length; // length of buffer @@ -212,7 +222,7 @@ void PayloadConvert::addSensor(uint8_t buf[]) { } void PayloadConvert::addBME(bmeStatus_t value) { -#if(HAS_BME) +#if (HAS_BME) writeFloat(value.temperature); writePressure(value.pressure); writeUFloat(value.humidity); @@ -220,6 +230,13 @@ void PayloadConvert::addBME(bmeStatus_t value) { #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) { #ifdef HAS_BUTTON writeUint8(value); @@ -242,9 +259,7 @@ void PayloadConvert::uintToBytes(uint64_t value, uint8_t byteSize) { } } -void PayloadConvert::writeUptime(uint64_t uptime) { - writeUint64(uptime); -} +void PayloadConvert::writeUptime(uint64_t uptime) { writeUint64(uptime); } void PayloadConvert::writeVersion(char *version) { 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::writeUFloat(float value) { - writeUint16(value * 100); -} +void PayloadConvert::writeUFloat(float value) { writeUint16(value * 100); } -void PayloadConvert::writePressure(float value) { - writeUint16(value * 10); -} +void PayloadConvert::writePressure(float value) { writeUint16(value * 10); } /** * Uses a 16bit two's complement with two decimals, so the range is @@ -312,10 +323,11 @@ void PayloadConvert::writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, #elif ((PAYLOAD_ENCODER == 3) || (PAYLOAD_ENCODER == 4)) -void PayloadConvert::addByte(uint8_t value) { - /* +void PayloadConvert::addByte(uint8_t value) { + /* not implemented - */ } + */ +} void PayloadConvert::addSDS(sdsStatus_t sds) { #if (HAS_SDS011) @@ -412,7 +424,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius, } void PayloadConvert::addGPS(gpsStatus_t value) { -#if(HAS_GPS) +#if (HAS_GPS) int32_t lat = value.latitude / 100; int32_t lon = value.longitude / 100; int32_t alt = value.altitude * 100; @@ -433,18 +445,18 @@ void PayloadConvert::addGPS(gpsStatus_t value) { } void PayloadConvert::addSensor(uint8_t buf[]) { -#if(HAS_SENSORS) -// to come -/* - uint8_t length = buf[0]; - memcpy(buffer, buf+1, length); - cursor += length; // length of buffer -*/ +#if (HAS_SENSORS) + // to come + /* + uint8_t length = buf[0]; + memcpy(buffer, buf+1, length); + cursor += length; // length of buffer + */ #endif // HAS_SENSORS } void PayloadConvert::addBME(bmeStatus_t value) { -#if(HAS_BME) +#if (HAS_BME) // data value conversions to meet cayenne data type definition // 0.1°C per bit => -3276,7 .. +3276,7 °C @@ -510,7 +522,7 @@ void PayloadConvert::addTime(time_t value) { } #endif // PAYLOAD_ENCODER -void PayloadConvert::addChars( char * string, int len) { - for (int i=0; i < len; i++) - addByte(string[i]); +void PayloadConvert::addChars(char *string, int len) { + for (int i = 0; i < len; i++) + addByte(string[i]); }