From ce1626410f25ff170141d6e4884438448fbca61e Mon Sep 17 00:00:00 2001 From: "Rich O." Date: Wed, 4 Nov 2026 09:24:51 -0500 Subject: [PATCH] palm-client: a command the radio doesn't answer closes the session (offline, not "online" with every command failing), with retries as after a wake; after a quiet minute a time query checks the link is still there --- palm-client/src/convo_form.c | 1 + palm-client/src/main.c | 7 ++++++ palm-client/src/session.c | 49 +++++++++++++++++++++++++++++++++--- palm-client/src/session.h | 2 ++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/palm-client/src/convo_form.c b/palm-client/src/convo_form.c index b9a7848..cf75e06 100644 --- a/palm-client/src/convo_form.c +++ b/palm-client/src/convo_form.c @@ -416,6 +416,7 @@ static void Send(FormType *form) FldDelete(field, 0, FldGetTextLength(field)); DrawCounter(); Refresh(true); + DrawStatus(); /* offline now if the radio didn't answer */ if (err == vmErrNoReply || (err != errNone && err != vmErrRadio)) { AppErrorText(err, msg); FrmCustomAlert(SettingsErrorAlert, msg, "", ""); diff --git a/palm-client/src/main.c b/palm-client/src/main.c index 990ad0b..a10cb7b 100644 --- a/palm-client/src/main.c +++ b/palm-client/src/main.c @@ -201,6 +201,13 @@ static void AppEventLoop(void) Err err; do { + if (SessionTakeLost()) { + /* the radio stopped answering: show offline and keep trying, as after a wake */ + gWantConnection = true; + gRetries = 0; + gRetryAt = TimGetTicks() + 2 * SysTicksPerSecond(); + FrmUpdateForm(FrmGetActiveFormID(), VM_UPDATE_DATA); + } EvtGetEvent(&event, EventTimeout()); CheckWake(); if (event.eType == nilEvent) { diff --git a/palm-client/src/session.c b/palm-client/src/session.c index f8db1d3..f3a2ae1 100644 --- a/palm-client/src/session.c +++ b/palm-client/src/session.c @@ -31,6 +31,8 @@ static VmFrameDecoder gDecoder; static Boolean gConnected = false; +static Boolean gLost = false; /* the radio stopped answering: see SessionTakeLost */ +static UInt32 gHeardAt = 0; /* ticks when the radio last sent anything */ static Boolean gMsgWaiting = false; static UInt16 gChanged = 0; static VmDeviceInfo gDevice; @@ -162,6 +164,8 @@ static Err WaitForAny(const UInt8 *codes, UInt16 n, Int32 timeout) } gRxPos = 0; gRxLen = TransportRecv(gRx, sizeof(gRx), left, &err); + if (gRxLen) + gHeardAt = TimGetTicks(); } } @@ -183,6 +187,7 @@ static void DrainInput(void) gRxLen = TransportRecv(gRx, sizeof(gRx), 0, &err); if (gRxLen == 0) break; + gHeardAt = TimGetTicks(); } VmDecoderReset(&gDecoder); } @@ -205,12 +210,24 @@ static Err RequestAny(const UInt8 *frame, UInt16 len, const UInt8 *codes, UInt16 if (err == serErrTimeOut) continue; if (err != errNone) - return err; + break; err = WaitForAny(codes, n, VM_REPLY_TIMEOUT); if (err != vmErrNoReply) return err; } - return err == serErrTimeOut ? vmErrNoReply : err; + if (err == serErrTimeOut) + err = vmErrNoReply; + /* + * The radio itself always answers at once, so the link is gone (the bridge + * stopped, a cable pulled): offline, rather than "online" with every + * command failing. gConnected first, so the disconnect sends nothing. + */ + if (gConnected) { + gConnected = false; + gLost = true; + SessionDisconnect(); + } + return err; } static Err Request(const UInt8 *frame, UInt16 len, UInt8 code, UInt16 tries) @@ -310,6 +327,7 @@ static Err OpenAndQuery(void) return err; } gConnected = true; + gHeardAt = TimGetTicks(); gScopeMode = VM_SCOPE_UNKNOWN; return errNone; } @@ -490,7 +508,7 @@ const VmConv *SessionSoundConv(UInt8 kind) Err SessionSyncMessages(void) { static const UInt8 codes[] = { VM_RESP_CONTACT_MSG_V3, VM_RESP_CHANNEL_MSG_V3, VM_RESP_NO_MORE_MESSAGES }; - UInt8 frame[VM_HEADER_LEN + 1]; + UInt8 frame[VM_HEADER_LEN + 5]; UInt16 len = VmBuildSyncNextMessage(frame, sizeof(frame)); UInt16 n; VmMessage m; @@ -566,7 +584,7 @@ static Err ApplyScope(const VmConv *conv) Err SessionGetDefaultScope(Char *name) { - UInt8 frame[VM_HEADER_LEN + 1]; + UInt8 frame[VM_HEADER_LEN + 5]; UInt8 key[VM_SCOPE_KEY_SIZE]; Err err; @@ -719,12 +737,27 @@ Err SessionRetry(UInt16 index) return SendRecord(index); } +/* After a quiet minute, asks the radio the time, so a lost link shows (RequestAny) while idle. */ +#define VM_QUIET_TICKS (60 * SysTicksPerSecond()) + +static void CheckAlive(void) +{ + UInt8 frame[VM_HEADER_LEN + 5]; + UInt16 len; + + if (TimGetTicks() - gHeardAt < VM_QUIET_TICKS) + return; + len = VmBuildGetTime(frame, sizeof(frame)); + Request(frame, len, VM_RESP_CURR_TIME, 1); +} + UInt16 SessionPoll(void) { UInt16 changed; if (gConnected) { DrainInput(); + CheckAlive(); if (gMsgWaiting) SessionSyncMessages(); if (MessagesExpireAcks(SessionNow())) @@ -901,6 +934,14 @@ Boolean SessionIsConnected(void) return gConnected; } +Boolean SessionTakeLost(void) +{ + Boolean lost = gLost; + + gLost = false; + return lost; +} + Boolean SessionMessageWaiting(void) { return gMsgWaiting; diff --git a/palm-client/src/session.h b/palm-client/src/session.h index 0d76411..73fba80 100644 --- a/palm-client/src/session.h +++ b/palm-client/src/session.h @@ -42,6 +42,8 @@ Err SessionConnect(void); Err SessionConnectLight(void); void SessionDisconnect(void); Boolean SessionIsConnected(void); +/* True once after the radio stopped answering a command and the session closed itself; clears it. */ +Boolean SessionTakeLost(void); Boolean SessionMessageWaiting(void); /* What the radio last reported (valid while connected). */