mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
This change counts when readData returns an err code other than RADIOLIB_ERR_NONE. In most cases this is going to be a CRC error. This counter is exposed in the `stats-packets` command, and in the repeater stats payload (4 additional bytes to the payload, which is now 56 bytes with this change. My incompetent robot claims the total payload size is 96 bytes (unverified but probably close).
72 lines
2.1 KiB
C++
72 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <Mesh.h>
|
|
#include <RadioLib.h>
|
|
|
|
class RadioLibWrapper : public mesh::Radio {
|
|
protected:
|
|
PhysicalLayer* _radio;
|
|
mesh::MainBoard* _board;
|
|
uint32_t n_recv, n_sent, n_recv_errors;
|
|
int16_t _noise_floor, _threshold;
|
|
uint16_t _num_floor_samples;
|
|
int32_t _floor_sample_sum;
|
|
|
|
void idle();
|
|
void startRecv();
|
|
float packetScoreInt(float snr, int sf, int packet_len);
|
|
virtual bool isReceivingPacket() =0;
|
|
|
|
public:
|
|
RadioLibWrapper(PhysicalLayer& radio, mesh::MainBoard& board) : _radio(&radio), _board(&board) { n_recv = n_sent = 0; }
|
|
|
|
void begin() override;
|
|
virtual void powerOff() { _radio->sleep(); }
|
|
int recvRaw(uint8_t* bytes, int sz) override;
|
|
uint32_t getEstAirtimeFor(int len_bytes) override;
|
|
bool startSendRaw(const uint8_t* bytes, int len) override;
|
|
bool isSendComplete() override;
|
|
void onSendFinished() override;
|
|
bool isInRecvMode() const override;
|
|
bool isChannelActive();
|
|
|
|
bool isReceiving() override {
|
|
if (isReceivingPacket()) return true;
|
|
|
|
return isChannelActive();
|
|
}
|
|
|
|
virtual float getCurrentRSSI() =0;
|
|
|
|
int getNoiseFloor() const override { return _noise_floor; }
|
|
void triggerNoiseFloorCalibrate(int threshold) override;
|
|
void resetAGC() override;
|
|
|
|
void loop() override;
|
|
|
|
uint32_t getPacketsRecv() const { return n_recv; }
|
|
uint32_t getPacketsRecvErrors() const { return n_recv_errors; }
|
|
uint32_t getPacketsSent() const { return n_sent; }
|
|
void resetStats() { n_recv = n_sent = n_recv_errors = 0; }
|
|
|
|
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
|
|
};
|
|
|
|
/**
|
|
* \brief an RNG impl using the noise from the LoRa radio as entropy.
|
|
* NOTE: this is VERY SLOW! Use only for things like creating new LocalIdentity
|
|
*/
|
|
class RadioNoiseListener : public mesh::RNG {
|
|
PhysicalLayer* _radio;
|
|
public:
|
|
RadioNoiseListener(PhysicalLayer& radio): _radio(&radio) { }
|
|
|
|
void random(uint8_t* dest, size_t sz) override {
|
|
for (int i = 0; i < sz; i++) {
|
|
dest[i] = _radio->randomByte() ^ (::random(0, 256) & 0xFF);
|
|
}
|
|
}
|
|
};
|