"""Poll the micrOBU's station-link STATUS and show its log, from the native USB Serial/JTAG port. py -3.11 tools/station_status_watch.py COM6 [seconds] [--configure] [--rx] Speaks the station-link framing of obu-firmware (0xAA55, type, u16 length, payload, CRC-16/CCITT-FALSE over type..payload, little endian; frame type 0x10 = LINK, 0x7F = LOG text). Sends STATUS_REQUEST once a second; the 131-octet snapshot comes back in CONFIRM.detail (docs/station-link.pdf). --configure send STATION_CONFIGURE (cyclist, channel 180, 10 dBm, unsigned, no beaconing) after 2 s, which starts the radio --rx print the first V2X_RX messages (MicrOBU extension, opcode 0x90) and a total DTR and RTS stay low: toggling them resets the board over USB Serial/JTAG. Needs pyserial (the ESP-IDF python env has it). """ import struct import sys import time import serial LINK, LOG = 0x10, 0x7F STATION_CONFIGURE, STATUS_REQUEST = 0x01, 0x0C CONFIRM, V2X_RX = 0x80, 0x90 def crc16(data, crc=0xFFFF): for b in data: crc ^= b << 8 for _ in range(8): crc = ((crc << 1) ^ 0x1021) & 0xFFFF if crc & 0x8000 else (crc << 1) & 0xFFFF return crc def frame(ftype, payload): head = bytes([ftype]) + struct.pack(" 1 else 10 ser = serial.Serial(port, 115200, timeout=0.1) ser.dtr = False ser.rts = False buf = bytearray() start = time.time() seq, last, configured, rx = 1, 0.0, False, 0 while time.time() - start < seconds: if "--configure" in flags and not configured and time.time() - start > 2: ser.write(link(STATION_CONFIGURE, 100, struct.pack(" 1: ser.write(link(STATUS_REQUEST, seq)) seq, last = seq + 1, time.time() buf += ser.read(4096) while True: i = buf.find(b"\xAA\x55") if i < 0 or len(buf) < i + 7: break ftype, n = buf[i + 2], struct.unpack("= 2 and body[0] == 0 and body[1] == 131: d = body[2:] u32 = lambda o: struct.unpack_from("