bugfix message queuing to LMIC while LMIC is busy

This commit is contained in:
Verkehrsrot 2019-08-28 10:48:39 +02:00
parent bbca15a76e
commit 829ab0ea05
6 changed files with 27 additions and 25 deletions

View File

@ -45,6 +45,9 @@
#define I2C_MUTEX_LOCK() (xSemaphoreTake(I2Caccess, pdMS_TO_TICKS(10)) == pdTRUE) #define I2C_MUTEX_LOCK() (xSemaphoreTake(I2Caccess, pdMS_TO_TICKS(10)) == pdTRUE)
#define I2C_MUTEX_UNLOCK() (xSemaphoreGive(I2Caccess)) #define I2C_MUTEX_UNLOCK() (xSemaphoreGive(I2Caccess))
enum sendprio_t { prio_low, prio_normal, prio_high };
enum timesource_t { _gps, _rtc, _lora, _unsynced };
// Struct holding devices's runtime configuration // Struct holding devices's runtime configuration
typedef struct { typedef struct {
uint8_t lorasf; // 7-12, lora spreadfactor uint8_t lorasf; // 7-12, lora spreadfactor
@ -73,6 +76,7 @@ typedef struct {
typedef struct { typedef struct {
uint8_t MessageSize; uint8_t MessageSize;
uint8_t MessagePort; uint8_t MessagePort;
sendprio_t MessagePrio;
uint8_t Message[PAYLOAD_BUFFER_SIZE]; uint8_t Message[PAYLOAD_BUFFER_SIZE];
} MessageBuffer_t; } MessageBuffer_t;
@ -95,9 +99,6 @@ typedef struct {
float gas; // raw gas sensor signal float gas; // raw gas sensor signal
} bmeStatus_t; } bmeStatus_t;
enum sendprio_t { prio_low, prio_normal, prio_high };
enum timesource_t { _gps, _rtc, _lora, _unsynced };
extern std::set<uint16_t, std::less<uint16_t>, Mallocator<uint16_t>> macs; extern std::set<uint16_t, std::less<uint16_t>, Mallocator<uint16_t>> macs;
extern std::array<uint64_t, 0xff>::iterator it; extern std::array<uint64_t, 0xff>::iterator it;
extern std::array<uint64_t, 0xff> beacons; extern std::array<uint64_t, 0xff> beacons;

View File

@ -35,7 +35,7 @@ void os_getDevEui(u1_t *buf);
void showLoraKeys(void); void showLoraKeys(void);
void switch_lora(uint8_t sf, uint8_t tx); void switch_lora(uint8_t sf, uint8_t tx);
void lora_send(osjob_t *job); void lora_send(osjob_t *job);
void lora_enqueuedata(MessageBuffer_t *message, sendprio_t prio); void lora_enqueuedata(MessageBuffer_t *message);
void lora_queuereset(void); void lora_queuereset(void);
#if (TIME_SYNC_LORAWAN) #if (TIME_SYNC_LORAWAN)
void user_request_network_time_callback(void *pVoidUserUTCTime, void user_request_network_time_callback(void *pVoidUserUTCTime,

View File

@ -28,7 +28,7 @@ licenses. Refer to LICENSE.txt file in repository for more details.
esp_err_t spi_init(); esp_err_t spi_init();
void spi_enqueuedata(MessageBuffer_t *message, sendprio_t prio); void spi_enqueuedata(MessageBuffer_t *message);
void spi_queuereset(); void spi_queuereset();
#endif // _SPISLAVE_H #endif // _SPISLAVE_H

View File

@ -391,21 +391,16 @@ void switch_lora(uint8_t sf, uint8_t tx) {
void lora_send(osjob_t *job) { void lora_send(osjob_t *job) {
MessageBuffer_t SendBuffer; MessageBuffer_t SendBuffer;
// Check if there is a pending TX/RX job running, if yes don't eat data if (xQueueReceive(LoraSendQueue, &SendBuffer, (TickType_t)0) == pdTRUE) {
// since it cannot be sent right now // SendBuffer now filled with next payload from queue
if ((LMIC.opmode & (OP_JOINING | OP_REJOIN | OP_TXDATA | OP_POLL)) != 0) { if (LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message,
// waiting for LoRa getting ready SendBuffer.MessageSize,
} else { (cfg.countermode & 0x02)) == 0) {
if (xQueueReceive(LoraSendQueue, &SendBuffer, (TickType_t)0) == pdTRUE) { ESP_LOGI(TAG, "%d byte(s) sent to LoRa", SendBuffer.MessageSize);
// SendBuffer now filled with next payload from queue } else {
if (!LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message, lora_enqueuedata(&SendBuffer);
SendBuffer.MessageSize, (cfg.countermode & 0x02))) { // ESP_LOGE(TAG, "could not send %d byte(s) to LoRa, rescheduled",
ESP_LOGI(TAG, "%d byte(s) sent to LoRa", SendBuffer.MessageSize); // SendBuffer.MessageSize);
} else {
ESP_LOGE(TAG, "could not send %d byte(s) to LoRa",
SendBuffer.MessageSize);
}
// sprintf(display_line7, "PACKET QUEUED");
} }
} }
// reschedule job every 0,5 - 1 sec. including a bit of random to prevent // reschedule job every 0,5 - 1 sec. including a bit of random to prevent
@ -441,10 +436,12 @@ esp_err_t lora_stack_init() {
return ESP_OK; // continue main program return ESP_OK; // continue main program
} }
void lora_enqueuedata(MessageBuffer_t *message, sendprio_t prio) { void lora_enqueuedata(MessageBuffer_t *message) {
// enqueue message in LORA send queue // enqueue message in LORA send queue
BaseType_t ret; BaseType_t ret;
MessageBuffer_t DummyBuffer; MessageBuffer_t DummyBuffer;
sendprio_t prio = message->MessagePrio;
switch (prio) { switch (prio) {
case prio_high: case prio_high:
// clear space in queue if full, then fallthrough to normal // clear space in queue if full, then fallthrough to normal

View File

@ -10,9 +10,11 @@ void sendcycle() {
// 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 SendPayload(uint8_t port, sendprio_t prio) { void SendPayload(uint8_t port, sendprio_t prio) {
MessageBuffer_t SendBuffer; // contains MessageSize, MessagePort, Message[] MessageBuffer_t SendBuffer; // contains MessageSize, MessagePort, MessagePrio, Message[]
SendBuffer.MessageSize = payload.getSize(); SendBuffer.MessageSize = payload.getSize();
SendBuffer.MessagePrio = prio;
switch (PAYLOAD_ENCODER) { switch (PAYLOAD_ENCODER) {
case 1: // plain -> no mapping case 1: // plain -> no mapping
case 2: // packed -> no mapping case 2: // packed -> no mapping
@ -42,10 +44,10 @@ void SendPayload(uint8_t port, sendprio_t prio) {
// enqueue message in device's send queues // enqueue message in device's send queues
#if (HAS_LORA) #if (HAS_LORA)
lora_enqueuedata(&SendBuffer, prio); lora_enqueuedata(&SendBuffer);
#endif #endif
#ifdef HAS_SPI #ifdef HAS_SPI
spi_enqueuedata(&SendBuffer, prio); spi_enqueuedata(&SendBuffer);
#endif #endif
} // SendPayload } // SendPayload

View File

@ -147,10 +147,12 @@ esp_err_t spi_init() {
return ret; return ret;
} }
void spi_enqueuedata(MessageBuffer_t *message, sendprio_t prio) { void spi_enqueuedata(MessageBuffer_t *message) {
// enqueue message in SPI send queue // enqueue message in SPI send queue
BaseType_t ret; BaseType_t ret;
MessageBuffer_t DummyBuffer; MessageBuffer_t DummyBuffer;
sendprio_t prio = message->MessagePrio;
switch (prio) { switch (prio) {
case prio_high: case prio_high:
// clear space in queue if full, then fallthrough to normal // clear space in queue if full, then fallthrough to normal