mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
fix(kiss_modem): improve RX delivery and noise floor sampling
This commit is contained in:
parent
1af013c741
commit
f445b5acdc
3 changed files with 29 additions and 10 deletions
|
|
@ -99,6 +99,11 @@ void KissModem::loop() {
|
|||
|
||||
if (_rx_len < KISS_MAX_FRAME_SIZE) {
|
||||
_rx_buf[_rx_len++] = b;
|
||||
} else {
|
||||
/* Buffer full with no FEND; reset so we don't stay stuck ignoring input. */
|
||||
_rx_len = 0;
|
||||
_rx_escaped = false;
|
||||
_rx_active = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -197,4 +197,6 @@ public:
|
|||
|
||||
void onPacketReceived(int8_t snr, int8_t rssi, const uint8_t* packet, uint16_t len);
|
||||
bool isTxBusy() const { return _tx_state != TX_IDLE; }
|
||||
/** True only when radio is actually transmitting; use to skip recvRaw in main loop. */
|
||||
bool isActuallyTransmitting() const { return _tx_state == TX_SENDING; }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -112,16 +112,12 @@ void setup() {
|
|||
void loop() {
|
||||
modem->loop();
|
||||
|
||||
if ((uint32_t)(millis() - next_noise_floor_calib_ms) >= NOISE_FLOOR_CALIB_INTERVAL_MS) {
|
||||
radio_driver.triggerNoiseFloorCalibrate(0);
|
||||
next_noise_floor_calib_ms = millis();
|
||||
}
|
||||
radio_driver.loop();
|
||||
|
||||
if (!modem->isTxBusy()) {
|
||||
if ((uint32_t)(millis() - next_agc_reset_ms) >= AGC_RESET_INTERVAL_MS) {
|
||||
radio_driver.resetAGC();
|
||||
next_agc_reset_ms = millis();
|
||||
if (!modem->isActuallyTransmitting()) {
|
||||
if (!modem->isTxBusy()) {
|
||||
if ((uint32_t)(millis() - next_agc_reset_ms) >= AGC_RESET_INTERVAL_MS) {
|
||||
radio_driver.resetAGC();
|
||||
next_agc_reset_ms = millis();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t rx_buf[256];
|
||||
|
|
@ -131,5 +127,21 @@ void loop() {
|
|||
int8_t rssi = (int8_t)radio_driver.getLastRSSI();
|
||||
modem->onPacketReceived(snr, rssi, rx_buf, rx_len);
|
||||
}
|
||||
/* Sample noise floor right after drain: we're in STATE_RX so wrapper can collect. */
|
||||
for (int i = 0; i < 16; i++) {
|
||||
radio_driver.loop();
|
||||
}
|
||||
}
|
||||
|
||||
/* Trigger starts a new 64-sample calibration window every 2s. */
|
||||
if ((uint32_t)(millis() - next_noise_floor_calib_ms) >= NOISE_FLOOR_CALIB_INTERVAL_MS) {
|
||||
radio_driver.triggerNoiseFloorCalibrate(0);
|
||||
next_noise_floor_calib_ms = millis();
|
||||
}
|
||||
radio_driver.loop();
|
||||
if (!modem->isActuallyTransmitting()) {
|
||||
for (int i = 0; i < 15; i++) {
|
||||
radio_driver.loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue