feat: automate FT1 factory test status reporting
This commit is contained in:
@@ -16,6 +16,9 @@ MESSAGE_TYPES = {
|
||||
"node_result",
|
||||
"session_result",
|
||||
"power_off",
|
||||
"device_ready",
|
||||
"command_ack",
|
||||
"status_snapshot",
|
||||
}
|
||||
NODE_NAMES = (
|
||||
"BOOT_AUDIO",
|
||||
@@ -126,6 +129,22 @@ def parse_ft1_line(line: str) -> dict | None:
|
||||
raise ProtocolError("节点汇总无效: " + ", ".join(missing))
|
||||
if msg_type == "power_off":
|
||||
_require_int(message, "code", 0)
|
||||
if msg_type == "device_ready":
|
||||
if not isinstance(message.get("fw"), str):
|
||||
raise ProtocolError("device_ready 缺少 fw")
|
||||
if msg_type == "command_ack":
|
||||
if message.get("command") != "START" or not isinstance(message.get("accepted"), bool):
|
||||
raise ProtocolError("command_ack 字段无效")
|
||||
if msg_type == "status_snapshot":
|
||||
active_node = message.get("active_node")
|
||||
if isinstance(active_node, bool) or not isinstance(active_node, int) or active_node < -1 or active_node >= len(NODE_NAMES):
|
||||
raise ProtocolError("status_snapshot active_node 无效")
|
||||
nodes = message.get("nodes")
|
||||
if not isinstance(nodes, dict):
|
||||
raise ProtocolError("status_snapshot 缺少 nodes")
|
||||
missing = [name for name in NODE_NAMES if nodes.get(name) not in {"WAIT", "PASS", "FAIL"}]
|
||||
if missing:
|
||||
raise ProtocolError("status_snapshot 节点状态缺失: " + ", ".join(missing))
|
||||
return message
|
||||
|
||||
|
||||
@@ -145,6 +164,8 @@ class FT1Session:
|
||||
session_start_seen: bool = False
|
||||
session_result_seen: bool = False
|
||||
power_off_seen: bool = False
|
||||
device_ready_seen: bool = False
|
||||
start_ack_seen: bool = False
|
||||
nodes: dict[str, str] = field(default_factory=lambda: {name: "WAIT" for name in NODE_NAMES})
|
||||
node_details: dict[str, dict] = field(default_factory=dict)
|
||||
messages: list[dict] = field(default_factory=list)
|
||||
@@ -182,6 +203,20 @@ class FT1Session:
|
||||
self.firmware = str(message.get("fw", ""))
|
||||
self.start_time = message.get("start_time")
|
||||
return f"会话开始 {self.firmware or self.session}"
|
||||
if msg_type == "device_ready":
|
||||
self.device_ready_seen = True
|
||||
self.firmware = str(message.get("fw", ""))
|
||||
return f"设备已识别 {self.firmware}"
|
||||
if msg_type == "command_ack":
|
||||
self.start_ack_seen = bool(message.get("accepted"))
|
||||
return "START 已确认" if self.start_ack_seen else "START 被拒绝"
|
||||
if msg_type == "status_snapshot":
|
||||
self.nodes.update(message["nodes"])
|
||||
active_node = message["active_node"]
|
||||
self.current_node = NODE_NAMES[active_node] if active_node >= 0 else ""
|
||||
if active_node >= 0:
|
||||
self.nodes[self.current_node] = "RUNNING"
|
||||
return "状态广播 " + ", ".join(f"{name}={self.nodes[name]}" for name in NODE_NAMES)
|
||||
if msg_type == "node_start":
|
||||
name = message["name"]
|
||||
self.current_node = name
|
||||
|
||||
Reference in New Issue
Block a user