libpax integration fixes (sendtimer, rcommands)

This commit is contained in:
cyberman54 2021-04-13 16:37:17 +02:00
parent 44e5daaf02
commit 71aa55863b
6 changed files with 48 additions and 9 deletions

View File

@ -445,14 +445,14 @@ Send for example `83` `86` as Downlink on Port 2 to get battery status and time/
0x0A set payload send cycle 0x0A set payload send cycle
0 ... 255 payload send cycle in seconds/2 5 ... 255 payload send cycle in seconds/2
e.g. 120 -> payload is transmitted each 240 seconds [default] e.g. 120 -> payload is transmitted each 240 seconds [default]
0x0B set Wifi channel hopping interval timer 0x0B set Wifi channel hopping interval timer
0 ... 255 duration for scanning a wifi channel in seconds/100 0 ... 255 duration for scanning a wifi channel in seconds/100
e.g. 50 -> each channel is scanned for 500 milliseconds [default] e.g. 50 -> each channel is scanned for 500 milliseconds [default]
0 means no hopping, scanning on channel WIFI_CHANNEL_MIN only 0 means no hopping, scanning on fixed single channel WIFI_CHANNEL_1
0x0C set Bluetooth channel switch interval timer 0x0C set Bluetooth channel switch interval timer
@ -524,7 +524,7 @@ Send for example `83` `86` as Downlink on Port 2 to get battery status and time/
0x19 set sleep cycle 0x19 set sleep cycle
bytes 1..2 = device sleep cycle in seconds/10 (MSB) bytes 1..2 = device sleep cycle in seconds/10 (MSB), 1 ... 255
e.g. {0x04, 0xB0} -> device sleeps 20 minutes after each send cycle [default = 0] e.g. {0x04, 0xB0} -> device sleeps 20 minutes after each send cycle [default = 0]
0x20 load device configuration 0x20 load device configuration

View File

@ -5,6 +5,7 @@
#include <esp_event_loop.h> // needed for Wifi event handler #include <esp_event_loop.h> // needed for Wifi event handler
#include <esp32-hal-timer.h> // needed for timers #include <esp32-hal-timer.h> // needed for timers
#include <esp_coexist.h> // needed for coex version display #include <esp_coexist.h> // needed for coex version display
#include <esp_wifi.h> // needed for wifi init / deinit
#include "globals.h" #include "globals.h"
#include "reset.h" #include "reset.h"

View File

@ -22,6 +22,7 @@ void sendData(void);
void checkSendQueues(void); void checkSendQueues(void);
void flushQueues(void); void flushQueues(void);
bool allQueuesEmtpy(void); bool allQueuesEmtpy(void);
void setSendIRQ(void); void setSendIRQ(TimerHandle_t xTimer = NULL);
void initSendDataTimer(uint8_t sendcycle);
#endif // _SENDDATA_H_ #endif // _SENDDATA_H_

View File

@ -281,8 +281,9 @@ void setup() {
if (RTC_runmode == RUNMODE_MAINTENANCE) if (RTC_runmode == RUNMODE_MAINTENANCE)
start_boot_menu(); start_boot_menu();
#if ((WIFICOUNTER) || (BLECOUNTER))
// use libpax timer to trigger cyclic senddata
ESP_LOGI(TAG, "Starting libpax..."); ESP_LOGI(TAG, "Starting libpax...");
#if (defined WIFICOUNTER || defined BLECOUNTER)
struct libpax_config_t configuration; struct libpax_config_t configuration;
libpax_default_config(&configuration); libpax_default_config(&configuration);
@ -304,6 +305,9 @@ void setup() {
} else { } else {
init_libpax(); init_libpax();
} }
#else
// use stand alone timer to trigger cyclic senddata
initSendDataTimer(cfg.sendcycle * 2);
#endif #endif
#if (BLECOUNTER) #if (BLECOUNTER)

View File

