diff --git a/src/main.cpp b/src/main.cpp index f4e811f54..a6affea1f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -151,6 +151,8 @@ void userButtonPressedLong() screen.adjustBrightness(); } +RadioInterface *rIf = NULL; + void setup() { #ifdef USE_SEGGER @@ -298,8 +300,7 @@ void setup() digitalWrite(SX1262_ANT_SW, 1); #endif - // MUST BE AFTER service.init, so we have our radio config settings (from nodedb init) - RadioInterface *rIf = NULL; + // radio init MUST BE AFTER service.init, so we have our radio config settings (from nodedb init) #if defined(RF95_IRQ) if (!rIf) { @@ -405,6 +406,9 @@ void loop() loopWifi(); + // For debugging + // if (rIf) ((RadioLibInterface *)rIf)->isActivelyReceiving(); + // Show boot screen for first 3 seconds, then switch to normal operation. static bool showingBootScreen = true; if (showingBootScreen && (millis() > 3000)) { diff --git a/src/mesh/RadioLibInterface.h b/src/mesh/RadioLibInterface.h index d393077b5..b1d62bdb7 100644 --- a/src/mesh/RadioLibInterface.h +++ b/src/mesh/RadioLibInterface.h @@ -137,6 +137,11 @@ class RadioLibInterface : public RadioInterface, private concurrency::PeriodicTa */ virtual void startReceive() = 0; + /** are we actively receiving a packet (only called during receiving state) + * This method is only public to facilitate debugging. Do not call. + */ + virtual bool isActivelyReceiving() = 0; + private: /** if we have something waiting to send, start a short random timer so we can come check for collision before actually doing * the transmit @@ -176,9 +181,6 @@ class RadioLibInterface : public RadioInterface, private concurrency::PeriodicTa /** 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() = 0; - /** * Raw ISR handler that just calls our polymorphic method */ diff --git a/src/mesh/SX1262Interface.cpp b/src/mesh/SX1262Interface.cpp index b17acd9fe..a177441a4 100644 --- a/src/mesh/SX1262Interface.cpp +++ b/src/mesh/SX1262Interface.cpp @@ -179,16 +179,18 @@ void SX1262Interface::startReceive() /** Could we send right now (i.e. either not actively receving or transmitting)? */ bool SX1262Interface::isActivelyReceiving() { - // The IRQ status will be cleared when we start our read operation. Check if we've started a preamble, but haven't yet + // The IRQ status will be cleared when we start our read operation. Check if we've started a header, but haven't yet // received and handled the interrupt for reading the packet/handling errors. + // FIXME: it would be better to check for preamble, but we currently have our ISR not set to fire for packets that + // never even get a valid header, so we don't want preamble to get set and stay set due to noise on the network. uint16_t irq = lora.getIrqStatus(); - bool hasPreamble = (irq & SX126X_IRQ_PREAMBLE_DETECTED); + bool hasPreamble = (irq & SX126X_IRQ_HEADER_VALID); // this is not correct - often always true - need to add an extra conditional // size_t bytesPending = lora.getPacketLength(); - // if (hasPreamble || bytesPending) DEBUG_MSG("rx hasPre %d, bytes %d\n", hasPreamble, bytesPending); + // if (hasPreamble) DEBUG_MSG("rx hasPreamble\n"); return hasPreamble; }