Fix: expand HistorySample::recv_errors from uint16_t to uint32_t

The error_rate graph showed all zeros after ~65535 receive errors had
accumulated.  Root cause was a two-part bug:

1. In MyMesh::updateStatsHistory(), recv_errors was clamped to 0xFFFF
   via min<uint32_t>(..., 0xFFFF).  Once the counter reached 65535,
   every subsequent sample stored the same constant value, making the
   per-interval delta always zero and therefore error_rate always zero.

2. HistorySample::recv_errors was declared as uint16_t while the
   underlying counter (n_recv_errors) is uint32_t.  parseSummaryLine()
   also truncated the restored value back to uint16_t.

Fix:
- Remove the clamp in MyMesh::updateStatsHistory(); assign
  getPacketsRecvErrors() (uint32_t) directly.
- Change HistorySample::recv_errors from uint16_t to uint32_t,
  moving it next to the other uint32_t fields.
- Update both parseSummaryLine() code paths to cast recv_errors to
  uint32_t instead of uint16_t.

The archive format is unchanged: recv_errors is written as %u and
read back into an unsigned local, which is correct for a 32-bit
value on ESP32.
This commit is contained in:
Valentin V. Bartenev
2026-05-20 19:53:12 +03:00
rodzic 6a3a29f429
commit e11d14e6cc
3 zmienionych plików z 4 dodań i 4 usunięć
+1 -1
Wyświetl plik
@@ -1876,7 +1876,7 @@ void MyMesh::updateStatsHistory(unsigned long now_ms) {
sample.battery_mv = battery_mv;
sample.queue_len = static_cast<uint16_t>(_mgr->getOutboundTotal());
sample.error_flags = _err_flags;
sample.recv_errors = static_cast<uint16_t>(min<uint32_t>(radio_driver.getPacketsRecvErrors(), 0xFFFF));
sample.recv_errors = radio_driver.getPacketsRecvErrors();
sample.neighbour_count = static_cast<uint16_t>(min<size_t>(getNeighbourCount(), 0xFFFF));
sample.direct_dups =
static_cast<uint16_t>(min<uint32_t>(((SimpleMeshTables *)getTables())->getNumDirectDups(), 0xFFFF));