SX1262: Tried making RX more reliable

... it didn't get any more reliable.
This commit is contained in:
Dominic Höglinger 2025-09-30 05:16:40 +02:00
parent dfadaab667
commit 320f05d20f
4 changed files with 34 additions and 8 deletions

View File

@ -68,13 +68,14 @@ bool RadiolibThreadedDevice::isThreadInterrupted() const {
int32_t RadiolibThreadedDevice::threadMain() { int32_t RadiolibThreadedDevice::threadMain() {
int rc = doBegin(getModulation()); int rc = doBegin(getModulation());
bool hasRx = false;
if (rc != 0) { if (rc != 0) {
return rc; return rc;
} }
setState(State::On); setState(State::On);
while (!isThreadInterrupted()) { while (!isThreadInterrupted()) {
doListen(); hasRx = doListen();
// Thread might've been interrupted in the meanwhile // Thread might've been interrupted in the meanwhile
if (isThreadInterrupted()) { if (isThreadInterrupted()) {
@ -84,7 +85,9 @@ int32_t RadiolibThreadedDevice::threadMain() {
if (getTxQueueSize() > 0) { if (getTxQueueSize() > 0) {
doTransmit(); doTransmit();
} else { } else {
doReceive(); if (hasRx) {
doReceive();
}
} }
} }

View File

@ -20,7 +20,7 @@ protected:
virtual int doBegin(const Modulation modulation) = 0; virtual int doBegin(const Modulation modulation) = 0;
virtual void doEnd() = 0; virtual void doEnd() = 0;
virtual void doTransmit() = 0; virtual void doTransmit() = 0;
virtual void doListen() = 0; virtual bool doListen() = 0;
virtual void doReceive() = 0; virtual void doReceive() = 0;
public: public:

View File

@ -396,7 +396,7 @@ void Sx1262::doTransmit() {
uint16_t rc = RADIOLIB_ERR_NONE; uint16_t rc = RADIOLIB_ERR_NONE;
rc = radio.standby(); rc = radio.standby();
if (rc != RADIOLIB_ERR_NONE) { if (rc != RADIOLIB_ERR_NONE) {
TT_LOG_W(TAG, "RadioLib returned %hi on standby", rc); TT_LOG_W(TAG, "RadioLib returned %hi on TX standby", rc);
} }
if (getModulation() == Modulation::Fsk) { if (getModulation() == Modulation::Fsk) {
@ -412,6 +412,9 @@ void Sx1262::doTransmit() {
auto txEventFlags = events.wait(SX1262_INTERRUPT_BIT | SX1262_DIO1_EVENT_BIT, tt::EventFlag::WaitAny, auto txEventFlags = events.wait(SX1262_INTERRUPT_BIT | SX1262_DIO1_EVENT_BIT, tt::EventFlag::WaitAny,
pdMS_TO_TICKS(SX1262_TX_TIMEOUT_MILLIS)); pdMS_TO_TICKS(SX1262_TX_TIMEOUT_MILLIS));
// Clean up after transmission
radio.finishTransmit();
// Thread might've been interrupted in the meanwhile // Thread might've been interrupted in the meanwhile
if (isThreadInterrupted()) { if (isThreadInterrupted()) {
return; return;
@ -430,13 +433,31 @@ void Sx1262::doTransmit() {
} }
} }
void Sx1262::doListen() { bool Sx1262::doListen() {
uint16_t rc = RADIOLIB_ERR_NONE;
if (getModulation() != Modulation::LrFhss) { if (getModulation() != Modulation::LrFhss) {
radio.startReceive(); //rc = radio.startReceive(SX1262_RX_TIMEOUT_MILLIS);
events.wait(SX1262_INTERRUPT_BIT | SX1262_DIO1_EVENT_BIT | SX1262_QUEUED_TX_BIT); rc = radio.startReceive();
if (rc == RADIOLIB_ERR_NONE) {
auto flags = events.wait(SX1262_INTERRUPT_BIT | SX1262_DIO1_EVENT_BIT | SX1262_QUEUED_TX_BIT, tt::EventFlag::WaitAny,
pdMS_TO_TICKS(SX1262_RX_TIMEOUT_MILLIS));
if (!(flags & SX1262_DIO1_EVENT_BIT)) {
TT_LOG_D(TAG, "SX1262 DIO RX Timeout");
rc = radio.standby();
if (rc != RADIOLIB_ERR_NONE) {
TT_LOG_W(TAG, "RadioLib returned %hi on RX standby", rc);
}
return false;
} else {
return true;
}
}
return false;
} else { } else {
// LR-FHSS modem only supports TX // LR-FHSS modem only supports TX
events.wait(SX1262_INTERRUPT_BIT | SX1262_QUEUED_TX_BIT); events.wait(SX1262_INTERRUPT_BIT | SX1262_QUEUED_TX_BIT);
return false;
} }
} }
@ -463,6 +484,7 @@ void Sx1262::doReceive() {
}; };
publishRx(rxPacket); publishRx(rxPacket);
radio.finishReceive();
} }
// A delay before a new command improves reliability // A delay before a new command improves reliability

View File

@ -27,6 +27,7 @@ public:
private: private:
static constexpr auto SX1262_DEFAULT_NAME = "SX1262"; static constexpr auto SX1262_DEFAULT_NAME = "SX1262";
static constexpr auto SX1262_COOLDOWN_MILLIS = 100; static constexpr auto SX1262_COOLDOWN_MILLIS = 100;
static constexpr auto SX1262_RX_TIMEOUT_MILLIS = 10'000;
static constexpr auto SX1262_TX_TIMEOUT_MILLIS = 2000; static constexpr auto SX1262_TX_TIMEOUT_MILLIS = 2000;
static constexpr auto SX1262_INTERRUPT_BIT = BIT0; static constexpr auto SX1262_INTERRUPT_BIT = BIT0;
static constexpr auto SX1262_DIO1_EVENT_BIT = BIT1; static constexpr auto SX1262_DIO1_EVENT_BIT = BIT1;
@ -74,7 +75,7 @@ protected:
virtual int doBegin(const Modulation modulation) override; virtual int doBegin(const Modulation modulation) override;
virtual void doEnd() override; virtual void doEnd() override;
virtual void doTransmit() override; virtual void doTransmit() override;
virtual void doListen() override; virtual bool doListen() override;
virtual void doReceive() override; virtual void doReceive() override;
public: public: