small code sanitizations

This commit is contained in:
Klaus K Wilting 2018-08-11 19:12:04 +02:00
parent d704acc3e5
commit fcd9357116
12 changed files with 49 additions and 62 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
#define HAS_SPI 1 // comment out if device shall not send data via SPI

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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<uint16_t> macs; // associative container holding unique MAC
// adress hashes (Wifi + BLE)
std::set<uint16_t> 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()
}

View File

@ -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