small code sanitizations
This commit is contained in:
parent
d704acc3e5
commit
fcd9357116
@ -1,7 +1,7 @@
|
|||||||
// Hardware related definitions for ebox ESP32-bit with external connected RFM95 LoRa
|
// 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_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_SPI 1 // comment out if device shall not send data via SPI
|
||||||
#define CFG_sx1276_radio 1
|
#define CFG_sx1276_radio 1
|
||||||
|
|
||||||
#define HAS_LED GPIO_NUM_23 // blue LED on board
|
#define HAS_LED GPIO_NUM_23 // blue LED on board
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Hardware related definitions for generic ESP32 boards
|
// 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_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_sx1276_radio 1 // select LoRa chip
|
||||||
//#define CFG_sx1272_radio 1 // select LoRa chip
|
//#define CFG_sx1272_radio 1 // select LoRa chip
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Hardware related definitions for Heltec LoRa-32 Board
|
// Hardware related definitions for Heltec LoRa-32 Board
|
||||||
|
|
||||||
#define HAS_LORA 1 // comment out if device shall not send data via 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_SPI 1 // comment out if device shall not send data via SPI
|
||||||
#define CFG_sx1276_radio 1
|
#define CFG_sx1276_radio 1
|
||||||
|
|
||||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
||||||
|
@ -5,4 +5,4 @@
|
|||||||
#define HAS_LED 22 // on board LED on GPIO22
|
#define HAS_LED 22 // on board LED on GPIO22
|
||||||
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
#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
|
#define HAS_SPI 1 // comment out if device shall not send data via SPI
|
@ -1,7 +1,7 @@
|
|||||||
// Hardware related definitions for Pycom LoPy Board (NOT LoPy4)
|
// 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_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_SPI 1 // comment out if device shall not send data via SPI
|
||||||
#define CFG_sx1272_radio 1
|
#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_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
|
#define HAS_RGB_LED GPIO_NUM_0 // WS2812B RGB LED on GPIO0
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Hardware related definitions for Pycom LoPy Board (not: LoPy4)
|
// 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_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_SPI 1 // comment out if device shall not send data via SPI
|
||||||
#define CFG_sx1276_radio 1
|
#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_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
|
#define HAS_RGB_LED GPIO_NUM_0 // WS2812B RGB LED on GPIO0
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Hardware related definitions for TTGO T-Beam board
|
// Hardware related definitions for TTGO T-Beam board
|
||||||
|
|
||||||
#define HAS_LORA 1 // comment out if device shall not send data via 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_SPI 1 // comment out if device shall not send data via SPI
|
||||||
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
|
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
|
||||||
|
|
||||||
#define BOARD_HAS_PSRAM // use extra 4MB external RAM
|
#define BOARD_HAS_PSRAM // use extra 4MB external RAM
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Hardware related definitions for TTGOv1 board
|
// Hardware related definitions for TTGOv1 board
|
||||||
|
|
||||||
#define HAS_LORA 1 // comment out if device shall not send data via 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_SPI 1 // comment out if device shall not send data via SPI
|
||||||
#define CFG_sx1276_radio 1
|
#define CFG_sx1276_radio 1
|
||||||
|
|
||||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Hardware related definitions for TTGO V2 Board
|
// Hardware related definitions for TTGO V2 Board
|
||||||
|
|
||||||
#define HAS_LORA 1 // comment out if device shall not send data via 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_SPI 1 // comment out if device shall not send data via SPI
|
||||||
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
|
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
|
||||||
|
|
||||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
|
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
/ - labelled v1.6 on pcb -> "new"
|
/ - labelled v1.6 on pcb -> "new"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define HAS_LORA 1 // comment out if device shall not send data via 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_SPI 1 // comment out if device shall not send data via SPI
|
||||||
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
|
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
|
||||||
|
|
||||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
|
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
|
||||||
|
54
src/main.cpp
54
src/main.cpp
@ -42,14 +42,19 @@ volatile int ButtonPressedIRQ = 0, ChannelTimerIRQ = 0, SendCycleTimerIRQ = 0,
|
|||||||
DisplayTimerIRQ = 0, HomeCycleIRQ = 0;
|
DisplayTimerIRQ = 0, HomeCycleIRQ = 0;
|
||||||
|
|
||||||
// RTos send queues for payload transmit
|
// 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_TYPE timerMux =
|
||||||
portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ
|
portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ
|
||||||
// handler shared variables
|
// handler shared variables
|
||||||
|
|
||||||
std::set<uint16_t> macs; // associative container holding unique MAC
|
std::set<uint16_t> macs; // container holding unique MAC adress hashes
|
||||||
// adress hashes (Wifi + BLE)
|
|
||||||
|
|
||||||
// initialize payload encoder
|
// initialize payload encoder
|
||||||
PayloadConvert payload(PAYLOAD_BUFFER_SIZE);
|
PayloadConvert payload(PAYLOAD_BUFFER_SIZE);
|
||||||
@ -107,26 +112,6 @@ void setup() {
|
|||||||
|
|
||||||
#endif // verbose
|
#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
|
// read settings from NVRAM
|
||||||
loadConfig(); // includes initialize if necessary
|
loadConfig(); // includes initialize if necessary
|
||||||
|
|
||||||
@ -137,9 +122,28 @@ void setup() {
|
|||||||
// initialize LoRa
|
// initialize LoRa
|
||||||
#ifdef HAS_LORA
|
#ifdef HAS_LORA
|
||||||
strcat_P(features, " 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
|
#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)
|
#if (HAS_LED != NOT_A_PIN)
|
||||||
pinMode(HAS_LED, OUTPUT);
|
pinMode(HAS_LED, OUTPUT);
|
||||||
strcat_P(features, " LED");
|
strcat_P(features, " LED");
|
||||||
@ -326,8 +330,6 @@ void loop() {
|
|||||||
processSendBuffer();
|
processSendBuffer();
|
||||||
// check send cycle and enqueue payload if cycle is expired
|
// check send cycle and enqueue payload if cycle is expired
|
||||||
sendPayload();
|
sendPayload();
|
||||||
// reset watchdog
|
|
||||||
vTaskDelay(1 / portTICK_PERIOD_MS);
|
|
||||||
|
|
||||||
} // loop()
|
} // loop()
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,6 @@
|
|||||||
// 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 SendData(uint8_t port) {
|
void SendData(uint8_t port) {
|
||||||
|
|
||||||
int m1 = 0, m2 = 0;
|
|
||||||
m1 = ESP.getFreeHeap();
|
|
||||||
|
|
||||||
MessageBuffer_t SendBuffer;
|
MessageBuffer_t SendBuffer;
|
||||||
|
|
||||||
SendBuffer.MessageSize = payload.getSize();
|
SendBuffer.MessageSize = payload.getSize();
|
||||||
@ -35,18 +32,11 @@ void SendData(uint8_t port) {
|
|||||||
reset_salt(); // get new salt for salting hashes
|
reset_salt(); // get new salt for salting hashes
|
||||||
ESP_LOGI(TAG, "Counter cleared");
|
ESP_LOGI(TAG, "Counter cleared");
|
||||||
}
|
}
|
||||||
|
|
||||||
m2 = ESP.getFreeHeap();
|
|
||||||
if (m2 - m1)
|
|
||||||
ESP_LOGI(TAG, "SendData %d bytes", m2 - m1);
|
|
||||||
|
|
||||||
} // SendData
|
} // SendData
|
||||||
|
|
||||||
// cyclic called function to prepare payload to send
|
// cyclic called function to prepare payload to send
|
||||||
void sendPayload() {
|
void sendPayload() {
|
||||||
|
|
||||||
int m1 = 0, m2 = 0;
|
|
||||||
m1 = ESP.getFreeHeap();
|
|
||||||
if (SendCycleTimerIRQ) {
|
if (SendCycleTimerIRQ) {
|
||||||
portENTER_CRITICAL(&timerMux);
|
portENTER_CRITICAL(&timerMux);
|
||||||
SendCycleTimerIRQ = 0;
|
SendCycleTimerIRQ = 0;
|
||||||
@ -77,11 +67,6 @@ void sendPayload() {
|
|||||||
#endif
|
#endif
|
||||||
SendData(COUNTERPORT);
|
SendData(COUNTERPORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
m2 = ESP.getFreeHeap();
|
|
||||||
if (m2 - m1)
|
|
||||||
ESP_LOGI(TAG, "sendpayload %d bytes", m2 - m1);
|
|
||||||
|
|
||||||
} // sendpayload()
|
} // sendpayload()
|
||||||
|
|
||||||
// interrupt handler used for payload send cycle timer
|
// interrupt handler used for payload send cycle timer
|
||||||
@ -108,7 +93,7 @@ void processSendBuffer() {
|
|||||||
// SendBuffer gets struct MessageBuffer with next payload from queue
|
// SendBuffer gets struct MessageBuffer with next payload from queue
|
||||||
LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message,
|
LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message,
|
||||||
SendBuffer.MessageSize, (cfg.countermode & 0x02));
|
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");
|
sprintf(display_line7, "PACKET QUEUED");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,13 +101,13 @@ void processSendBuffer() {
|
|||||||
|
|
||||||
#ifdef HAS_SPI
|
#ifdef HAS_SPI
|
||||||
if (xQueueReceive(SPISendQueue, &SendBuffer, (TickType_t)0) == pdTRUE) {
|
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
|
#endif
|
||||||
|
|
||||||
m2 = ESP.getFreeHeap();
|
m2 = ESP.getFreeHeap();
|
||||||
if (m2 - m1)
|
if (m2 - m1)
|
||||||
ESP_LOGI(TAG, "processSendBuffer %d bytes", m2 - m1);
|
ESP_LOGI(TAG, "processSendBuffer consumed %d bytes", m2 - m1);
|
||||||
|
|
||||||
} // processSendBuffer
|
} // processSendBuffer
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user