Improve meter ingestion resilience under UART gaps
This commit is contained in:
@@ -4,9 +4,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// LoRa TX/RX windows can block the main loop for several seconds at SF12.
|
||||
// Keep partial frame state long enough so valid telegrams are not dropped.
|
||||
static constexpr uint32_t METER_FRAME_TIMEOUT_MS = 20000;
|
||||
// Dedicated reader task pumps UART continuously; keep timeout short so parser can
|
||||
// recover quickly from broken frames.
|
||||
static constexpr uint32_t METER_FRAME_TIMEOUT_MS = 3000;
|
||||
static constexpr size_t METER_FRAME_MAX = 512;
|
||||
|
||||
enum class MeterRxState : uint8_t {
|
||||
@@ -142,6 +142,13 @@ bool meter_poll_frame(const char *&frame, size_t &len) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fast resync if a new telegram starts before current frame completed.
|
||||
if (c == '/') {
|
||||
g_frame_len = 0;
|
||||
g_frame_buf[g_frame_len++] = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (g_frame_len + 1 >= sizeof(g_frame_buf)) {
|
||||
g_rx_overflow++;
|
||||
g_rx_state = MeterRxState::WaitStart;
|
||||
|
||||
Reference in New Issue
Block a user