restructured wifi channel rotation

This commit is contained in:
Klaus K Wilting 2018-09-22 12:20:24 +02:00
parent 5678a5b23c
commit ff759e1533
5 changed files with 16 additions and 27 deletions

View File

@ -291,8 +291,7 @@ void setup() {
Task Core Prio Purpose
====================================================================
IDLE 0 0 ESP32 arduino scheduler
wifiloop 0 1 switches Wifi channels
gpsloop 0 2 reasd data from GPS over serial or i2c
gpsloop 0 2 read data from GPS over serial or i2c
IDLE 1 0 Arduino loop() -> unused
loraloop 1 1 runs the LMIC stack
statemachine 1 3 switches process logic
@ -338,8 +337,6 @@ void setup() {
// arduino-esp32 core. Note: do this *after* wifi has started, since
// function gets it's seed from RF noise
reset_salt(); // get new 16bit for salting hashes
xTaskCreatePinnedToCore(wifi_channel_loop, "wifiloop", 2048, (void *)1, 1,
&WifiLoopTask, 0);
// start state machine
ESP_LOGI(TAG, "Starting Statemachine...");
@ -366,12 +363,15 @@ void stateMachine(void *pvParameters) {
updateDisplay();
#endif
// check housekeeping cycle and if expired do the work
// check wifi scan cycle and if due rotate channel
if (ChannelTimerIRQ)
switchWifiChannel(channel);
// check housekeeping cycle and if due do the work
if (HomeCycleIRQ)
doHousekeeping();
// check send queue and process it
processSendBuffer();
// check send cycle and enqueue payload if cycle is expired
enqueuePayload();
// check send cycle and if due enqueue payload to send
if (SendCycleTimerIRQ)
sendPayload();
// yield to CPU

View File

@ -74,7 +74,7 @@ void IRAM_ATTR SendCycleIRQ() {
}
// interrupt triggered function to eat data from RTos send queues and transmit it
void processSendBuffer() {
void enqueuePayload() {
MessageBuffer_t SendBuffer;
#ifdef HAS_LORA
@ -98,7 +98,7 @@ void processSendBuffer() {
}
#endif
} // processSendBuffer
} // enqueuePayload
void flushQueues() {
#ifdef HAS_LORA

View File

@ -4,7 +4,7 @@
void SendData(uint8_t port);
void sendPayload(void);
void SendCycleIRQ(void);
void processSendBuffer(void);
void enqueuePayload(void);
void flushQueues();
#endif // _SENDDATA_H_

View File

@ -43,28 +43,17 @@ void wifi_sniffer_init(void) {
ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true)); // now switch on monitor mode
}
// Wifi channel rotation task
void wifi_channel_loop(void *pvParameters) {
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
while (1) {
if (ChannelTimerIRQ) {
// Wifi channel rotation
void switchWifiChannel(uint8_t &ch) {
portENTER_CRITICAL(&timerMux);
ChannelTimerIRQ = 0;
portEXIT_CRITICAL(&timerMux);
// rotates variable channel 1..WIFI_CHANNEL_MAX
channel = (channel % WIFI_CHANNEL_MAX) + 1;
esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
ESP_LOGD(TAG, "Wifi set channel %d", channel);
ch = (ch % WIFI_CHANNEL_MAX) + 1;
esp_wifi_set_channel(ch, WIFI_SECOND_CHAN_NONE);
ESP_LOGD(TAG, "Wifi set channel %d", &ch);
}
vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU
} // end of infinite wifi channel rotation loop
}
// IRQ handler
void IRAM_ATTR ChannelSwitchIRQ() {
portENTER_CRITICAL(&timerMux);

View File

@ -28,6 +28,6 @@ typedef struct {
void wifi_sniffer_init(void);
void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type);
void ChannelSwitchIRQ(void);
void wifi_channel_loop(void *pvParameters);
void switchWifiChannel(uint8_t &ch);
#endif