SX1262: Tried making RX more reliable
... it didn't get any more reliable.
This commit is contained in:
parent
dfadaab667
commit
320f05d20f
@ -68,13 +68,14 @@ bool RadiolibThreadedDevice::isThreadInterrupted() const {
|
||||
int32_t RadiolibThreadedDevice::threadMain() {
|
||||
|
||||
int rc = doBegin(getModulation());
|
||||
bool hasRx = false;
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
setState(State::On);
|
||||
|
||||
while (!isThreadInterrupted()) {
|
||||
doListen();
|
||||
hasRx = doListen();
|
||||
|
||||
// Thread might've been interrupted in the meanwhile
|
||||
if (isThreadInterrupted()) {
|
||||
@ -84,7 +85,9 @@ int32_t RadiolibThreadedDevice::threadMain() {
|
||||
if (getTxQueueSize() > 0) {
|
||||
doTransmit();
|
||||
} else {
|
||||
doReceive();
|
||||
if (hasRx) {
|
||||
doReceive();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ protected:
|
||||
virtual int doBegin(const Modulation modulation) = 0;
|
||||
virtual void doEnd() = 0;
|
||||
virtual void doTransmit() = 0;
|
||||
virtual void doListen() = 0;
|
||||
virtual bool doListen() = 0;
|
||||
virtual void doReceive() = 0;
|
||||
|
||||
public:
|
||||
|
||||
@ -396,7 +396,7 @@ void Sx1262::doTransmit() {
|
||||
uint16_t rc = RADIOLIB_ERR_NONE;
|
||||
rc = radio.standby();
|
||||
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) {
|
||||
@ -412,6 +412,9 @@ void Sx1262::doTransmit() {
|
||||
auto txEventFlags = events.wait(SX1262_INTERRUPT_BIT | SX1262_DIO1_EVENT_BIT, tt::EventFlag::WaitAny,
|
||||
pdMS_TO_TICKS(SX1262_TX_TIMEOUT_MILLIS));
|
||||
|
||||
// Clean up after transmission
|
||||
radio.finishTransmit();
|
||||
|
||||
// Thread might've been interrupted in the meanwhile
|
||||
if (isThreadInterrupted()) {
|
||||
return;
|
||||
@ -430,13 +433,31 @@ void Sx1262::doTransmit() {
|
||||
}
|
||||
}
|
||||
|
||||
void Sx1262::doListen() {
|
||||
bool Sx1262::doListen() {
|
||||
uint16_t rc = RADIOLIB_ERR_NONE;
|
||||
|
||||
if (getModulation() != Modulation::LrFhss) {
|
||||
radio.startReceive();
|
||||
events.wait(SX1262_INTERRUPT_BIT | SX1262_DIO1_EVENT_BIT | SX1262_QUEUED_TX_BIT);
|
||||
//rc = radio.startReceive(SX1262_RX_TIMEOUT_MILLIS);
|
||||
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 {
|
||||
// LR-FHSS modem only supports TX
|
||||
events.wait(SX1262_INTERRUPT_BIT | SX1262_QUEUED_TX_BIT);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -463,6 +484,7 @@ void Sx1262::doReceive() {
|
||||
};
|
||||
|
||||
publishRx(rxPacket);
|
||||
radio.finishReceive();
|
||||
}
|
||||
|
||||
// A delay before a new command improves reliability
|
||||
|
||||
@ -27,6 +27,7 @@ public:
|
||||
private:
|
||||
static constexpr auto SX1262_DEFAULT_NAME = "SX1262";
|
||||
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_INTERRUPT_BIT = BIT0;
|
||||
static constexpr auto SX1262_DIO1_EVENT_BIT = BIT1;
|
||||
@ -74,7 +75,7 @@ protected:
|
||||
virtual int doBegin(const Modulation modulation) override;
|
||||
virtual void doEnd() override;
|
||||
virtual void doTransmit() override;
|
||||
virtual void doListen() override;
|
||||
virtual bool doListen() override;
|
||||
virtual void doReceive() override;
|
||||
|
||||
public:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user