1
0
Files
h8-536-decoder/ccu_emulator/frames.py
2026-05-27 11:50:10 +10:00

60 lines
1.8 KiB
Python

from __future__ import annotations
from h8536.bench_connect_lcd import format_frame, frame_checksum, frame_checksum_ok, parse_frame
FRAME_LENGTH = 6
HEARTBEAT_FRAME = bytes.fromhex("0000000080DA")
# Command 0, selector 0, value 0x8080. This seeds E000/E800 selector zero.
ACTIVE_SEED_COMMAND0 = bytes.fromhex("00000080805A")
# The older bench cadence sequence. It is still useful as an optional wake-up
# strategy because the real panel proved timing-sensitive around these frames.
CONNECT_CADENCE_SEQUENCE = (
bytes.fromhex("04000040001E"),
bytes.fromhex("0400008000DE"),
bytes.fromhex("040000C0009E"),
)
# Command 5, selector 0x0040, value ignored. ROM trace shows this is the safest
# neutral report-consume candidate.
NEUTRAL_ACK_FRAME = bytes.fromhex("05004000001F")
def build_frame(command: int, selector: int, value: int) -> bytes:
"""Build a six-byte host frame for simple page-0/page-1 selectors.
This helper covers the selector encodings we currently use in fake-CCU
probes. Keep more exotic mapping in one place when we learn it.
"""
if not 0 <= command <= 0xFF:
raise ValueError("command byte out of range")
if not 0 <= selector <= 0x01FF:
raise ValueError("selector out of supported range 0x000-0x1FF")
if not 0 <= value <= 0xFFFF:
raise ValueError("value out of range")
if selector <= 0x007F:
byte1 = 0x00
byte2 = selector
elif selector <= 0x017F:
byte1 = 0x01
byte2 = selector - 0x0080
else:
byte1 = 0x02
byte2 = selector - 0x0180
frame = bytes(
[
command & 0xFF,
byte1 & 0xFF,
byte2 & 0xFF,
(value >> 8) & 0xFF,
value & 0xFF,
]
)
return frame + bytes([frame_checksum(frame)])