refactoring LMIC send queueing
This commit is contained in:
parent
1c5edbb6a4
commit
78c8ed3e97
@ -248,6 +248,11 @@ void onEvent(ev_t ev) {
|
||||
: PSTR("TX COMPLETE"));
|
||||
sprintf(display_line6, " "); // clear previous lmic status
|
||||
|
||||
// schedule next transmission with some random delay to prevent systematic
|
||||
// collisions
|
||||
os_setTimedCallback(&sendjob, os_getTime() + ms2osticks(random(500)),
|
||||
lora_send);
|
||||
|
||||
if (LMIC.dataLen) { // did we receive payload data -> display info
|
||||
ESP_LOGI(TAG, "Received %d bytes of payload, RSSI %d SNR %d",
|
||||
LMIC.dataLen, LMIC.rssi, LMIC.snr / 4);
|
||||
@ -391,23 +396,23 @@ void switch_lora(uint8_t sf, uint8_t tx) {
|
||||
|
||||
void lora_send(osjob_t *job) {
|
||||
MessageBuffer_t SendBuffer;
|
||||
if (xQueueReceive(LoraSendQueue, &SendBuffer, (TickType_t)0) == pdTRUE) {
|
||||
// SendBuffer now filled with next payload from queue
|
||||
|
||||
// Check if there is not a current TX/RX job running
|
||||
if (LMIC.opmode & OP_TXRXPEND) {
|
||||
ESP_LOGE(TAG, "LMIC busy, data not sent and lost");
|
||||
return;
|
||||
}
|
||||
|
||||
// fetch next payload to send from queue or wait until new payload shows up in
|
||||
// queue
|
||||
if (xQueueReceive(LoraSendQueue, &SendBuffer, portMAX_DELAY) == pdTRUE) {
|
||||
if (LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message,
|
||||
SendBuffer.MessageSize,
|
||||
(cfg.countermode & 0x02)) == 0) {
|
||||
ESP_LOGI(TAG, "%d byte(s) sent to LoRa", SendBuffer.MessageSize);
|
||||
} else {
|
||||
lora_enqueuedata(&SendBuffer);
|
||||
// ESP_LOGE(TAG, "could not send %d byte(s) to LoRa, rescheduled",
|
||||
// SendBuffer.MessageSize);
|
||||
SendBuffer.MessageSize, (cfg.countermode & 0x02)) == 0)
|
||||
ESP_LOGI(TAG, "%d byte(s) delivered to LMIC", SendBuffer.MessageSize);
|
||||
else
|
||||
lora_enqueuedata(&SendBuffer); // re-enqueue unsent message
|
||||
}
|
||||
}
|
||||
// reschedule job every 0,5 - 1 sec. including a bit of random to prevent
|
||||
// systematic collisions
|
||||
os_setTimedCallback(job, os_getTime() + 500 + ms2osticks(random(500)),
|
||||
lora_send);
|
||||
}
|
||||
|
||||
esp_err_t lora_stack_init() {
|
||||
assert(SEND_QUEUE_SIZE);
|
||||
@ -438,15 +443,17 @@ esp_err_t lora_stack_init() {
|
||||
|
||||
void lora_enqueuedata(MessageBuffer_t *message) {
|
||||
// enqueue message in LORA send queue
|
||||
BaseType_t ret;
|
||||
BaseType_t ret = pdFALSE;
|
||||
MessageBuffer_t DummyBuffer;
|
||||
sendprio_t prio = message->MessagePrio;
|
||||
|
||||
switch (prio) {
|
||||
case prio_high:
|
||||
// clear space in queue if full, then fallthrough to normal
|
||||
if (uxQueueSpacesAvailable(LoraSendQueue) == 0)
|
||||
// clear some space in queue if full, then fallthrough to prio_normal
|
||||
if (uxQueueSpacesAvailable(LoraSendQueue) == 0) {
|
||||
xQueueReceive(LoraSendQueue, &DummyBuffer, (TickType_t)0);
|
||||
ESP_LOGW(TAG, "LORA sendqueue purged, data is lost");
|
||||
}
|
||||
case prio_normal:
|
||||
ret = xQueueSendToFront(LoraSendQueue, (void *)message, (TickType_t)0);
|
||||
break;
|
||||
@ -455,7 +462,9 @@ void lora_enqueuedata(MessageBuffer_t *message) {
|
||||
ret = xQueueSendToBack(LoraSendQueue, (void *)message, (TickType_t)0);
|
||||
break;
|
||||
}
|
||||
if (ret != pdTRUE)
|
||||
if (ret == pdTRUE)
|
||||
ESP_LOGD(TAG, "LORA sendqueue data enqueued");
|
||||
else
|
||||
ESP_LOGW(TAG, "LORA sendqueue is full");
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ void SendPayload(uint8_t port, sendprio_t prio) {
|
||||
default:
|
||||
SendBuffer.MessagePort = port;
|
||||
}
|
||||
memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize());
|
||||
memcpy(SendBuffer.Message, payload.getBuffer(), SendBuffer.MessageSize);
|
||||
|
||||
// enqueue message in device's send queues
|
||||
#if (HAS_LORA)
|
||||
|
Loading…
Reference in New Issue
Block a user