From d704acc3e5563fc73f9dba06dc75d2d40b8fb326 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 10 Aug 2018 16:33:47 +0200 Subject: [PATCH] link check disabled; SendBuffer no more global (does not solve mem leak) --- src/display.cpp | 2 +- src/globals.h | 7 +++++++ src/lorawan.cpp | 10 +++++----- src/main.cpp | 4 ---- src/senddata.cpp | 44 +++++++++++++++++++++++++++++++++++--------- src/senddata.h | 7 ------- 6 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index c3617538..b2fecf09 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -114,7 +114,7 @@ void refreshtheDisplay() { // update Battery status (line 2) #ifdef HAS_BATTERY_PROBE u8x8.setCursor(0, 2); - u8x8.printf("B:%.1fV", batt_voltage / 1000.0); + u8x8.printf(batt_voltage > 4000 ? "B:USB " : "B:%.1fV", batt_voltage / 1000.0); #endif // update GPS status (line 2) diff --git a/src/globals.h b/src/globals.h index 33548607..f064b258 100644 --- a/src/globals.h +++ b/src/globals.h @@ -37,6 +37,13 @@ typedef struct { char version[10]; // Firmware version } configData_t; +// Struct holding payload for data send queue +typedef struct { + uint8_t MessageSize; + uint8_t MessagePort; + uint8_t Message[PAYLOAD_BUFFER_SIZE]; +} MessageBuffer_t; + // global variables extern configData_t cfg; // current device configuration extern char display_line6[], display_line7[]; // screen buffers diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 7b6b3a74..ea0709ff 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -172,13 +172,13 @@ void onEvent(ev_t ev) { strcpy_P(buff, PSTR("JOINED")); sprintf(display_line6, " "); // clear previous lmic status - // set cyclic lmic link check to off because is not supported by ttn - // (but enabled by lmic after join) - LMIC_setLinkCheckMode(0); - // set data rate adaptation according to saved setting LMIC_setAdrMode(cfg.adrmode); - + + // set cyclic lmic link check to off if no ADR because is not supported by + // ttn (but enabled by lmic after join) + LMIC_setLinkCheckMode(cfg.adrmode); + // Set data rate and transmit power (note: txpower seems to be ignored by // the library) switch_lora(cfg.lorasf, cfg.txpower); diff --git a/src/main.cpp b/src/main.cpp index dd826c2e..4f41ee09 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -109,8 +109,6 @@ void setup() { // initialize send queues for transmit channels #ifdef HAS_LORA - //--> LoraSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(struct SendBuffer - //*)); LoraSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t)); if (LoraSendQueue == 0) { ESP_LOGE(TAG, "Could not create LORA send queue. Aborting."); @@ -120,8 +118,6 @@ void setup() { SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE); #endif #ifdef HAS_SPI - //--> SPISendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(struct SendBuffer - //*)); SPISendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t)); if (SPISendQueue == 0) { ESP_LOGE(TAG, "Could not create SPI send queue. Aborting."); diff --git a/src/senddata.cpp b/src/senddata.cpp index 748ae07d..767aa84b 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -1,26 +1,31 @@ // Basic Config #include "globals.h" -MessageBuffer_t SendBuffer; - // 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(); SendBuffer.MessagePort = PAYLOAD_ENCODER <= 2 - ? port - : (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT); + ? port + : (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT); memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize()); // enqueue message in LoRa send queue #ifdef HAS_LORA - if (xQueueSendToBack(LoraSendQueue, (void *)&SendBuffer, (TickType_t)0) == pdTRUE) + if (xQueueSendToBack(LoraSendQueue, (void *)&SendBuffer, (TickType_t)0) == + pdTRUE) ESP_LOGI(TAG, "%d bytes enqueued to send on LoRa", payload.getSize()); #endif // enqueue message in SPI send queue #ifdef HAS_SPI - if (xQueueSendToBack(SPISendQueue, (void *)&SendBuffer, (TickType_t)0) == pdTRUE) + if (xQueueSendToBack(SPISendQueue, (void *)&SendBuffer, (TickType_t)0) == + pdTRUE) ESP_LOGI(TAG, "%d bytes enqueued to send on SPI", payload.getSize()); #endif @@ -31,10 +36,17 @@ void SendData(uint8_t port) { 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; @@ -65,6 +77,11 @@ 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 @@ -77,27 +94,36 @@ void IRAM_ATTR SendCycleIRQ() { // cyclic called function to eat data from RTos send queues and transmit it void processSendBuffer() { + int m1 = 0, m2 = 0; + m1 = ESP.getFreeHeap(); + + MessageBuffer_t SendBuffer; + #ifdef HAS_LORA // Check if there is a pending TX/RX job running if ((LMIC.opmode & (OP_JOINING | OP_REJOIN | OP_TXDATA | OP_POLL)) != 0) { // LoRa Busy -> don't eat data from queue, since it cannot be sent } else { - if (xQueueReceive(LoraSendQueue, &(SendBuffer), (TickType_t)0) == pdTRUE) { + if (xQueueReceive(LoraSendQueue, &SendBuffer, (TickType_t)0) == pdTRUE) { // 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"); } } #endif #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); } #endif + m2 = ESP.getFreeHeap(); + if (m2 - m1) + ESP_LOGI(TAG, "processSendBuffer %d bytes", m2 - m1); + } // processSendBuffer void flushQueues() { diff --git a/src/senddata.h b/src/senddata.h index e709cedc..806899d6 100644 --- a/src/senddata.h +++ b/src/senddata.h @@ -1,13 +1,6 @@ #ifndef _SENDDATA_H #define _SENDDATA_H -// Struct holding payload for data send queue -typedef struct { - uint8_t MessageSize; - uint8_t MessagePort; - uint8_t Message[PAYLOAD_BUFFER_SIZE]; -} MessageBuffer_t; - void SendData(uint8_t port); void sendPayload(void); void SendCycleIRQ(void);