Fragment large V2X_RX messages and decode road-RSU SPATEMs

The firmware dropped every received ITS message over 494 bytes (one link
message), so a road RSU's 888-byte SPATEM and 1198-byte MAPEM never reached
the phone. V2X_RX now goes out in link fragments up to 2300 bytes, best
effort and non-blocking; messages up to 494 bytes are unchanged.

The app's SPATEM decoder then refused those messages because they carry
intersection and movement names and advisory speed lists. It now reads past
both, checked against asn1tools on 718 distinct messages.

Adds the pure fragmenter with host tests and a pcap replay, a Kotlin
cross-check on the firmware's own fragments, tools/rx_size_compare.py,
docs/08-large-message-reception.md and station-link revision 3.
This commit is contained in:
Ashin Walpola
2026-11-23 17:34:56 +01:00
parent 7dd83dba3d
commit ce18a393ea
24 changed files with 3305 additions and 2305 deletions
+89
View File
@@ -5,6 +5,95 @@ Engineering to-do list. The reviewer-facing open items live in
## Waiting on hardware
### Large SPATEM / MAPEM through V2X_RX in fragments (added 2026-11-23)
The 2026-11-23 bench run (CiT node sending a 377 B MAPEM and 58 B SPATEM, then 1198 B and 888 B ones; phone on
BLE) lost every large message: 0 of 1537 MAPEMs and 0 of 3004 SPATEMs against 98.5 % / 96.5 % of the small ones,
because `Station::forward_raw` dropped everything over 494 bytes. Firmware now sends those in link fragments
(`link_fragment.hpp`, `v2x_rx_plan`; NOTES.md). Done on the PC, not flashed yet: `make check` in
`obu-firmware/test/host` (46 unit tests, the pcap replay of 3384 + 1727 large messages through unwrap -> fragments ->
two reassemblers, fuzz), the app's `LinkReassemblyTest` on the firmware's own fragments, asn1tools on the large
payloads, ESP-IDF 6.0.2 image build.
- [x] Flashed to COM10 and run against the Berliner Tor RSU (2026-11-23 17:08-17:20, phone on BLE): MAPEM 1198 B 92.9 %,
SPATEM 888 B 81.7 % of what the node heard, `radio_dropped` 0. The V2X screens stayed empty because the app's
`SpatemUperCodec` refused the RSU's SPATEMs (intersection and movement names, advisory speeds); fixed and checked
against asn1tools on all 718 distinct messages, **needs the app reinstalled on the phone**.
- [ ] (original plan) Flash COM6 (`--no-stub` recipe, read the app descriptor first) and repeat the bench run: the node alternating
small and large MAPEM/SPATEM, the phone on BLE, a pcap recorded at the same time. Compare with
`py -3.11 tools/rx_size_compare.py LOG.db capture.pcap replay.tsv` (the header says how to make replay.tsv).
Accept: small messages stay at ~96-98 % of what the node saw, the large ones arrive at a comparable rate,
CAMs unchanged (92-96 % on 2026-11-23).
- [ ] `radio_dropped` (link_status) stays 0 with the large messages, as it did on 2026-11-23 without them, and no BLE
disconnects. If it moves, the fragments hold the station task too long: look at the fragment cap and BLE notify
failures (the board's LOG line "V2X_RX: ... fragmented (... not taken by any transport)", 1 per 10 s).
- [ ] The same over USB, and once with the app set to Raw frames: RAW_FRAME must still deliver the large ones, V2X_RX must
not send them a second time (`raw_covered_`), and switching back to V2X_RX must work without a reconnect.
- [ ] TX unchanged: a phone-originated CAM (signed and unsigned) is still seen by the node in the same session.
### App refresh: map dashboard, V2X switch, routing (added 2026-11-19)
Map-first dashboard (MapLibre, glass panels, folding bottom bar), "V2X ON/OFF" switch in the MicrOBU
box, V2X sending decoupled from trip recording, "Where to?" search and bicycle routing. Built, 185
unit tests green, and driven on the emulator with a mocked GPS fix (map, search, route preview and
guidance all work). Not checked without the ESP32-C5 or a phone on a bike:
- [ ] Connect the ESP32-C5 with no trip recording: V2X turns on by itself and the second ESP32 (or
`tools/cit_one_rx_watch.py`) hears the phone's CAMs. Switch it off on the Connection screen (tap the
MicrOBU box on the dashboard): they stop, and the dashboard box reads "V2X OFF".
Unplug and reconnect: it is on again, even if it was switched off before.
- [ ] Screen off for 5 minutes with V2X on: CAMs keep coming at 1 Hz (`V2xTransmitService` holds the
process and GNSS; the "V2X on" notification is showing).
- [ ] Connect while the app is in the background on Android 14+: the loop still sends if the foreground
service is refused (the start is allowed to fail), but the notification will be missing.
- [ ] CiT One selected: the V2X switch is disabled and mirrors the link, and nothing is sent by the phone.
- [ ] MicrOBU box shows the real battery percentage over BLE and USB, amber and red at the warn and
shutdown voltages.
- [ ] On a ride: heading-up mode tilts and turns the map with the course; guidance announces the turn
before the corner; going off route reroutes within about 15 s.
- [ ] GLOSA hint (speed box) at a real signalised junction with MAPEM and SPATEM on the air: the
advice matches the lights. The rules are unit-tested only; never tried against a live signal.
- [ ] Motion gate (`MotionDetector`): standing still indoors with GPS wandering, the speed box reads 0;
then ride: it never reads 0 while moving, in each mount (handlebar, bag, pocket). Thresholds
(`ENTER_STD` 0.15, `EXIT_STD` 0.07 m/s², 8 s hold) are from synthetic data only; a smooth-road
ride on a handlebar mount is the case most likely to need tuning. Not applied to the CAM speed
the phone transmits yet, which is still the raw GNSS speed.
- [ ] Settings > Developer > CAM pinger (moved from the V2X screen): starts and stops, shows the
loopback count, only appears with the ESP32-C5 selected.
- [ ] Decide the satellite and terrain tile provider (the layer buttons are in the map settings,
disabled until `MapLayer.styleUrl` has a source), and where routing and search run for real:
the app now sends the rider's position to photon.komoot.io and valhalla1.openstreetmap.de, which
are shared demo instances.
### Why the simulated car drops out of the V2X screen while the phone transmits (added 2026-11-19)
The bench beacon (`obu-cam-transmistter`, station 0x0BADC0DE) vanishes from the V2X screen for a
moment and comes back while the phone is sending. The V2X screen forgets a station after 3 s without
a CAM (`staleRemoteMs`), so these are gaps of 3 s or more. Hypothesis: the ESP32-C5 shares its radio
between BLE and ITS-G5 and a transmission and a reception collide with a BLE event.
Not confirmed. Read from the firmware source only, not measured: the TX hold for BLE
(`Station::hold_for_ble_guard`) is a busy-wait of at most 3.5 ms, too short to overflow the 16-frame
receive queue, so a queue overflow from transmitting is unlikely; the firmware's own notes say a frame
handed to the radio during a BLE connection event is accepted and never transmitted, and nothing says
reception is spared; frames the radio never delivers (or the PHY flags bad) are in no counter.
Tooling is in: the V2X data logger (schema 3) now records `link_status` once a second, and
`tools/rx_gap_analysis.py` accounts for every gap in the beacon's frames (lost before the radio saw
them, dropped in the firmware queue, or lost between board and phone) per condition, and checks
whether the gaps recur at a steady interval (two clocks beating). Self-tested on synthetic data only.
- [ ] Install the current build on the Pixel. Beacon on, 1-2 m from the OBU, nothing else on 5.9 GHz.
- [ ] Settings > Developer > V2X data logger > Start logging, then four stretches of at least 3
minutes each in one log, switching between them without stopping the log:
BLE with V2X off (Connection screen), BLE with V2X on, then the same two over USB
(cable from the phone to the OBU, Settings > Connection > ESP32 link = USB).
- [ ] Stop, pull the `.db` (`adb exec-out run-as com.hawhamburg.micr0bu cat files/v2x_logs/<file>`)
and run `python tools/rx_gap_analysis.py <file>.db`. The table says which condition loses frames,
and where; if the beacon's frames vanish before the radio and only on BLE with V2X on, BLE
coexistence with transmitting is the cause, and the recurrence line says whether it is a beat.
- [ ] If it is coexistence: the lever is in the firmware (the colleague's BLE guard calibrates only
TX), not the app; options are fewer or longer-interval BLE events while transmitting, or USB.
### Sensor fusion phase 1: logging and test rides (added 2026-11-18)
Settings > Ride (phone position, Record motion sensors) and the fusion data in the V2X data logger,