palm-client: clock line on Node (Visor, UTC, offset, radio, system pref)

The radio clock stays ~9 h behind although Settings shows UTC -5: at
connect it was set to Visor time minus 5 h, i.e. an offset of +5 was in
effect, and later saves read the radio clock without setting it. Rather
than guess, Node now shows the Visor's clock, the computed UTC and the
offset in effect, the radio's clock as last read, and Palm OS's
prefMinutesWestOfGMT (the offset's default).
This commit is contained in:
rich committed 2026-11-01 16:01:10 -05:00
1 parent 157646e093
commit fa11770c13
3 files changed
+53 -1

No files matched your search

+39
View File
@@ -9,6 +9,7 @@
#include "session.h"
#include "app.h"
#include "node_form.h"
#include "ui/draw.h"
#define VM_LABEL_CHARS 22 /* the info labels in the .rcp are padded to this width */
@@ -70,6 +71,41 @@ static void ShowRadioInfo(FormType *form)
CtlSetLabel(FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainConnectButton)), "Disconnect");
}
/*
* Clock check, small font, under the radio details:
* Visor 17:02 UTC 22:02 (-5h)
* radio 11:57 UTC sys -300
* "sys" is Palm OS's own minutes-west-of-GMT preference (the offset's default).
*/
static void DrawClockLine(void)
{
DateTimeType dt;
RectangleType r;
Char line[48], utc[8], radio[8];
UInt32 now = TimGetSeconds();
Int16 off = SessionUtcOffset();
UInt32 rt = SessionRadioTime();
FontID old = FntSetFont(vmSmallFont);
RctSetRectangle(&r, 0, 104, 160, 20);
WinEraseRectangle(&r, 0);
TimSecondsToDateTime(SessionNow() + 2082844800UL, &dt);
StrPrintF(utc, "%02u:%02u", dt.hour, dt.minute);
TimSecondsToDateTime(now, &dt);
StrPrintF(line, "Visor %02u:%02u UTC %s (%s%d:%02dh)", dt.hour, dt.minute, utc,
off < 0 ? "-" : "+", (off < 0 ? -off : off) / 60, (off < 0 ? -off : off) % 60);
WinDrawChars(line, StrLen(line), 5, 105);
if (rt) {
TimSecondsToDateTime(rt + 2082844800UL, &dt);
StrPrintF(radio, "%02u:%02u", dt.hour, dt.minute);
} else {
StrCopy(radio, "--:--");
}
StrPrintF(line, "radio %s UTC sys %ld", radio, (Int32)PrefGetPreference(prefMinutesWestOfGMT));
WinDrawChars(line, StrLen(line), 5, 113);
FntSetFont(old);
}
static FormType *gStatusForm;
static void ShowStatus(const Char *text)
@@ -90,6 +126,7 @@ static void ConnectOrDisconnect(FormType *form)
gStatusForm = form;
err = AppConnect(ShowStatus, true);
ShowRadioInfo(form);
DrawClockLine();
if (err != errNone) {
AppErrorText(err, msg);
SetLabel(form, MainNameLabel, msg);
@@ -127,10 +164,12 @@ Boolean NodeFormHandleEvent(EventType *event)
FrmSetControlGroupSelection(form, MainLinkGroup, link);
ShowRadioInfo(form);
FrmDrawForm(form);
DrawClockLine();
return true;
}
case frmUpdateEvent:
ShowRadioInfo(form);
DrawClockLine();
return true;
case ctlSelectEvent:
+12 -1
View File
@@ -180,6 +180,9 @@ 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 UInt32 gRadioTimeAt = 0;
void SessionSyncClock(void)
{
UInt8 frame[VM_HEADER_LEN + 5];
@@ -190,12 +193,20 @@ void SessionSyncClock(void)
if (Request(frame, len, VM_RESP_CURR_TIME, 1) != errNone ||
!VmParseCurrTime(gDecoder.payload, gDecoder.len, &radio))
return;
gRadioTime = radio;
gRadioTimeAt = TimGetSeconds();
if (radio + VM_CLOCK_SLACK < now) {
len = VmBuildSetTime(frame, sizeof(frame), now);
Request(frame, len, VM_RESP_OK, 1);
if (Request(frame, len, VM_RESP_OK, 1) == errNone)
gRadioTime = now;
}
}
UInt32 SessionRadioTime(void)
{
return gRadioTime ? gRadioTime + (TimGetSeconds() - gRadioTimeAt) : 0;
}
Err SessionConnect(void)
{
Err err;
+2
View File
@@ -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);
/* The radio's clock (UTC) as last read, advanced by the time since; 0 if never read. */
UInt32 SessionRadioTime(void);
/*
* Call regularly (the app does on nilEvent): handles pushes, pulls waiting