From fcd9357116aa9ca65617c6fe7d0362c190149359 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 11 Aug 2018 19:12:04 +0200 Subject: [PATCH] small code sanitizations --- src/hal/ebox.h | 4 ++-- src/hal/generic.h | 2 +- src/hal/heltec.h | 4 ++-- src/hal/lolin32lite.h | 2 +- src/hal/lopy.h | 4 ++-- src/hal/lopy4.h | 4 ++-- src/hal/ttgobeam.h | 4 ++-- src/hal/ttgov1.h | 4 ++-- src/hal/ttgov2.h | 4 ++-- src/hal/ttgov21.h | 4 ++-- src/main.cpp | 54 ++++++++++++++++++++++--------------------- src/senddata.cpp | 21 +++-------------- 12 files changed, 49 insertions(+), 62 deletions(-) diff --git a/src/hal/ebox.h b/src/hal/ebox.h index ff622bea..121fea58 100644 --- a/src/hal/ebox.h +++ b/src/hal/ebox.h @@ -1,7 +1,7 @@ // Hardware related definitions for ebox ESP32-bit with external connected RFM95 LoRa -#define HAS_LORA 1 // comment out if device shall not send data via LoRa -#define HAS_SPI 1 // comment out if device shall not send data via SPI +#define HAS_LORA 1 // comment out if device shall not send data via LoRa +#define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1276_radio 1 #define HAS_LED GPIO_NUM_23 // blue LED on board diff --git a/src/hal/generic.h b/src/hal/generic.h index 52fa279c..bedff5e8 100644 --- a/src/hal/generic.h +++ b/src/hal/generic.h @@ -1,7 +1,7 @@ // Hardware related definitions for generic ESP32 boards #define HAS_LORA 1 // comment out if device shall not send data via LoRa or has no LoRa -#define HAS_SPI 1 // comment out if device shall not send data via SPI +#define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1276_radio 1 // select LoRa chip //#define CFG_sx1272_radio 1 // select LoRa chip diff --git a/src/hal/heltec.h b/src/hal/heltec.h index 95ffe469..a860df50 100644 --- a/src/hal/heltec.h +++ b/src/hal/heltec.h @@ -1,7 +1,7 @@ // Hardware related definitions for Heltec LoRa-32 Board -#define HAS_LORA 1 // comment out if device shall not send data via LoRa -#define HAS_SPI 1 // comment out if device shall not send data via SPI +#define HAS_LORA 1 // comment out if device shall not send data via LoRa +#define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1276_radio 1 #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board diff --git a/src/hal/lolin32lite.h b/src/hal/lolin32lite.h index e1947d3c..7b400cf5 100644 --- a/src/hal/lolin32lite.h +++ b/src/hal/lolin32lite.h @@ -5,4 +5,4 @@ #define HAS_LED 22 // on board LED on GPIO22 #define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW -#define HAS_SPI 1 // comment out if device shall not send data via SPI \ No newline at end of file +#define HAS_SPI 1 // comment out if device shall not send data via SPI \ No newline at end of file diff --git a/src/hal/lopy.h b/src/hal/lopy.h index bacbfcfe..0e414326 100644 --- a/src/hal/lopy.h +++ b/src/hal/lopy.h @@ -1,7 +1,7 @@ // Hardware related definitions for Pycom LoPy Board (NOT LoPy4) -#define HAS_LORA 1 // comment out if device shall not send data via LoRa -#define HAS_SPI 1 // comment out if device shall not send data via SPI +#define HAS_LORA 1 // comment out if device shall not send data via LoRa +#define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1272_radio 1 #define HAS_LED NOT_A_PIN // LoPy has no on board LED, so we use RGB LED on LoPy #define HAS_RGB_LED GPIO_NUM_0 // WS2812B RGB LED on GPIO0 diff --git a/src/hal/lopy4.h b/src/hal/lopy4.h index 38f89e10..9e1169ab 100644 --- a/src/hal/lopy4.h +++ b/src/hal/lopy4.h @@ -1,7 +1,7 @@ // Hardware related definitions for Pycom LoPy Board (not: LoPy4) -#define HAS_LORA 1 // comment out if device shall not send data via LoRa -#define HAS_SPI 1 // comment out if device shall not send data via SPI +#define HAS_LORA 1 // comment out if device shall not send data via LoRa +#define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1276_radio 1 #define HAS_LED NOT_A_PIN // LoPy4 has no on board LED, so we use RGB LED on LoPy4 #define HAS_RGB_LED GPIO_NUM_0 // WS2812B RGB LED on GPIO0 diff --git a/src/hal/ttgobeam.h b/src/hal/ttgobeam.h index 8c3b38d7..ac5b1574 100644 --- a/src/hal/ttgobeam.h +++ b/src/hal/ttgobeam.h @@ -1,7 +1,7 @@ // Hardware related definitions for TTGO T-Beam board -#define HAS_LORA 1 // comment out if device shall not send data via LoRa -#define HAS_SPI 1 // comment out if device shall not send data via SPI +#define HAS_LORA 1 // comment out if device shall not send data via LoRa +#define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1276_radio 1 // HPD13A LoRa SoC #define BOARD_HAS_PSRAM // use extra 4MB external RAM diff --git a/src/hal/ttgov1.h b/src/hal/ttgov1.h index f25bda03..fb04cbb0 100644 --- a/src/hal/ttgov1.h +++ b/src/hal/ttgov1.h @@ -1,7 +1,7 @@ // Hardware related definitions for TTGOv1 board -#define HAS_LORA 1 // comment out if device shall not send data via LoRa -#define HAS_SPI 1 // comment out if device shall not send data via SPI +#define HAS_LORA 1 // comment out if device shall not send data via LoRa +#define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1276_radio 1 #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board diff --git a/src/hal/ttgov2.h b/src/hal/ttgov2.h index 240b687d..e622af02 100644 --- a/src/hal/ttgov2.h +++ b/src/hal/ttgov2.h @@ -1,7 +1,7 @@ // Hardware related definitions for TTGO V2 Board -#define HAS_LORA 1 // comment out if device shall not send data via LoRa -#define HAS_SPI 1 // comment out if device shall not send data via SPI +#define HAS_LORA 1 // comment out if device shall not send data via LoRa +#define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1276_radio 1 // HPD13A LoRa SoC #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C diff --git a/src/hal/ttgov21.h b/src/hal/ttgov21.h index ec58f82f..06cda59f 100644 --- a/src/hal/ttgov21.h +++ b/src/hal/ttgov21.h @@ -6,8 +6,8 @@ / - labelled v1.6 on pcb -> "new" */ -#define HAS_LORA 1 // comment out if device shall not send data via LoRa -#define HAS_SPI 1 // comment out if device shall not send data via SPI +#define HAS_LORA 1 // comment out if device shall not send data via LoRa +#define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1276_radio 1 // HPD13A LoRa SoC #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C diff --git a/src/main.cpp b/src/main.cpp index 4f41ee09..1b258f14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,14 +42,19 @@ volatile int ButtonPressedIRQ = 0, ChannelTimerIRQ = 0, SendCycleTimerIRQ = 0, DisplayTimerIRQ = 0, HomeCycleIRQ = 0; // RTos send queues for payload transmit -QueueHandle_t LoraSendQueue, SPISendQueue; +#ifdef HAS_LORA +QueueHandle_t LoraSendQueue; +#endif + +#ifdef HAS_SPI +QueueHandle_t SPISendQueue; +#endif portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ // handler shared variables -std::set macs; // associative container holding unique MAC -// adress hashes (Wifi + BLE) +std::set macs; // container holding unique MAC adress hashes // initialize payload encoder PayloadConvert payload(PAYLOAD_BUFFER_SIZE); @@ -107,26 +112,6 @@ void setup() { #endif // verbose -// initialize send queues for transmit channels -#ifdef HAS_LORA - LoraSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t)); - if (LoraSendQueue == 0) { - ESP_LOGE(TAG, "Could not create LORA send queue. Aborting."); - exit(0); - } else - ESP_LOGI(TAG, "LORA send queue created, size %d Bytes", - SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE); -#endif -#ifdef HAS_SPI - SPISendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t)); - if (SPISendQueue == 0) { - ESP_LOGE(TAG, "Could not create SPI send queue. Aborting."); - exit(0); - } else - ESP_LOGI(TAG, "SPI send queue created, size %d Bytes", - SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE); -#endif - // read settings from NVRAM loadConfig(); // includes initialize if necessary @@ -137,9 +122,28 @@ void setup() { // initialize LoRa #ifdef HAS_LORA strcat_P(features, " LORA"); + LoraSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t)); + if (LoraSendQueue == 0) { + ESP_LOGE(TAG, "Could not create LORA send queue. Aborting."); + exit(0); + } else + ESP_LOGI(TAG, "LORA send queue created, size %d Bytes", + SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE); #endif - // initialize led +// initialize SPI +#ifdef HAS_SPI + strcat_P(features, " SPI"); + SPISendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t)); + if (SPISendQueue == 0) { + ESP_LOGE(TAG, "Could not create SPI send queue. Aborting."); + exit(0); + } else + ESP_LOGI(TAG, "SPI send queue created, size %d Bytes", + SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE); +#endif + + // initialize led #if (HAS_LED != NOT_A_PIN) pinMode(HAS_LED, OUTPUT); strcat_P(features, " LED"); @@ -326,8 +330,6 @@ void loop() { processSendBuffer(); // check send cycle and enqueue payload if cycle is expired sendPayload(); - // reset watchdog - vTaskDelay(1 / portTICK_PERIOD_MS); } // loop() } diff --git a/src/senddata.cpp b/src/senddata.cpp index 767aa84b..aa8308ff 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -4,9 +4,6 @@ // put data to send in RTos Queues used for transmit over channels Lora and SPI void SendData(uint8_t port) { - int m1 = 0, m2 = 0; - m1 = ESP.getFreeHeap(); - MessageBuffer_t SendBuffer; SendBuffer.MessageSize = payload.getSize(); @@ -35,18 +32,11 @@ void SendData(uint8_t port) { reset_salt(); // get new salt for salting hashes ESP_LOGI(TAG, "Counter cleared"); } - - m2 = ESP.getFreeHeap(); - if (m2 - m1) - ESP_LOGI(TAG, "SendData %d bytes", m2 - m1); - } // SendData // cyclic called function to prepare payload to send void sendPayload() { - int m1 = 0, m2 = 0; - m1 = ESP.getFreeHeap(); if (SendCycleTimerIRQ) { portENTER_CRITICAL(&timerMux); SendCycleTimerIRQ = 0; @@ -77,11 +67,6 @@ void sendPayload() { #endif SendData(COUNTERPORT); } - - m2 = ESP.getFreeHeap(); - if (m2 - m1) - ESP_LOGI(TAG, "sendpayload %d bytes", m2 - m1); - } // sendpayload() // interrupt handler used for payload send cycle timer @@ -108,7 +93,7 @@ void processSendBuffer() { // SendBuffer gets struct MessageBuffer with next payload from queue LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message, SendBuffer.MessageSize, (cfg.countermode & 0x02)); - ESP_LOGI(TAG, "%d bytes sent to LoRa", SendBuffer.MessageSize); + //ESP_LOGI(TAG, "%d bytes sent to LoRa", SendBuffer.MessageSize); sprintf(display_line7, "PACKET QUEUED"); } } @@ -116,13 +101,13 @@ void processSendBuffer() { #ifdef HAS_SPI if (xQueueReceive(SPISendQueue, &SendBuffer, (TickType_t)0) == pdTRUE) { - ESP_LOGI(TAG, "%d bytes sent to SPI", SendBuffer.MessageSize); + //ESP_LOGI(TAG, "%d bytes sent to SPI", SendBuffer.MessageSize); } #endif m2 = ESP.getFreeHeap(); if (m2 - m1) - ESP_LOGI(TAG, "processSendBuffer %d bytes", m2 - m1); + ESP_LOGI(TAG, "processSendBuffer consumed %d bytes", m2 - m1); } // processSendBuffer