Commit Graph
14 Commits
Author SHA1 Message Date
Ashin Walpola 03efcfd4ee Ask for an ATT MTU of 517 so a 512-octet link message is not split
The app requests 517 and needs 515 for a 494-octet V2X_RX; the station's 512 left a
message of 492 to 494 octets to be fragmented, which the app does not reassemble.
Record the TX-loss measurement in TODO: BLE adds no measurable loss over USB.
2026-11-11 15:23:01 +01:00
Ashin Walpola 37707548ca Rotate the link-layer address with the pseudonym again
The app sends the pseudonym's MAC in the 16-octet STATION_CONFIGURE (address_configuration
0), the station uses it for unsigned frames too, and a different MAC reconfigures the
station. A ride rotates it with the station ID; the bench CAM pinger keeps one. Without a
MAC the station behaves as before (ticket-derived when signed, random when unsigned).

tools/station_tx_test.py plays the phone over USB and reads the station's own raw capture
(source MAC, signed or not, submitted and completed counts). Add the 16-octet form to the
spec (revision 2), a firmware unit test and an app test. Fix the stale Connection texts.
2026-11-11 15:02:39 +01:00
Ashin Walpola a7a6c39ca1 Record the 2026-11-11 bench run of the new firmware in TODO 2026-11-11 14:33:42 +01:00
Ashin Walpola c78b66341b Fix the XIAO battery reading: busy-wait for the divider to settle
At CONFIG_FREERTOS_HZ=100 pdMS_TO_TICKS(5) is zero ticks, so the switched divider
had not settled when the ADC was read and battery_mv came out as 0. Wait 5 ms with
esp_rom_delay_us and configure GPIO26 with gpio_config. The XIAO on COM10 now
reads 4153-4156 mV on a charging cell.
2026-11-11 14:17:38 +01:00
Ashin Walpola fd006192e7 Update the notes for the new firmware and name Niklas Dathe
README, docs/06, TODO and the architecture diagram describe the microbu-firmware
based obu-firmware and station-link revision 2, add the hardware checks for the
new image, and credit Niklas Dathe as the author of the station firmware and its
interface specification. Ignore LaTeX build output next to station-link.tex.
2026-11-11 00:13:58 +01:00
Ashin Walpola 8cbe3c337c Decode MAPEM and show traffic lights per lane
MapemUperCodec decodes MAPEM (MapData) from the ESP32-C5 (BTP port 2003)
and the CiT One's v2x/rx/mapem topic: intersection and lane names, the
reference point, lane types and directions, all node offset sizes and node
attributes, and each lane's connections with their signal groups. It
returns null on what it cannot size (extensions, regional data, computed
lanes) rather than guess.

TrafficLights.join places SPATEM signal groups on the MAPEM's ingress
lanes, gives each connection its turn (its maneuver, else the lane's, else
the angle between the lanes), picks the MAPEM whose revision the SPATEM
names when two are on air, and matches the rider to an ingress lane from
position and heading. The dashboard card then names the intersection and
shows the rider's lane, the distance to its stop line and one chip per
signal group with its turn arrows; the V2X map puts the light on the
reference point and draws the lanes in their signal colours.

