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
parent 6a3a29f429
commit e11d14e6cc
3 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -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));
+2 -2
View File
@@ -687,6 +687,7 @@ bool StatsHistory::parseSummaryLine(const char* line, HistorySample& sample) con
sample.uptime_secs = static_cast<uint32_t>(uptime_secs);
sample.packets_sent = static_cast<uint32_t>(packets_sent);
sample.packets_recv = static_cast<uint32_t>(packets_recv);
sample.recv_errors = static_cast<uint32_t>(recv_errors);
sample.heap_free = static_cast<uint32_t>(heap_free);
sample.heap_min = static_cast<uint32_t>(heap_free);
sample.psram_free = static_cast<uint32_t>(psram_free);
@@ -694,7 +695,6 @@ bool StatsHistory::parseSummaryLine(const char* line, HistorySample& sample) con
sample.battery_mv = static_cast<uint16_t>(battery_mv);
sample.queue_len = static_cast<uint16_t>(queue_len);
sample.error_flags = static_cast<uint16_t>(error_flags);
sample.recv_errors = static_cast<uint16_t>(recv_errors);
sample.neighbour_count = static_cast<uint16_t>(neighbour_count);
sample.direct_dups = static_cast<uint16_t>(direct_dups);
sample.flood_dups = static_cast<uint16_t>(flood_dups);
@@ -777,6 +777,7 @@ bool StatsHistory::parseSummaryLine(const char* line, HistorySample& sample) con
sample.uptime_secs = static_cast<uint32_t>(uptime_secs);
sample.packets_sent = static_cast<uint32_t>(packets_sent);
sample.packets_recv = static_cast<uint32_t>(packets_recv);
sample.recv_errors = static_cast<uint32_t>(recv_errors);
sample.heap_free = static_cast<uint32_t>(heap_free);
sample.heap_min = static_cast<uint32_t>(heap_free);
sample.psram_free = static_cast<uint32_t>(psram_free);
@@ -784,7 +785,6 @@ bool StatsHistory::parseSummaryLine(const char* line, HistorySample& sample) con
sample.battery_mv = static_cast<uint16_t>(battery_mv);
sample.queue_len = static_cast<uint16_t>(queue_len);
sample.error_flags = static_cast<uint16_t>(error_flags);
sample.recv_errors = static_cast<uint16_t>(recv_errors);
sample.neighbour_count = static_cast<uint16_t>(neighbour_count);
sample.direct_dups = static_cast<uint16_t>(direct_dups);
sample.flood_dups = static_cast<uint16_t>(flood_dups);
+1 -1
View File
@@ -10,6 +10,7 @@ struct HistorySample {
uint32_t uptime_secs;
uint32_t packets_sent;
uint32_t packets_recv;
uint32_t recv_errors;
uint32_t heap_free;
uint32_t heap_min;
uint32_t psram_free;
@@ -17,7 +18,6 @@ struct HistorySample {
uint16_t battery_mv;
uint16_t queue_len;
uint16_t error_flags;
uint16_t recv_errors;
uint16_t neighbour_count;
uint16_t direct_dups;
uint16_t flood_dups;