From 2d1a9afb44e0110efe6731804cc2457eae47478a Mon Sep 17 00:00:00 2001 From: "Rich O." Date: Sun, 1 Nov 2026 16:06:28 -0500 Subject: [PATCH] palm-client: don't move a set radio clock more than a week A slip in the Visor's date picker (Oct 1 2027 instead of Nov 1 2026) went straight into the radio, whose clock only moves forward, so it can't be undone without a radio reboot. When the radio's clock looks set (after 2025-01-01), SessionSyncClock now only corrects drift under 7 days and otherwise flags a mismatch, shown on the Node clock line. --- palm-client/src/node_form.c | 5 ++++- palm-client/src/session.c | 16 ++++++++++++++++ palm-client/src/session.h | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/palm-client/src/node_form.c b/palm-client/src/node_form.c index 0fd0cd1..91c2854 100644 --- a/palm-client/src/node_form.c +++ b/palm-client/src/node_form.c @@ -101,7 +101,10 @@ static void DrawClockLine(void) } else { StrCopy(radio, "--"); } - StrPrintF(line, "radio %s UTC sys %ld", radio, (Int32)PrefGetPreference(prefMinutesWestOfGMT)); + if (SessionClockMismatch()) + StrPrintF(line, "radio %s UTC MISMATCH: check date", radio); + else + StrPrintF(line, "radio %s UTC sys %ld", radio, (Int32)PrefGetPreference(prefMinutesWestOfGMT)); WinDrawChars(line, StrLen(line), 5, 113); FntSetFont(old); } diff --git a/palm-client/src/session.c b/palm-client/src/session.c index 93ad919..6f617de 100644 --- a/palm-client/src/session.c +++ b/palm-client/src/session.c @@ -13,6 +13,8 @@ #define VM_SYNC_MAX 50 /* messages pulled per sync, so the UI isn't blocked forever */ #define VM_ACK_MIN_SECS 10 /* shortest wait for a DM ack, whatever the radio estimates */ #define VM_CLOCK_SLACK 60 /* radio clock behind ours by more than this gets set forward */ +#define VM_CLOCK_MAX_STEP (7UL * 86400UL) /* a bigger jump means one clock is wrong: don't guess */ +#define VM_CLOCK_VALID 1735689600UL /* 2025-01-01: a radio clock before this was never set */ #define PALM_EPOCH_OFFSET 2082844800UL /* 1904-01-01 (Palm) to 1970-01-01 (Unix) */ static VmFrameDecoder gDecoder; @@ -181,6 +183,7 @@ static Err QueryRadio(UInt16 firstTries) /* Sets the radio's clock from ours if it's behind (the firmware only lets it move forward). */ static UInt32 gRadioTime = 0; /* radio clock at gRadioTimeAt (our local seconds) */ +static Boolean gClockMismatch = false; static UInt32 gRadioTimeAt = 0; void SessionSyncClock(void) @@ -195,6 +198,14 @@ void SessionSyncClock(void) return; gRadioTime = radio; gRadioTimeAt = TimGetSeconds(); + /* + * The radio's clock can only move forward, so a wrong Visor date (a slip in + * the date picker set it 11 months ahead once) can't be undone short of a + * radio reboot. If the radio's clock looks set, only correct small drift. + */ + gClockMismatch = radio >= VM_CLOCK_VALID && (now > radio + VM_CLOCK_MAX_STEP || radio > now + VM_CLOCK_MAX_STEP); + if (gClockMismatch) + return; if (radio + VM_CLOCK_SLACK < now) { len = VmBuildSetTime(frame, sizeof(frame), now); if (Request(frame, len, VM_RESP_OK, 1) == errNone) @@ -202,6 +213,11 @@ void SessionSyncClock(void) } } +Boolean SessionClockMismatch(void) +{ + return gClockMismatch; +} + UInt32 SessionRadioTime(void) { return gRadioTime ? gRadioTime + (TimGetSeconds() - gRadioTimeAt) : 0; diff --git a/palm-client/src/session.h b/palm-client/src/session.h index 44d7cac..d5d60a9 100644 --- a/palm-client/src/session.h +++ b/palm-client/src/session.h @@ -59,6 +59,8 @@ void SessionSetUtcOffset(Int16 minutes); Int16 SessionUtcOffset(void); /* Sets the radio's clock to ours (UTC) if it's behind; it can only move forward. */ void SessionSyncClock(void); +/* True if the radio's and the Visor's clocks differ by more than a week (one is wrong; not synced). */ +Boolean SessionClockMismatch(void); /* The radio's clock (UTC) as last read, advanced by the time since; 0 if never read. */ UInt32 SessionRadioTime(void);