From a4fd57a8aa10b2dfa0b90b210a4d193f378012ab Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 22 Jul 2018 12:11:13 +0200 Subject: [PATCH 1/3] code sanitizations --- src/blecsan.cpp | 4 +--- src/macsniff.h | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 1c16d663..042d5f34 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -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 @@ -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: diff --git a/src/macsniff.h b/src/macsniff.h index ee2d7e7b..22992f09 100644 --- a/src/macsniff.h +++ b/src/macsniff.h @@ -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 \ No newline at end of file From 46bca9e5f2fce950d7583f718a9039aae7129bee Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 22 Jul 2018 16:12:46 +0200 Subject: [PATCH 2/3] bugfix payload encoding --- src/main.cpp | 4 +- src/paxcounter.conf | 4 +- src/payload.cpp | 102 ++++++++++++++++++++++---------------------- 3 files changed, 57 insertions(+), 53 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 784fe0ad..d4f2ead2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 501cc1c2..0315b773 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -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 3 // 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 diff --git a/src/payload.cpp b/src/payload.cpp index eafc5053..433028bc 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -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,19 @@ void PayloadConvert::addConfig(configData_t value) { void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius) { - int16_t val = celsius * 10; + uint16_t val = celsius * 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(voltage); + buffer[cursor++] = lowByte(voltage); #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(val); + buffer[cursor++] = lowByte(val); } #ifdef HAS_GPS @@ -242,15 +243,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 From 62ebb534bad69a4944ce2fd739c18162271ac78a Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 22 Jul 2018 16:44:51 +0200 Subject: [PATCH 3/3] bugfix payload encoding --- src/paxcounter.conf | 2 +- src/payload.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 0315b773..7481c001 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -40,7 +40,7 @@ #define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec. // LoRa payload default parameters -#define PAYLOAD_ENCODER 3 // select payload encoder: 1=Plain [default], 2=Packed, 3=CayenneLPP dynmic, 4=CayenneLPP packed +#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 diff --git a/src/payload.cpp b/src/payload.cpp index 433028bc..bc0da00b 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -219,19 +219,20 @@ void PayloadConvert::addConfig(configData_t value) { void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius) { - uint16_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++] = highByte(voltage); - buffer[cursor++] = lowByte(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++] = highByte(val); - buffer[cursor++] = lowByte(val); + buffer[cursor++] = highByte(temp); + buffer[cursor++] = lowByte(temp); } #ifdef HAS_GPS