Tested on recorded messages only: every distinct MAPEM on record (17 from
the 2026-03-18 drive, 288-1348 bytes, plus the bench RSU's) decodes field
for field like asn1tools; with a recorded SPATEM of the same intersection
and revision, 340 of 341 signalled exits find their movement (3/165's
group 65 never appears in its SPATEMs), and the geometric turn agrees with
198 of 201 stated maneuvers. tools/mapem_corpus.py rebuilds the fixtures.
2026-10-28 16:48:52 +01:00
Ashin Walpola fc3354a4ba 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.
2026-10-28 16:48:37 +01:00
Ashin Walpola 9f77f9f0e4 Monitor the XIAO's battery and make the XIAO the production board
The production OBU is now a Seeed XIAO ESP32-C5 (8 MB flash, one native
USB-C port) on a LiPo with no protection board. The firmware reads the
cell on GPIO6 (divider switched by GPIO26) every 5 s, sends it in STATUS
(battery_mv and battery_flags, octets 103-105; decoders accept 103 or
>= 106 octets), warns below 3.50 V and deep-sleeps below 3.30 V when no
phone is on USB, waking every 5 min to check the cell again. Thresholds
are in Kconfig; host test `make battery`.

The app shows voltage, a rough percentage and the low/critical state on
the ESP32-C5 card and in the top bar. With several bonded micrOBUs (a
replaced board stays bonded), the BLE link tries the one that last
connected first and moves on to the next after each failure.

tools/station_status_watch.py reads STATUS from the native port.
2026-10-28 16:48:18 +01:00
Ashin Walpola c13c3891c9 Add a V2X data logger to Settings > Developer
Records every received V2X message (CAM, DENM, SPATEM, MAPEM, VAM) into one
SQLite file per run, with a timestamp, the phone's GNSS fix, the OBU's GNSS fix
where there is one (CiT One), and RSSI where the hardware reports it (ESP32-C5).
Works on both hardware paths: V2X_RX frames from the ESP32 link, and the raw
v2x/rx plus processed v2x-uca topics over MQTT. The UPER bytes are stored
untouched; CAM, DENM and SPATEM also get a few decoded columns.

A foreground service keeps it recording with the screen locked. Subscribes to
v2x/rx/mapem so MAPEM is received on the CiT One.

The current ESP32-C5 firmware forwards only BTP ports 2001, 2002 and 2004, so
MAPEM and VAM appear in an ESP32 log only once it accepts 2003 and 2018.

Checked on a Pixel 9 Pro against a simulated car and an RSU: 10 minutes with the
screen locked and forced deep Doze, no gaps, files pass integrity_check.
2026-10-02 16:16:02 +02:00
Ashin Walpola d107534eb2 Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
obu-firmware builds against the vanetza-idf C-ITS library, which until now
came from the colleague's microbu-esp32c5 tree beside the repository and was
not tracked here, so a clone of this repository could not build the firmware
it ships. The library alone is now part of obu-firmware, as
obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit
cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from
there by default; -DVANETZA_IDF_DIR still points the build elsewhere.

The rest of the colleague's tree (their own VAM firmware, PKI tooling,
station-link Python tools, the V2X2MAP bridge) stays out of this repository
and gitignored; nothing is pushed to their repository. NOTES.md, docs/06,
TODO.md and the pcap verifier's usage line point at the new location.
2026-09-24 10:56:05 +02:00
Ashin Walpola 2f60623e18 Document the signed-ITS/VAM/BLE work and how it was verified
docs/06-signed-its-vam-ble.md: who does what between phone and ESP32-C5
(signing lives on the board), the link protocol, recovery paths (USB
heartbeat watchdog, BLE supervision timeout and auto-reconnect, board-reset
reconfiguration, app restart), the demo PKI, and what is still open.

obu-firmware/test/verify_signed_pcap.py checks the IEEE 1609.2 signatures in
a pcap with asn1tools and OpenSSL, independent of the firmware. On a capture
of the CAM pinger (2026-09-23) all 12 signed CAMs verify under the demo
ticket, whose chain verifies too. The CiT One receives the same CAMs but its
MQTT interface exposes no security information, so it cannot confirm the
signature itself. The V2X2MAP bridge on COM10 now verifies against the demo
chain as well (change in the colleague's repository); signed CAMs and VAMs
show as verified.

TODO.md: bench checks confirmed so far ticked; open are BLE/ITS-G5
coexistence, time_regression over a longer stationary run, and board reset
recovery over BLE.
2026-09-23 17:28:14 +02:00
Ashin Walpola 7285fa19b7 Count and surface RX-queue drops on the ESP32-C5's promiscuous path
wifi_promisc_rx_cb() fed s_rx_queue with a 0-timeout xQueueSend() and never
checked whether it succeeded, so a burst of captured frames arriving faster
than rx_forward_task could drain them vanished with no counter anywhere -
none of oversizeDrops/txFailures/rxCrcErrors caught it. Added a rxQueueDrops
counter, threaded it through the STATUS heartbeat as a new trailing uint16
(old firmware/app on either side still parse fine), and surfaced it on the
CAM Pinger card.

Confirmed on the bench: flashed to the production OBU (COM3) and installed
the matching app build on the phone, then watched the counter over logcat
against obu-cam-transmistter's ~3.3 Hz beacon - it is real (0 -> 89 -> 90
across two sessions) but bursty around connect/reconnect rather than a
continuous overflow under steady single-station traffic.
2026-09-22 14:45:17 +02:00
Ashin Walpola 01204a2c22 Give the V2X live map its own screen, and a traffic light per SPATEM
The map was a third view mode inside the V2X Monitor's topic pane, below
the use case alert panel and the DENM/CAM TX cards. On a phone that left
it about a third of the display tall, which is not enough to see where
anything is relative to anything else - the one thing a map is for. It
is now its own destination, V2xMapScreen on route v2x_map, reached from
a map button in that screen's header. The button sits in the header
rather than the view-mode row so it is also reachable from the message
detail pane and does not move as the available modes change with the
selected hardware. The status bar and bottom nav are hidden on this
route; the screen carries its own floating back button, and system back
still works. Both hardware paths get the same screen: everything drawn
comes from CamUseCaseRepository, which already merges the CiT One's MQTT
feed and the ESP32-C5's serial feed into one set of flows.

With the map gone from the toggle row, the row offers a single choice on
the ESP32-C5 path - there is no broker there and `topics` is always
empty - so it is hidden entirely in that mode.

SPATEM markers. Hazards already drew as a warning triangle; signalised
intersections did not draw at all. They now draw as a traffic light with
one lamp lit. Two things are worth knowing, because neither is forced by
the data:

