Ver código fonte

* startSendRaw() now returns false if fail

Scott Powell 1 ano atrás
pai
commit
b08436eba7

+ 10 - 1
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

+ 2 - 1
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.

+ 7 - 4
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() {

+ 1 - 1
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;
 

+ 6 - 5
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() {

+ 1 - 1
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;