Update embedded app debugging workflow

This commit is contained in:
zoukai committed 2026-10-22 14:09:49 +08:00
1 parent d50be29246
commit 38807e5f97
13 files changed
+846 -122

No files matched your search

+5 -10
View File
@@ -193,15 +193,14 @@ class SerialWebSession(DeviceSession):
def __init__(self, base_url: str, expected_port: str, timeout: float) -> None:
self.base_url = base_url.rstrip("/")
self.timeout = timeout
self.client_id = "module-debug-" + uuid.uuid4().hex
page = self._request("/").decode("utf-8", errors="replace")
match = re.search(r'data-token="([^"]+)"', page)
if not match:
raise DebugError("串口网页控制台没有返回会话令牌")
self.token = html.unescape(match.group(1))
status = json.loads(
self._request("/api/status?client=" + urllib.parse.quote(self.client_id))
)
# 只有用户的网页维护页面租约。自动化读状态/日志不能冒充网页保活,
# 否则用户关闭最后页面后,本工具轮询会阻止串口按约定释放。
status = json.loads(self._request("/api/status"))
if not status.get("isOpen"):
raise DebugError("串口网页控制台存在,但串口没有打开")
actual_port = str(status.get("port") or "")
@@ -234,9 +233,7 @@ class SerialWebSession(DeviceSession):
def run(self, command: str, timeout: float = 20.0) -> Tuple[int, str]:
marker = "__CODEX_MODULE_RESULT_%s__" % uuid.uuid4().hex
wrapped = "(%s); rc=$?; printf '\\n%s=%%s\\n' \"$rc\"" % (command, marker)
start_log = self._request(
"/api/log?client=" + urllib.parse.quote(self.client_id)
).decode("utf-8", errors="replace")
start_log = self._request("/api/log").decode("utf-8", errors="replace")
self._request(
"/api/send?ending=CR",
data=wrapped.encode("utf-8"),
@@ -247,9 +244,7 @@ class SerialWebSession(DeviceSession):
pattern = re.compile(re.escape(marker) + r"=(-?\d+)")
while time.monotonic() < deadline:
time.sleep(0.2)
latest = self._request(
"/api/log?client=" + urllib.parse.quote(self.client_id)
).decode("utf-8", errors="replace")
latest = self._request("/api/log").decode("utf-8", errors="replace")
matches = pattern.findall(latest)
if matches:
offset = min(len(start_log), len(latest))