From dea92ced65fee2746d5dcf4ca29b5aa206aefa25 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Wed, 31 Mar 2021 16:20:48 +0200 Subject: [PATCH] fix issue #773 (libpax counts display integration) --- README.md | 2 +- include/cyclic.h | 1 - include/display.h | 1 + src/cyclic.cpp | 26 +++++--------------------- src/display.cpp | 18 +++++++++++------- src/ledmatrixdisplay.cpp | 13 ++++++++----- src/rcommand.cpp | 8 +++----- src/senddata.cpp | 11 +++-------- 8 files changed, 32 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 1af14989..56dc1376 100644 --- a/README.md +++ b/README.md @@ -437,7 +437,7 @@ Send for example `8386` as Downlink on Port 2 to get battery status and time/dat 0x09 reset functions (send this command UNconfirmed only to avoid boot loops!) 0 = restart device (coldstart) - 1 = zeroize MAC counter + 1 = (reserved, currently does nothing) 2 = reset device to factory settings and restart device 3 = flush send queues 4 = restart device (warmstart) diff --git a/include/cyclic.h b/include/cyclic.h index 26ce3fd5..3623a7b5 100644 --- a/include/cyclic.h +++ b/include/cyclic.h @@ -18,7 +18,6 @@ extern Ticker cyclicTimer; void setCyclicIRQ(void); void doHousekeeping(void); -void reset_counters(void); uint32_t getFreeRAM(); #endif diff --git a/include/display.h b/include/display.h index 8fb8120f..8b16f412 100644 --- a/include/display.h +++ b/include/display.h @@ -1,6 +1,7 @@ #ifndef _DISPLAY_H #define _DISPLAY_H +#include #include "cyclic.h" #include "qrcode.h" diff --git a/src/cyclic.cpp b/src/cyclic.cpp index dd115007..d197e234 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -89,24 +89,18 @@ void doHousekeeping() { // check free heap memory if (ESP.getMinFreeHeap() <= MEM_LOW) { - ESP_LOGI(TAG, + ESP_LOGW(TAG, "Memory full, counter cleared (heap low water mark = %d Bytes / " "free heap = %d bytes)", ESP.getMinFreeHeap(), ESP.getFreeHeap()); - reset_counters(); // clear macs container and reset all counters - - if (ESP.getMinFreeHeap() <= MEM_LOW) // check again - do_reset(true); // memory leak, reset device + do_reset(true); // memory leak, reset device } // check free PSRAM memory #ifdef BOARD_HAS_PSRAM if (ESP.getMinFreePsram() <= MEM_LOW) { - ESP_LOGI(TAG, "PSRAM full, counter cleared"); - reset_counters(); // clear macs container and reset all counters - - if (ESP.getMinFreePsram() <= MEM_LOW) // check again - do_reset(true); // memory leak, reset device + ESP_LOGW(TAG, "PSRAM full, counter cleared"); + do_reset(true); // memory leak, reset device } #endif @@ -128,14 +122,4 @@ uint32_t getFreeRAM() { #else return ESP.getFreePsram(); #endif -} - -void reset_counters() { - -#if ((WIFICOUNTER) || (BLECOUNTER)) -#ifdef HAS_DISPLAY - dp_plotCurve(0, true); -#endif - -#endif -} +} \ No newline at end of file diff --git a/src/display.cpp b/src/display.cpp index fa2ecab8..7c5b6d9a 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -159,7 +159,7 @@ void dp_init(bool verbose) { #if !(BOOTMENU) delay(8000); #endif - + #endif // HAS_LORA } // verbose @@ -175,12 +175,15 @@ void dp_init(bool verbose) { void dp_refresh(bool nextPage) { + // update counter values from libpax + libpax_counter_count(&count_from_libpax); + #ifndef HAS_BUTTON static uint32_t framecounter = 0; #endif // update histogram - dp_plotCurve(macs.size(), false); + dp_plotCurve(count_from_libpax.pax, false); // if display is switched off we don't refresh it to relax cpu if (!DisplayIsOn && (DisplayIsOn == cfg.screenon)) @@ -238,7 +241,7 @@ void dp_drawPage(time_t t, bool nextpage) { // display number of unique macs total Wifi + BLE if (DisplayPage < 5) { dp_setFont(MY_FONT_STRETCHED); - dp_printf("%-5d", macs.size()); + dp_printf("%-5d", count_from_libpax.pax); } switch (DisplayPage) { @@ -262,7 +265,7 @@ void dp_drawPage(time_t t, bool nextpage) { #if ((WIFICOUNTER) && (BLECOUNTER)) if (cfg.wifiscan) - dp_printf("WIFI:%-5d", libpax_macs_wifi); + dp_printf("WIFI:%-5d", count_from_libpax.wifi_count); else dp_printf("WIFI:off"); if (cfg.blescan) @@ -271,17 +274,17 @@ void dp_drawPage(time_t t, bool nextpage) { dp_printf(" CWA:%-5d", cwa_report()); else #endif - dp_printf("BLTH:%-5d", libpax_macs_ble); + dp_printf("BLTH:%-5d", count_from_libpax.ble_count); else dp_printf(" BLTH:off"); #elif ((WIFICOUNTER) && (!BLECOUNTER)) if (cfg.wifiscan) - dp_printf("WIFI:%-5d", libpax_macs_wifi); + dp_printf("WIFI:%-5d", count_from_libpax.wifi_count); else dp_printf("WIFI:off"); #elif ((!WIFICOUNTER) && (BLECOUNTER)) if (cfg.blescan) - dp_printf("BLTH:%-5d", libpax_macs_ble); + dp_printf("BLTH:%-5d", count_from_libpax.ble_count); #if (COUNT_ENS) if (cfg.enscount) dp_printf("(CWA:%d)", cwa_report()); @@ -719,6 +722,7 @@ void dp_plotCurve(uint16_t count, bool reset) { static uint16_t last_count = 0, col = 0, row = 0; uint16_t v_scroll = 0; + // nothing new to plot? -> then exit early if ((last_count == count) && !reset) return; diff --git a/src/ledmatrixdisplay.cpp b/src/ledmatrixdisplay.cpp index 3e273731..c727a766 100644 --- a/src/ledmatrixdisplay.cpp +++ b/src/ledmatrixdisplay.cpp @@ -76,9 +76,12 @@ void refreshTheMatrixDisplay(bool nextPage) { if (cfg.countermode == 1) + // update counter values from libpax + libpax_counter_count(&count_from_libpax); + { // cumulative counter mode -> display total number of pax - if (ulLastNumMacs != macs.size()) { - ulLastNumMacs = macs.size(); + if (ulLastNumMacs != count_from_libpax.pax) { + ulLastNumMacs = count_from_libpax.pax; matrix.clear(); DrawNumber(String(ulLastNumMacs)); } @@ -86,10 +89,10 @@ void refreshTheMatrixDisplay(bool nextPage) { else { // cyclic counter mode -> plot a line diagram - if (ulLastNumMacs != macs.size()) { + if (ulLastNumMacs != count_from_libpax.pax) { // next count cycle? - if (macs.size() == 0) { + if (count_from_libpax.pax == 0) { // matrix full? then scroll left 1 dot, else increment column if (col < (LED_MATRIX_WIDTH - 1)) @@ -101,7 +104,7 @@ void refreshTheMatrixDisplay(bool nextPage) { matrix.drawPoint(col, row, 0); // clear current dot // scale and set new dot - ulLastNumMacs = macs.size(); + ulLastNumMacs = count_from_libpax.pax; level = ulLastNumMacs / LINE_DIAGRAM_DIVIDER; row = level <= LED_MATRIX_HEIGHT ? LED_MATRIX_HEIGHT - 1 - level % LED_MATRIX_HEIGHT diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 4b0801d3..5a48f466 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -16,9 +16,8 @@ void set_reset(uint8_t val[]) { ESP_LOGI(TAG, "Remote command: restart device cold"); do_reset(false); break; - case 1: // reset MAC counter - ESP_LOGI(TAG, "Remote command: reset MAC counter"); - reset_counters(); // clear macs + case 1: // reserved + // reset MAC counter deprecated by libpax integration break; case 2: // reset device to factory settings ESP_LOGI(TAG, @@ -105,7 +104,6 @@ void set_countmode(uint8_t val[]) { "Remote command: set counter mode called with invalid parameter(s)"); return; } - reset_counters(); // clear macs } void set_screensaver(uint8_t val[]) { @@ -187,7 +185,7 @@ void set_beacon(uint8_t val[]) { memmove(val, val + 1, 6); // strip off storage id beacons[id] = macConvert(val); // store beacon MAC in array ESP_LOGI(TAG, "Remote command: set beacon ID#%d", id); - //printKey("MAC", val, 6, false); // show beacon MAC + // printKey("MAC", val, 6, false); // show beacon MAC } void set_monitor(uint8_t val[]) { diff --git a/src/senddata.cpp b/src/senddata.cpp index 12fe735c..d7665526 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -88,7 +88,8 @@ void sendData() { ESP_LOGI(TAG, "Sending libpax wifi count: %d", libpax_macs_wifi); payload.addCount(libpax_macs_wifi, MAC_SNIFF_WIFI); if (cfg.blescan) { - ESP_LOGI(TAG, "Sending libpax ble count: %d", libpax_macs_ble); + ESP_LOGI(TAG, "Sending libpax ble count: %d", + libpax_macs_ble); payload.addCount(libpax_macs_ble, MAC_SNIFF_BLE); } #endif @@ -114,14 +115,8 @@ void sendData() { payload.addSDS(sds_status); #endif SendPayload(COUNTERPORT); - // clear counter if not in cumulative counter mode - if (cfg.countermode != 1) { - reset_counters(); // clear macs container and reset all counters - ESP_LOGI(TAG, "Counter cleared"); - } #ifdef HAS_DISPLAY - else - dp_plotCurve(macs.size(), true); + dp_plotCurve(libpax_macs_ble + libpax_macs_wifi, true); #endif break; #endif