diff --git a/src/rf95/RadioLibInterface.cpp b/src/rf95/RadioLibInterface.cpp index f1413fa8b..9ae539bd1 100644 --- a/src/rf95/RadioLibInterface.cpp +++ b/src/rf95/RadioLibInterface.cpp @@ -73,8 +73,8 @@ ErrorCode RadioLibInterface::send(MeshPacket *p) // we almost certainly guarantee no one outside will like the packet we are sending. if (canSendImmediately()) { // if the radio is idle, we can send right away - DEBUG_MSG("immediate send on mesh fr=0x%x,to=0x%x,id=%d\n (txGood=%d,rxGood=%d,rxBad=%d)\n", p->from, p->to, p->id, -1, - -1, -1); + DEBUG_MSG("immediate send on mesh fr=0x%x,to=0x%x,id=%d\n (txGood=%d,rxGood=%d,rxBad=%d)\n", p->from, p->to, p->id, + txGood, rxGood, rxBad); startSend(p); return ERRNO_OK; @@ -95,8 +95,6 @@ void RadioLibInterface::loop() if (wasPending) { pending = ISR_NONE; // If the flag was set, it is _guaranteed_ the ISR won't be running, because it masked itself - DEBUG_MSG("Handling a LORA interrupt %d!\n", wasPending); - if (wasPending == ISR_TX) handleTransmitInterrupt(); else if (wasPending == ISR_RX) @@ -122,6 +120,7 @@ void RadioLibInterface::startNextWork() void RadioLibInterface::handleTransmitInterrupt() { + DEBUG_MSG("handling lora TX interrupt\n"); assert(sendingPacket); // Were we sending? completeSending(); @@ -130,6 +129,8 @@ void RadioLibInterface::handleTransmitInterrupt() void RadioLibInterface::completeSending() { if (sendingPacket) { + txGood++; + // We are done sending that packet, release it packetPool.release(sendingPacket); sendingPacket = NULL; @@ -142,12 +143,15 @@ void RadioLibInterface::handleReceiveInterrupt() assert(isReceiving); isReceiving = false; + DEBUG_MSG("handling lora RX interrupt\n"); + // read the number of actually received bytes size_t length = iface.getPacketLength(); int state = iface.readData(radiobuf, length); if (state != ERR_NONE) { DEBUG_MSG("ignoring received packet due to error=%d\n", state); + rxBad++; } else { // Skip the 4 headers that are at the beginning of the rxBuf int32_t payloadLen = length - sizeof(PacketHeader); @@ -167,9 +171,11 @@ void RadioLibInterface::handleReceiveInterrupt() if (!pb_decode_from_bytes(payload, payloadLen, SubPacket_fields, p)) { DEBUG_MSG("Invalid protobufs in received mesh packet, discarding.\n"); packetPool.release(mp); + // rxBad++; not really a hw errpr } else { // parsing was successful, queue for our recipient mp->has_payload = true; + txGood++; deliverToReceiver(mp); } diff --git a/src/rf95/RadioLibInterface.h b/src/rf95/RadioLibInterface.h index eb5123390..161b3c30d 100644 --- a/src/rf95/RadioLibInterface.h +++ b/src/rf95/RadioLibInterface.h @@ -17,7 +17,7 @@ class RadioLibInterface : public RadioInterface /** * What sort of interrupt do we expect our helper thread to now handle */ - volatile PendingISR pending; + volatile PendingISR pending = ISR_NONE; /** Our ISR code currently needs this to find our active instance */ @@ -28,6 +28,11 @@ class RadioLibInterface : public RadioInterface */ static void isrTxLevel0(); + /** + * Debugging counts + */ + uint32_t rxBad = 0, rxGood = 0, txGood = 0; + protected: float bw = 125; uint8_t sf = 9; diff --git a/src/rf95/SX1262Interface.cpp b/src/rf95/SX1262Interface.cpp index 9b59804a0..d8c5e28da 100644 --- a/src/rf95/SX1262Interface.cpp +++ b/src/rf95/SX1262Interface.cpp @@ -100,7 +100,11 @@ bool SX1262Interface::canSendImmediately() // We wait _if_ we are partially though receiving a packet (rather than just merely waiting for one). // To do otherwise would be doubly bad because not only would we drop the packet that was on the way in, // we almost certainly guarantee no one outside will like the packet we are sending. - bool busy = sendingPacket != NULL || (isReceiving && lora.getPacketLength() > 0); + bool busyTx = sendingPacket != NULL; + bool busyRx = isReceiving && lora.getPacketLength() > 0; - return !busy; + if (busyTx || busyRx) + DEBUG_MSG("Can not set now, busyTx=%d, busyRx=%d\n", busyTx, busyRx); + + return !busyTx && !busyRx; } \ No newline at end of file