Stateful JSON-RPC client for serial communication. Accepts a SerialInterface for serial I/O. Use create_serial_interface() to create the appropriate backend (pyserial or fbuild). If no serial_interface is provided, an fbuild backend is created by default. To use pyserial, create th
| 99 | |
| 100 | |
| 101 | class RpcClient: |
| 102 | """Stateful JSON-RPC client for serial communication. |
| 103 | |
| 104 | Accepts a SerialInterface for serial I/O. Use create_serial_interface() |
| 105 | to create the appropriate backend (pyserial or fbuild). |
| 106 | |
| 107 | If no serial_interface is provided, an fbuild backend is created by default. |
| 108 | To use pyserial, create the interface externally and pass it in: |
| 109 | |
| 110 | from ci.util.serial_interface import create_serial_interface |
| 111 | iface = create_serial_interface(port, use_pyserial=True) |
| 112 | client = RpcClient(port, serial_interface=iface) |
| 113 | |
| 114 | Attributes: |
| 115 | port: Serial port path |
| 116 | baudrate: Serial baud rate (default: 115200) |
| 117 | timeout: Default RPC response timeout in seconds |
| 118 | response_prefix: Prefix for RPC responses (default: "REMOTE: ") |
| 119 | """ |
| 120 | |
| 121 | RESPONSE_PREFIX = "REMOTE: " |
| 122 | |
| 123 | # Post-ACK timeout floor for async (Phase 3) RPCs. After the device sends |
| 124 | # `{"acknowledged": true}` the client restarts its wait with at least this |
| 125 | # many seconds for the final response (or the caller-supplied timeout, |
| 126 | # whichever is larger). Picked generously so a 100-LED runSingleTest on a |
| 127 | # slow MCU has headroom; the typical run on Teensy 4 finishes in 80-90s. |
| 128 | # See FastLED#3060. |
| 129 | ASYNC_POST_ACK_TIMEOUT: float = 600.0 |
| 130 | |
| 131 | def __init__( |
| 132 | self, |
| 133 | port: str, |
| 134 | baudrate: int = 115200, |
| 135 | timeout: float = 10.0, |
| 136 | read_timeout: float = 0.5, |
| 137 | serial_interface: SerialInterface | None = None, |
| 138 | verbose: bool = False, |
| 139 | crash_decoder: CrashTraceDecoder | None = None, |
| 140 | ): |
| 141 | """Initialize RPC client. |
| 142 | |
| 143 | Args: |
| 144 | port: Serial port path (e.g., "/dev/ttyUSB0", "COM3") |
| 145 | baudrate: Serial baud rate (default: 115200) |
| 146 | timeout: Default timeout for RPC operations in seconds |
| 147 | read_timeout: Timeout for individual serial reads (unused with fbuild) |
| 148 | serial_interface: Pre-created SerialInterface. If None, an fbuild |
| 149 | backend is created automatically on connect(). |
| 150 | verbose: If True, enable detailed RPC logging |
| 151 | crash_decoder: Optional CrashTraceDecoder for inline crash decoding. |
| 152 | """ |
| 153 | self.port = port |
| 154 | self.baudrate = baudrate |
| 155 | self.timeout = timeout |
| 156 | self.read_timeout = read_timeout |
| 157 | self.verbose = verbose |
| 158 | self._serial: SerialInterface | None = serial_interface |
no outgoing calls