diff --git a/src/rf95/RF95Interface.cpp b/src/rf95/RF95Interface.cpp index 5cd6d6b03..f8f64c9a5 100644 --- a/src/rf95/RF95Interface.cpp +++ b/src/rf95/RF95Interface.cpp @@ -106,18 +106,9 @@ void RF95Interface::startReceive() } /** Could we send right now (i.e. either not actively receving or transmitting)? */ -bool RF95Interface::canSendImmediately() +bool RF95Interface::isActivelyReceiving() { - // 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 busyTx = sendingPacket != NULL; - bool busyRx = isReceiving && lora->isReceiving(); - - if (busyTx || busyRx) - DEBUG_MSG("Can not set now, busyTx=%d, busyRx=%d\n", busyTx, busyRx); - - return !busyTx && !busyRx; + return lora->isReceiving(); } bool RF95Interface::sleep() diff --git a/src/rf95/RF95Interface.h b/src/rf95/RF95Interface.h index 911e81a01..d0b5fd7f2 100644 --- a/src/rf95/RF95Interface.h +++ b/src/rf95/RF95Interface.h @@ -38,9 +38,9 @@ class RF95Interface : public RadioLibInterface */ virtual void enableInterrupt(void (*callback)()) { lora->setDio0Action(callback); } - /** Could we send right now (i.e. either not actively receiving or transmitting)? */ - virtual bool canSendImmediately(); - + /** are we actively receiving a packet (only called during receiving state) */ + virtual bool isActivelyReceiving(); + /** * Start waiting to receive a message */ diff --git a/src/rf95/RadioLibInterface.cpp b/src/rf95/RadioLibInterface.cpp index f067cd9fc..3653e29f9 100644 --- a/src/rf95/RadioLibInterface.cpp +++ b/src/rf95/RadioLibInterface.cpp @@ -64,6 +64,22 @@ void RadioLibInterface::applyModemConfig() } } +/** Could we send right now (i.e. either not actively receving or transmitting)? */ +bool RadioLibInterface::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. + PendingISR isPending = pending; + bool busyTx = sendingPacket != NULL; + bool busyRx = isReceiving && isActivelyReceiving(); + + if (busyTx || busyRx || isPending) + DEBUG_MSG("Can not send yet, busyTx=%d, busyRx=%d, intPend=%d\n", busyTx, busyRx, isPending); + + return !busyTx && !busyRx && !isPending; +} + /// Send a packet (possibly by enquing in a private fifo). This routine will /// later free() the packet to pool. This routine is not allowed to stall because it is called from /// bluetooth comms code. If the txmit queue is empty it might return an error diff --git a/src/rf95/RadioLibInterface.h b/src/rf95/RadioLibInterface.h index a71a0a00e..bf5e20f7c 100644 --- a/src/rf95/RadioLibInterface.h +++ b/src/rf95/RadioLibInterface.h @@ -101,7 +101,10 @@ class RadioLibInterface : public RadioInterface void applyModemConfig(); /** Could we send right now (i.e. either not actively receiving or transmitting)? */ - virtual bool canSendImmediately() = 0; + virtual bool canSendImmediately(); + + /** are we actively receiving a packet (only called during receiving state) */ + virtual bool isActivelyReceiving() = 0; /** * Start waiting to receive a message diff --git a/src/rf95/SX1262Interface.cpp b/src/rf95/SX1262Interface.cpp index e69074e04..d2842956c 100644 --- a/src/rf95/SX1262Interface.cpp +++ b/src/rf95/SX1262Interface.cpp @@ -100,18 +100,9 @@ void SX1262Interface::startReceive() } /** Could we send right now (i.e. either not actively receving or transmitting)? */ -bool SX1262Interface::canSendImmediately() +bool SX1262Interface::isActivelyReceiving() { - // 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 busyTx = sendingPacket != NULL; - bool busyRx = isReceiving && lora.getPacketLength() > 0; - - if (busyTx || busyRx) - DEBUG_MSG("Can not set now, busyTx=%d, busyRx=%d\n", busyTx, busyRx); - - return !busyTx && !busyRx; + return lora.getPacketLength() > 0; } bool SX1262Interface::sleep() diff --git a/src/rf95/SX1262Interface.h b/src/rf95/SX1262Interface.h index 39c6e7c09..18ab8ef75 100644 --- a/src/rf95/SX1262Interface.h +++ b/src/rf95/SX1262Interface.h @@ -36,8 +36,8 @@ class SX1262Interface : public RadioLibInterface */ virtual void enableInterrupt(void (*callback)()) { lora.setDio1Action(callback); } - /** Could we send right now (i.e. either not actively receiving or transmitting)? */ - virtual bool canSendImmediately(); + /** are we actively receiving a packet (only called during receiving state) */ + virtual bool isActivelyReceiving(); /** * Start waiting to receive a message @@ -47,6 +47,7 @@ class SX1262Interface : public RadioLibInterface * Add SNR data to received messages */ virtual void addReceiveMetadata(MeshPacket *mp); + private: void setStandby(); }; \ No newline at end of file