* new packet score function
This commit is contained in:
@@ -21,11 +21,6 @@ public:
|
|||||||
|
|
||||||
float packetScore(float snr, int packet_len) override {
|
float packetScore(float snr, int packet_len) override {
|
||||||
int sf = ((CustomLLCC68 *)_radio)->spreadingFactor;
|
int sf = ((CustomLLCC68 *)_radio)->spreadingFactor;
|
||||||
const float A = 0.7;
|
return packetScoreInt(snr, sf, packet_len);
|
||||||
const float B = 0.4;
|
|
||||||
|
|
||||||
float ber = exp(-pow(10, (snr / 10)) / (A * pow(10, (snr / 10)) + B * (1 << sf)));
|
|
||||||
|
|
||||||
return pow(1 - ber, packet_len * 8);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,11 +22,6 @@ public:
|
|||||||
|
|
||||||
float packetScore(float snr, int packet_len) override {
|
float packetScore(float snr, int packet_len) override {
|
||||||
int sf = ((CustomSX1262 *)_radio)->spreadingFactor;
|
int sf = ((CustomSX1262 *)_radio)->spreadingFactor;
|
||||||
const float A = 0.7;
|
return packetScoreInt(snr, sf, packet_len);
|
||||||
const float B = 0.4;
|
|
||||||
|
|
||||||
float ber = exp(-pow(10, (snr / 10)) / (A * pow(10, (snr / 10)) + B * (1 << sf)));
|
|
||||||
|
|
||||||
return pow(1 - ber, packet_len * 8);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,11 +21,6 @@ public:
|
|||||||
|
|
||||||
float packetScore(float snr, int packet_len) override {
|
float packetScore(float snr, int packet_len) override {
|
||||||
int sf = ((CustomSX1268 *)_radio)->spreadingFactor;
|
int sf = ((CustomSX1268 *)_radio)->spreadingFactor;
|
||||||
const float A = 0.7;
|
return packetScoreInt(snr, sf, packet_len);
|
||||||
const float B = 0.4;
|
|
||||||
|
|
||||||
float ber = exp(-pow(10, (snr / 10)) / (A * pow(10, (snr / 10)) + B * (1 << sf)));
|
|
||||||
|
|
||||||
return pow(1 - ber, packet_len * 8);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -96,3 +96,24 @@ float RadioLibWrapper::getLastRSSI() const {
|
|||||||
float RadioLibWrapper::getLastSNR() const {
|
float RadioLibWrapper::getLastSNR() const {
|
||||||
return _radio->getSNR();
|
return _radio->getSNR();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Approximate SNR threshold per SF for successful reception (based on Semtech datasheets)
|
||||||
|
static float snr_threshold[] = {
|
||||||
|
-7.5, // SF7 needs at least -7.5 dB SNR
|
||||||
|
-10, // SF8 needs at least -10 dB SNR
|
||||||
|
-12.5, // SF9 needs at least -12.5 dB SNR
|
||||||
|
-15, // SF10 needs at least -15 dB SNR
|
||||||
|
-17.5,// SF11 needs at least -17.5 dB SNR
|
||||||
|
-20 // SF12 needs at least -20 dB SNR
|
||||||
|
};
|
||||||
|
|
||||||
|
float RadioLibWrapper::packetScoreInt(float snr, int sf, int packet_len) {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ protected:
|
|||||||
uint32_t n_recv, n_sent;
|
uint32_t n_recv, n_sent;
|
||||||
|
|
||||||
void idle();
|
void idle();
|
||||||
|
float packetScoreInt(float snr, int sf, int packet_len);
|
||||||
|
|
||||||
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; }
|
||||||
@@ -26,7 +27,7 @@ public:
|
|||||||
virtual float getLastRSSI() const override;
|
virtual float getLastRSSI() const override;
|
||||||
virtual float getLastSNR() const override;
|
virtual float getLastSNR() const override;
|
||||||
|
|
||||||
float packetScore(float snr, int packet_len) override { return 0.85f; } // stub impl
|
float packetScore(float snr, int packet_len) override { return packetScoreInt(snr, 10, packet_len); } // assume sf=10
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -97,8 +97,8 @@ mesh::Packet* StaticPoolPacketManager::removeOutboundByIdx(int i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StaticPoolPacketManager::queueInbound(mesh::Packet* packet, uint32_t scheduled_for) {
|
void StaticPoolPacketManager::queueInbound(mesh::Packet* packet, uint32_t scheduled_for) {
|
||||||
// TODO
|
rx_queue.add(packet, 0, scheduled_for);
|
||||||
}
|
}
|
||||||
mesh::Packet* StaticPoolPacketManager::getNextInbound(uint32_t now) {
|
mesh::Packet* StaticPoolPacketManager::getNextInbound(uint32_t now) {
|
||||||
return NULL; // TODO
|
return rx_queue.get(now);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user