Merge pull request #118 from cyberman54/development

bugfix payload encoding
This commit is contained in:
Verkehrsrot 2018-07-22 16:52:20 +02:00 committed by GitHub
commit c01f51d77b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 60 deletions

View File

@ -6,6 +6,7 @@ https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner
// Basic Config
#include "globals.h"
#include "macsniff.h"
// Bluetooth specific includes
#include <esp_bt.h>
@ -19,9 +20,6 @@ https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner
// local Tag for logging
static const char TAG[] = "bluetooth";
// defined in macsniff.cpp
bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type);
const char *bt_addr_t_to_string(esp_ble_addr_type_t type) {
switch (type) {
case BLE_ADDR_TYPE_PUBLIC:

View File

@ -6,7 +6,6 @@
// Hash function for scrambling MAC addresses
#include "hash.h"
#include "led.h"
#define MAC_SNIFF_WIFI 0
@ -31,8 +30,6 @@ uint16_t reset_salt(void);
void wifi_sniffer_init(void);
void wifi_sniffer_set_channel(uint8_t channel);
void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type);
// function defined in rokkithash.cpp
uint32_t rokkit(const char *, int);
bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type);
#endif

View File

@ -381,7 +381,9 @@ void setup() {
#elif PAYLOAD_ENCODER == 2
strcat_P(features, " PAYLOAD_PACKED");
#elif PAYLOAD_ENCODER == 3
strcat_P(features, " PAYLOAD_CAYENNE");
strcat_P(features, " PAYLOAD_LPP_DYN");
#elif PAYLOAD_ENCODER == 4
strcat_P(features, " PAYLOAD_LPP_PKD");
#endif
// show compiled features

View File

@ -40,8 +40,8 @@
#define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec.
// LoRa payload default parameters
#define PAYLOAD_ENCODER 1 // select payload encoder: 1=Plain [default], 2=Packed, 3=CayenneLPP
#define SEND_SECS 120 // payload send cycle [seconds/2] -> 240 sec.
#define PAYLOAD_ENCODER 1 // select payload encoder: 1=Plain [default], 2=Packed, 3=CayenneLPP dynmic, 4=CayenneLPP packed
#define SEND_SECS 30 // payload send cycle [seconds/2] -> 60 sec.
#define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle
#define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results

View File

@ -20,10 +20,10 @@ uint8_t *PayloadConvert::getBuffer(void) { return buffer; }
#if PAYLOAD_ENCODER == 1
void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
buffer[cursor++] = value1 >> 8;
buffer[cursor++] = value1;
buffer[cursor++] = value2 >> 8;
buffer[cursor++] = value2;
buffer[cursor++] = highByte(value1);
buffer[cursor++] = lowByte(value1);
buffer[cursor++] = highByte(value2);
buffer[cursor++] = lowByte(value2);
}
void PayloadConvert::addConfig(configData_t value) {
@ -33,8 +33,8 @@ void PayloadConvert::addConfig(configData_t value) {
buffer[cursor++] = value.screensaver;
buffer[cursor++] = value.screenon;
buffer[cursor++] = value.countermode;
buffer[cursor++] = value.rssilimit >> 8;
buffer[cursor++] = value.rssilimit;
buffer[cursor++] = highByte(value.rssilimit);
buffer[cursor++] = lowByte(value.rssilimit);
buffer[cursor++] = value.sendcycle;
buffer[cursor++] = value.wifichancycle;
buffer[cursor++] = value.blescantime;
@ -49,37 +49,38 @@ void PayloadConvert::addConfig(configData_t value) {
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
float cputemp) {
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 >> 16;
buffer[cursor++] = uptime >> 8;
buffer[cursor++] = uptime;
buffer[cursor++] = (uint32_t)cputemp >> 24;
buffer[cursor++] = (uint32_t)cputemp >> 16;
buffer[cursor++] = (uint32_t)cputemp >> 8;
buffer[cursor++] = (uint32_t)cputemp;
uint32_t temp = (uint32_t)cputemp;
buffer[cursor++] = highByte(voltage);
buffer[cursor++] = lowByte(voltage);
buffer[cursor++] = (byte) ((uptime & 0xFF00000000000000) >> 56 );
buffer[cursor++] = (byte) ((uptime & 0x00FF000000000000) >> 48 );
buffer[cursor++] = (byte) ((uptime & 0x0000FF0000000000) >> 40 );
buffer[cursor++] = (byte) ((uptime & 0x000000FF00000000) >> 32 );
buffer[cursor++] = (byte) ((uptime & 0x00000000FF000000) >> 24 );
buffer[cursor++] = (byte) ((uptime & 0x0000000000FF0000) >> 16 );
buffer[cursor++] = (byte) ((uptime & 0x000000000000FF00) >> 8 );
buffer[cursor++] = (byte) ((uptime & 0x00000000000000FF) );
buffer[cursor++] = (byte) ((temp & 0xFF000000) >> 24 );
buffer[cursor++] = (byte) ((temp & 0x00FF0000) >> 16 );
buffer[cursor++] = (byte) ((temp & 0x0000FF00) >> 8 );
buffer[cursor++] = (byte) ((temp & 0x000000FF) );
}
#ifdef HAS_GPS
void PayloadConvert::addGPS(gpsStatus_t value) {
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++] = (byte) ((value.latitude & 0xFF000000) >> 24 );
buffer[cursor++] = (byte) ((value.latitude & 0x00FF0000) >> 16 );
buffer[cursor++] = (byte) ((value.latitude & 0x0000FF00) >> 8 );
buffer[cursor++] = (byte) ((value.latitude & 0x000000FF) );
buffer[cursor++] = (byte) ((value.longitude & 0xFF000000) >> 24 );
buffer[cursor++] = (byte) ((value.longitude & 0x00FF0000) >> 16 );
buffer[cursor++] = (byte) ((value.longitude & 0x0000FF00) >> 8 );
buffer[cursor++] = (byte) ((value.longitude & 0x000000FF) );
buffer[cursor++] = value.satellites;
buffer[cursor++] = value.hdop >> 8;
buffer[cursor++] = value.hdop;
buffer[cursor++] = value.altitude >> 8;
buffer[cursor++] = value.altitude;
buffer[cursor++] = highByte(value.hdop);
buffer[cursor++] = lowByte(value.hdop);
buffer[cursor++] = highByte(value.altitude);
buffer[cursor++] = lowByte(value.altitude);
}
#endif
@ -198,14 +199,14 @@ void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL;
#endif
buffer[cursor++] = LPP_ANALOG_INPUT; // workaround, type meter not found?
buffer[cursor++] = val1 >> 8;
buffer[cursor++] = val1;
buffer[cursor++] = highByte(val1);
buffer[cursor++] = lowByte(val1);
#if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_COUNT_BLE_CHANNEL;
#endif
buffer[cursor++] = LPP_ANALOG_INPUT; // workaround, type meter not found?
buffer[cursor++] = val2 >> 8;
buffer[cursor++] = val2;
buffer[cursor++] = highByte(val2);
buffer[cursor++] = lowByte(val2);
}
void PayloadConvert::addConfig(configData_t value) {
@ -218,19 +219,20 @@ void PayloadConvert::addConfig(configData_t value) {
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime,
float celsius) {
int16_t val = celsius * 10;
uint16_t temp = celsius * 10;
uint16_t volt = voltage / 10;
#if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_BATT_CHANNEL;
#endif
buffer[cursor++] = LPP_ANALOG_INPUT;
buffer[cursor++] = voltage >> 8;
buffer[cursor++] = voltage;
buffer[cursor++] = highByte(volt);
buffer[cursor++] = lowByte(volt);
#if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_TEMP_CHANNEL;
#endif
buffer[cursor++] = LPP_TEMPERATURE;
buffer[cursor++] = (uint16_t)val >> 8;
buffer[cursor++] = (uint16_t)val;
buffer[cursor++] = highByte(temp);
buffer[cursor++] = lowByte(temp);
}
#ifdef HAS_GPS
@ -242,15 +244,16 @@ void PayloadConvert::addGPS(gpsStatus_t value) {
buffer[cursor++] = LPP_GPS_CHANNEL;
#endif
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;
buffer[cursor++] = (byte) ((lat & 0xFF0000) >> 16 );
buffer[cursor++] = (byte) ((lat & 0x00FF00) >> 8 );
buffer[cursor++] = (byte) ((lat & 0x0000FF) );
buffer[cursor++] = (byte) ((lon & 0xFF0000) >> 16 );
buffer[cursor++] = (byte) ((lon & 0x00FF00) >> 8 );
buffer[cursor++] = (byte) ((lon & 0x0000FF) );
buffer[cursor++] = (byte) ((alt & 0xFF0000) >> 16 );
buffer[cursor++] = (byte) ((alt & 0x00FF00) >> 8 );
buffer[cursor++] = (byte) ((alt & 0x0000FF) );
}
#endif