feat(ui): page radio and system status

This commit is contained in:
mikecarper committed 2026-09-21 15:35:46 -07:00
1 parent 653578c818
commit b089b745fa
28 files changed
+2075 -73

No files matched your search

+38
View File
@@ -64,6 +64,44 @@ int main() {
mesh::ui::SmallMessageText body(display);
assert(body.capitalHeight() == 6);
// The repeater's T096 status column uses the driver's normal 6x8 font.
const char* status_rows[] = {"GPS:OFF", "FEM:OFF", "RXB:OFF", "RXPS:OFF", "CAD:OFF"};
for (int i = 0; i < 5; ++i) {
assert(display.getTextWidth(status_rows[i]) <= 50);
display.clear();
display.drawTextRightAlign(158, 10 + (i < 4 ? i : 5) * 10, status_rows[i]);
assert(canvas.x >= 108 && canvas.x + display.getTextWidth(status_rows[i]) <= 158);
}
const char* noise_floor_rows[] = {"N1:-123.4", "N2:-123.4", "N1:4.2s", "N2:WAIT"};
for (const char* noise_floor : noise_floor_rows) {
// Decimal per-radio floors need 54px. The final T096 row has no wide
// left-column field, so it may use four pixels of its empty gutter.
assert(display.getTextWidth(noise_floor) <= 54);
display.clear();
display.drawTextRightAlign(158, 70, noise_floor);
assert(canvas.x >= 104 && canvas.x + display.getTextWidth(noise_floor) <= 158);
}
const char* radio_tags[] = {"R2:ON", "T2:ON"};
for (const char* tag : radio_tags) {
assert(display.getTextWidth(tag) <= 50);
display.clear();
display.drawTextRightAlign(158, 50, tag);
assert(canvas.x >= 108 && canvas.x + display.getTextWidth(tag) <= 158);
}
const char* dual_radio_rows[] = {"R1 F:2500.000 S:12", "T1 B:1625.00 C:8",
"R2 F:2500.000 S:12", "T2 B:1625.00 C:8"};
for (const char* row : dual_radio_rows) {
assert(display.getTextWidth(row) <= 108);
}
assert(display.getTextWidth("ID:ABCDEF") <= 108);
assert(display.getTextWidth("R2:RXTX") <= 108);
assert(display.getTextWidth("X:AUTO") <= 108);
// The name owns the full normal-font top row; radio/status columns start
// below it and cannot cause name wrapping.
canvas.prints = 0;
assert(display.getTextWidth("MercerWoodMesh T096 Node") <= 160);
display.drawTextEllipsized(0, 0, 160, "MercerWoodMesh T096 Node");
assert(canvas.prints == 1);
#if defined(HELTEC_T096)
assert(body.lineCount(12) == 8);
// Check all 95 real font glyphs against their native bitmap coordinates.
@@ -19,6 +19,18 @@ TEST(NoiseFloorEstimator, RequiresACompleteSpacedBlock) {
EXPECT_GT(NoiseFloorEstimator::WINDOW_TIMEOUT_MS, 3150U);
}
TEST(NoiseFloorEstimator, ReportsBestCaseRemainingSecondsWithTenths) {
NoiseFloorEstimator n;
EXPECT_EQ(64, n.samplesRemaining());
EXPECT_FLOAT_EQ(3.2f, n.secondsRemaining());
for (unsigned i = 0; i < 20; ++i) ASSERT_TRUE(n.add(-100, i * 50));
EXPECT_EQ(44, n.samplesRemaining());
EXPECT_FLOAT_EQ(2.2f, n.secondsRemaining());
for (unsigned i = 20; i < 64; ++i) ASSERT_TRUE(n.add(-100, i * 50));
EXPECT_EQ(0, n.samplesRemaining());
EXPECT_FLOAT_EQ(0.0f, n.secondsRemaining());
}
TEST(NoiseFloorEstimator, RejectsSparseLowOutliersAndMajorityTraffic) {
NoiseFloorEstimator n;
int32_t floor = 0;
@@ -39,7 +39,9 @@ Context makeContext(const char* name = "Ridgeline North") {
c.freq = 910.525f;
c.sf = 7;
c.bw = 62.5f;
c.radio_label = "";
c.link_up = true;
c.dual_radio = false;
return c;
}
@@ -157,6 +159,18 @@ TEST(ObserverDashboardFormat, EmptyWindowNeverProducesNanOrInfinity) {
EXPECT_STREQ("RX --", status.left);
}
TEST(ObserverDashboardFormat, StatusRowIdentifiesAnActiveSecondRadio) {
Context ctx = makeContext();
ctx.dual_radio = true;
RowText status;
composeRow(ROW_STATUS, ctx, makeEmpty(), &status);
EXPECT_STREQ("WiFi OK R2 ON", status.right);
ctx.link_up = false;
composeRow(ROW_STATUS, ctx, makeEmpty(), &status);
EXPECT_STREQ("WiFi -- R2 ON", status.right);
}
TEST(ObserverDashboardFormat, EveryRowFitsTheCharacterBudget) {
for (const Profile& p : {portrait(), landscape()}) {
for (const RadioActivitySnapshot& s : {makeBusy(), makeEmpty()}) {
@@ -506,6 +520,27 @@ TEST(ObserverDashboardSignature, LinkStateOnlyTouchesTheStatusRow) {
}
}
TEST(ObserverDashboardSignature, SecondRadioStateOnlyTouchesTheStatusRow) {
Layout l = portraitLayout();
RadioActivitySnapshot s = makeBusy();
Context single = makeContext();
Context dual = makeContext();
dual.dual_radio = true;
uint32_t sa[ROW_COUNT], sb[ROW_COUNT];
allRowSignatures(l, single, s, sa);
allRowSignatures(l, dual, s, sb);
for (int r = 0; r < ROW_COUNT; r++) {
if (r == ROW_STATUS) {
EXPECT_NE(sa[r], sb[r]);
} else {
EXPECT_EQ(sa[r], sb[r]) << "row " << r;
}
}
}
TEST(ObserverDashboardSignature, PartialRepaintDrawsOnlyTheChangedRow) {
Profile p = portrait();
Context ctx = makeContext();
@@ -0,0 +1,74 @@
#include <helpers/ui/RadioProfileDisplayPage.h>
#include <gtest/gtest.h>
TEST(RadioProfileDisplayPage, AlternatesEverySevenSecondsOnlyWhenEnabled) {
using mesh::ui::RADIO_PROFILE_DISPLAY_PAGE_MILLIS;
using mesh::ui::showSecondaryRadioProfilePage;
EXPECT_FALSE(showSecondaryRadioProfilePage(false, RADIO_PROFILE_DISPLAY_PAGE_MILLIS));
EXPECT_FALSE(showSecondaryRadioProfilePage(true, 0));
EXPECT_FALSE(showSecondaryRadioProfilePage(true, RADIO_PROFILE_DISPLAY_PAGE_MILLIS - 1));
EXPECT_TRUE(showSecondaryRadioProfilePage(true, RADIO_PROFILE_DISPLAY_PAGE_MILLIS));
EXPECT_TRUE(showSecondaryRadioProfilePage(true, 2 * RADIO_PROFILE_DISPLAY_PAGE_MILLIS - 1));
EXPECT_FALSE(showSecondaryRadioProfilePage(true, 2 * RADIO_PROFILE_DISPLAY_PAGE_MILLIS));
}
TEST(RadioProfileDisplayPage, LabelsTemporaryAndSavedProfilesClearly) {
EXPECT_STREQ("R1", mesh::ui::radioProfileDisplayTag(false, false));
EXPECT_STREQ("T1", mesh::ui::radioProfileDisplayTag(false, true));
EXPECT_STREQ("R2", mesh::ui::radioProfileDisplayTag(true, false));
EXPECT_STREQ("T2", mesh::ui::radioProfileDisplayTag(true, true));
}
TEST(RadioProfileDisplayPage, PlacesSystemStatusAfterEachRadioProfile) {
using mesh::ui::RADIO_PROFILE_DISPLAY_PAGE_MILLIS;
using mesh::ui::radioProfileDisplayPageIndex;
using mesh::ui::showRadioProfileSystemStatusPage;
using mesh::ui::showSecondaryRadioProfilePage;
// Dual-radio: R1, R2, system status, then back to R1.
EXPECT_EQ(0, radioProfileDisplayPageIndex(true, 1, 0));
EXPECT_EQ(1, radioProfileDisplayPageIndex(true, 1,
RADIO_PROFILE_DISPLAY_PAGE_MILLIS));
EXPECT_EQ(2, radioProfileDisplayPageIndex(true, 1,
2 * RADIO_PROFILE_DISPLAY_PAGE_MILLIS));
EXPECT_TRUE(showSecondaryRadioProfilePage(true, 1,
RADIO_PROFILE_DISPLAY_PAGE_MILLIS));
uint8_t status_page = 99;
EXPECT_TRUE(showRadioProfileSystemStatusPage(true, 1,
2 * RADIO_PROFILE_DISPLAY_PAGE_MILLIS, &status_page));
EXPECT_EQ(0, status_page);
// A very short display gets each status sub-page without losing either
// radio profile from the cycle.
EXPECT_TRUE(showRadioProfileSystemStatusPage(true, 2,
3 * RADIO_PROFILE_DISPLAY_PAGE_MILLIS, &status_page));
EXPECT_EQ(1, status_page);
EXPECT_FALSE(showRadioProfileSystemStatusPage(true, 2,
4 * RADIO_PROFILE_DISPLAY_PAGE_MILLIS, &status_page));
}
TEST(RadioProfileDisplayPage, ManualPagesDoNotDependOnElapsedTime) {
using mesh::ui::radioProfileManualPageIndex;
using mesh::ui::showRadioProfileSystemStatusPage;
using mesh::ui::showSecondaryRadioProfilePage;
// A repeater begins on R1 and only changes page when its button handler
// advances this selected-page value.
EXPECT_FALSE(mesh::ui::showManualSecondaryRadioProfilePage(true,
static_cast<uint8_t>(0)));
EXPECT_TRUE(mesh::ui::showManualSecondaryRadioProfilePage(true,
static_cast<uint8_t>(1)));
EXPECT_EQ(0, radioProfileManualPageIndex(true, 1, 3));
uint8_t status_page = 99;
EXPECT_TRUE(mesh::ui::showManualRadioProfileSystemStatusPage(true, 1,
static_cast<uint8_t>(2), &status_page));
EXPECT_EQ(0, status_page);
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
+36 -1
View File
@@ -12,11 +12,13 @@ HARNESS = r'''
#include <initializer_list>
#include <RadioProfiles.h>
#include <helpers/radiolib/RXPowerSaving.h>
#include <helpers/radiolib/NoiseFloorEstimator.h>
#define RADIOLIB_ERR_NONE 0
#define STATE_IDLE 0
#define STATE_RX 1
#define STATE_TX_WAIT 3
#define STATE_INT_READY 16
#define NF_CALIB_SETTLE_MS 7UL
#define MESH_DEBUG_PRINTLN(...) ((void)0)
namespace mesh { enum class RadioParamApplyResult { APPLIED, BUSY, FAILED }; }
static uint64_t elapsed_us;
@@ -33,7 +35,14 @@ struct RadioLibWrapper {
bool _rx_ps_enabled=true, _rx_ps_armed=true, _rx_ps_continuous_fallback=false;
bool _profile_saved_rxps=false, _profile_rxps_suspended=false;
bool _profile_standby_held=false, _saved_standby_xosc=false;
bool _nf_calib_active=false, _noise_floor_valid=true, _profile_refresh_required=false;
bool _nf_calib_active=false, _nf_refresh_requested=false, _noise_floor_valid=true, _noise_floor_secondary_valid=true, _profile_refresh_required=false;
unsigned long _nf_last_calib=0, _nf_calib_deadline=0, _nf_sample_from=0;
NoiseFloorEstimator _floor_estimator;
NoiseFloorEstimator _secondary_floor_estimator;
static constexpr uint32_t NoiseFloorSettleMillis=7UL;
NoiseFloorEstimator& profileFloorEstimator(uint8_t profile) {
return profile == 1 ? _secondary_floor_estimator : _floor_estimator;
}
uint32_t _rx_ps_rx_us=50000, _rx_ps_sleep_us=50000;
uint8_t _active_profile=0, _cur_sf=7, _cur_cr=5;
uint32_t _profile_generation=1, _profile_visit_us=0, _profile_retry_at=0;
@@ -184,6 +193,7 @@ int main() {
}
{
RadioLibWrapper w; w.enable();
w._nf_refresh_requested=false; // exercise the ordinary, post-calibration cadence
assert(w._profile_rxps_suspended && !w._rx_ps_enabled && !w._rx_ps_armed);
assert(w.chip.standbyXOSC && w._profile_standby_held && !w._saved_standby_xosc);
w.setProfileStandbyWarm(true); // repeated requests must not overwrite the saved RC policy
@@ -211,9 +221,34 @@ int main() {
w._profiles.secondary.params.bw=62.5;
++w._profiles.generation[1];
w.serviceProfileScan();assert(w._active_profile==1); // slower channel first
w._nf_refresh_requested=false; // ordinary cadence after the replacement baseline
elapsed_us+=w._profiles.listenUs(1)-1;w.serviceProfileScan();assert(w._active_profile==1);
elapsed_us++;w.serviceProfileScan();assert(w._active_profile==0);
}
{
// SX126x profiles need at most a 7ms settle. A shorter visit is extended
// only to that bound, never to the former 20ms calibration bound.
RadioLibWrapper w;
w._nf_refresh_requested=true;
w.enable();
const auto primary_visit=w._profiles.listenUs(0);
const auto calibrated_visit=primary_visit < 7000 ? 7000 : primary_visit;
elapsed_us += calibrated_visit - 1; w.serviceProfileScan(); assert(w._active_profile==0);
elapsed_us++; w.serviceProfileScan(); assert(w._active_profile==1);
}
{
// Between spaced noise samples, even a very short profile must keep its
// normal visit. Calibration may not turn every fast scan hop into 7ms.
RadioLibWrapper w;
w._nf_refresh_requested=true;
w.enable();
w._floor_estimator.add(-100, millis());
w._active_profile=0;
w._profile_visit_us=micros();
const auto primary_visit=w._profiles.listenUs(0);
elapsed_us += primary_visit - 1; w.serviceProfileScan(); assert(w._active_profile==0);
elapsed_us++; w.serviceProfileScan(); assert(w._active_profile==1);
}
{
RadioLibWrapper w;w.enable();w.fail=true;
elapsed_us+=100000;w.serviceProfileScan();
+91 -6
View File
@@ -36,7 +36,8 @@ HARNESS = r'''
#define NF_CALIB_INTERVAL_MS 2000UL
#define NF_CALIB_TIMEOUT_MS NoiseFloorEstimator::WINDOW_TIMEOUT_MS
#define NF_CONTINUOUS_TIMEOUT_MS NoiseFloorEstimator::WINDOW_TIMEOUT_MS
#define NF_CALIB_SETTLE_MS 20UL
#define NF_CALIB_SETTLE_MS 7UL
#define NF_FAST_PROFILE_REFRESH_INTERVAL_MS (15UL * 60UL * 1000UL)
static volatile uint8_t state = STATE_RX;
static uint32_t now_ms = 0;
uint32_t millis() { return now_ms; }
@@ -62,11 +63,15 @@ struct RadioLibWrapper {
bool serviceCarrierWave() { return false; } // dedicated CW harness owns this path
mesh::RadioProfiles _profiles;
uint32_t _profile_visit_us = 0;
uint32_t _profile_scan_generation[2] = {};
uint8_t _active_profile = 0;
bool _profile_rxps_suspended = false;
void serviceProfileScan() {} // separate profile-scan harness exercises tuning
Board board; Board* _board = &board;
Radio radio; Radio* _radio = &radio;
bool _rx_ps_enabled = false, _rx_ps_armed = false, _rx_ps_continuous_fallback = false;
bool _nf_calib_active = false, _nf_refresh_requested = true, _noise_floor_valid = true;
bool _nf_calib_active = false, _nf_refresh_requested = true, _noise_floor_valid = true,
_noise_floor_secondary_valid = true;
bool _cad_enabled = true, packet = false, busy = false, inject_arm_irq = false;
bool _rx_boosted_gain_valid = false, _cur_rx_boosted_gain = false;
bool _wd_last_busy = false;
@@ -75,12 +80,17 @@ struct RadioLibWrapper {
unsigned long _nf_last_calib = 0, _nf_calib_deadline = 0, _nf_sample_from = 0;
unsigned long _wd_last_transition = 0, _wd_stuck_thresh = 0, _wd_observe_ms = 0;
int16_t _threshold = 0, _noise_floor = -105;
int32_t _noise_floor_centi_dbm = -10500;
int32_t _noise_floor_centi_dbm = -10500, _noise_floor_secondary_centi_dbm = -10600;
int arm_result = 0, chip_mode = 1;
float rssi = -100;
unsigned arms = 0, stops = 0, soft = 0, hard = 0, reads = 0, mode_reads = 0;
bool inject_mode_irq = false;
NoiseFloorEstimator _floor_estimator;
NoiseFloorEstimator _secondary_floor_estimator;
NoiseFloorEstimator& profileFloorEstimator(uint8_t profile) {
return profile == 1 ? _secondary_floor_estimator : _floor_estimator;
}
uint16_t profilePreamble(uint8_t profile) const { return _profiles.preamble(profile, 32); }
RadioLibWrapper() { state = STATE_RX; now_ms = 100; }
bool isChipBusy() { return busy; }
bool isReceivingPacket() { return packet; }
@@ -109,6 +119,7 @@ struct RadioLibWrapper {
void startRecv();
void checkReceiveMode(uint32_t);
void loop();
void triggerNoiseFloorCalibrate(int);
void requestRestartRecv();
void noiseFloorCalibCheck(unsigned long);
void endNoiseFloorCalib(unsigned long);
@@ -180,13 +191,13 @@ int main() {
{
RadioLibWrapper w;
w.startRecv();
for (; now_ms < 120; ++now_ms) w.loop();
for (; now_ms < 107; ++now_ms) w.loop();
assert(w.reads == 0);
w.loop();
assert(w.reads == 1);
now_ms = 200;
w.startRecv(); // CAD/TX re-arm must settle again, retaining earlier samples
for (; now_ms < 220; ++now_ms) w.loop();
for (; now_ms < 207; ++now_ms) w.loop();
assert(w.reads == 1 && w._floor_estimator.count() == 1);
w.loop();
assert(w.reads == 2 && w._floor_estimator.count() == 2);
@@ -200,6 +211,80 @@ int main() {
}
assert(w._noise_floor_centi_dbm == -10125);
}
// After dual-profile initialization, the Dispatcher's two-second
// maintenance tick updates the threshold but must not restart calibration.
// A profile whose normal visit is under 7 ms gets one new bounded 7 ms
// sample set after fifteen minutes; a naturally long profile does not.
{
RadioLibWrapper w;
mesh::RadioProfileConfig second;
second.params.freq = 910.5; second.params.bw = 62.5; second.params.sf = 7; second.params.cr = 5;
second.mode = mesh::RadioProfileMode::RxTx;
w._profiles.primary = second.params;
w._profiles.setSecondary(second, false);
w._nf_refresh_requested = false;
w._noise_floor_valid = w._noise_floor_secondary_valid = true;
w.triggerNoiseFloorCalibrate(7);
assert(!w._nf_refresh_requested && w._threshold == 7);
w._noise_floor_secondary_valid = false;
w.triggerNoiseFloorCalibrate(8);
assert(w._nf_refresh_requested && w._threshold == 8);
}
{
RadioLibWrapper w;
mesh::RadioProfileConfig second;
second.params.freq = 910.5; second.params.bw = 500; second.params.sf = 5; second.params.cr = 5;
second.mode = mesh::RadioProfileMode::Rx;
w._profiles.primary = second.params;
w._profiles.setSecondary(second, false);
w._nf_refresh_requested = false;
w._noise_floor_valid = w._noise_floor_secondary_valid = true;
w._nf_last_calib = now_ms;
now_ms += NF_FAST_PROFILE_REFRESH_INTERVAL_MS - 1;
w.triggerNoiseFloorCalibrate(7);
assert(!w._nf_refresh_requested);
++now_ms;
w.triggerNoiseFloorCalibrate(7);
assert(w._nf_refresh_requested);
}
{
RadioLibWrapper w;
mesh::RadioProfileConfig second;
second.params.freq = 910.5; second.params.bw = 62.5; second.params.sf = 7; second.params.cr = 5;
second.mode = mesh::RadioProfileMode::Rx;
w._profiles.primary = second.params;
w._profiles.setSecondary(second, false);
w._nf_refresh_requested = false;
w._noise_floor_valid = w._noise_floor_secondary_valid = true;
w._nf_last_calib = now_ms;
now_ms += NF_FAST_PROFILE_REFRESH_INTERVAL_MS;
w.triggerNoiseFloorCalibrate(7);
assert(!w._nf_refresh_requested);
}
now_ms = 100; // subsequent timing tests use their original short timeline
// R1 and R2 collect distinct RSSI populations across alternating visits;
// publishing one must never blend the other channel into its floor.
{
RadioLibWrapper w;
mesh::RadioProfileConfig second;
second.params.freq = 910.5; second.params.bw = 62.5; second.params.sf = 7; second.params.cr = 5;
second.mode = mesh::RadioProfileMode::RxTx;
w._profiles.primary = second.params;
w._profiles.setSecondary(second, false);
w._profile_scan_generation[0] = w._profiles.generation[0];
w._profile_scan_generation[1] = w._profiles.generation[1];
w._profile_rxps_suspended = true;
w._noise_floor_valid = w._noise_floor_secondary_valid = false;
w._nf_refresh_requested = true;
w._nf_sample_from = 0;
for (unsigned i = 0; i < NoiseFloorEstimator::SAMPLE_COUNT; ++i) {
w._active_profile = 0; w.rssi = -100; w.loop(); now_ms += 50;
w._active_profile = 1; w.rssi = -90; w.loop(); now_ms += 50;
}
w.loop(); // publish after both profile estimators complete
assert(!w._nf_refresh_requested && w._noise_floor_centi_dbm == -10000);
assert(w._noise_floor_secondary_centi_dbm == -9000);
}
// Hardware standby RSSI is not background noise, even if software says RX.
{
RadioLibWrapper w;
@@ -505,7 +590,7 @@ int main() {
source = (ROOT / 'src/helpers/radiolib/RadioLibWrappers.cpp').read_text()
names = [('int16_t','performChannelScanWithTimeout'), ('bool','isPacketPendingOrReceiving'),
('bool','isChannelActive'), ('void','startRecv'), ('void','checkReceiveMode'),
('void','loop'), ('void','requestRestartRecv'), ('void','noiseFloorCalibCheck'),
('void','loop'), ('void','triggerNoiseFloorCalibrate'), ('void','requestRestartRecv'), ('void','noiseFloorCalibCheck'),
('void','endNoiseFloorCalib'), ('void','requestNoiseFloorRefresh'),
('void','recalibrateNoiseFloor'), ('void','resetAGC')]
methods = '\n'.join(method(source, f'{kind} RadioLibWrapper::{name}(') for kind,name in names)