fix: bootstrap serial monitor on UART open
This commit is contained in:
+15
-1
@@ -811,7 +811,21 @@ class NodeOpsExecutor:
|
||||
command.extend([*(["-p", port] if port else []), *(["-b", str(baud)] if baud else [])])
|
||||
output = self._spawn_output(command, serial_dir, timeout_ms)
|
||||
body = self._parse_json(output.get("stdout"))
|
||||
return {**output, "ok": output.get("ok") and body.get("success") is True, "bindingSource": "serial-monitor-cli", "port": port or None, "baudRate": baud, "response": body or None}
|
||||
server_start = None
|
||||
if action == "start" and self._serial_server_unreachable(body):
|
||||
server_start = self._spawn_output([*command_base, "server", "start"], serial_dir, timeout_ms)
|
||||
server_body = self._parse_json(server_start.get("stdout"))
|
||||
server_start = {**server_start, "response": server_body or None}
|
||||
if server_start.get("ok") and server_body.get("success") is True:
|
||||
output = self._spawn_output(command, serial_dir, timeout_ms)
|
||||
body = self._parse_json(output.get("stdout"))
|
||||
return {**output, "ok": output.get("ok") and body.get("success") is True, "bindingSource": "serial-monitor-cli", "port": port or None, "baudRate": baud, "response": body or None, "serverStart": server_start}
|
||||
|
||||
def _serial_server_unreachable(self, body: dict) -> bool:
|
||||
data = body.get("data") if isinstance(body.get("data"), dict) else {}
|
||||
request = data.get("request") if isinstance(data.get("request"), dict) else {}
|
||||
diagnosis = data.get("diagnosis") if isinstance(data.get("diagnosis"), dict) else {}
|
||||
return body.get("success") is False and (request.get("code") == "ECONNREFUSED" or diagnosis.get("status") == "not_running")
|
||||
|
||||
def _uart_write(self, args: dict) -> dict:
|
||||
data = str(args.get("data") or "")
|
||||
|
||||
Reference in New Issue
Block a user