feat(ui): add on-device diagnostics screen (Tools > Diagnostics)

Shows packet counts by category (RX/TX), radio noise floor/RSSI/SNR,
packet-pool free count and outbound queue length, uptime, and heap/stack
headroom on a single scrollable screen.

Adds generic per-payload-type RX/TX counters to Dispatcher (mesh layer),
plus pool-free/queue-length getters, and a new DeviceDiag helper for
nRF52 heap (linker-symbol + sbrk) and stack (FreeRTOS high-water-mark)
stats — the only platform needed for the 3 in-scope boards (Wio Tracker
L1 OLED/Eink, GAT562 30S), all nRF52840.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-06-18 22:34:52 +02:00
co-authored by Claude Sonnet 4.6
parent 99cbe51797
commit 327e659d51
8 changed files with 200 additions and 2 deletions
+31
View File
@@ -0,0 +1,31 @@
#include "DeviceDiag.h"
#if defined(NRF52_PLATFORM)
#include "FreeRTOS.h"
#include "task.h"
// Same linker symbols + _sbrk() the core's own new.cpp uses to implement
// malloc's heap (see framework-arduinoadafruitnrf52/cores/nRF5/new.cpp) —
// there's no separate "free heap" API on this core, so this mirrors it.
extern "C" char* _sbrk(int incr);
extern unsigned char __HeapBase[];
extern unsigned char __HeapLimit[];
void DeviceDiag::getHeapStats(uint32_t& free_bytes, uint32_t& total_bytes) {
total_bytes = (uint32_t)(__HeapLimit - __HeapBase);
uint32_t used = (uint32_t)((unsigned char*)_sbrk(0) - __HeapBase);
free_bytes = (used < total_bytes) ? (total_bytes - used) : 0;
}
uint32_t DeviceDiag::getStackFreeBytes() {
return (uint32_t)uxTaskGetStackHighWaterMark(NULL) * sizeof(StackType_t);
}
#else
void DeviceDiag::getHeapStats(uint32_t& free_bytes, uint32_t& total_bytes) {
free_bytes = 0; total_bytes = 0;
}
uint32_t DeviceDiag::getStackFreeBytes() { return 0; }
#endif
+10
View File
@@ -0,0 +1,10 @@
#pragma once
#include <stdint.h>
// Cross-platform free-heap / stack-headroom estimate for the on-device
// diagnostics screen. A total_bytes of 0 means "not supported on this
// platform" — callers should display "N/A" rather than 0/0.
struct DeviceDiag {
static void getHeapStats(uint32_t& free_bytes, uint32_t& total_bytes);
static uint32_t getStackFreeBytes(); // current task's min-ever headroom; 0 = unsupported
};