small code sanitizations
This commit is contained in:
parent
d704acc3e5
commit
fcd9357116
52
src/main.cpp
52
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,6 +122,25 @@ 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
|
||||||
|
|
||||||
|
// 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
|
#endif
|
||||||
|
|
||||||
// initialize led
|
// initialize 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