@ -55,27 +55,38 @@ void set_reset(uint8_t val[]) {
void set_rssi(uint8_t val[]) { void set_rssi(uint8_t val[]) {
cfg.rssilimit = val[0] * -1; cfg.rssilimit = val[0] * -1;
#if ((WIFICOUNTER) || (BLECOUNTER))
libpax_counter_stop(); libpax_counter_stop();
libpax_config_t current_config; libpax_config_t current_config;
libpax_get_current_config(&current_config); libpax_get_current_config(&current_config);
current_config.wifi_rssi_threshold = cfg.rssilimit; current_config.wifi_rssi_threshold = cfg.rssilimit;
libpax_update_config(&current_config); libpax_update_config(&current_config);
init_libpax(); init_libpax();
#endif
ESP_LOGI(TAG, "Remote command: set RSSI limit to %d", cfg.rssilimit); ESP_LOGI(TAG, "Remote command: set RSSI limit to %d", cfg.rssilimit);
} }
void set_sendcycle(uint8_t val[]) { void set_sendcycle(uint8_t val[]) {
cfg.sendcycle = val[0]; if (val[0] < 5)
return;
// update send cycle interrupt [seconds / 2] // update send cycle interrupt [seconds / 2]
cfg.sendcycle = val[0];
ESP_LOGI(TAG, "Remote command: set send cycle to %d seconds", ESP_LOGI(TAG, "Remote command: set send cycle to %d seconds",
cfg.sendcycle * 2); cfg.sendcycle * 2);
#if ((WIFICOUNTER) || (BLECOUNTER))
libpax_counter_stop(); libpax_counter_stop();
init_libpax(); init_libpax();
#else
// modify senddata timer
initSendDataTimer(cfg.sendcycle * 2);
#endif
} }
void set_sleepcycle(uint8_t val[]) { void set_sleepcycle(uint8_t val[]) {
// swap byte order from msb to lsb, note: this is a platform dependent hack // swap byte order from msb to lsb, note: this is a platform dependent hack
uint16_t t = __builtin_bswap16(*(uint16_t *)(val)); uint16_t t = __builtin_bswap16(*(uint16_t *)(val));
if (t == 0)
return;
cfg.sleepcycle = t; cfg.sleepcycle = t;
ESP_LOGI(TAG, "Remote command: set sleep cycle to %d seconds", ESP_LOGI(TAG, "Remote command: set sleep cycle to %d seconds",
cfg.sleepcycle * 10); cfg.sleepcycle * 10);
@ -83,6 +94,7 @@ void set_sleepcycle(uint8_t val[]) {
void set_wifichancycle(uint8_t val[]) { void set_wifichancycle(uint8_t val[]) {
cfg.wifichancycle = val[0]; cfg.wifichancycle = val[0];
#if (WIFICOUNTER)
libpax_counter_stop(); libpax_counter_stop();
libpax_config_t current_config; libpax_config_t current_config;
libpax_get_current_config(&current_config); libpax_get_current_config(&current_config);
@ -100,16 +112,19 @@ void set_wifichancycle(uint8_t val[]) {
current_config.wifi_channel_switch_interval = cfg.wifichancycle; current_config.wifi_channel_switch_interval = cfg.wifichancycle;
libpax_update_config(&current_config); libpax_update_config(&current_config);
init_libpax(); init_libpax();
#endif
} }
void set_blescantime(uint8_t val[]) { void set_blescantime(uint8_t val[]) {
cfg.blescantime = val[0]; cfg.blescantime = val[0];
#if (BLECOUNTER)
libpax_counter_stop(); libpax_counter_stop();
libpax_config_t current_config; libpax_config_t current_config;
libpax_get_current_config(&current_config); libpax_get_current_config(&current_config);
current_config.blescantime = cfg.blescantime; current_config.blescantime = cfg.blescantime;
libpax_update_config(&current_config); libpax_update_config(&current_config);
init_libpax(); init_libpax();
#endif
} }
void set_countmode(uint8_t val[]) { void set_countmode(uint8_t val[]) {
@ -257,24 +272,28 @@ void set_loraadr(uint8_t val[]) {
void set_blescan(uint8_t val[]) { void set_blescan(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val[0] ? "on" : "off"); ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val[0] ? "on" : "off");
cfg.blescan = val[0] ? 1 : 0; cfg.blescan = val[0] ? 1 : 0;
#if (BLECOUNTER)
libpax_counter_stop(); libpax_counter_stop();
libpax_config_t current_config; libpax_config_t current_config;
libpax_get_current_config(&current_config); libpax_get_current_config(&current_config);
current_config.blecounter = cfg.blescan; current_config.blecounter = cfg.blescan;
libpax_update_config(&current_config); libpax_update_config(&current_config);
init_libpax(); init_libpax();
#endif
} }
void set_wifiscan(uint8_t val[]) { void set_wifiscan(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set WIFI scanner to %s", ESP_LOGI(TAG, "Remote command: set WIFI scanner to %s",
val[0] ? "on" : "off"); val[0] ? "on" : "off");
cfg.wifiscan = val[0] ? 1 : 0; cfg.wifiscan = val[0] ? 1 : 0;
#if (WIFICOUNTER)
libpax_counter_stop(); libpax_counter_stop();
libpax_config_t current_config; libpax_config_t current_config;
libpax_get_current_config(&current_config); libpax_get_current_config(&current_config);
current_config.wificounter = cfg.wifiscan; current_config.wificounter = cfg.wifiscan;
libpax_update_config(&current_config); libpax_update_config(&current_config);
init_libpax(); init_libpax();
#endif
} }
void set_wifiant(uint8_t val[]) { void set_wifiant(uint8_t val[]) {

View File

@ -1,7 +1,22 @@
// Basic Config // Basic Config
#include "senddata.h" #include "senddata.h"
void setSendIRQ() { xTaskNotify(irqHandlerTask, SENDCYCLE_IRQ, eSetBits); } void setSendIRQ(TimerHandle_t xTimer) {
xTaskNotify(irqHandlerTask, SENDCYCLE_IRQ, eSetBits);
}
void initSendDataTimer(uint8_t sendcycle) {
static TimerHandle_t SendDataTimer = NULL;
if (SendDataTimer == NULL) {
SendDataTimer =
xTimerCreate("SendDataTimer", pdMS_TO_TICKS(sendcycle * 1000), pdTRUE,
(void *)0, setSendIRQ);
xTimerStart(SendDataTimer, 0);
} else {
xTimerChangePeriod(SendDataTimer, pdMS_TO_TICKS(sendcycle * 1000), 0);
}
}
// put data to send in RTos Queues used for transmit over channels Lora and SPI // put data to send in RTos Queues used for transmit over channels Lora and SPI
void SendPayload(uint8_t port) { void SendPayload(uint8_t port) {
@ -86,8 +101,7 @@ void sendData() {
ESP_LOGI(TAG, "Sending libpax wifi count: %d", libpax_macs_wifi); ESP_LOGI(TAG, "Sending libpax wifi count: %d", libpax_macs_wifi);
payload.addCount(libpax_macs_wifi, MAC_SNIFF_WIFI); payload.addCount(libpax_macs_wifi, MAC_SNIFF_WIFI);
if (cfg.blescan) { if (cfg.blescan) {
ESP_LOGI(TAG, "Sending libpax ble count: %d", ESP_LOGI(TAG, "Sending libpax ble count: %d", libpax_macs_ble);
libpax_macs_ble);
payload.addCount(libpax_macs_ble, MAC_SNIFF_BLE); payload.addCount(libpax_macs_ble, MAC_SNIFF_BLE);
} }
#endif #endif