From b38ac8392884ebc5abf4817ddb3fbe4e476392c9 Mon Sep 17 00:00:00 2001 From: Jason Huebert Date: Fri, 16 Oct 2026 14:51:47 -0500 Subject: [PATCH] refactor: fold mesh clock reset indirection --- examples/simple_repeater/MeshClockSync.cpp | 19 +++++++------------ examples/simple_repeater/MeshClockSync.h | 9 ++++----- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/examples/simple_repeater/MeshClockSync.cpp b/examples/simple_repeater/MeshClockSync.cpp index 8128426d..b9741bda 100644 --- a/examples/simple_repeater/MeshClockSync.cpp +++ b/examples/simple_repeater/MeshClockSync.cpp @@ -23,23 +23,18 @@ uint32_t MeshClockSync::buildFloor() { return meshclock::buildEpoch(); } -// The state a fresh node starts in, and the baseline load() resets to before it -// reads the file: disabled, empty batch, no decision yet. One definition, so -// construction and reload cannot drift apart. -void MeshClockSync::resetToDefaults() { +MeshClockSync::MeshClockSync() { + reset(); +} + +// The state a fresh node starts in: disabled, empty batch, no decision yet. One +// definition, so construction and reload cannot drift apart. +void MeshClockSync::reset() { memset(samples, 0, sizeof(samples)); count = 0; enabled = false; last_result = IDLE; last_delta = 0; -} - -MeshClockSync::MeshClockSync() { - reset(); -} - -void MeshClockSync::reset() { - resetToDefaults(); save_flag.reset(); // a reset supersedes any edit still waiting to be written } diff --git a/examples/simple_repeater/MeshClockSync.h b/examples/simple_repeater/MeshClockSync.h index f2f6b197..e48f646e 100644 --- a/examples/simple_repeater/MeshClockSync.h +++ b/examples/simple_repeater/MeshClockSync.h @@ -70,7 +70,8 @@ public: // PUB_KEY_SIZE origin key, local_now this node's RTC now. void onAdvert(uint32_t advert_ts, const uint8_t* pub_key, uint32_t local_now); - // Back to a freshly constructed sync (disabled, empty batch), for tests. + // Back to a freshly constructed sync: disabled, empty batch, nothing pending + // to save. Used by construction and load(), and directly by tests. void reset(); // --- status for the CLI --- @@ -78,8 +79,8 @@ public: Result getLastResult() const { return last_result; } int32_t getLastDeltaSecs() const { return last_delta; } // signed for display - // Lower plausibility bound for an advert timestamp, derived from the build - // epoch. Exposed for a boundary test. + // Lower plausibility bound for an advert timestamp: this firmware's build + // epoch. Adverts dated earlier are refused. Exposed for the boundary test. static uint32_t buildFloor(); private: @@ -95,8 +96,6 @@ private: void (*set_fn)(void*, uint32_t) = NULL; void* set_ctx = NULL; - // state of a fresh node, and the baseline load() resets to before it reads - void resetToDefaults(); bool hasSource(const uint8_t* fp) const; void clear() { count = 0; } void evaluate(uint32_t local_now);