diff --git a/palm-client/src/node_form.c b/palm-client/src/node_form.c index 16197d2..b6ab459 100644 --- a/palm-client/src/node_form.c +++ b/palm-client/src/node_form.c @@ -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: diff --git a/palm-client/src/session.c b/palm-client/src/session.c index 2f387b2..93ad919 100644 --- a/palm-client/src/session.c +++ b/palm-client/src/session.c @@ -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; diff --git a/palm-client/src/session.h b/palm-client/src/session.h index f73b51d..44d7cac 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); +/* 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