Bläddra i källkod

* basic CAD before TX, for sx126x wrappers

Scott Powell 1 år sedan
förälder
incheckning
de27dfacb6

+ 1 - 1
src/Dispatcher.cpp

@@ -121,7 +121,7 @@ void Dispatcher::checkRecv() {
 void Dispatcher::checkSend() {
   if (_mgr->getOutboundCount() == 0) return;  // nothing waiting to send
   if (!millisHasNowPassed(next_tx_time)) return;   // still in 'radio silence' phase (from airtime budget setting)
-  if (_radio->isReceiving()) return;  // check if radio is currently mid-receive
+  if (_radio->isReceiving()) return;  // LBT - check if radio is currently mid-receive, or if channel activity
 
   outbound = _mgr->getNextOutbound(_ms->getMillis());
   if (outbound) {

+ 8 - 1
src/helpers/CustomSX1262Wrapper.h

@@ -6,7 +6,14 @@
 class CustomSX1262Wrapper : public RadioLibWrapper {
 public:
   CustomSX1262Wrapper(CustomSX1262& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { }
-  bool isReceiving() override { return ((CustomSX1262 *)_radio)->isReceiving(); }
+  bool isReceiving() override { 
+    if (((CustomSX1262 *)_radio)->isReceiving()) return true;
+
+    idle();  // put sx126x into standby
+    // do some basic CAD (blocks for ~12780 micros (on SF 10)!)
+    if (((CustomSX1262 *)_radio)->scanChannel() == RADIOLIB_LORA_DETECTED) return true;
+    return false;
+  }
   float getLastRSSI() const override { return ((CustomSX1262 *)_radio)->getRSSI(); }
   float getLastSNR() const override { return ((CustomSX1262 *)_radio)->getSNR(); }
 };

+ 8 - 1
src/helpers/CustomSX1268Wrapper.h

@@ -6,7 +6,14 @@
 class CustomSX1268Wrapper : public RadioLibWrapper {
 public:
   CustomSX1268Wrapper(CustomSX1268& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { }
-  bool isReceiving() override { return ((CustomSX1268 *)_radio)->isReceiving(); }
+  bool isReceiving() override { 
+    if (((CustomSX1268 *)_radio)->isReceiving()) return true;
+
+    idle();  // put sx126x into standby
+    // do some basic CAD (blocks for ~12780 micros (on SF 10)!)
+    if (((CustomSX1268 *)_radio)->scanChannel() == RADIOLIB_LORA_DETECTED) return true;
+    return false;
+  }
   float getLastRSSI() const override { return ((CustomSX1268 *)_radio)->getRSSI(); }
   float getLastSNR() const override { return ((CustomSX1268 *)_radio)->getSNR(); }
 };

+ 5 - 0
src/helpers/RadioLibWrappers.cpp

@@ -30,6 +30,11 @@ void RadioLibWrapper::begin() {
   }
 }
 
+void RadioLibWrapper::idle() {
+  _radio->standby();
+  state = STATE_IDLE;   // need another startReceive()
+}
+
 int RadioLibWrapper::recvRaw(uint8_t* bytes, int sz) {
   if (state & STATE_INT_READY) {
     int len = _radio->getPacketLength();

+ 2 - 0
src/helpers/RadioLibWrappers.h

@@ -9,6 +9,8 @@ protected:
   mesh::MainBoard* _board;
   uint32_t n_recv, n_sent;
 
+  void idle();
+
 public:
   RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board) { n_recv = n_sent = 0; }