From 092842a4c0eb71b8ef7184a92a50b26b0e7e0daf Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 5 Oct 2020 13:56:41 +0200 Subject: [PATCH] PR #653 merged and added some corrections --- include/cyclic.h | 2 +- include/globals.h | 6 ++-- src/blecsan.cpp | 9 +++--- src/configmanager.cpp | 11 +++---- src/cyclic.cpp | 4 +-- src/hal/ttgov21new.h | 2 +- src/main.cpp | 2 +- src/rcommand.cpp | 71 ++++++++++++++++--------------------------- src/sensor.cpp | 8 ++--- 9 files changed, 47 insertions(+), 68 deletions(-) diff --git a/include/cyclic.h b/include/cyclic.h index 732f2843..6bd9b2a7 100644 --- a/include/cyclic.h +++ b/include/cyclic.h @@ -11,7 +11,7 @@ #include "sds011read.h" #include "sdcard.h" -extern Ticker housekeeper; +extern Ticker cyclicTimer; void setCyclicIRQ(void); void doHousekeeping(void); diff --git a/include/globals.h b/include/globals.h index 73245469..324c5328 100644 --- a/include/globals.h +++ b/include/globals.h @@ -82,11 +82,11 @@ typedef struct __attribute__((packed)) { uint8_t monitormode; // 0=disabled, 1=enabled uint8_t runmode; // 0=normal, 1=update uint8_t payloadmask; // bitswitches for payload data - uint8_t enscount; // 0=disabled 1= enabled - + #ifdef HAS_BME680 - uint8_t bsecstate[BSEC_MAX_STATE_BLOB_SIZE + 1]; // BSEC state for BME680 sensor + uint8_t + bsecstate[BSEC_MAX_STATE_BLOB_SIZE + 1]; // BSEC state for BME680 sensor #endif } configData_t; diff --git a/src/blecsan.cpp b/src/blecsan.cpp index c7085276..9a60e456 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -168,12 +168,13 @@ IRAM_ATTR void gap_callback_handler(esp_gap_ble_cb_event_t event, mac_add((uint8_t *)p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE); - if (cfg.enscount){ - // check for ens signature +#if (COUNT_ENS) + if (cfg.enscount) { + // check for ens signature if (NULL != strstr((const char *)p->scan_rst.ble_adv, ensMagicBytes)) - cwa_mac_add(hashedmac); + cwa_mac_add(hashedmac); } - +#endif /* to be improved in vendorfilter if: // you can search for elements in the payload using the diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 45bb36e7..edbca433 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -49,12 +49,11 @@ static void defaultConfig(configData_t *myconfig) { myconfig->blescan = 1; // 0=disabled, 1=enabled myconfig->wifiscan = 1; // 0=disabled, 1=enabled myconfig->wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4) - myconfig->vendorfilter = VENDORFILTER; // 0=disabled, 1=enabled - myconfig->rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%) - myconfig->monitormode = 0; // 0=disabled, 1=enabled - myconfig->payloadmask = PAYLOADMASK; // all payload switched on - myconfig->enscount =0; // 0= disabled, 1 = enabled - + myconfig->vendorfilter = VENDORFILTER; // 0=disabled, 1=enabled + myconfig->rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%) + myconfig->monitormode = 0; // 0=disabled, 1=enabled + myconfig->payloadmask = PAYLOADMASK; // all payload switched on + myconfig->enscount = 0; // 0=disabled, 1=enabled #ifdef HAS_BME680 // initial BSEC state for BME680 sensor diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 0b484065..c57a0863 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -7,7 +7,7 @@ // Local logging tag static const char TAG[] = __FILE__; -Ticker housekeeper; +Ticker cyclicTimer; #if (HAS_SDS011) extern boolean isSDS011Active; @@ -150,7 +150,7 @@ uint32_t getFreeRAM() { void reset_counters() { #if ((WIFICOUNTER) || (BLECOUNTER)) - macs.clear(); // clear all macs container + macs.clear(); // clear all macs container macs_wifi = 0; macs_ble = 0; #ifdef HAS_DISPLAY diff --git a/src/hal/ttgov21new.h b/src/hal/ttgov21new.h index 4b08748d..f4583bdc 100644 --- a/src/hal/ttgov21new.h +++ b/src/hal/ttgov21new.h @@ -1,6 +1,6 @@ // clang-format off // upload_speed 921600 -// board esp32dev +// board ttgo-lora32-v21new #ifndef _TTGOV21NEW_H #define _TTGOV21NEW_H diff --git a/src/main.cpp b/src/main.cpp index cf70f79d..bcecd934 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -486,7 +486,7 @@ void setup() { // cyclic function interrupts sendTimer.attach(cfg.sendcycle * 2, setSendIRQ); - housekeeper.attach(HOMECYCLE, setCyclicIRQ); + cyclicTimer.attach(HOMECYCLE, setCyclicIRQ); #if (TIME_SYNC_INTERVAL) diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 58bc8ca7..eb15dd0d 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -340,54 +340,35 @@ void set_flush(uint8_t val[]) { }; void set_enscount(uint8_t val[]) { - ESP_LOGI(TAG, "Remote command: set ENS_COUNT to %s", - val[0] ? "on" : "off"); + ESP_LOGI(TAG, "Remote command: set ENS_COUNT to %s", val[0] ? "on" : "off"); cfg.enscount = val[0] ? 1 : 0; - if (val[0]) - cfg.payloadmask |= SENSOR1_DATA; - else - cfg.payloadmask &= ~SENSOR1_DATA; - - + if (val[0]) + cfg.payloadmask |= SENSOR1_DATA; + else + cfg.payloadmask &= ~SENSOR1_DATA; } - // assign previously defined functions to set of numeric remote commands - // format: opcode, function, #bytes params, - // flag (true = do make settings persistent / false = don't) - // - static const cmd_t table[] = { - {0x01, set_rssi, 1, true}, - {0x02, set_countmode, 1, true}, - {0x03, set_gps, 1, true}, - {0x04, set_display, 1, true}, - {0x05, set_loradr, 1, true}, - {0x06, set_lorapower, 1, true}, - {0x07, set_loraadr, 1, true}, - {0x08, set_screensaver, 1, true}, - {0x09, set_reset, 1, false}, - {0x0a, set_sendcycle, 1, true}, - {0x0b, set_wifichancycle, 1, true}, - {0x0c, set_blescantime, 1, true}, - {0x0d, set_vendorfilter, 1, false}, - {0x0e, set_blescan, 1, true}, - {0x0f, set_wifiant, 1, true}, - {0x10, set_rgblum, 1, true}, - {0x11, set_monitor, 1, true}, - {0x12, set_beacon, 7, false}, - {0x13, set_sensor, 2, true}, - {0x14, set_payloadmask, 1, true}, - {0x15, set_bme, 1, true}, - {0x16, set_batt, 1, true}, - {0x17, set_wifiscan, 1, true}, - {0x18, set_enscount, 1, true}, - {0x80, get_config, 0, false}, - {0x81, get_status, 0, false}, - {0x83, get_batt, 0, false}, - {0x84, get_gps, 0, false}, - {0x85, get_bme, 0, false}, - {0x86, get_time, 0, false}, - {0x87, set_time, 0, false}, - {0x99, set_flush, 0, false}}; +// assign previously defined functions to set of numeric remote commands +// format: opcode, function, #bytes params, +// flag (true = do make settings persistent / false = don't) +// +static const cmd_t table[] = { + {0x01, set_rssi, 1, true}, {0x02, set_countmode, 1, true}, + {0x03, set_gps, 1, true}, {0x04, set_display, 1, true}, + {0x05, set_loradr, 1, true}, {0x06, set_lorapower, 1, true}, + {0x07, set_loraadr, 1, true}, {0x08, set_screensaver, 1, true}, + {0x09, set_reset, 1, false}, {0x0a, set_sendcycle, 1, true}, + {0x0b, set_wifichancycle, 1, true}, {0x0c, set_blescantime, 1, true}, + {0x0d, set_vendorfilter, 1, false}, {0x0e, set_blescan, 1, true}, + {0x0f, set_wifiant, 1, true}, {0x10, set_rgblum, 1, true}, + {0x11, set_monitor, 1, true}, {0x12, set_beacon, 7, false}, + {0x13, set_sensor, 2, true}, {0x14, set_payloadmask, 1, true}, + {0x15, set_bme, 1, true}, {0x16, set_batt, 1, true}, + {0x17, set_wifiscan, 1, true}, {0x18, set_enscount, 1, true}, + {0x80, get_config, 0, false}, {0x81, get_status, 0, false}, + {0x83, get_batt, 0, false}, {0x84, get_gps, 0, false}, + {0x85, get_bme, 0, false}, {0x86, get_time, 0, false}, + {0x87, set_time, 0, false}, {0x99, set_flush, 0, false}}; static const uint8_t cmdtablesize = sizeof(table) / sizeof(table[0]); // number of commands in command table diff --git a/src/sensor.cpp b/src/sensor.cpp index a8901505..bb34030e 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -56,16 +56,14 @@ uint8_t *sensor_read(uint8_t sensor) { // insert user specific sensor data frames here // note: Sensor1 fields are used for ENS count, if ENS detection enabled -#if COUNT_ENS -if (cfg.enscount) - payload.addCount(cwa_report(), MAC_SNIFF_BLE_CWA); +#if (COUNT_ENS) + if (cfg.enscount) + payload.addCount(cwa_report(), MAC_SNIFF_BLE_CWA); #else - if(!cfg.enscount) buf[0] = length; buf[1] = 0x01; buf[2] = 0x02; buf[3] = 0x03; - #endif break; case 2: