reset.cpp lora code sanitization

This commit is contained in:
cyberman54 2022-11-20 17:17:07 +01:00
parent cbdad346ca
commit 3df387a207
3 changed files with 16 additions and 11 deletions

View File

@ -37,6 +37,7 @@ void os_getDevEui(u1_t *buf);
void lora_send(void *pvParameters);
void lora_enqueuedata(MessageBuffer_t *message);
void lora_queuereset(void);
void lora_waitforidle(uint16_t timeout_sec);
uint32_t lora_queuewaiting(void);
void myEventCallback(void *pUserData, ev_t ev);
void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,

View File

@ -334,6 +334,18 @@ uint32_t lora_queuewaiting(void) {
return uxQueueMessagesWaiting(LoraSendQueue);
}
// blocking wait until LMIC is idle
void lora_waitforidle(uint16_t timeout_sec) {
ESP_LOGI(TAG, "Waiting until LMIC is idle...");
for (int i = timeout_sec; i > 0; i--) {
if ((LMIC.opmode & (OP_JOINING | OP_TXDATA | OP_POLL | OP_TXRXPEND)) ||
os_queryTimeCriticalJobs(sec2osticks(timeout_sec)))
vTaskDelay(pdMS_TO_TICKS(1000));
else
break;
}
}
// LMIC loop task
void lmictask(void *pvParameters) {
_ASSERT((uint32_t)pvParameters == 1);

View File

@ -88,7 +88,6 @@ void enter_deepsleep(const uint32_t wakeup_sec, gpio_num_t wakeup_gpio) {
ESP_LOGI(TAG, "Preparing to sleep...");
RTC_runmode = RUNMODE_SLEEP;
int i;
// validate wake up pin, if we have
if (!GPIO_IS_VALID_GPIO(wakeup_gpio))
@ -108,22 +107,15 @@ void enter_deepsleep(const uint32_t wakeup_sec, gpio_num_t wakeup_gpio) {
// wait a while (max 100 sec) to clear send queues
ESP_LOGI(TAG, "Waiting until send queues are empty...");
for (i = 100; i > 0; i--) {
for (int i = 100; i > 0; i--) {
if (allQueuesEmtpy())
break;
vTaskDelay(pdMS_TO_TICKS(1000));
}
/// wait until LMIC is idle
// wait up to 100secs until LMIC is idle
#if (HAS_LORA)
ESP_LOGI(TAG, "Waiting until LMIC is idle...");
for (i = 100; i > 0; i--) {
if ((LMIC.opmode & (OP_JOINING | OP_TXDATA | OP_POLL | OP_TXRXPEND)) ||
os_queryTimeCriticalJobs(sec2osticks(wakeup_sec)))
vTaskDelay(pdMS_TO_TICKS(1000));
else
break;
}
lora_waitforidle(100);
#endif // (HAS_LORA)
// shutdown MQTT safely