"""只核对附件编码，不打开串口、不发命令。请与JSON放在同一目录。"""
import json
from pathlib import Path

fixture = json.loads(Path(__file__).with_name("serial-command-fixture.json").read_text(encoding="utf-8"))
encoded = fixture["command_text"].encode(fixture["encoding"]) + bytes.fromhex(fixture["terminator_hex"])
assert encoded == bytes.fromhex(fixture["tx_hex"])
assert fixture["execution_allowed"] is False
def demo_response_state(data):
    if not data.endswith(b":"):
        return "incomplete"
    if b"ERR" in data:
        return "error"
    return "processing_finished_not_picture_verified"

assert demo_response_state(b":") == "processing_finished_not_picture_verified"
assert demo_response_state(b"ERR\r:") == "error"
assert demo_response_state(b"ERR") == "incomplete"
print(encoded.hex(" "))
print("编码一致；未绑定机型，未执行设备命令；错误文本与冒号不可混为成功。")
