Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/helpers/radiolib/CustomLLCC68Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,5 @@ class CustomLLCC68Wrapper : public RadioLibWrapper {
}
float getLastRSSI() const override { return ((CustomLLCC68 *)_radio)->getRSSI(); }
float getLastSNR() const override { return ((CustomLLCC68 *)_radio)->getSNR(); }

float packetScore(float snr, int packet_len) override {
int sf = ((CustomLLCC68 *)_radio)->spreadingFactor;
return packetScoreInt(snr, sf, packet_len);
}
int getCurrentSF() const override { return ((CustomLLCC68 *)_radio)->spreadingFactor; }
};
1 change: 1 addition & 0 deletions src/helpers/radiolib/CustomLR1110Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ class CustomLR1110Wrapper : public RadioLibWrapper {
float getLastRSSI() const override { return ((CustomLR1110 *)_radio)->getRSSI(); }
float getLastSNR() const override { return ((CustomLR1110 *)_radio)->getSNR(); }
int16_t setRxBoostedGainMode(bool en) { return ((CustomLR1110 *)_radio)->setRxBoostedGainMode(en); };
int getCurrentSF() const override { return ((CustomLR1110 *)_radio)->spreadingFactor; }
};
6 changes: 1 addition & 5 deletions src/helpers/radiolib/CustomSTM32WLxWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,5 @@ class CustomSTM32WLxWrapper : public RadioLibWrapper {
}
float getLastRSSI() const override { return ((CustomSTM32WLx *)_radio)->getRSSI(); }
float getLastSNR() const override { return ((CustomSTM32WLx *)_radio)->getSNR(); }

float packetScore(float snr, int packet_len) override {
int sf = ((CustomSTM32WLx *)_radio)->spreadingFactor;
return packetScoreInt(snr, sf, packet_len);
}
int getCurrentSF() const override { return ((CustomSTM32WLx *)_radio)->spreadingFactor; }
};
6 changes: 1 addition & 5 deletions src/helpers/radiolib/CustomSX1262Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,5 @@ class CustomSX1262Wrapper : public RadioLibWrapper {
}
float getLastRSSI() const override { return ((CustomSX1262 *)_radio)->getRSSI(); }
float getLastSNR() const override { return ((CustomSX1262 *)_radio)->getSNR(); }

float packetScore(float snr, int packet_len) override {
int sf = ((CustomSX1262 *)_radio)->spreadingFactor;
return packetScoreInt(snr, sf, packet_len);
}
int getCurrentSF() const override { return ((CustomSX1262 *)_radio)->spreadingFactor; }
};
6 changes: 1 addition & 5 deletions src/helpers/radiolib/CustomSX1268Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,5 @@ class CustomSX1268Wrapper : public RadioLibWrapper {
}
float getLastRSSI() const override { return ((CustomSX1268 *)_radio)->getRSSI(); }
float getLastSNR() const override { return ((CustomSX1268 *)_radio)->getSNR(); }

float packetScore(float snr, int packet_len) override {
int sf = ((CustomSX1268 *)_radio)->spreadingFactor;
return packetScoreInt(snr, sf, packet_len);
}
int getCurrentSF() const override { return ((CustomSX1268 *)_radio)->spreadingFactor; }
};
6 changes: 1 addition & 5 deletions src/helpers/radiolib/CustomSX1276Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,5 @@ class CustomSX1276Wrapper : public RadioLibWrapper {
}
float getLastRSSI() const override { return ((CustomSX1276 *)_radio)->getRSSI(); }
float getLastSNR() const override { return ((CustomSX1276 *)_radio)->getSNR(); }

float packetScore(float snr, int packet_len) override {
int sf = ((CustomSX1276 *)_radio)->spreadingFactor;
return packetScoreInt(snr, sf, packet_len);
}
int getCurrentSF() const override { return ((CustomSX1276 *)_radio)->spreadingFactor; }
};
19 changes: 11 additions & 8 deletions src/helpers/radiolib/RadioLibWrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,16 @@ static float snr_threshold[] = {
-20 // SF12 needs at least -20 dB SNR
};

float RadioLibWrapper::packetScoreInt(float snr, int sf, int packet_len) {
float RadioLibWrapper::packetScoreByAirtime(float snr, int sf, uint32_t airtime_ms) {
if (sf < 7) return 0.0f;

if (snr < snr_threshold[sf - 7]) return 0.0f; // Below threshold, no chance of success

auto success_rate_based_on_snr = (snr - snr_threshold[sf - 7]) / 10.0;
auto collision_penalty = 1 - (packet_len / 256.0); // Assuming max packet of 256 bytes

return max(0.0, min(1.0, success_rate_based_on_snr * collision_penalty));
if (snr < snr_threshold[sf - 7]) return 0.0f;

float success = (snr - snr_threshold[sf - 7]) / 10.0f;
// Penalize by time-on-air to account for BW/CR/SF.
// 0 ms => no penalty, ~300 ms+ => strong penalty (tunable).
float airtime_penalty = 1.0f - min(1.0f, (float)airtime_ms / 300.0f);
float score = success * airtime_penalty;
if (score < 0.0f) score = 0.0f;
if (score > 1.0f) score = 1.0f;
return score;
}
6 changes: 4 additions & 2 deletions src/helpers/radiolib/RadioLibWrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RadioLibWrapper : public mesh::Radio {

void idle();
void startRecv();
float packetScoreInt(float snr, int sf, int packet_len);
float packetScoreByAirtime(float snr, int sf, uint32_t airtime_ms);
virtual bool isReceivingPacket() =0;

public:
Expand Down Expand Up @@ -50,7 +50,9 @@ class RadioLibWrapper : public mesh::Radio {
virtual float getLastRSSI() const override;
virtual float getLastSNR() const override;

float packetScore(float snr, int packet_len) override { return packetScoreInt(snr, 10, packet_len); } // assume sf=10
// Default assumed SF=10, kept as fallback for backward compatibility.
virtual int getCurrentSF() const { return 10; }
float packetScore(float snr, int packet_len) override { return packetScoreByAirtime(snr, getCurrentSF(), getEstAirtimeFor(packet_len)); }
};

/**
Expand Down