Forward MAPEM and VAM from the ESP32-C5, and add a bench listener

gn_unwrap.c now passes BTP ports 2003 (MAPEM) and 2018 (VAM), signed or
not, besides CAM, DENM and SPATEM. A message over 494 bytes still does not
fit one 512-octet link message (also the largest GATT value) and is dropped
and counted, not fragmented. The bench RSU's MAPEM is 295 bytes.

CONFIG_MICROBU_BENCH_LISTEN (off in sdkconfig) is for a board whose only PC
connection is the UART0 console: it configures itself receive-only at boot
and logs every V2X_RX message; tools/bench_listen_watch.py tallies the log.
On air on 2026-10-28 it forwarded 104 MAPEM, 185 SPATEM and 472 CAM in
90 s, with nothing oversize. The RSU sent all of them unsigned.

Host tests: signed GeoBroadcast SPATEM/MAPEM frames of 58 to 1243 bytes
with every truncation length; the replay cuts frames at c5_radio.cpp's
2346 bytes (not the old C firmware's 800) and checks MAPEMs with asn1tools.
This commit is contained in:
Ashin Walpola
2026-10-28 16:48:37 +01:00
parent 9f77f9f0e4
commit fc3354a4ba
12 changed files with 246 additions and 55 deletions
+62
View File
@@ -0,0 +1,62 @@
"""Tally what an obu-firmware BENCH LISTEN build (CONFIG_MICROBU_BENCH_LISTEN) hears, from its UART0 console.
py -3.11 tools/bench_listen_watch.py COM3 [seconds]
The bench build logs one line per message its raw RX path (gn_unwrap.c) unwraps, e.g.
I (12345) station: V2X_RX port 2003 msgid 5, 295 bytes, -61 dBm, GBC
This counts them per BTP port: how many, sizes, RSSI range, how many signed, how many too big for a
link message (dropped). Opening the port resets the board (DTR/RTS), so the first lines are the boot.
Needs pyserial (the ESP-IDF python env has it).
"""
import collections
import re
import sys
import time
import serial
LINE = re.compile(r"V2X_RX port (\d+) msgid (\d+), (\d+) bytes, (-?\d+) dBm(.*)")
NAMES = {2001: 'CAM', 2002: 'DENM', 2003: 'MAPEM', 2004: 'SPATEM', 2018: 'VAM'}
def main():
port = sys.argv[1]
seconds = float(sys.argv[2]) if len(sys.argv) > 2 else 60
stats = collections.defaultdict(lambda: {'n': 0, 'sizes': set(), 'msgids': set(), 'rssi': [],
'signed': 0, 'gbc': 0, 'oversize': 0})
with serial.Serial(port, 115200, timeout=0.5) as s:
end = time.monotonic() + seconds
buffer = b''
while time.monotonic() < end:
buffer += s.read(4096)
*lines, buffer = buffer.split(b'\n')
for raw in lines:
text = raw.decode(errors='replace').rstrip()
m = LINE.search(text)
if not m:
if 'BENCH' in text or 'radio' in text or ' E (' in text or text.startswith('E ('):
print(text)
continue
p, msgid, length, rssi, rest = int(m[1]), int(m[2]), int(m[3]), int(m[4]), m[5]
st = stats[p]
st['n'] += 1
st['sizes'].add(length)
st['msgids'].add(msgid)
st['rssi'].append(rssi)
st['signed'] += 'signed' in rest
st['gbc'] += 'GBC' in rest
st['oversize'] += 'OVERSIZE' in rest
print(f"\n{seconds:.0f} s on {port}:")
print(f"{'port':>5} {'type':7} {'count':>6} {'msgid':>6} {'bytes':>12} {'dBm':>10} {'signed':>7} {'GBC':>5} {'oversize':>9}")
for p in sorted(stats):
st = stats[p]
sizes = f"{min(st['sizes'])}-{max(st['sizes'])}" if len(st['sizes']) > 1 else str(min(st['sizes']))
msgids = ','.join(map(str, sorted(st['msgids'])))
rssi = f"{min(st['rssi'])}..{max(st['rssi'])}"
print(f"{p:>5} {NAMES.get(p, '?'):7} {st['n']:>6} {msgids:>6} {sizes:>12} {rssi:>10} {st['signed']:>7} {st['gbc']:>5} {st['oversize']:>9}")
if not stats:
print(" nothing: is it the bench build (BENCH LISTEN line at boot), and is anything on air?")
if __name__ == '__main__':
main()