diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index 7a415f07..2b4c4675 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -234,7 +234,16 @@ void Dispatcher::checkSend() { uint32_t max_airtime = _radio->getEstAirtimeFor(len)*3/2; outbound_start = _ms->getMillis(); - _radio->startSendRaw(raw, len); + bool success = _radio->startSendRaw(raw, len); + if (!success) { + MESH_DEBUG_PRINTLN("%s Dispatcher::loop(): ERROR: send start failed!", getLogDateTime()); + + logTxFail(outbound, outbound->getRawLength()); + + releasePacket(outbound); // return to pool + outbound = NULL; + return; + } outbound_expiry = futureMillis(max_airtime); #if MESH_PACKET_LOGGING diff --git a/src/Dispatcher.h b/src/Dispatcher.h index 393d0856..96db4fc5 100644 --- a/src/Dispatcher.h +++ b/src/Dispatcher.h @@ -42,8 +42,9 @@ public: * \brief starts the raw packet send. (no wait) * \param bytes the raw packet data * \param len the length in bytes + * \returns true if successfully started */ - virtual void startSendRaw(const uint8_t* bytes, int len) = 0; + virtual bool startSendRaw(const uint8_t* bytes, int len) = 0; /** * \returns true if the previous 'startSendRaw()' completed successfully. diff --git a/src/helpers/RadioLibWrappers.cpp b/src/helpers/RadioLibWrappers.cpp index 03f8f3ce..fa678431 100644 --- a/src/helpers/RadioLibWrappers.cpp +++ b/src/helpers/RadioLibWrappers.cpp @@ -77,13 +77,16 @@ uint32_t RadioLibWrapper::getEstAirtimeFor(int len_bytes) { return _radio->getTimeOnAir(len_bytes) / 1000; } -void RadioLibWrapper::startSendRaw(const uint8_t* bytes, int len) { - state = STATE_TX_WAIT; +bool RadioLibWrapper::startSendRaw(const uint8_t* bytes, int len) { _board->onBeforeTransmit(); int err = _radio->startTransmit((uint8_t *) bytes, len); - if (err != RADIOLIB_ERR_NONE) { - MESH_DEBUG_PRINTLN("RadioLibWrapper: error: startTransmit(%d)", err); + if (err == RADIOLIB_ERR_NONE) { + state = STATE_TX_WAIT; + return true; } + MESH_DEBUG_PRINTLN("RadioLibWrapper: error: startTransmit(%d)", err); + idle(); // trigger another startRecv() + return false; } bool RadioLibWrapper::isSendComplete() { diff --git a/src/helpers/RadioLibWrappers.h b/src/helpers/RadioLibWrappers.h index c9621cf6..a97987ef 100644 --- a/src/helpers/RadioLibWrappers.h +++ b/src/helpers/RadioLibWrappers.h @@ -19,7 +19,7 @@ public: void begin() override; int recvRaw(uint8_t* bytes, int sz) override; uint32_t getEstAirtimeFor(int len_bytes) override; - void startSendRaw(const uint8_t* bytes, int len) override; + bool startSendRaw(const uint8_t* bytes, int len) override; bool isSendComplete() override; void onSendFinished() override; diff --git a/src/helpers/esp32/ESPNOWRadio.cpp b/src/helpers/esp32/ESPNOWRadio.cpp index 9cdc0234..a48a3430 100644 --- a/src/helpers/esp32/ESPNOWRadio.cpp +++ b/src/helpers/esp32/ESPNOWRadio.cpp @@ -67,18 +67,19 @@ uint32_t ESPNOWRadio::intID() { return n + m; } -void ESPNOWRadio::startSendRaw(const uint8_t* bytes, int len) { +bool ESPNOWRadio::startSendRaw(const uint8_t* bytes, int len) { // Send message via ESP-NOW is_send_complete = false; esp_err_t result = esp_now_send(broadcastAddress, bytes, len); if (result == ESP_OK) { n_sent++; ESPNOW_DEBUG_PRINTLN("Send success"); - } else { - last_send_result = result; - is_send_complete = true; - ESPNOW_DEBUG_PRINTLN("Send failed: %d", result); + return true; } + last_send_result = result; + is_send_complete = true; + ESPNOW_DEBUG_PRINTLN("Send failed: %d", result); + return false; } bool ESPNOWRadio::isSendComplete() { diff --git a/src/helpers/esp32/ESPNOWRadio.h b/src/helpers/esp32/ESPNOWRadio.h index ab645f12..4b33df58 100644 --- a/src/helpers/esp32/ESPNOWRadio.h +++ b/src/helpers/esp32/ESPNOWRadio.h @@ -12,7 +12,7 @@ public: void init(); int recvRaw(uint8_t* bytes, int sz) override; uint32_t getEstAirtimeFor(int len_bytes) override; - void startSendRaw(const uint8_t* bytes, int len) override; + bool startSendRaw(const uint8_t* bytes, int len) override; bool isSendComplete() override; void onSendFinished() override;