added payload.cpp and and payload.h

This commit is contained in:
Klaus K Wilting 2018-06-16 13:18:36 +02:00
parent fe5da9358e
commit 12c6dcb0ff
3 changed files with 127 additions and 2 deletions

View File

@ -14,8 +14,8 @@
;env_default = heltec
;env_default = ttgov1
;env_default = ttgov2
env_default = ttgov21
;env_default = ttgobeam
;env_default = ttgov21
env_default = ttgobeam
;env_default = lopy
;env_default = lopy4
;env_default = fipy

89
src/payload.cpp Normal file
View File

@ -0,0 +1,89 @@
#include "globals.h"
#include "payload.h"
TTNplain::TTNplain(uint8_t size) : maxsize(size) {
buffer = (uint8_t *)malloc(size);
cursor = 0;
}
TTNplain::~TTNplain(void) { free(buffer); }
void TTNplain::reset(void) { cursor = 0; }
uint8_t TTNplain::getSize(void) { return cursor; }
uint8_t *TTNplain::getBuffer(void) {
// uint8_t[cursor] result;
// memcpy(result, buffer, cursor);
// return result;
return buffer;
}
uint8_t TTNplain::copy(uint8_t *dst) {
memcpy(dst, buffer, cursor);
return cursor;
}
void TTNplain::addCount(uint16_t value1, uint16_t value2) {
cursor = TTN_PAYLOAD_COUNTER;
buffer[cursor] = (macs_wifi & 0xff00) >> 8;
buffer[cursor++] = macs_wifi & 0xff;
buffer[cursor++] = (macs_ble & 0xff00) >> 8;
buffer[cursor++] = macs_ble & 0xff;
}
void TTNplain::addGPS(gpsStatus_t value) {
cursor = TTN_PAYLOAD_GPS;
buffer[cursor++] = value.latitude >> 24;
buffer[cursor++] = value.latitude >> 16;
buffer[cursor++] = value.latitude >> 8;
buffer[cursor++] = value.latitude;
buffer[cursor++] = value.longitude >> 24;
buffer[cursor++] = value.longitude >> 16;
buffer[cursor++] = value.longitude >> 8;
buffer[cursor++] = value.longitude;
buffer[cursor++] = value.satellites;
buffer[cursor++] = value.hdop >> 8;
buffer[cursor++] = value.hdop;
buffer[cursor++] = value.altitude >> 8;
buffer[cursor++] = value.altitude;
}
void TTNplain::addConfig(configData_t value) {
cursor = TTN_PAYLOAD_CONFIG;
buffer[cursor++] = value.lorasf;
buffer[cursor++] = value.adrmode;
buffer[cursor++] = value.screensaver;
buffer[cursor++] = value.screenon;
buffer[cursor++] = value.countermode;
buffer[cursor++] = value.rssilimit >> 8;
buffer[cursor++] = value.rssilimit;
buffer[cursor++] = value.sendcycle;
buffer[cursor++] = value.wifichancycle;
buffer[cursor++] = value.blescantime;
buffer[cursor++] = value.blescan;
buffer[cursor++] = value.wifiant;
buffer[cursor++] = value.vendorfilter;
buffer[cursor++] = value.rgblum;
buffer[cursor++] = value.gpsmode;
memcpy(buffer + cursor, value.version, 10);
}
void TTNplain::addStatus(uint16_t voltage, uint64_t uptime, float cputemp) {
cursor = TTN_PAYLOAD_STATUS;
buffer[cursor++] = voltage >> 8;
buffer[cursor++] = voltage;
buffer[cursor++] = uptime >> 56;
buffer[cursor++] = uptime >> 48;
buffer[cursor++] = uptime >> 40;
buffer[cursor++] = uptime >> 32;
buffer[cursor++] = uptime >> 24;
buffer[cursor++] = uptime >> 32;
buffer[cursor++] = uptime >> 16;
buffer[cursor++] = uptime >> 8;
buffer[cursor++] = (uint32_t) cputemp >> 24;
buffer[cursor++] = (uint32_t) cputemp >> 16;
buffer[cursor++] = (uint32_t) cputemp >> 8;
buffer[cursor++] = (uint32_t) cputemp;
}

36
src/payload.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef _PAYLOAD_H_
#define _PAYLOAD_H_
#include <Arduino.h>
#define TTN_PAYLOAD_COUNTER 0
#define TTN_PAYLOAD_GPS 4
#define TTN_PAYLOAD_CONFIG 0
#define TTN_PAYLOAD_STATUS 0
class TTNplain {
public:
TTNplain(uint8_t size);
~TTNplain();
void reset(void);
uint8_t getSize(void);
uint8_t *getBuffer(void);
uint8_t copy(uint8_t *buffer);
// application payloads
void addCount(uint16_t value1, uint16_t value2);
void addGPS(gpsStatus_t value);
// payloads for get rcommands
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