# -*- coding: utf-8 -*- """keys 套件:TM1629 和弦垫全键注入(RTT `chord key N`). 判定:CHORD_KEY_OK,或 [KEY] inject 日志(RTT 丢 ACK 时兜底)。 """ from __future__ import annotations from ..transports.rtt_session import open_session SUITE = "keys" 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:]) def run(report, ctx) -> None: with open_session(ctx.device) as sess: sess.cmd("log clear", 0.2) if not _chord_ok(sess, 0): 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): ok = _chord_ok(sess, key) report.add(SUITE, f"chord key {key}", "PASS" if ok else "FAIL", "" if ok else "无 ACK") sess.pump(0.05) ok = _chord_ok(sess, 0) report.add(SUITE, "chord key 0 释放", "PASS" if ok else "FAIL", "" if ok else "无 ACK") for xp in (0, 6, 11): 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:]) report.add(SUITE, f"chord xpose {xp}", "PASS" if ok else "FAIL", "" if ok else "无 ACK") sess.cmd_ack("chord xpose 0", "CHORD_XPOSE_OK", timeout_s=2.0, retries=3)