Repeater, room server, sensor, companion: a node with the RX duty cycle on no longer stops transmitting

Changelog: Repeater, room server, sensor, companion: a node with the RX duty cycle (`radio.rxps`) on no longer stops transmitting, `set radio.rxps off` takes effect at once, and a node silent for weeks keeps sending
Changelog-cs: Repeater, room server, sensor, companion: uzel se zapnutým RX duty cycle (`radio.rxps`) už nepřestane vysílat, `set radio.rxps off` platí hned a uzel, který týdny mlčel, dál vysílá
Changelog-topic: rxps-stall-46
This commit is contained in:
tth committed 2026-12-04 00:09:28 +01:00
1 parent 63823f526b
commit 9daead0089
3 files changed
+60 -3

No files matched your search

+6
View File
@@ -157,6 +157,12 @@ void Dispatcher::loop() {
next_agc_reset_time = futureMillis(getAGCResetInterval());
}
// Keep an already-elapsed next_tx_time from ageing past 2^31 ms (~24.8 days)
// during long TX silence and wrapping into the future in millisHasNowPassed().
if (millisHasNowPassed(next_tx_time)) {
next_tx_time = _ms->getMillis() - 1;
}
// check inbound (delayed) queue
{
Packet* pkt = _mgr->getNextInbound(_ms->getMillis());
+18 -3
View File
@@ -120,6 +120,7 @@ void RadioLibWrapper::resetAGC() {
_nf_last_calib = 0;
#endif
doResetAGC();
resetReceivingState();
state = STATE_IDLE; // trigger a startReceive()
// Reset noise floor sampling so it reconverges from scratch.
@@ -217,7 +218,10 @@ void RadioLibWrapper::startRecv() {
int err = _radio->startReceive();
#endif
if (err == RADIOLIB_ERR_NONE) {
state = STATE_RX;
// Preserve STATE_INT_READY if a DIO1 edge fired before startReceive() returned.
noInterrupts();
state = (state & STATE_INT_READY) | STATE_RX;
interrupts();
} else {
MESH_DEBUG_PRINTLN("RadioLibWrapper: error: startReceive(%d)", err);
}
@@ -498,12 +502,23 @@ uint32_t RadioLibWrapper::getEstAirtimeFor(int len_bytes) {
bool RadioLibWrapper::startSendRaw(const uint8_t* bytes, int len) {
#ifdef WITH_RX_POWERSAVING
if (_rx_ps_armed) stopReceiveDutyCycle();
if (_rx_ps_armed) {
stopReceiveDutyCycle();
} else {
_radio->standby();
}
#else
_radio->standby();
#endif
_board->onBeforeTransmit();
// Enter STATE_TX_WAIT after standby() (so no late RX_DONE can fire) and
// before startTransmit() (so a TX_DONE arriving after SoftDevice preemption
// cannot be overwritten by a late state store).
noInterrupts();
state = STATE_TX_WAIT;
interrupts();
int err = _radio->startTransmit((uint8_t *) bytes, len);
if (err == RADIOLIB_ERR_NONE) {
state = STATE_TX_WAIT;
return true;
}
MESH_DEBUG_PRINTLN("RadioLibWrapper: error: startTransmit(%d)", err);
+36
View File
@@ -40,6 +40,8 @@ public:
int standby_calls = 0;
int start_receive_calls = 0;
int read_data_calls = 0;
bool fire_dio1_in_start_tx = false;
bool fire_dio1_in_start_rx = false;
void setPacketReceivedAction(void (*func)(void)) override { isr_fn = func; }
void fireDio1() { if (isr_fn) isr_fn(); }
@@ -58,6 +60,18 @@ public:
int16_t startReceive() override {
start_receive_calls++;
irq_flags = 0;
if (fire_dio1_in_start_rx) {
fire_dio1_in_start_rx = false;
irq_flags = (1UL << RADIOLIB_IRQ_RX_DONE);
fireDio1();
}
return RADIOLIB_ERR_NONE;
}
int16_t startTransmit(uint8_t*, size_t) override {
if (fire_dio1_in_start_tx) {
fire_dio1_in_start_tx = false;
fireDio1();
}
return RADIOLIB_ERR_NONE;
}
size_t getPacketLength(bool) override { return next_pkt_len; }
@@ -230,6 +244,28 @@ TEST_F(RxpsFixture, KickRxClearsIrqAndResetsReceivingState) {
EXPECT_GT(wrap.reset_receiving_calls, 0);
}
TEST_F(RxpsFixture, TxDoneInsideStartTransmitIsNotLost) {
// Simulate TX_DONE arriving before startTransmit() returns (e.g. BLE
// SoftDevice preemption on nRF52).
radio.fire_dio1_in_start_tx = true;
uint8_t tx[4] = {1, 2, 3, 4};
ASSERT_TRUE(wrap.startSendRaw(tx, sizeof(tx)));
EXPECT_TRUE(wrap.isSendComplete());
wrap.onSendFinished();
}
TEST_F(RxpsFixture, RxDoneInsideStartReceiveIsNotLost) {
ASSERT_TRUE(wrap.setRxPowerSaving(false, 20000, 60000));
radio.fire_dio1_in_start_rx = true;
radio.next_pkt_len = 6;
uint8_t buf[16];
// First recvRaw() re-arms continuous RX; DIO1 fires before startReceive() returns.
EXPECT_EQ(wrap.recvRaw(buf, sizeof(buf)), 0);
// Next recvRaw() must see STATE_INT_READY and read the packet.
EXPECT_EQ(wrap.recvRaw(buf, sizeof(buf)), 6);
EXPECT_EQ(wrap.getPacketsRecv(), 1u);
}
} // namespace
int main(int argc, char** argv) {