- SPATEM carries signal state but no geometry, which is MAPEM's job and
  MAPEM is not decoded. The only position available is the sending RSU's
  own CAM, so the light is drawn there, and that RSU is drawn once - as
  the light, not as a CAM pin with a light on top of it. An intersection
  whose sender has not been heard over CAM cannot be placed; the map
  says how many rather than dropping them silently.
- Which lamp lights follows the rule DashboardScreen's SignalCard
  already uses, the signal group changing soonest speaking for the
  intersection, so the same intersection reads the same way in both
  places instead of inventing a second convention.

Four drawables rather than one tinted at runtime: setTint recolours
every path in a vector, so a single shared asset would turn the whole
light one flat colour and stop it reading as a traffic light.

Marker reuse. Every incoming message recomposes the map, and the update
block cleared the overlay list and rebuilt every Marker, decoding and
mutating a fresh Drawable per marker - at up to 10 Hz per station. It
also called animateTo(own) on every update, restarting the pan animation
before it could finish. Drawables are now loaded once per alert level
and phase and shared (osmdroid sets the icon's bounds on each draw, so
one instance across markers is safe), Markers are cached by key, and the
overlay list is only reordered, which moves references without
allocating. Following uses setCenter, keeping animateTo for the one move
worth seeing: the rider asking for follow back.

Follow-own now hands over to the rider on the first touch and returns
via the location button, which lights up while following. Before this
the map could not be panned at all while traffic was flowing, since the
next CAM dragged the viewport back.

Also on the map view: tiles scaled to DPI, the floating +/- buttons off
(they sit where the thumb lands and duplicate pinch), a zoom range, and
more tile threads so a pan that exposes a screenful of new tiles is not
served two at a time.

Compiles and the unit tests pass. None of it has been seen with live
traffic; TODO.md lists the on-device checks under "Waiting on hardware",
including which of the HAW RSUs send CAM alongside SPATEM.
2026-09-15 17:23:01 +02:00
Ashin Walpola 75d6d3b85c Receive signed ITS messages and forward each at its declared length
Signed packets. A GeoNetworking Basic Header NextHeader of 2 means a
TS 103 097 (IEEE 1609.2) envelope follows, with the Common Header
inside it. gn_unwrap_its rejected all of these, and most real traffic is
signed: the 2026-08-17 capture holds 157 signed frames from 15 source
MACs against 2 unsecured stations. It now opens a COER-encoded
signedData, or a bare unsecuredData, and parses the inner packet as
before. The inner packet comes first inside tbsData, so the certificate
and signature are never parsed, and the signature is not verified - the
firmware has no trust store. Such messages reach the phone with the new
V2X_RX flags bit1, signed but not verified. The app reads only bit0 and
is unaffected until it learns the flag. Encrypted payloads, nested
signing and the legacy v1.2.1 envelope are still rejected. All 157
recorded signed frames have the layout this reads, in all three COER
length forms, and asn1tools decodes every envelope to the same inner
packet.

Payload bounds. Every frame recorded through the ESP32-C5's promiscuous
RX, about 15 000 of them, ends in 8 bytes that are not part of the
802.11 frame and not a valid FCS. obu-firmware reads frames through the
same API and took the rest of the frame as the message, so it forwarded
those 8 bytes to the phone after every message. UPER decoders stop where
the message ends, so nothing visibly broke, but the bytes cost serial
bandwidth and 8 bytes of the DENM's headroom, and they stayed attached
wherever raw payloads were stored or passed on. The payload is now
exactly what the Common Header's payload-length field declares, which is
also what separates a signed message from its signature.

A frame longer than main.c's 800-byte capture buffer is now reported as
truncated instead of being forwarded cut off, and counted as an oversize
drop through the new serial_link_note_oversize_drop, as it was when the
cut-off frame failed serial_link's size check.

Host tests in obu-firmware/test/host build the firmware sources
unmodified with MSYS2 gcc; `make` runs all three.
- test_chain: frames from the firmware's TX code checked byte by byte
  against EN 302 636-4-1 and parsed back, including hand-built signed
  frames, the payload-length rule, the RX trailer, and every truncation
  length against a no-access guard page. 1731 checks, 0 failures.
- test_replay and check_replay.py: all 15 145 recorded frames through
  gn_unwrap_its, cut to 800 bytes as on the board, and re-derived
  independently in Python with the envelope decoded by asn1tools. They
  agree on every record; 15 131 accepted, 157 of them signed. 11 043 of
  the 11 106 distinct messages re-encode byte-identically. The other 63
  fail the same way with the old 8 bytes put back, so the boundary is
  not the cause: 5 are our own CAMs from before the 2026-08-20
  yawRateConfidence fix, and the rest, from other stations, are a
  follow-up in TODO.md.
- fuzz_gn_unwrap: random edits of every recorded frame, each run against
  the guard page. 50 000 000 iterations, no crash.

obu-firmware/test/pcap_gn_tally.py tallies GeoNetworking header fields
per station over captures; it is how the other stations' lifetimes were
measured. TODO.md collects what is still open, including the on-air
check for this change: it builds on IDF 6.1 but has not been flashed.
2026-09-11 20:19:40 +02:00