* added Radio::loop() virtual function
* RadioLibWrapper: new isChannelActive() based on current RSSI being above noise_floor + THRESHOLD
This commit is contained in:
@@ -36,6 +36,8 @@ uint32_t Dispatcher::getCADFailMaxDuration() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Dispatcher::loop() {
|
void Dispatcher::loop() {
|
||||||
|
_radio->loop();
|
||||||
|
|
||||||
// check for radio 'stuck' in mode other than Rx
|
// check for radio 'stuck' in mode other than Rx
|
||||||
bool is_recv = _radio->isInRecvMode();
|
bool is_recv = _radio->isInRecvMode();
|
||||||
if (is_recv != prev_isrecv_mode) {
|
if (is_recv != prev_isrecv_mode) {
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void onSendFinished() = 0;
|
virtual void onSendFinished() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief do any processing needed on each loop cycle
|
||||||
|
*/
|
||||||
|
virtual void loop() { }
|
||||||
|
|
||||||
virtual bool isInRecvMode() const = 0;
|
virtual bool isInRecvMode() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ public:
|
|||||||
bool isReceivingPacket() override {
|
bool isReceivingPacket() override {
|
||||||
return ((CustomLLCC68 *)_radio)->isReceiving();
|
return ((CustomLLCC68 *)_radio)->isReceiving();
|
||||||
}
|
}
|
||||||
|
float getCurrentRSSI() override {
|
||||||
|
return ((CustomLLCC68 *)_radio)->getRSSI(false);
|
||||||
|
}
|
||||||
float getLastRSSI() const override { return ((CustomLLCC68 *)_radio)->getRSSI(); }
|
float getLastRSSI() const override { return ((CustomLLCC68 *)_radio)->getRSSI(); }
|
||||||
float getLastSNR() const override { return ((CustomLLCC68 *)_radio)->getSNR(); }
|
float getLastSNR() const override { return ((CustomLLCC68 *)_radio)->getSNR(); }
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ public:
|
|||||||
bool isReceivingPacket() override {
|
bool isReceivingPacket() override {
|
||||||
return ((CustomLR1110 *)_radio)->isReceiving();
|
return ((CustomLR1110 *)_radio)->isReceiving();
|
||||||
}
|
}
|
||||||
|
float getCurrentRSSI() override {
|
||||||
|
float rssi = -110;
|
||||||
|
((CustomLR1110 *)_radio)->getRssiInst(&rssi);
|
||||||
|
return rssi;
|
||||||
|
}
|
||||||
|
|
||||||
void onSendFinished() override {
|
void onSendFinished() override {
|
||||||
RadioLibWrapper::onSendFinished();
|
RadioLibWrapper::onSendFinished();
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ public:
|
|||||||
bool isReceivingPacket() override {
|
bool isReceivingPacket() override {
|
||||||
return ((CustomSTM32WLx *)_radio)->isReceiving();
|
return ((CustomSTM32WLx *)_radio)->isReceiving();
|
||||||
}
|
}
|
||||||
|
float getCurrentRSSI() override {
|
||||||
|
return ((CustomSTM32WLx *)_radio)->getRSSI(false);
|
||||||
|
}
|
||||||
float getLastRSSI() const override { return ((CustomSTM32WLx *)_radio)->getRSSI(); }
|
float getLastRSSI() const override { return ((CustomSTM32WLx *)_radio)->getRSSI(); }
|
||||||
float getLastSNR() const override { return ((CustomSTM32WLx *)_radio)->getSNR(); }
|
float getLastSNR() const override { return ((CustomSTM32WLx *)_radio)->getSNR(); }
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ public:
|
|||||||
bool isReceivingPacket() override {
|
bool isReceivingPacket() override {
|
||||||
return ((CustomSX1262 *)_radio)->isReceiving();
|
return ((CustomSX1262 *)_radio)->isReceiving();
|
||||||
}
|
}
|
||||||
|
float getCurrentRSSI() override {
|
||||||
|
return ((CustomSX1262 *)_radio)->getRSSI(false);
|
||||||
|
}
|
||||||
float getLastRSSI() const override { return ((CustomSX1262 *)_radio)->getRSSI(); }
|
float getLastRSSI() const override { return ((CustomSX1262 *)_radio)->getRSSI(); }
|
||||||
float getLastSNR() const override { return ((CustomSX1262 *)_radio)->getSNR(); }
|
float getLastSNR() const override { return ((CustomSX1262 *)_radio)->getSNR(); }
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ public:
|
|||||||
bool isReceivingPacket() override {
|
bool isReceivingPacket() override {
|
||||||
return ((CustomSX1268 *)_radio)->isReceiving();
|
return ((CustomSX1268 *)_radio)->isReceiving();
|
||||||
}
|
}
|
||||||
|
float getCurrentRSSI() override {
|
||||||
|
return ((CustomSX1268 *)_radio)->getRSSI(false);
|
||||||
|
}
|
||||||
float getLastRSSI() const override { return ((CustomSX1268 *)_radio)->getRSSI(); }
|
float getLastRSSI() const override { return ((CustomSX1268 *)_radio)->getRSSI(); }
|
||||||
float getLastSNR() const override { return ((CustomSX1268 *)_radio)->getSNR(); }
|
float getLastSNR() const override { return ((CustomSX1268 *)_radio)->getSNR(); }
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ public:
|
|||||||
bool isReceivingPacket() override {
|
bool isReceivingPacket() override {
|
||||||
return ((CustomSX1276 *)_radio)->isReceiving();
|
return ((CustomSX1276 *)_radio)->isReceiving();
|
||||||
}
|
}
|
||||||
|
float getCurrentRSSI() override {
|
||||||
|
return ((CustomSX1276 *)_radio)->getRSSI(false);
|
||||||
|
}
|
||||||
float getLastRSSI() const override { return ((CustomSX1276 *)_radio)->getRSSI(); }
|
float getLastRSSI() const override { return ((CustomSX1276 *)_radio)->getRSSI(); }
|
||||||
float getLastSNR() const override { return ((CustomSX1276 *)_radio)->getSNR(); }
|
float getLastSNR() const override { return ((CustomSX1276 *)_radio)->getSNR(); }
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,12 @@
|
|||||||
#define STATE_TX_DONE 4
|
#define STATE_TX_DONE 4
|
||||||
#define STATE_INT_READY 16
|
#define STATE_INT_READY 16
|
||||||
|
|
||||||
|
#ifndef INTERFERENCE_THRESHOLD_DB
|
||||||
|
#define INTERFERENCE_THRESHOLD_DB 14
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NUM_NOISE_FLOOR_SAMPLES 64
|
||||||
|
|
||||||
static volatile uint8_t state = STATE_IDLE;
|
static volatile uint8_t state = STATE_IDLE;
|
||||||
|
|
||||||
// this function is called when a complete packet
|
// this function is called when a complete packet
|
||||||
@@ -28,6 +34,12 @@ void RadioLibWrapper::begin() {
|
|||||||
if (_board->getStartupReason() == BD_STARTUP_RX_PACKET) { // received a LoRa packet (while in deep sleep)
|
if (_board->getStartupReason() == BD_STARTUP_RX_PACKET) { // received a LoRa packet (while in deep sleep)
|
||||||
setFlag(); // LoRa packet is already received
|
setFlag(); // LoRa packet is already received
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_noise_floor = -140;
|
||||||
|
|
||||||
|
// start average out some samples
|
||||||
|
_num_floor_samples = 0;
|
||||||
|
_floor_sample_sum = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioLibWrapper::idle() {
|
void RadioLibWrapper::idle() {
|
||||||
@@ -35,6 +47,20 @@ void RadioLibWrapper::idle() {
|
|||||||
state = STATE_IDLE; // need another startReceive()
|
state = STATE_IDLE; // need another startReceive()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RadioLibWrapper::loop() {
|
||||||
|
if (state == STATE_RX && _num_floor_samples < NUM_NOISE_FLOOR_SAMPLES) {
|
||||||
|
if (!isReceivingPacket()) {
|
||||||
|
_num_floor_samples++;
|
||||||
|
_floor_sample_sum += getCurrentRSSI();
|
||||||
|
}
|
||||||
|
} else if (_floor_sample_sum != 0) {
|
||||||
|
_noise_floor = _floor_sample_sum / NUM_NOISE_FLOOR_SAMPLES;
|
||||||
|
_floor_sample_sum = 0;
|
||||||
|
|
||||||
|
MESH_DEBUG_PRINTLN("RadioLibWrapper: noise_floor = %d", (int)_noise_floor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RadioLibWrapper::startRecv() {
|
void RadioLibWrapper::startRecv() {
|
||||||
int err = _radio->startReceive();
|
int err = _radio->startReceive();
|
||||||
if (err == RADIOLIB_ERR_NONE) {
|
if (err == RADIOLIB_ERR_NONE) {
|
||||||
@@ -109,15 +135,7 @@ void RadioLibWrapper::onSendFinished() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool RadioLibWrapper::isChannelActive() {
|
bool RadioLibWrapper::isChannelActive() {
|
||||||
idle(); // put sx126x into standby
|
return getCurrentRSSI() > _noise_floor + INTERFERENCE_THRESHOLD_DB;
|
||||||
// do some basic CAD (blocks for ~12780 micros (on SF 10)!)
|
|
||||||
bool activity = _radio->scanChannel() == RADIOLIB_LORA_DETECTED;
|
|
||||||
if (activity) {
|
|
||||||
startRecv();
|
|
||||||
} else {
|
|
||||||
idle();
|
|
||||||
}
|
|
||||||
return activity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float RadioLibWrapper::getLastRSSI() const {
|
float RadioLibWrapper::getLastRSSI() const {
|
||||||
|
|||||||
@@ -8,11 +8,15 @@ protected:
|
|||||||
PhysicalLayer* _radio;
|
PhysicalLayer* _radio;
|
||||||
mesh::MainBoard* _board;
|
mesh::MainBoard* _board;
|
||||||
uint32_t n_recv, n_sent;
|
uint32_t n_recv, n_sent;
|
||||||
|
int16_t _noise_floor;
|
||||||
|
uint16_t _num_floor_samples;
|
||||||
|
int32_t _floor_sample_sum;
|
||||||
|
|
||||||
void idle();
|
void idle();
|
||||||
void startRecv();
|
void startRecv();
|
||||||
float packetScoreInt(float snr, int sf, int packet_len);
|
float packetScoreInt(float snr, int sf, int packet_len);
|
||||||
virtual bool isReceivingPacket() =0;
|
virtual bool isReceivingPacket() =0;
|
||||||
|
virtual float getCurrentRSSI() =0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board) { n_recv = n_sent = 0; }
|
RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board) { n_recv = n_sent = 0; }
|
||||||
@@ -32,6 +36,8 @@ public:
|
|||||||
return isChannelActive();
|
return isChannelActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loop() override;
|
||||||
|
|
||||||
uint32_t getPacketsRecv() const { return n_recv; }
|
uint32_t getPacketsRecv() const { return n_recv; }
|
||||||
uint32_t getPacketsSent() const { return n_sent; }
|
uint32_t getPacketsSent() const { return n_sent; }
|
||||||
void resetStats() { n_recv = n_sent = 0; }
|
void resetStats() { n_recv = n_sent = 0; }
|
||||||
|
|||||||
Reference in New Issue
Block a user