Protocols · the seams
ZTHREAT — zvision to tablets
One UDP datagram is exactly one frame of contacts. This is not NMEA: no leading
$, no checksum, and a numeric grammar pinned explicitly on both sides —
because a wire format must not inherit its host language's parser.
Frame format
ZTHREAT;<id>:<relAzDeg>:<size>:<collision>;<id>:<relAzDeg>:<size>:<collision>;...
A bare ZTHREAT with no contacts is an explicit all-clear, and is
what the runner emits on shutdown.
ZTHREAT;1:-12.0:0.300:0;2:4.5:0.900:1
| Field | Type | Meaning |
|---|---|---|
id | integer | Track id. 0 is the “unidentified” id and never latches the tracker light. Ids are namespaced per camera as camera_index × 1000 + local_id. |
relAzDeg | fixed-point, 1 decimal | Bearing relative to the vehicle's nose. Negative = left, positive = right. Full circle: ±180. |
size | fixed-point, 3 decimals | Apparent size, 0 = far → 1 = near. A sensor prominence proxy for range, not a distance. |
collision | 0 or 1 | Constant-bearing-while-growing collision flag |
There is no leading $ and no checksum — UDP already carries a checksum, and
the frame is validated structurally.
Limits
| Constant | Value |
|---|---|
| Header | ZTHREAT |
| Frame separator | ; |
| Field separator | : |
| Fields per contact | 4 |
| Max absolute azimuth | 180.0 |
| Max contacts per frame | 32 |
| Azimuth decimals | 1 |
| Size decimals | 3 |
The 32-contact cap keeps a frame inside one MTU — a fragmented multicast datagram over lossy WiFi essentially never arrives. When a frame would exceed the cap the producer sorts by collision first, then size descending and truncates, so the contacts that survive are the ones that matter.
Bearings past ±180 are garbage rather than rear contacts, and are
dropped. size is clamped into 0–1 by the consumer. A malformed
collision flag never costs the driver a contact — the body is still drawn, just
not in collision red; anything that is not exactly "1" is false.
The numeric grammar is pinned, deliberately
id -?[0-9]{1,9}
number -?[0-9]{1,9}(\.[0-9]{1,6})?
Both sides check these patterns explicitly rather than delegating to toFloatOrNull /
float(). A wire format must not inherit its host language's parser
quirks. [0-9] rather than \d, because Python's \d
also matches Unicode digits and Java's does not.
Framing whitespace is spelled out as exactly " \t\n\r\v\f" on both sides,
because Kotlin's trim() and Python's strip() disagree about which Unicode
code points count, and a wire contract cannot depend on that.
Nine integer digits keeps an id inside Int32 and keeps every value far below 32-bit float range, so no parsed number can be NaN or infinite.
Producer rules
- Contacts with a non-finite azimuth or size are dropped at the producer. A NaN
would serialise as the literal
nan, which both parsers reject anyway — but a producer must keep its own frames well-formed rather than leaning on the consumer's guard being there. - Fixed-point formatting rounds half-to-even on both sides. The Kotlin side uses
BigDecimal, which is locale-independent by construction —String.formatwould follow the device locale and emit0,300. - The Kotlin side restores the sign of
-0.0from the raw float bits, becauseBigDecimalhas no negative zero and would spell it0.0— and a contact a hair to the left of the nose is exactly where that shows up.
What the consumer does with a frame
NetworkThreatSource publishes the parsed contacts and marks the feed alive. A
1.5 s silence watchdog clears both. RoutedThreatSource
derives an explicit feed state:
| State | Meaning | Shown as |
|---|---|---|
LIVE | Frames arriving | n CONTACTS CLEAR (or an alert), solid ring rim |
DEMO | No frames, synthetic source enabled | n CONTACTS DEMO, dotted grey rim |
ABSENT | No frames, no synthetic source | NO VISION, dotted red rim |
It must never trigger the demo fallback. On a deployed vehicle the demo source is disabled, so
a dead feed reads ABSENT rather than inventing pedestrians. The word
CLEAR may only appear when the feed is LIVE.
ZCOVER — camera coverage
A dead camera stops producing contacts for its arc, and on the wire that is identical to
“that arc is clear”. ZCOVER is the low-rate companion channel that lets the
surround ring tell blind from clear. It rides the same group, port and socket as
ZTHREAT, so an old tablet's ThreatProtocol.parse() simply returns null for
it, and an old Jetson never sends one.
ZCOVER;<start>:<end>;<start>:<end>;...
ZCOVER;-64.0:64.0
- Covered arcs ride the wire, not blind ones, so the degenerate empty message
fails blind: a bare
ZCOVERmeans the whole ring is blind, and is sent on exit. - At most 16 arcs, degrees off the nose to one decimal, swept clockwise;
the numeric grammar and 32-bit rounding are shared with
ZTHREAT. - Producer (
zvision/coverage_protocol.py): the union of arcs whose camera delivered a frame within 3.0 s, emitted at 1 Hz plus immediately on any change. - Consumer (
core/vision/CoverageProtocol.kt→NetworkThreatSource): its own 5 s staleness timer, and it never marks the threat feed alive, so coverage alone cannot resurrect a deadZTHREATfeed. Stale or missing coverage falls back to the staticSurroundRing.COVERED_ARCS(±64°). - Its own golden corpus,
protocol/coverage-protocol-golden.json, generated byjetson/tools/gen_coverage_golden.pyand read by both suites.
Two hand-written implementations, neither authoritative
| File | Role | |
|---|---|---|
| Producer | jetson/zvision/threat_protocol.py | format_frame runs on the vehicle |
| Consumer | app/…/core/vision/ThreatProtocol.kt | parse runs on the vehicle |
Each also carries the other direction (parse_frame / format)
purely as a mirror. Nothing on the vehicle exercises those halves — which is
exactly why they drifted for months without anyone noticing. A cross-language contract rots in
whichever direction nobody executes.
The shared truth is a measured corpus that both test suites read. The golden corpus →
The bearing reference is settled
Bearings on this channel are computed by zvision's pixel_to_bearing,
fed by --fov-ref, which now defaults to d (diagonal). The
tablet assumes the forward thermal camera covers ±64°, and the
Python side now computes the same ±64° by default, so the two
sides agree without anyone remembering a flag — confirmed by measurement.
Read the full argument →
Converted fromdocs/PROTOCOLS.md §3 · protocol/README.md · jetson/DEPLOY.md