K1Guitar/tools/test_uni_bp_xpose.py

76 lines
2.7 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.

#!/usr/bin/env python3
"""万能模式:拨片上推 + 琴颈键快移调 RTT 验证。
路径:tone bin3 → pick hold 1 → chord key 2/20
期望:MSG id=24 (BP_TRANSPOSE),[xpose] bp key=… trans=…
"""
from __future__ import annotations
import sys
import time
from pathlib import Path
TOOLS = Path(__file__).resolve().parent
if str(TOOLS) not in sys.path:
sys.path.insert(0, str(TOOLS))
from k1_harness.transports.rtt_session import open_session # noqa: E402
def has_any(lines, *needles):
return any(all(n in ln for n in needles) for ln in lines)
def main() -> int:
results = []
with open_session(reset=True) as sess:
sess.cmd_ack("tone bin3", "TONE_BIN3", timeout_s=4.0, retries=4)
sess.pump(0.4)
tab_ok = has_any(sess.lines, "TONE_BIN3") or has_any(sess.lines, "tab=0")
results.append(("tone bin3 进万能", tab_ok, "TONE_BIN3" if tab_ok else "无 ACK"))
mark = len(sess.lines)
sess.cmd("chord key 2", settle=0.6)
after = sess.lines[mark:]
key_ok = has_any(after, "CHORD_KEY_OK") or has_any(after, "tm1629 key=2")
no_xpose = not has_any(after, "id=24") and not has_any(after, "bp key=")
results.append((
"无上推时 key2 不移调",
key_ok and no_xpose,
f"key_ok={key_ok} leaked_xpose={not no_xpose} lines={after[-8:]}",
))
mark = len(sess.lines)
hold_ok = sess.cmd_ack("pick hold 1", "PICK_HOLD_OK", timeout_s=2.5, retries=5)
results.append(("pick hold 1", hold_ok, "PICK_HOLD_OK" if hold_ok else "固件无 pick hold 命令,需重烧"))
if hold_ok:
mark = len(sess.lines)
sess.cmd_ack("chord key 2", "CHORD_KEY_OK", timeout_s=2.5, retries=4)
sess.pump(0.5)
after = sess.lines[mark:]
got_c = has_any(after, "bp key=2") or has_any(after, "id=24")
results.append(("上推+key2 → C(0)", got_c, " ".join(after[-12:])))
mark = len(sess.lines)
sess.cmd_ack("chord key 20", "CHORD_KEY_OK", timeout_s=2.5, retries=4)
sess.pump(0.5)
after = sess.lines[mark:]
got_b = has_any(after, "trans=11") or has_any(after, "bp key=20")
results.append(("上推+key20 → B(11)", got_b, " ".join(after[-12:])))
sess.cmd("pick hold 0", settle=0.2)
sess.cmd("chord key 0", settle=0.2)
print("\n=== 万能琴颈移调 RTT ===")
fail = 0
for name, ok, detail in results:
print(f"{'PASS' if ok else 'FAIL'} {name} {detail}")
if not ok:
fail += 1
return 1 if fail else 0
if __name__ == "__main__":
raise SystemExit(main())