114 lines
7.7 KiB
Markdown
114 lines
7.7 KiB
Markdown
# Large SPATEM / MAPEM reception (2026-11-23)
|
|||
|
|
|
||
|
|
Why a road RSU's SPATEMs and MAPEMs did not reach the phone's V2X screens, in two independent places, and what was
|
||
|
|
changed. Interface changes are in `obu-firmware/docs/station-link.tex` (revision 3).
|
||
|
|
|
||
|
|
## Symptom
|
||
|
|
|
||
|
|
A MAPEM and a SPATEM compiled to sit below 494 bytes arrived on the phone; larger ones did not. Later, with the
|
||
|
|
firmware fixed, the phone *logger* showed the RSU's large messages but the app's V2X screens stayed empty.
|
||
|
|
|
||
|
|
The "larger" test messages were far above the limit: **888 bytes (SPATEM) and 1198 bytes (MAPEM)**, from the
|
||
|
|
Berliner Tor RSU (station 1095348116, intersection 23, 6 lanes, 5 signal groups). The small pair were 377 B (MAPEM)
|
||
|
|
and 58 B (SPATEM). The test therefore showed that nothing is fragmented on that path, not where a cutoff sits.
|
||
|
|
|
||
|
|
## Problem 1: the firmware dropped everything over 494 bytes
|
||
|
|
|
||
|
|
**It did receive them.** The radio captures frames up to 2346 bytes, and the firmware's own `gn_unwrap.c`, replayed
|
||
|
|
on the PC over the CiT node's pcap (`its5_20261123_150746.pcap`, 27 367 frames), accepts all of them: 1727 MAPEMs
|
||
|
|
of 1198 B and 3384 SPATEMs of 888 B. They are valid: asn1tools decodes every distinct one and re-encodes it
|
||
|
|
byte-identically.
|
||
|
|
|
||
|
|
**The firmware then threw them away.** `V2X_RX` (opcode 0x90, MicrOBU's own) was designed as one link message. A link
|
||
|
|
message is at most 512 octets (the largest GATT value), minus 4 header and 14 prefix octets leaves **494 bytes** of
|
||
|
|
ITS payload. `Station::forward_raw` called `v2x_rx_fits()`, and for a longer message only incremented
|
||
|
|
`raw_oversize_` and returned. The fragmenting code (`LinkService::send_fragmented`, used for `RAW_FRAME`, PKI and
|
||
|
|
indications) existed and the app already reassembled any fragmented opcode, but the gate in front of it meant a
|
||
|
|
`V2X_RX` was never offered to it.
|
||
|
|
|
||
|
|
**Why nobody noticed:**
|
||
|
|
- It was a known, documented limit (`gn_unwrap.h`, `NOTES.md`, TODO.md: "road MAPEMs over 494 bytes are still dropped as
|
||
|
|
oversize (no fragmentation)"), but every earlier bench run used the bench RSU, whose messages are 58 and 295 bytes.
|
||
|
|
- The drop was silent where the phone could see it. The counter lived only in the firmware, STATUS has a fixed
|
||
|
|
131-octet layout with no field for it, and the only trace was one LOG line per 10 s on the USB log, which a phone on
|
||
|
|
BLE never gets.
|
||
|
|
- Comparing the phone log with a second receiver (the node's pcap) is what exposed it: 0 of 1537 large MAPEMs and
|
||
|
|
0 of 3004 large SPATEMs reached the phone, against 98.5 % and 96.5 % of the small ones.
|
||
|
|
|
||
|
|
**What the 2026-11-23 COM10 read did and did not show.** An early check of COM10's log concluded the board "never saw
|
||
|
|
a large message". That was wrong. `tools/station_status_watch.py` prints only the first few V2X_RX lines unless asked,
|
||
|
|
and opening the port reset the board. It showed nothing about large messages either way.
|
||
|
|
|
||
|
|
### Fix (obu-firmware)
|
||
|
|
- `v2x_rx.hpp`: `v2x_rx_plan()` decides `single` (up to 494 B, byte-identical to before), `fragmented` (up to
|
||
|
|
`v2x_rx_max_forward` = 2300 B), `covered_by_raw` (large and `RAW_CAPTURE` on) or `drop`.
|
||
|
|
- `link_fragment.hpp` (new, host-testable): `split_fragments()` is the one fragmenter. `LinkService::send_fragmented`
|
||
|
|
uses it, with the same bytes on the wire as before.
|
||
|
|
- Best effort, never blocking: fragments of a large `V2X_RX` go out on serial through the non-blocking
|
||
|
|
`try_write`, no retry, no wait. The first failed fragment ends that message; the app drops the incomplete stream
|
||
|
|
(2 s idle, or the next first fragment). A transport that would need more than 8 fragments (ATT MTU 23) skips the
|
||
|
|
message.
|
||
|
|
- `serial::try_write` now writes nothing when no USB host is connected.
|
||
|
|
- Counters `raw_fragmented_`, `raw_fragment_failed_`, `raw_covered_`, `raw_oversize_`, in the throttled LOG line.
|
||
|
|
STATUS is unchanged.
|
||
|
|
- The app's V2X_RX / Raw frames switch is untouched. While `RAW_CAPTURE` is on a large message is not sent a second
|
||
|
|
time as V2X_RX.
|
||
|
|
- TX path untouched.
|
||
|
|
|
||
|
|
### Result on air (COM10, BLE, 17:08-17:20)
|
||
|
|
`tools/rx_size_compare.py` on the new phone log and node pcap: MAPEM 1198 B 92.9 % of what the node heard, SPATEM
|
||
|
|
888 B 81.7 %, CAMs 92.5-99.3 %, `radio_dropped` 0, no BLE disconnects.
|
||
|
|
|
||
|
|
## Problem 2: the app's SPATEM decoder refused the RSU's messages
|
||
|
|
|
||
|
|
**Why the logger had them and the screens did not.** Both read the same `V2X_RX` frames from `Esp32Link`. They differ
|
||
|
|
in what they do with the bytes:
|
||
|
|
- `V2xLogger` stores the raw UPER payload and classifies it from the ITS PDU header. Decoding only fills convenience
|
||
|
|
columns (position, speed, a summary), inside `runCatching`, so a decoder that fails leaves them NULL and the row is
|
||
|
|
stored anyway.
|
||
|
|
- `CamUseCaseRepository.handleSpatUper` hands the bytes to `SpatemUperCodec.decode`; on `null` it logs
|
||
|
|
"decode FAILED" and emits nothing, so no SPAT reached the traffic-light screens.
|
||
|
|
|
||
|
|
**Why the decoder returned null.** `SpatemUperCodec` returned null whenever it met an optional it could not size.
|
||
|
|
The RSU's SPATEM uses two such fields on every intersection:
|
||
|
|
- `name` / `movementName` (`DescriptiveName`, IA5String SIZE(1..63)): "Berliner Tor / Kolbergstrasse" and one per
|
||
|
|
movement.
|
||
|
|
- `speeds` (`AdvisorySpeedList`) on every event: a greenwave and an ecoDrive advice per phase. This, with the names
|
||
|
|
and the 8 events per movement, is why the message is 888 bytes and not ~58.
|
||
|
|
|
||
|
|
The decoder's header comment said it had been validated against 79 042 SPATEMs from the 2026-03-18 drive; those
|
||
|
|
messages simply carried neither field. The gap was latent: until the firmware forwarded large messages, an 888-byte
|
||
|
|
SPATEM never reached the app, so the decoder never met one.
|
||
|
|
|
||
|
|
The MAPEM decoded correctly all along (it already reads names); the traffic-light screens need the SPATEM as well.
|
||
|
|
|
||
|
|
### Fix (app)
|
||
|
|
`SpatemUperCodec` now walks, without keeping, `DescriptiveName` (6-bit length n-1, then 7 bits per character) and
|
||
|
|
`AdvisorySpeedList` (4-bit count n-1; per entry: extension bit, five optional bits, type = extension bit plus 2 bits,
|
||
|
|
speed 9 bits, confidence 3 bits, distance 14 bits, class 8 bits). Regional extensions and extension values still
|
||
|
|
return null. Widths come from `dsrc_2_2_1.asn`.
|
||
|
|
|
||
|
|
## Verification
|
||
|
|
|
||
|
|
| Check | Result |
|
||
|
|
|---|---|
|
||
|
|
| Firmware host suite (`make check` in `obu-firmware/test/host`): chain, replay with asn1tools, 2 M-iteration fuzz, battery, firmware | pass; the firmware unit tests grew from 40 to 46 |
|
||
|
|
| `test_v2x_fragments`: the node pcap through unwrap, plan, fragments, two independent reassemblers, at link limits 512 and 244, with a lost fragment | 5111 large messages, 0 failures |
|
||
|
|
| App `LinkReassemblyTest` on the firmware's own fragments (`v2x_rx_fragments.tsv`) | pass |
|
||
|
|
| `SpatemUperCodec` against asn1tools on every distinct SPATEM of the new phone log | 718 of 718 equal field for field, 3590 movements |
|
||
|
|
| App unit suite | 197 tests, 0 failures |
|
||
|
|
| ESP-IDF 6.0.2 image build | 0x1f7aa0 bytes, 34 % of the app partition free |
|
||
|
|
|
||
|
|
## Files changed
|
||
|
|
Firmware: `v2x_rx.hpp`, `link_fragment.hpp` (new), `link_service.cpp/.hpp`, `station.cpp/.hpp`, `serial_link.cpp`,
|
||
|
|
`gn_unwrap.h` (comment), `NOTES.md`, `README.md`, `docs/station-link.tex`. Tests: `test_firmware.cpp`,
|
||
|
|
`test_v2x_fragments.cpp` (new), `Makefile`. App: `SpatemUperCodec.kt`, `SpatemUperCodecTest.kt`,
|
||
|
|
`LinkReassemblyTest.kt`, resources `v2x_rx_fragments.tsv`, `spatem_road_rsu_888.hex`. Tool: `tools/rx_size_compare.py`.
|
||
|
|
|
||
|
|
## Still open
|
||
|
|
- The V2X screens on the phone with the rebuilt app (this document was written before that check).
|
||
|
|
- MAPEM / SPATEM loss on BLE rises with size (58-byte SPATEM 96.5 % on 2026-11-23 earlier, 888-byte SPATEM 81.7 % now): a lost fragment loses
|
||
|
|
the message. If the screens need better, options are a smaller fragment cadence or a loss counter in the app
|
||
|
|
(`LinkReassembly.dropped`).
|
||
|
|
- Advisory speeds are walked, not used; a GLOSA display could read them.
|