K1Guitar/tools/k1_harness/suites/keys_tm1617.py

35 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""keys1617 套件:TM1617 段落/导航键注入(RTT `tm1617 key N`).
键值:0=KEY_MAIN_D(SEG5) 1=KEY_MAIN_C(SEG6) 2=KEY_MAIN_B(SEG7) 3=KEY_MAIN_A(SEG8) 4=释放(KEY_NULL)
需要固件含 app_tm1617_inject_key 钩子;无 ACK 时记 SKIP。
"""
from __future__ import annotations
from ..transports.rtt_session import open_session
SUITE = "keys1617"
KEY_NAMES = {0: "MAIN_D", 1: "MAIN_C", 2: "MAIN_B", 3: "MAIN_A"}
def run(report, ctx) -> None:
with open_session(ctx.device) as sess:
if not sess.cmd_ack("tm1617 key 4", "TM1617_KEY_OK", timeout_s=2.0, retries=3):
report.add(SUITE, "TM1617 注入命令探测", "SKIP",
"无 TM1617_KEY_OK:固件缺少 'tm1617 key' 命令(需 app_tm1617_inject_key 钩子)")
return
report.add(SUITE, "TM1617 注入命令探测", "PASS", "TM1617_KEY_OK")
for key, name in KEY_NAMES.items():
ok = sess.cmd_ack(f"tm1617 key {key}", "TM1617_KEY_OK", timeout_s=2.0, retries=3)
if not ok:
report.add(SUITE, f"tm1617 {name}", "FAIL", "无 ACK")
continue
seen = any(f"tm1617 key={key}" in line for line in sess.lines[-30:])
report.add(SUITE, f"tm1617 {name}", "PASS",
"" if seen else "ACK 有;[KEY] 日志未捕获")
sess.pump(0.1)
ok = sess.cmd_ack("tm1617 key 4", "TM1617_KEY_OK", timeout_s=2.0, retries=3)
report.add(SUITE, "tm1617 释放(KEY_NULL)", "PASS" if ok else "FAIL", "" if ok else "无 ACK")