Skip to content

Commit 438e255

Browse files
greatgitsbyclaude
andcommitted
esim: remove unnecessary sleeps from AtClient retry loops
lte.sh already blocks until the modem is online, so no post-reset sleep needed. open_isdr and send_apdu retry loops recover without delays. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a7e21f4 commit 438e255

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

system/hardware/tici/lpa.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
MM = "org.freedesktop.ModemManager1"
2424
MM_MODEM = MM + ".Modem"
2525
ES10X_MSS = 120
26+
OPEN_ISDR_RETRIES = 10
27+
OPEN_ISDR_RETRY_DELAY = 0.25
28+
OPEN_ISDR_RESET_ATTEMPT = 5
29+
SEND_APDU_RETRIES = 3
2630
DEBUG = os.environ.get("DEBUG") == "1"
2731

2832
# TLV Tags
@@ -146,24 +150,20 @@ def _open_isdr_once(self) -> None:
146150
raise RuntimeError("Failed to open ISD-R application")
147151

148152
def open_isdr(self) -> None:
149-
for attempt in range(10):
153+
for attempt in range(OPEN_ISDR_RETRIES):
150154
try:
151155
self._open_isdr_once()
152156
return
153-
except (RuntimeError, TimeoutError, termios.error):
154-
from openpilot.common.swaglog import cloudlog
155-
cloudlog.warning("open_isdr attempt %d failed, retrying", attempt + 1)
156-
if attempt == 3:
157-
# SIM may be stuck (CME ERROR 13) — reset modem via lte.sh
157+
except (RuntimeError, TimeoutError, termios.error, serial.SerialException):
158+
time.sleep(OPEN_ISDR_RETRY_DELAY)
159+
if attempt == OPEN_ISDR_RESET_ATTEMPT:
160+
# reset modem via lte.sh
158161
subprocess.run(['/usr/comma/lte/lte.sh', 'start'], capture_output=True)
159-
time.sleep(5)
160-
self._ensure_serial(reconnect=True)
161-
else:
162-
time.sleep(2.0)
162+
self._serial = None # serial port will be re-opened on next attempt
163163
raise RuntimeError("Failed to open ISD-R after retries")
164164

165-
def send_apdu(self, apdu: bytes, max_retries: int = 3) -> tuple[bytes, int, int]:
166-
for attempt in range(max_retries):
165+
def send_apdu(self, apdu: bytes) -> tuple[bytes, int, int]:
166+
for attempt in range(SEND_APDU_RETRIES):
167167
try:
168168
if not self.channel:
169169
self.open_isdr()
@@ -178,9 +178,8 @@ def send_apdu(self, apdu: bytes, max_retries: int = 3) -> tuple[bytes, int, int]
178178
raise RuntimeError("Missing +CGLA response")
179179
except (RuntimeError, ValueError):
180180
self.channel = None
181-
if attempt == max_retries - 1:
181+
if attempt == SEND_APDU_RETRIES - 1:
182182
raise
183-
time.sleep(1 + attempt)
184183
raise RuntimeError("send_apdu failed")
185184

186185

0 commit comments

Comments
 (0)