From 453559cd5c6f01f552eddb8821885ccf78fd7e32 Mon Sep 17 00:00:00 2001 From: "Rich O." Date: Wed, 4 Nov 2026 09:45:55 -0500 Subject: [PATCH] palm-client: a reconnect in steps is lighter on the app: reads that can't wait check what's buffered first (SrmReceiveCheck), steps 4 times a second instead of 10, its DEVICE_QUERY send waits 100 ms instead of 250 --- palm-client/src/main.c | 2 +- palm-client/src/session.h | 2 +- palm-client/src/transport_srm.c | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/palm-client/src/main.c b/palm-client/src/main.c index 954247e..4c123d2 100644 --- a/palm-client/src/main.c +++ b/palm-client/src/main.c @@ -122,7 +122,7 @@ static Boolean gWantConnection = false; /* we were connected when the Visor sl * later (8.5 min in all). */ #define VM_RETRIES 8 -#define VM_STEP_TICKS (SysTicksPerSecond() / 10) +#define VM_STEP_TICKS (SysTicksPerSecond() / 4) static UInt32 gRetryAt = 0; /* ticks; 0: no retry due */ static UInt16 gRetries = 0; diff --git a/palm-client/src/session.h b/palm-client/src/session.h index c250107..d01e656 100644 --- a/palm-client/src/session.h +++ b/palm-client/src/session.h @@ -45,7 +45,7 @@ void SessionDisconnect(void); /* * A connect in steps, so the app keeps running while it finds the radio * (reconnects after a wake or a lost link). Start opens the link; then call - * Step every tenth of a second or so until it returns something other than + * Step a few times a second until it returns something other than * vmErrPending: errNone once connected and synced, or the error (link * closed). SessionConnect or SessionDisconnect abandons it. */ diff --git a/palm-client/src/transport_srm.c b/palm-client/src/transport_srm.c index 6624fb4..26ec5a9 100644 --- a/palm-client/src/transport_srm.c +++ b/palm-client/src/transport_srm.c @@ -4,6 +4,7 @@ #define VM_BAUD 115200 #define VM_SEND_TRIES 8 /* SrmSend attempts for one buffer (USB re-attach) */ #define VM_SEND_WAIT (SysTicksPerSecond() / 4) /* each: 2 s in all */ +#define VM_ONCE_WAIT (SysTicksPerSecond() / 10) /* TransportSendOnce */ static UInt16 gPortId; static Boolean gPortOpen = false; @@ -81,13 +82,20 @@ Err TransportSend(const UInt8 *buf, UInt16 len) Err TransportSendOnce(const UInt8 *buf, UInt16 len) { + Int32 wait = VM_ONCE_WAIT; + UInt16 size = sizeof(wait); + UInt32 sent; Err err = errNone; if (gPort == VM_PORT_SBLORA) return SbTransportSend(buf, len); if (!gPortOpen) return serErrNotOpen; - if (SrmSend(gPortId, (void *)buf, len, &err) == len) + SrmControl(gPortId, srmCtlSetCtsTimeout, &wait, &size); + sent = SrmSend(gPortId, (void *)buf, len, &err); + wait = VM_SEND_WAIT; + SrmControl(gPortId, srmCtlSetCtsTimeout, &wait, &size); + if (sent == len) return errNone; SrmClearErr(gPortId); return err != errNone ? err : serErrTimeOut; @@ -106,6 +114,9 @@ UInt16 TransportRecv(UInt8 *buf, UInt16 max, Int32 timeoutTicks, Err *errP) return 0; } + /* without waiting: only if something's there (a read that can't wait still costs the USB driver time) */ + if (timeoutTicks == 0 && (SrmReceiveCheck(gPortId, &avail) != errNone || avail == 0)) + return 0; /* Block for the first byte, then take whatever else is already buffered. */ n = SrmReceive(gPortId, buf, 1, timeoutTicks, errP); if (n == 0) {