diff --git a/src/MeshRadio.cpp b/src/MeshRadio.cpp index 3ac730bc4..b3a74e7f1 100644 --- a/src/MeshRadio.cpp +++ b/src/MeshRadio.cpp @@ -130,6 +130,8 @@ void MeshRadio::reloadConfig() ErrorCode MeshRadio::send(MeshPacket *p) { + lastTxStart = millis(); + if (useHardware) return rf95.send(p); else { @@ -138,7 +140,15 @@ ErrorCode MeshRadio::send(MeshPacket *p) } } +#define TX_WATCHDOG_TIMEOUT 30 * 1000 + void MeshRadio::loop() { - // Currently does nothing, since we do it all in ISRs now + // It should never take us more than 30 secs to send a packet, if it does, we have a bug + uint32_t now = millis(); + if (lastTxStart != 0 && (now - lastTxStart) > TX_WATCHDOG_TIMEOUT && rf95.mode() == RHGenericDriver::RHModeTx) { + DEBUG_MSG("ERROR! Bug! Tx packet took too long to send, forcing radio into rx mode"); + rf95.setModeRx(); + lastTxStart = 0; // Stop checking for now, because we just warned the developer + } } diff --git a/src/MeshRadio.h b/src/MeshRadio.h index 1b7ecfb51..293d5852c 100644 --- a/src/MeshRadio.h +++ b/src/MeshRadio.h @@ -87,10 +87,11 @@ class MeshRadio void reloadConfig(); private: - // RHDatagram manager; // RHReliableDatagram manager; // don't use mesh yet RHMesh manager; - // MeshRXHandler rxHandler; + + /// Used for the tx timer watchdog, to check for bugs in our transmit code, msec of last time we did a send + uint32_t lastTxStart = 0; /// low level send, might block for mutiple seconds ErrorCode sendTo(NodeNum dest, const uint8_t *buf, size_t len);