Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace mesh {
#ifndef NOISE_FLOOR_CALIB_INTERVAL
#define NOISE_FLOOR_CALIB_INTERVAL 2000 // 2 seconds
#endif
#ifndef AGC_FORCED_RESET_MILLIS
#define AGC_FORCED_RESET_MILLIS (24UL*60*60*1000) // reset AGC at least once a day, even on a busy channel
#endif

void Dispatcher::begin() {
n_sent_flood = n_sent_direct = 0;
Expand Down Expand Up @@ -131,7 +134,20 @@ void Dispatcher::loop() {
}

if (getAGCResetInterval() > 0 && millisHasNowPassed(next_agc_reset_time)) {
_radio->resetAGC();
// a reset takes the radio off the air, so (as in Meshtastic) skip it while packets are still
// being decoded: the gain is not stuck then. Still reset at least once per AGC_FORCED_RESET_MILLIS.
unsigned long now = _ms->getMillis();
bool hearing = last_rx_good_time != 0 && now - last_rx_good_time < (unsigned long) getAGCResetInterval();
bool forced = last_agc_reset_time == 0 || now - last_agc_reset_time >= AGC_FORCED_RESET_MILLIS;
if (_mgr->getOutboundTotal() > 0) {
MESH_DEBUG_PRINTLN("%s Dispatcher::loop(): AGC reset skipped, tx queued", getLogDateTime());
} else if (hearing && !forced) {
MESH_DEBUG_PRINTLN("%s Dispatcher::loop(): AGC reset skipped, last rx %lu ms ago", getLogDateTime(), now - last_rx_good_time);
} else {
MESH_DEBUG_PRINTLN("%s Dispatcher::loop(): AGC reset", getLogDateTime());
_radio->resetAGC();
last_agc_reset_time = now ? now : 1;
}
next_agc_reset_time = futureMillis(getAGCResetInterval());
}

Expand Down Expand Up @@ -236,6 +252,7 @@ void Dispatcher::checkRecv() {
}
#endif
logRx(pkt, pkt->getRawLength(), score); // hook for custom logging
last_rx_good_time = _ms->getMillis();

if (pkt->isRouteFlood()) {
n_recv_flood++;
Expand Down
2 changes: 2 additions & 0 deletions src/Dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Dispatcher {
unsigned long cad_busy_start;
unsigned long radio_nonrx_start;
unsigned long next_floor_calib_time, next_agc_reset_time;
unsigned long last_rx_good_time, last_agc_reset_time;
bool prev_isrecv_mode;
uint32_t n_sent_flood, n_sent_direct;
uint32_t n_recv_flood, n_recv_direct;
Expand All @@ -146,6 +147,7 @@ class Dispatcher {
next_tx_time = ms.getMillis();
cad_busy_start = 0;
next_floor_calib_time = next_agc_reset_time = 0;
last_rx_good_time = last_agc_reset_time = 0;
_err_flags = 0;
radio_nonrx_start = 0;
prev_isrecv_mode = true;
Expand Down