Queue wait time

This commit is contained in:
Klaus K Wilting 2018-08-08 00:05:38 +02:00
parent 0e6b6fb025
commit 5fbcd0aebb

View File

@ -1,26 +1,26 @@
// Basic Config // Basic Config
#include "globals.h" #include "globals.h"
MessageBuffer_t SendBuffer; MessageBuffer_t SendBuffer;
// 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) {
SendBuffer.MessageSize = payload.getSize(); SendBuffer.MessageSize = payload.getSize();
SendBuffer.MessagePort = PAYLOAD_ENCODER <= 2 SendBuffer.MessagePort = PAYLOAD_ENCODER <= 2
? port ? port
: (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT); : (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT);
memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize()); memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize());
// enqueue message in LoRa send queue // enqueue message in LoRa send queue
#ifdef HAS_LORA #ifdef HAS_LORA
if (xQueueSendToBack(LoraSendQueue, (void *)&SendBuffer, (TickType_t)0)) if (xQueueSendToBack(LoraSendQueue, (void *)&SendBuffer, (TickType_t)0) == pdTRUE)
ESP_LOGI(TAG, "%d bytes enqueued to send on LoRa", payload.getSize()); ESP_LOGI(TAG, "%d bytes enqueued to send on LoRa", payload.getSize());
#endif #endif
// enqueue message in SPI send queue // enqueue message in SPI send queue
#ifdef HAS_SPI #ifdef HAS_SPI
if (xQueueSendToBack(SPISendQueue, (void *)&SendBuffer, (TickType_t)0)) if (xQueueSendToBack(SPISendQueue, (void *)&SendBuffer, (TickType_t)0) == pdTRUE)
ESP_LOGI(TAG, "%d bytes enqueued to send on SPI", payload.getSize()); ESP_LOGI(TAG, "%d bytes enqueued to send on SPI", payload.getSize());
#endif #endif
@ -82,10 +82,10 @@ void processSendBuffer() {
if ((LMIC.opmode & (OP_JOINING | OP_REJOIN | OP_TXDATA | OP_POLL)) != 0) { 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 // LoRa Busy -> don't eat data from queue, since it cannot be sent
} else { } else {
if (xQueueReceive(LoraSendQueue, &(SendBuffer), (TickType_t)10)) { if (xQueueReceive(LoraSendQueue, &(SendBuffer), (TickType_t)0) == pdTRUE) {
// SendBuffer now holds the struct MessageBuffer with next payload from queue // SendBuffer gets struct MessageBuffer with next payload from queue
LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message, SendBuffer.MessageSize, LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message,
(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");
} }
@ -93,7 +93,7 @@ void processSendBuffer() {
#endif #endif
#ifdef HAS_SPI #ifdef HAS_SPI
if (xQueueReceive(SPISendQueue, &(SendBuffer), (TickType_t)10)) { 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
@ -102,9 +102,9 @@ void processSendBuffer() {
void flushQueues() { void flushQueues() {
#ifdef HAS_LORA #ifdef HAS_LORA
xQueueReset(LoraSendQueue); xQueueReset(LoraSendQueue);
#endif #endif
#ifdef HAS_SPI #ifdef HAS_SPI
xQueueReset(SPISendQueue); xQueueReset(SPISendQueue);
#endif #endif
} }