import struct

DUMP = r"C:/Users/vikto/Documents/Claude/rt-4d/radio-spi-dump.bin"
with open(DUMP, "rb") as f:
    cal = f.read(0x1000)

base = 0x20
REC = 0x70

# HEADER 0x00-0x1f
hdr = cal[0:0x20]
print("HEADER bytes:", " ".join(f"{b:02x}" for b in hdr))
# try interpret as u16 LE and u32 LE
u16 = struct.unpack("<16H", hdr)
print("as u16 LE:", u16)
u32 = struct.unpack("<8I", hdr)
print("as u32 LE:", [hex(x) for x in u32])
# The tail 3a 3c 3f 41 44 47 4a 4b 4c 4d 4e 4f 50 51 52 80 looks like a small table of 16 ascending bytes
print("\nheader bytes 0x10-0x1f (ascending table?):", [hex(b) for b in hdr[0x10:0x20]])
print("diffs:", [hdr[0x10:0x20][i+1]-hdr[0x10:0x20][i] for i in range(15)])

# Dump all 15 populated records fully, grouped by 8-byte lines with offset labels
print("\n\n==== 15 populated records (each 0x70) ====")
for idx in range(15):
    off = base+idx*REC
    r = cal[off:off+REC]
    print(f"\n### REC {idx} @0x{off:03x}  b0={r[0]:02x} b1={r[1]:02x}")
    for i in range(0, REC, 16):
        row = r[i:i+16]
        hexs = " ".join(f"{b:02x}" for b in row)
        print(f"  +{i:02x}: {hexs}")
