2018-06-16 13:18:36 +02:00
|
|
|
#ifndef _PAYLOAD_H_
|
|
|
|
#define _PAYLOAD_H_
|
|
|
|
|
2021-03-31 09:04:13 +02:00
|
|
|
#include "sensor.h"
|
2020-01-22 15:44:54 +01:00
|
|
|
#include "sds011read.h"
|
2021-03-31 21:43:51 +02:00
|
|
|
#include "gpsread.h"
|
2020-01-22 15:44:54 +01:00
|
|
|
|
2019-02-27 00:52:27 +01:00
|
|
|
// MyDevices CayenneLPP 1.0 channels for Synamic sensor payload format
|
|
|
|
// all payload goes out on LoRa FPort 1
|
2018-07-21 17:14:27 +02:00
|
|
|
#if (PAYLOAD_ENCODER == 3)
|
2018-07-21 22:44:25 +02:00
|
|
|
|
2018-06-17 01:15:02 +02:00
|
|
|
#define LPP_GPS_CHANNEL 20
|
|
|
|
#define LPP_COUNT_WIFI_CHANNEL 21
|
|
|
|
#define LPP_COUNT_BLE_CHANNEL 22
|
|
|
|
#define LPP_BATT_CHANNEL 23
|
2018-07-21 18:25:03 +02:00
|
|
|
#define LPP_BUTTON_CHANNEL 24
|
2018-06-17 01:15:02 +02:00
|
|
|
#define LPP_ADR_CHANNEL 25
|
2018-11-17 21:39:49 +01:00
|
|
|
#define LPP_TEMPERATURE_CHANNEL 26
|
2018-07-24 18:44:13 +02:00
|
|
|
#define LPP_ALARM_CHANNEL 27
|
|
|
|
#define LPP_MSG_CHANNEL 28
|
2018-11-17 21:39:49 +01:00
|
|
|
#define LPP_HUMIDITY_CHANNEL 29
|
|
|
|
#define LPP_BAROMETER_CHANNEL 30
|
2019-03-09 15:25:44 +01:00
|
|
|
#define LPP_AIR_CHANNEL 31
|
2020-03-13 15:23:22 +01:00
|
|
|
#define LPP_PARTMATTER10_CHANNEL 32 // particular matter for PM 10
|
|
|
|
#define LPP_PARTMATTER25_CHANNEL 33 // particular matter for PM 2.5
|
2018-11-17 21:39:49 +01:00
|
|
|
|
2019-03-09 15:25:44 +01:00
|
|
|
// MyDevices CayenneLPP 2.0 types for Packed Sensor Payload, not using channels,
|
|
|
|
// but different FPorts
|
2018-06-17 01:15:02 +02:00
|
|
|
#define LPP_GPS 136 // 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01m
|
2018-11-17 21:39:49 +01:00
|
|
|
#define LPP_TEMPERATURE 103 // 2 bytes, 0.1°C signed MSB
|
2018-06-17 01:15:02 +02:00
|
|
|
#define LPP_DIGITAL_INPUT 0 // 1 byte
|
|
|
|
#define LPP_DIGITAL_OUTPUT 1 // 1 byte
|
|
|
|
#define LPP_ANALOG_INPUT 2 // 2 bytes, 0.01 signed
|
2018-06-17 11:07:29 +02:00
|
|
|
#define LPP_LUMINOSITY 101 // 2 bytes, 1 lux unsigned
|
2018-08-13 18:42:48 +02:00
|
|
|
#define LPP_PRESENCE 102 // 1 byte
|
2018-11-17 21:39:49 +01:00
|
|
|
#define LPP_HUMIDITY 104 // 1 byte, 0.5 % unsigned
|
|
|
|
#define LPP_BAROMETER 115 // 2 bytes, hPa unsigned MSB
|
2018-06-17 01:15:02 +02:00
|
|
|
|
2019-07-27 13:35:12 +02:00
|
|
|
#endif
|
|
|
|
|
2018-07-19 22:33:37 +02:00
|
|
|
class PayloadConvert {
|
|
|
|
|
2018-06-16 13:18:36 +02:00
|
|
|
public:
|
2018-07-19 22:33:37 +02:00
|
|
|
PayloadConvert(uint8_t size);
|
|
|
|
~PayloadConvert();
|
2018-06-16 13:18:36 +02:00
|
|
|
|
|
|
|
void reset(void);
|
|
|
|
uint8_t getSize(void);
|
|
|
|
uint8_t *getBuffer(void);
|
2019-03-09 15:25:44 +01:00
|
|
|
void addByte(uint8_t value);
|
2018-12-02 14:08:50 +01:00
|
|
|
void addCount(uint16_t value, uint8_t sniffytpe);
|
2018-06-16 13:18:36 +02:00
|
|
|
void addConfig(configData_t value);
|
2018-08-12 15:42:58 +02:00
|
|
|
void addStatus(uint16_t voltage, uint64_t uptime, float cputemp, uint32_t mem,
|
2021-03-21 21:12:31 +01:00
|
|
|
uint8_t reset0, uint32_t restarts);
|
2019-03-09 15:25:44 +01:00
|
|
|
void addAlarm(int8_t rssi, uint8_t message);
|
2018-11-27 11:21:20 +01:00
|
|
|
void addVoltage(uint16_t value);
|
2018-06-17 13:31:24 +02:00
|
|
|
void addGPS(gpsStatus_t value);
|
2018-11-14 23:10:59 +01:00
|
|
|
void addBME(bmeStatus_t value);
|
2018-07-21 18:25:03 +02:00
|
|
|
void addButton(uint8_t value);
|
2018-11-20 15:02:37 +01:00
|
|
|
void addSensor(uint8_t[]);
|
2019-02-24 13:35:22 +01:00
|
|
|
void addTime(time_t value);
|
2020-02-28 16:13:20 +01:00
|
|
|
void addSDS(sdsStatus_t value);
|
2020-02-03 15:24:07 +01:00
|
|
|
private:
|
|
|
|
void addChars( char* string, int len);
|
|
|
|
|
|
|
|
#if (PAYLOAD_ENCODER == 1) // format plain
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint8_t *buffer;
|
|
|
|
uint8_t cursor;
|
|
|
|
|
|
|
|
#elif (PAYLOAD_ENCODER == 2) // format packed
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint8_t *buffer;
|
|
|
|
uint8_t cursor;
|
|
|
|
void uintToBytes(uint64_t i, uint8_t byteSize);
|
|
|
|
void writeUptime(uint64_t unixtime);
|
|
|
|
void writeLatLng(double latitude, double longitude);
|
|
|
|
void writeUint64(uint64_t i);
|
|
|
|
void writeUint32(uint32_t i);
|
|
|
|
void writeUint16(uint16_t i);
|
|
|
|
void writeUint8(uint8_t i);
|
|
|
|
void writeFloat(float value);
|
2020-03-13 15:35:42 +01:00
|
|
|
void writeUFloat(float value);
|
2020-02-03 15:24:07 +01:00
|
|
|
void writePressure(float value);
|
|
|
|
void writeVersion(char *version);
|
|
|
|
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
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint8_t *buffer;
|
|
|
|
uint8_t maxsize;
|
|
|
|
uint8_t cursor;
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error No valid payload converter defined!
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
extern PayloadConvert payload;
|
2021-03-31 21:43:51 +02:00
|
|
|
extern uint8_t batt_level;
|
2020-02-03 15:24:07 +01:00
|
|
|
|
2020-01-22 15:44:54 +01:00
|
|
|
#endif // _PAYLOAD_H_
|