diff --git a/src/CustomRF95.cpp b/src/CustomRF95.cpp index bb80f878e..e369e5c00 100644 --- a/src/CustomRF95.cpp +++ b/src/CustomRF95.cpp @@ -5,8 +5,6 @@ #include "assert.h" #include "NodeDB.h" -#define MAX_TX_QUEUE 8 // max number of packets which can be waiting for transmission - /// A temporary buffer used for sending/receving packets, sized to hold the biggest buffer we might need #define MAX_RHPACKETLEN 251 static uint8_t radiobuf[MAX_RHPACKETLEN]; @@ -47,7 +45,12 @@ ErrorCode CustomRF95::send(MeshPacket *p) else { DEBUG_MSG("enquing packet for send from=0x%x, to=0x%x\n", p->from, p->to); - return txQueue.enqueue(p, 0) ? ERRNO_OK : ERRNO_UNKNOWN; // nowait + ErrorCode res = txQueue.enqueue(p, 0) ? ERRNO_OK : ERRNO_UNKNOWN; + + if (res != ERRNO_OK) // we weren't able to queue it, so we must drop it to prevent leaks + pool.release(p); + + return res; } } diff --git a/src/CustomRF95.h b/src/CustomRF95.h index 8039a01c4..7fa4d8e4c 100644 --- a/src/CustomRF95.h +++ b/src/CustomRF95.h @@ -7,6 +7,9 @@ #include "PointerQueue.h" #include "MeshTypes.h" +#define MAX_TX_QUEUE 16 // max number of packets which can be waiting for transmission + + /** * A version of the RF95 driver which is smart enough to manage packets via queues (no polling or blocking in user threads!) */ diff --git a/src/MeshRadio.h b/src/MeshRadio.h index 26b765542..71c0c5a7c 100644 --- a/src/MeshRadio.h +++ b/src/MeshRadio.h @@ -49,8 +49,6 @@ #error "HW_VERSION not set" #endif -#define MAX_TX_QUEUE 8 // max number of packets which can be waiting for transmission - /** * A raw low level interface to our mesh. Only understands nodenums and bytes (not protobufs or node ids) diff --git a/src/MeshService.cpp b/src/MeshService.cpp index 80efed0af..3412db8d1 100644 --- a/src/MeshService.cpp +++ b/src/MeshService.cpp @@ -218,7 +218,10 @@ void MeshService::handleToRadio(std::string s) void MeshService::sendToMesh(MeshPacket *p) { nodeDB.updateFrom(*p); // update our local DB for this packet (because phone might have sent position packets etc...) - assert(radio.send(p) == ERRNO_OK); + + // Note: We might return !OK if our fifo was full, at that point the only option we have is to drop it + if(radio.send(p) != ERRNO_OK) + DEBUG_MSG("Dropped packet because send queue was full!"); } MeshPacket *MeshService::allocForSending()