* dynamic noise floor sampling
This commit is contained in:
@@ -35,7 +35,7 @@ void RadioLibWrapper::begin() {
|
||||
setFlag(); // LoRa packet is already received
|
||||
}
|
||||
|
||||
_noise_floor = -140;
|
||||
_noise_floor = 0;
|
||||
|
||||
// start average out some samples
|
||||
_num_floor_samples = 0;
|
||||
@@ -47,13 +47,23 @@ void RadioLibWrapper::idle() {
|
||||
state = STATE_IDLE; // need another startReceive()
|
||||
}
|
||||
|
||||
void RadioLibWrapper::triggerNoiseFloorCalibrate() {
|
||||
if (_num_floor_samples >= NUM_NOISE_FLOOR_SAMPLES) { // ignore trigger if currently sampling
|
||||
_num_floor_samples = 0;
|
||||
_floor_sample_sum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void RadioLibWrapper::loop() {
|
||||
if (state == STATE_RX && _num_floor_samples < NUM_NOISE_FLOOR_SAMPLES) {
|
||||
if (!isReceivingPacket()) {
|
||||
_num_floor_samples++;
|
||||
_floor_sample_sum += getCurrentRSSI();
|
||||
int rssi = getCurrentRSSI();
|
||||
if (rssi < _noise_floor + INTERFERENCE_THRESHOLD_DB) { // only consider samples below current floor+THRESHOLD
|
||||
_num_floor_samples++;
|
||||
_floor_sample_sum += rssi;
|
||||
}
|
||||
}
|
||||
} else if (_floor_sample_sum != 0) {
|
||||
} else if (_num_floor_samples >= NUM_NOISE_FLOOR_SAMPLES && _floor_sample_sum != 0) {
|
||||
_noise_floor = _floor_sample_sum / NUM_NOISE_FLOOR_SAMPLES;
|
||||
_floor_sample_sum = 0;
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ protected:
|
||||
void startRecv();
|
||||
float packetScoreInt(float snr, int sf, int packet_len);
|
||||
virtual bool isReceivingPacket() =0;
|
||||
virtual float getCurrentRSSI() =0;
|
||||
|
||||
public:
|
||||
RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board) { n_recv = n_sent = 0; }
|
||||
@@ -36,6 +35,11 @@ public:
|
||||
return isChannelActive();
|
||||
}
|
||||
|
||||
virtual float getCurrentRSSI() =0;
|
||||
|
||||
int getNoiseFloor() const override { return _noise_floor; }
|
||||
void triggerNoiseFloorCalibrate() override;
|
||||
|
||||
void loop() override;
|
||||
|
||||
uint32_t getPacketsRecv() const { return n_recv; }
|
||||
|
||||
Reference in New Issue
Block a user