CayenneLPP payload encoder added (experimental)
This commit is contained in:
parent
692b90d230
commit
a6642ea8b6
@ -51,7 +51,7 @@ extern TTNplain payload;
|
|||||||
#elif (PAYLOAD_ENCODER == 2)
|
#elif (PAYLOAD_ENCODER == 2)
|
||||||
extern TTNserialized payload;
|
extern TTNserialized payload;
|
||||||
#elif (PAYLOAD_ENCODER == 3)
|
#elif (PAYLOAD_ENCODER == 3)
|
||||||
//extern CayenneLPP payload;
|
extern CayenneLPP payload;
|
||||||
#else
|
#else
|
||||||
#error "No valid payload converter defined"
|
#error "No valid payload converter defined"
|
||||||
#endif
|
#endif
|
@ -76,7 +76,7 @@ TTNplain payload(PAYLOAD_BUFFER_SIZE);
|
|||||||
#elif (PAYLOAD_ENCODER == 2)
|
#elif (PAYLOAD_ENCODER == 2)
|
||||||
TTNserialized payload(PAYLOAD_BUFFER_SIZE);
|
TTNserialized payload(PAYLOAD_BUFFER_SIZE);
|
||||||
#elif (PAYLOAD_ENCODER == 3)
|
#elif (PAYLOAD_ENCODER == 3)
|
||||||
//CayenneLPP payload(PAYLOAD_BUFFER_SIZE);
|
CayenneLPP payload(PAYLOAD_BUFFER_SIZE);
|
||||||
#else
|
#else
|
||||||
#error "No valid payload converter defined"
|
#error "No valid payload converter defined"
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,8 +41,9 @@
|
|||||||
#define SEND_SECS 30 // [seconds/2] -> 60 sec.
|
#define SEND_SECS 30 // [seconds/2] -> 60 sec.
|
||||||
#define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle
|
#define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle
|
||||||
#define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results
|
#define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results
|
||||||
#define PAYLOAD_ENCODER 1 // select payload encoder: 1 = Plain [default], 2 = Lora-hserialized, 3 = Cayenne LPP
|
#define PAYLOAD_ENCODER 3 // select payload encoder: 1 = Plain [default], 2 = Lora-serialized, 3 = CayenneLPP
|
||||||
#define PAYLOAD_BUFFER_SIZE 51 // maximum size of payload block per transmit
|
#define PAYLOAD_BUFFER_SIZE 51 // maximum size of payload block per transmit
|
||||||
|
#define CAYENNE_LPP 1 // uncomment this, if you need Cayenne LPP payload encoding
|
||||||
|
|
||||||
// Default LoRa Spreadfactor
|
// Default LoRa Spreadfactor
|
||||||
#define LORASFDEFAULT 9 // 7 ... 12 SF, according to LoRaWAN specs
|
#define LORASFDEFAULT 9 // 7 ... 12 SF, according to LoRaWAN specs
|
||||||
|
@ -81,7 +81,7 @@ void TTNplain::addStatus(uint16_t voltage, uint64_t uptime, float cputemp) {
|
|||||||
|
|
||||||
TTNserialized::TTNserialized(uint8_t size) {
|
TTNserialized::TTNserialized(uint8_t size) {
|
||||||
buffer = (uint8_t *)malloc(size);
|
buffer = (uint8_t *)malloc(size);
|
||||||
//LoraEncoder message(buffer);
|
// LoraEncoder message(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
TTNserialized::~TTNserialized(void) { free(buffer); }
|
TTNserialized::~TTNserialized(void) { free(buffer); }
|
||||||
@ -130,3 +130,67 @@ void TTNserialized::addStatus(uint16_t voltage, uint64_t uptime,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- Cayenne LPP format ---------- */
|
/* ---------------- Cayenne LPP format ---------- */
|
||||||
|
|
||||||
|
#ifdef CAYENNE_LPP
|
||||||
|
|
||||||
|
CayenneLPP::CayenneLPP(uint8_t size) {
|
||||||
|
buffer = (uint8_t *)malloc(size);
|
||||||
|
cursor = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CayenneLPP::~CayenneLPP(void) { free(buffer); }
|
||||||
|
|
||||||
|
void CayenneLPP::reset(void) { cursor = 0; }
|
||||||
|
|
||||||
|
uint8_t CayenneLPP::getSize(void) { return cursor; }
|
||||||
|
|
||||||
|
uint8_t *CayenneLPP::getBuffer(void) { return buffer; }
|
||||||
|
|
||||||
|
void CayenneLPP::addCount(uint16_t value1, uint16_t value2) {
|
||||||
|
buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL;
|
||||||
|
buffer[cursor++] = LPP_ANALOG_INPUT;
|
||||||
|
buffer[cursor++] = value1 >> 8;
|
||||||
|
buffer[cursor++] = value1;
|
||||||
|
buffer[cursor++] = LPP_COUNT_BLE_CHANNEL;
|
||||||
|
buffer[cursor++] = LPP_ANALOG_INPUT;
|
||||||
|
buffer[cursor++] = value2 >> 8;
|
||||||
|
buffer[cursor++] = value2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CayenneLPP::addGPS(gpsStatus_t value) {
|
||||||
|
int32_t lat = value.latitude * (int32_t) 10000;
|
||||||
|
int32_t lon = value.longitude * (int32_t) 10000;
|
||||||
|
int32_t alt = value.altitude * (int32_t) 100;
|
||||||
|
|
||||||
|
buffer[cursor++] = LPP_GPS_CHANNEL;
|
||||||
|
buffer[cursor++] = LPP_GPS;
|
||||||
|
buffer[cursor++] = lat >> 16;
|
||||||
|
buffer[cursor++] = lat >> 8;
|
||||||
|
buffer[cursor++] = lat;
|
||||||
|
buffer[cursor++] = lon >> 16;
|
||||||
|
buffer[cursor++] = lon >> 8;
|
||||||
|
buffer[cursor++] = lon;
|
||||||
|
buffer[cursor++] = alt >> 16;
|
||||||
|
buffer[cursor++] = alt >> 8;
|
||||||
|
buffer[cursor++] = alt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CayenneLPP::addConfig(configData_t value) {
|
||||||
|
buffer[cursor++] = LPP_ADR_CHANNEL;
|
||||||
|
buffer[cursor++] = LPP_DIGITAL_INPUT;
|
||||||
|
buffer[cursor++] = value.adrmode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CayenneLPP::addStatus(uint16_t voltage, uint64_t uptime, float cputemp) {
|
||||||
|
buffer[cursor++] = LPP_BATT_CHANNEL;
|
||||||
|
buffer[cursor++] = LPP_ANALOG_INPUT;
|
||||||
|
buffer[cursor++] = voltage >> 8;
|
||||||
|
buffer[cursor++] = voltage;
|
||||||
|
|
||||||
|
buffer[cursor++] = LPP_TEMP_CHANNEL;
|
||||||
|
buffer[cursor++] = LPP_TEMPERATURE;
|
||||||
|
buffer[cursor++] = (uint16_t) cputemp >> 8;
|
||||||
|
buffer[cursor++] = (uint16_t) cputemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CAYENNE_LPP
|
@ -14,11 +14,8 @@ public:
|
|||||||
uint8_t getSize(void);
|
uint8_t getSize(void);
|
||||||
uint8_t *getBuffer(void);
|
uint8_t *getBuffer(void);
|
||||||
|
|
||||||
// application payloads
|
|
||||||
void addCount(uint16_t value1, uint16_t value2);
|
void addCount(uint16_t value1, uint16_t value2);
|
||||||
void addGPS(gpsStatus_t value);
|
void addGPS(gpsStatus_t value);
|
||||||
|
|
||||||
// payloads for get rcommands
|
|
||||||
void addConfig(configData_t value);
|
void addConfig(configData_t value);
|
||||||
void addStatus(uint16_t voltage, uint64_t uptime, float cputemp);
|
void addStatus(uint16_t voltage, uint64_t uptime, float cputemp);
|
||||||
|
|
||||||
@ -37,11 +34,8 @@ public:
|
|||||||
uint8_t getSize(void);
|
uint8_t getSize(void);
|
||||||
uint8_t *getBuffer(void);
|
uint8_t *getBuffer(void);
|
||||||
|
|
||||||
// application payloads
|
|
||||||
void addCount(uint16_t value1, uint16_t value2);
|
void addCount(uint16_t value1, uint16_t value2);
|
||||||
void addGPS(gpsStatus_t value);
|
void addGPS(gpsStatus_t value);
|
||||||
|
|
||||||
// payloads for get rcommands
|
|
||||||
void addConfig(configData_t value);
|
void addConfig(configData_t value);
|
||||||
void addStatus(uint16_t voltage, uint64_t uptime, float cputemp);
|
void addStatus(uint16_t voltage, uint64_t uptime, float cputemp);
|
||||||
|
|
||||||
@ -50,4 +44,41 @@ private:
|
|||||||
LoraEncoder message(byte *buffer);
|
LoraEncoder message(byte *buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#ifdef CAYENNE_LPP
|
||||||
|
// LPP channels
|
||||||
|
#define LPP_GPS_CHANNEL 20
|
||||||
|
#define LPP_COUNT_WIFI_CHANNEL 21
|
||||||
|
#define LPP_COUNT_BLE_CHANNEL 22
|
||||||
|
#define LPP_BATT_CHANNEL 23
|
||||||
|
#define LPP_ADR_CHANNEL 25
|
||||||
|
#define LPP_TEMP_CHANNEL 26
|
||||||
|
// LPP types
|
||||||
|
#define LPP_GPS 136 // 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01m
|
||||||
|
#define LPP_TEMPERATURE 103 // 2 bytes, 0.1°C signed
|
||||||
|
#define LPP_DIGITAL_INPUT 0 // 1 byte
|
||||||
|
#define LPP_DIGITAL_OUTPUT 1 // 1 byte
|
||||||
|
#define LPP_ANALOG_INPUT 2 // 2 bytes, 0.01 signed
|
||||||
|
|
||||||
|
class CayenneLPP {
|
||||||
|
public:
|
||||||
|
CayenneLPP(uint8_t size);
|
||||||
|
~CayenneLPP();
|
||||||
|
|
||||||
|
void reset(void);
|
||||||
|
uint8_t getSize(void);
|
||||||
|
uint8_t *getBuffer(void);
|
||||||
|
|
||||||
|
void addCount(uint16_t value1, uint16_t value2);
|
||||||
|
void addGPS(gpsStatus_t value);
|
||||||
|
void addConfig(configData_t value);
|
||||||
|
void addStatus(uint16_t voltage, uint64_t uptime, float cputemp);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t *buffer;
|
||||||
|
uint8_t maxsize;
|
||||||
|
uint8_t cursor;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CAYENNE_LPP
|
||||||
|
|
||||||
|
#endif // _PAYLOAD_H_
|
||||||
|
Loading…
Reference in New Issue
Block a user