diff --git a/include/libpax_helpers.h b/include/libpax_helpers.h new file mode 100644 index 00000000..dd3c0238 --- /dev/null +++ b/include/libpax_helpers.h @@ -0,0 +1,10 @@ +#ifndef _LIBPAX_HELPERS_H +#define _LIBPAX_HELPERS_H + +#include "globals.h" +#include +#include + +void init_libpax(); + +#endif \ No newline at end of file diff --git a/src/libpax_helpers.cpp b/src/libpax_helpers.cpp new file mode 100644 index 00000000..b5693d65 --- /dev/null +++ b/src/libpax_helpers.cpp @@ -0,0 +1,18 @@ +#include "libpax_helpers.h" + +// libpax payload +#ifdef LIBPAX +struct count_payload_t count_from_libpax; +uint16_t volatile libpax_macs_ble, libpax_macs_wifi; + +void process_count(void) { + printf("pax: %d; %d; %d;\n", count_from_libpax.pax, count_from_libpax.wifi_count, count_from_libpax.ble_count); + libpax_macs_ble = count_from_libpax.ble_count; + libpax_macs_wifi = count_from_libpax.wifi_count; +} + +void init_libpax() { + libpax_counter_init(process_count, &count_from_libpax, 60*1000, 1); + libpax_counter_start(); +} +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index c03e136f..5195e99a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -86,6 +86,7 @@ triggers pps 1 sec impulse // Basic Config #include "main.h" +#include "libpax_helpers.h" configData_t cfg; // struct holds current device configuration char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer for LMIC event message @@ -96,8 +97,6 @@ uint8_t volatile channel = WIFI_CHANNEL_MIN; // channel rotation counter uint8_t volatile rf_load = 0; // RF traffic indicator #ifndef LIBPAX uint16_t volatile macs_wifi = 0, macs_ble = 0; // globals for display -#else -uint16_t volatile libpax_macs_ble, libpax_macs_wifi; #endif hw_timer_t *ppsIRQ = NULL, *displayIRQ = NULL, *matrixDisplayIRQ = NULL; @@ -119,16 +118,6 @@ TimeChangeRule myDST = DAYLIGHT_TIME; TimeChangeRule mySTD = STANDARD_TIME; Timezone myTZ(myDST, mySTD); -// libpax payload -#ifdef LIBPAX -struct count_payload_t count_from_libpax; - -void process_count(void) { - printf("pax: %d; %d; %d;\n", count_from_libpax.pax, count_from_libpax.wifi_count, count_from_libpax.ble_count); - libpax_macs_ble = count_from_libpax.ble_count; - libpax_macs_wifi = count_from_libpax.wifi_count; -} -#endif // local Tag for logging static const char TAG[] = __FILE__; @@ -340,8 +329,7 @@ ESP_LOGI(TAG, "Starting libpax..."); if(config_update != 0) { ESP_LOGE(TAG, "Error in libpax configuration."); } else { - libpax_counter_init(process_count, &count_from_libpax, 60*1000, 1); - libpax_counter_start(); + init_libpax(); } } else { ESP_LOGE(TAG, "Error in libpax configuration: Wifi and BLE are not supported at the same time!"); diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 353d25c0..ae0d99b7 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -1,6 +1,7 @@ // Basic Config #include "globals.h" #include "rcommand.h" +#include "libpax_helpers.h" // Local logging tag static const char TAG[] = __FILE__; @@ -248,27 +249,47 @@ void set_loraadr(uint8_t val[]) { void set_blescan(uint8_t val[]) { ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val[0] ? "on" : "off"); + cfg.blescan = val[0] ? 1 : 0; #ifndef LIBPAX macs_ble = 0; // clear BLE counter - cfg.blescan = val[0] ? 1 : 0; if (cfg.blescan) start_BLEscan(); else stop_BLEscan(); #else - // TODO update libpax configuration + if(cfg.blescan) { + cfg.wifiscan = 0; + // Restart of libpax while switching scannings does not work atm + // libpax_counter_stop(); + // libpax_config_t current_config; + // libpax_get_current_config(¤t_config); + // current_config.wificounter = 0; + // current_config.blecounter = 1; + // libpax_update_config(¤t_config); + // init_libpax(); + } #endif } void set_wifiscan(uint8_t val[]) { ESP_LOGI(TAG, "Remote command: set WIFI scanner to %s", val[0] ? "on" : "off"); + cfg.wifiscan = val[0] ? 1 : 0; #ifndef LIBPAX macs_wifi = 0; // clear WIFI counter - cfg.wifiscan = val[0] ? 1 : 0; switch_wifi_sniffer(cfg.wifiscan); #else - // TODO update libpax configuration + if(cfg.wifiscan) { + cfg.blescan = 0; + // Restart of libpax while switching scannings does not work atm + // libpax_counter_stop(); + // libpax_config_t current_config; + // libpax_get_current_config(¤t_config); + // current_config.wificounter = 1; + // current_config.blecounter = 0; + // libpax_update_config(¤t_config); + // init_libpax(); + } #endif }