2026-09-14 15:05:17 +08:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2026-09-14 16:16:11 +08:00
|
|
|
|
"""keys 套件:TM1629 和弦垫全键注入(RTT `chord key N`).
|
2026-09-14 15:05:17 +08:00
|
|
|
|
|
2026-09-14 16:16:11 +08:00
|
|
|
|
判定:CHORD_KEY_OK,或 [KEY] inject 日志(RTT 丢 ACK 时兜底)。
|
2026-09-14 15:05:17 +08:00
|
|
|
|
"""
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
from ..transports.rtt_session import open_session
|
|
|
|
|
|
|
|
|
|
|
|
SUITE = "keys"
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-09-14 16:16:11 +08:00
|
|
|
|
def _chord_ok(sess, key: int) -> bool:
|
|
|
|
|
|
if sess.cmd_ack(f"chord key {key}", "CHORD_KEY_OK", timeout_s=2.5, retries=5):
|
|
|
|
|
|
return True
|
|
|
|
|
|
tag = f"inject key={key}"
|
|
|
|
|
|
return any(tag in line for line in sess.lines[-40:])
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-09-14 15:05:17 +08:00
|
|
|
|
def run(report, ctx) -> None:
|
|
|
|
|
|
with open_session(ctx.device) as sess:
|
|
|
|
|
|
sess.cmd("log clear", 0.2)
|
|
|
|
|
|
|
2026-09-14 16:16:11 +08:00
|
|
|
|
if not _chord_ok(sess, 0):
|
2026-09-14 15:05:17 +08:00
|
|
|
|
report.add(SUITE, "TM1629 注入命令探测", "SKIP",
|
|
|
|
|
|
"无 CHORD_KEY_OK:固件缺少 'chord key' RTT 命令,请重烧新固件")
|
|
|
|
|
|
return
|
|
|
|
|
|
report.add(SUITE, "TM1629 注入命令探测", "PASS", "CHORD_KEY_OK")
|
|
|
|
|
|
|
|
|
|
|
|
for key in range(1, 24):
|
2026-09-14 16:16:11 +08:00
|
|
|
|
ok = _chord_ok(sess, key)
|
|
|
|
|
|
report.add(SUITE, f"chord key {key}", "PASS" if ok else "FAIL",
|
|
|
|
|
|
"" if ok else "无 ACK")
|
2026-09-14 15:05:17 +08:00
|
|
|
|
sess.pump(0.05)
|
|
|
|
|
|
|
2026-09-14 16:16:11 +08:00
|
|
|
|
ok = _chord_ok(sess, 0)
|
2026-09-14 15:05:17 +08:00
|
|
|
|
report.add(SUITE, "chord key 0 释放", "PASS" if ok else "FAIL", "" if ok else "无 ACK")
|
|
|
|
|
|
|
|
|
|
|
|
for xp in (0, 6, 11):
|
2026-09-14 16:16:11 +08:00
|
|
|
|
ok = sess.cmd_ack(f"chord xpose {xp}", "CHORD_XPOSE_OK", timeout_s=2.5, retries=5)
|
|
|
|
|
|
if not ok:
|
|
|
|
|
|
ok = any(f"xpose set {xp}" in l or f"xp={xp}" in l for l in sess.lines[-30:])
|
2026-09-14 15:05:17 +08:00
|
|
|
|
report.add(SUITE, f"chord xpose {xp}", "PASS" if ok else "FAIL", "" if ok else "无 ACK")
|
2026-09-14 16:16:11 +08:00
|
|
|
|
sess.cmd_ack("chord xpose 0", "CHORD_XPOSE_OK", timeout_s=2.0, retries=3)
|