Commit 7fa14fbf authored by Yann Garcia's avatar Yann Garcia
Browse files

Review [C] processing

parent db67853b
Loading
Loading
Loading
Loading
+17 −7
Changes for upper_tester/__main__.py: 17 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -3,9 +3,16 @@
@brief    Command-line entry point: python3.13 -m upper_tester --device /dev/quectel_at --port 12100
@details  Opens the modem, sends `ATE0` once (disable command echo so lines can be told
          apart from responses), and serves the upper-tester TCP protocol (see server.py)
          until interrupted (Ctrl-C), at which point the modem is reset (AT+CFUN=1,1)
          before the device is closed, so it isn't left in whatever state the last
          in-flight AT command left it in.
          until interrupted (Ctrl-C), at which point the modem is re-initialized
          (AT+CFUN=1, full functionality, *no* reset flag) before the device is closed,
          so it isn't left in whatever state the last in-flight AT command left it in
          (e.g. CFUN=0/4 from a MODEM_RESTART or DEREGISTER MMI command). This
          deliberately does not use AT+CFUN=1,1 (module reset): on Quectel modules
          that reboots the cellular/USB subsystem, which drops and re-enumerates the
          ttyUSB device -- on the Pi that meant /dev/ttyUSB2 could vanish for the
          ~15 s the module takes to come back, and a relaunch before then would fail
          to open it. AT+CFUN=1 changes RF functionality only; the USB link is
          untouched.
"""
import argparse
import asyncio
@@ -62,12 +69,15 @@ def main() -> None:
    try:
        asyncio.run(run())
    except KeyboardInterrupt:
        log.info("Ctrl-C received: resetting the modem before exit")
        log.info("Ctrl-C received: re-initializing the modem before exit")
        try:
            ok, text = modem.execute("AT+CFUN=1,1")
            log.info("AT+CFUN=1,1 -> %s %r", ok, text)
            # AT+CFUN=1, not AT+CFUN=1,1: restore full functionality without a module reset,
            # which would reboot the cellular/USB subsystem and drop the ttyUSB device (see
            # the module docstring).
            ok, text = modem.execute("AT+CFUN=1")
            log.info("AT+CFUN=1 -> %s %r", ok, text)
        except OSError as e:
            log.error("modem reset on exit failed: %s", e)
            log.error("modem re-initialization on exit failed: %s", e)
    finally:
        modem.close()