From 462303eed66d6f383d7057cf861e02a82f37906e Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Sat, 5 Dec 2026 16:03:02 +0100 Subject: [PATCH] Docs and TODO after the MilCAN / NGVA notes (docs/design.adoc "What the military vehicles do"): Silent Watch, Blackout of our own devices, a hardware interlock; the Pi on 12 V only behind a HAT with an STM32C5 (power supervisor, watchdog, the Pi's CAN, 5.1 V / 5 A); the outputs' controller moves to that STM32C5 ("The controller on the Pi's HAT": requests from keypads, mcu-lvgl and maptool, Zephyr, 16 MB flash for MCUboot and a black box; native_sim on SocketCAN first). TODO: can.json curves, multiplexing and warning limits after candinista; the mcu-lvgl panel in the Garmin style; TPMS off the car's CAN; Android Auto with the Pi as the phone (AOA over USB-OTG); a universal STM32C5 board v1 with TCAN1043 --- TODO.adoc | 91 +++++++++++++++++++++++++++++--- docs/design.adoc | 131 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 208 insertions(+), 14 deletions(-) diff --git a/TODO.adoc b/TODO.adoc index 87a4ba1..60f9f2a 100644 --- a/TODO.adoc +++ b/TODO.adoc @@ -254,6 +254,17 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho names) or a vxcan pair moved into the container's namespace by a host script ** [ ] The car-CAN → CANopen bridge's mapping (not decided yet) as signals in `data/can.json`; a dashboard panel for the `car.*` signals +** [ ] Signals in `data/can.json`, after candinista (github.com/mikeypi/candinista, its + `config.yaml`) — for third-party devices whose conversion we can't change: +*** [ ] A sensor curve: `x_values` → `y_values`, linear interpolation between points (NTC + temperature senders, pressure sensors), instead of `scale` / `offset` +*** [ ] Multiplexed signals: one byte of the frame says which channel it carries (`mux_byte`, + `mux_value`; e.g. Haltech TPMS, wheel 1–4 on one ID) +*** [ ] Warning limits per signal (`low_warn`, `high_warn`): the value coloured on its tile +** [ ] A display node on the CANopen bus (`mcu-lvgl`, ESP32-8048S043, 4.3" 800×480, LVGL) with + its own switch screens — it only sends requests to the controller and draws the state the + controller reports, so it works with the Pi off. The look: Garmin style, picked in the Design + canvas (PanelGarmin: Switches, Power, Tanks, Settings; the status bar is the navigation) ** [x] The GNSS node's PDO layout as `gnss.*` signals — `mcu-stm32-xiao-c5-2` (node 0x21, esphome-canopen), `data/can.json` in docs/deployment.adoc ** [x] `/can.html` diagnostics: interfaces, nodes (heartbeat, last EMCY, what they send), @@ -307,6 +318,12 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho ** [ ] Off the route: the gyro's yaw rate (the IMU node) or the compass, with map matching ** [ ] Back out of the tunnel: the first fixes taken only once consistent (HDOP, the jump from the estimate); the trip log keeps a straight line through the tunnel for now +* [ ] TPMS off the car's CAN (2026-12-05): the car's own TPMS read by the car gateway and passed on + as `car.tpms.*` signals in `data/can.json` (the 4 wheels, pressure, temperature where sent); + warnings: low pressure, a fast drop (a puncture). Find where the Yaris Cross has it — broadcast + on a CAN the gateway sees, or only on request (UDS from the TPMS ECU). No radio node of our own; + sniffing the 433 MHz sensors (`rtl_433` on the uConsole's SDR) only if the car's CAN doesn't + carry it === 3D navigation mode @@ -399,16 +416,32 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho *** [ ] Brick ↔ the car: a trip planned at home on brick handed to the car's server (with the library sync, or "send to the car") *** [ ] Push instead of polling (SSE) if 2 s ever feels slow -** [ ] Android Auto: the browser can't be cast there, only a native app — a small one with - the Car App Library's NavigationTemplate drawing its own map surface (MapLibre Native) off - the car server's trip and position (`/api/trip`, `/api/gnss/position`); only the map and - the next maneuver, planning stays on the web. Testable without the car: the tablet runs the - Android Auto head unit emulation (DHU) +** [ ] Android Auto with the Pi as the phone (2026-12-05): the Pi connects to the car's existing + Android Auto and shows maptool's navigation to the driver on the car's screen; the display on + the Pi / the tablet over Wi-Fi are the navigator's. No phone in the loop +*** [ ] Over USB first: the head unit is the host, switches the "phone" into Android Open + Accessory (AOA) mode, then the Android Auto protocol (AAP over TLS). The Pi must be a USB + gadget — USB-OTG: the Pi 5's USB-C port (`dwc2` peripheral), on a CM5 whether its carrier + brings out the USB 2.0 port; power from the HAT through the header, the USB-C data only + (car VBUS not connected). Wireless (Bluetooth, then Wi-Fi) later +*** [ ] First check the head unit accepts a foreign phone side: AARE + (github.com/prototux/AARE, an open phone-side reimplementation, an Android app) on a phone + in the Yaris Cross; from AARE, whether the head unit checks the phone's certificate (if it + wants a Google-signed one, this way is closed). No open phone side for Linux was found +*** [ ] Then a Linux phone side (the AAP messages are aasdk's protobufs, the same both ways), + tested at home against Google's Desktop Head Unit. Video is H.264: the Pi 5 / CM5 have no + hardware encoder, so software (x264 ultrafast) at the head unit's 800×480 or 1280×720, + 30 fps, one or two cores. Back from the car: touch and the rotary into maptool; to the car: + navigation prompts on AA's own audio channel, the turn arrows in the cluster where supported +*** [ ] Fallback: a native app on the phone — the Car App Library's NavigationTemplate drawing + its own map surface (MapLibre Native) off the car server's trip and position (`/api/trip`, + `/api/gnss/position`); only the map and the next maneuver, planning stays on the web *** [ ] Views by who's driving off which screen: no Android Auto connected → the 16" display shows the 3D follow view (heading-up, pitched) for the driver; Android Auto connected → it streams the 3D navigation to the driver, and the co-driver's display stays 2D (north-up - overview, planning). Needs the app to report connected/disconnected to the server (e.g. - next to `/api/gnss/position`) and the driving view to switch on it + overview, planning). Needs the Android Auto link (the Pi's phone side, or the fallback app) + to report connected/disconnected (e.g. next to `/api/gnss/position`) and the driving view + to switch on it ** [ ] A native Android app on Ferrostar (rerouting, Valhalla speed limits, TTS built in) over our Valhalla (`format: osrm`) — only if navigation is wanted on a phone outside the car; the car's 16" display is the Pi's browser either way. Ferrostar's web components are beta: no @@ -466,6 +499,21 @@ Planning in the NPS look, driving in the cockpit look, joined by the Unigrid bla Inspired by Garmin Tread / zūmo, but open and over CANopen — the nodes' side and the options are in home-gitops `docs/canopen-nodes.adoc` ("Inšpirácia: Garmin Tread / zūmo"): +* [ ] A universal STM32C5 board v1 (2026-12-05) instead of XIAOs (~9 € + VAT + 10 € postage + each; out of stock) and before role-specific boards — one design, one round of first-spin + fixes, 8–10 pieces for the IO nodes, the car gateway, the Meshtastic bridge, the + controller prototype. JLCPCB in batches, Basic parts assembled, the MCU by hand. The bare MCU + isn't reliably in stock either (TME showed 0, ~3.6 USD) — check before ordering the PCBs +** STM32C5A3CGT6 (LQFP48), 16 MB flash on QSPI (W25Q128, as on the XIAO, for Zephyr) +** 2× CAN transceiver, both TCAN1043 (CAN FD, VIO for 3.3 V, wake on bus traffic or the local + WAKE pin, INH switching the board's regulator → Silent Watch at µA); one part everywhere (one + JLCPCB extended-part fee), ~0.4–1 USD more than a TJA1051 at LCSC. Not selective wake + (TJA1145 / TCAN1145, SPI): any bus traffic wakes every node, fine while the bus is quiet +** Automotive 12 V in: reverse polarity, TVS, a buck to 3.3 V; SWD; the power + CAN connector + the same as the xt30_can_5v board (XT30 2+2) +** Headers with every free GPIO, SPI and UART: role add-ons on top — an output board, a + Meshtastic radio on UART (its firmware doesn't run on the C5) + * [ ] Hardware buttons (a CANopen keypad / a steering-wheel controller, read off `can0`): actions in `data/can.json` — pan, zoom ±, add a point (the position into the library or the trip), mark a place, switch views (navigation / overview / dashboard), mute / volume, the @@ -476,6 +524,17 @@ are in home-gitops `docs/canopen-nodes.adoc` ("Inšpirácia: Garmin Tread / zūm *** [x] Positions, strobe and dimmer (2026-12-04): a key steps through outputs (a knob up and down), blinking with a period, a knob's level by a step (a dimmable module: a byte per channel); in /keypad.html and /sim.html. Nothing real behind them yet *** [x] Switch tiles on the screen (2026-12-04, the canvas' GridSwitches): Menu → Switches (only when `/api/outputs` answers), 3×3 tiles per page (name, On / Off / Flashing / level, the key and mode driving it, its LED colour line), a group per module, All off, More ▸; a tap toggles (`switchesMenu` in `drive_menus.js`) *** [ ] Interlocks and conditions (speed, ignition), long press +*** [ ] The controller moves to the STM32C5 on the Pi's HAT (docs/design.adoc "The controller on + the Pi's HAT", 2026-12-05): first the CANopen objects for requests (toggle / on / off / level + from keypads, `mcu-lvgl`, maptool), the outputs' state (TPDO) and the configuration (bindings + over SDO), used by maptool's `outputs.rb` now; then the Zephyr firmware (MCUboot's second slot, + the black box and the bindings in the 16 MB external flash), checked against `outputs.rb`; + maptool fetches the black box when it comes up +**** [ ] Before more STM32C5 boards arrive (both XIAOs are in use): the controller in Zephyr as + `native_sim` on SocketCAN (`zephyr,native-linux-can`) — on a PC against `vcan0` with + `/sim.html` and the simulated outputs, on rpi-dev against `can0` and the real keypads; the + external flash emulated in a file; the same inputs give the same outputs as `outputs.rb`. + Only the chip's layer (CAN, flash, power) moves to the board later. Order more XIAO STM32C5 ** [x] CANopen TIME from maptool while no node sends it (2026-12-04, `lib/maptool/can_time.rb`); the GNSS node takes over once esphome-canopen has TIME *** [ ] A knob's hold (the eye), the focused row's badges in keypad mode, the knobs' LEDs (8Encoder colours over SDO) ** [x] The key mapping in our diagnostics (2026-12-04, `/keypad.html`, the canvas' GridBinding): pick a key or knob (or press it), what it drives, mode, menu, LEDs; saved per car in `data/drive/bindings.json`. Not yet: interlocks, conditions, long press; drive mode picks a change up only on reload @@ -483,6 +542,14 @@ are in home-gitops `docs/canopen-nodes.adoc` ("Inšpirácia: Garmin Tread / zūm * [ ] A virtual switch panel for the PDM node (like Garmin's PowerSwitch: tiles with icon, label, state and current, groups) + rules: by speed, sun/time of day, geofence (the trip's camp), ignition and battery voltage +** [ ] Blackout / camp mode: one key — keypad LEDs ~2 % dim red, screen Night at its lowest, + auxiliary outside lights off and inhibited (door → awning light) until left; road lights untouched +** [ ] Sleep (Silent Watch): outputs to their safe state, nodes NMT stopped / asleep, screen off; + what wakes them (a key, ignition / wake line, CAN wake-up) — node side in home-gitops + `docs/canopen-nodes.adoc` (TCAN1043 on every board: wake + INH, transparent until the firmware + uses its EN / nSTB pins; the "everyone to sleep" command from the controller) +** [ ] A node's hardware interlock (winch, inverter, heater off on a wire, MCU or bus dead or not) + shown on its tiles as "locked out" * [ ] The group over LoRa (Meshtastic / MeshCore through a node on the Pi): the others' positions as a live layer with trails, short messages, "come here" into the trip * [ ] Audio: volume / mute from the keypad and the app, navigation prompts ducking the music @@ -509,6 +576,16 @@ already offline work on the road. The Pi only serves; heavy builds stay on brick * [ ] Build on brick, ship to the Pi: `offline.pmtiles`, `terrain.pmtiles`, Valhalla `tiles.tar`, `places/*.sqlite`, `hiking_trails/*.geojson`, the ZIM — an rsync (only when refreshed, which is rare) instead of the Pi's own build buttons; hide/disable those there +* [ ] Powering the Pi (docs/design.adoc "What the military vehicles do"): preferred, the Pi on + 12 V only, anywhere in the car — the gateway node tells "car running" (car CAN data or its IGN + input); a HAT with an STM32C5 turns the Pi on (car running, or a wake from the network), asks + it to shut down cleanly and cuts power after, measures voltage / current; the HAT also has the + Pi's CAN (SPI controller + transceiver, `can0`), the STM32C5 a node on the same bus and the Pi's + watchdog (maptool's heartbeat — it sends none yet —, power-cycle when it hangs). The Pi 5 takes + 5 V only and wants ≥ 5 A: the HAT's buck 5.1 V / 5 A+ into the header's 5 V pins, and + `PSU_MAX_CURRENT=5000` in the EEPROM (powered off the header it can't tell, and limits USB to + 600 mA); the 12 V side survives a cold crank or shuts down cleanly. Fallback: the Pi on + the bus, 6-pin Deutsch DT (12 V, GND, CAN H, CAN L, IGN, spare), IGN read by the Pi * [x] Login without internet: Gitea OAuth can't run offline — let the car's LAN through without login (e.g. `TRUSTED_NETWORKS` CIDR list), or a local fallback account. Done: the session cookie is checked locally (90 days, no Gitea after the login), and rpi-dev has diff --git a/docs/design.adoc b/docs/design.adoc index 6530d73..9f38706 100644 --- a/docs/design.adoc +++ b/docs/design.adoc @@ -381,10 +381,11 @@ communication is lost, a confirmation for dangerous circuits. What it means for us: -* *maptool is the whole controller*: keypads, relay modules and lights - are I/O; the modes, timers, strobe, interlocks, conditions and LED - colours run in maptool — unless a device has its own firmware for that - function, which is outside our scope. +* *One controller*: keypads, relay modules and lights are I/O; the + modes, timers, strobe, interlocks, conditions and LED colours run in + one place — unless a device has its own firmware for that function, + which is outside our scope. Today that's maptool; it moves to the + STM32C5 on the Pi's HAT (below, "The controller on the Pi's HAT"). * *A binding* = an input (keypad node, key or encoder) + a mode + a target: an output (a relay or light channel, SDO/RPDO) or a screen function (zoom, the next profile, the next stop). Bindings live in the @@ -397,9 +398,9 @@ What it means for us: * *The LED colour on the screen*: a thin line in the key's LED colour under the tile or screen key it drives — dim off, full on, blinking red on a fault — so it's clear which key controls what. -* *Fail-safe*: a Hold output goes off when the keypad or maptool goes - silent; a relay node needs a heartbeat consumer on maptool and its own - safe state. +* *Fail-safe*: a Hold output goes off when the keypad or the controller + goes silent; a relay node consumes the controller's heartbeat and has + its own safe state. * *Encoders*: a value (dimmer, volume), a changer (profiles, wrap) or a parameter controller. The interim (Blink Marine style) keypad has 8 keys and 8 encoders: two move the map, one zooms, the rest are bound @@ -424,6 +425,122 @@ ECUMaster, "How-to Set Up Keyboards with Encoders in PMU" (v1.0, 2026-01-09); ECUMaster USA, CAN keypads with the PMU16; HP Academy, PDM control pad setup. +=== What the military vehicles do (MilCAN, NGVA; notes, 2026-12-05) + +From a chat with Gemini, checked only partly — treat the details as +leads, not facts. + +* *MilCAN* (the MilCAN working group, UK): *MilCAN A* on 29-bit + identifiers, J1939-like; *MilCAN B* on CANopen (11-bit). Used for the + vehicle electronics (vetronics: power, lights, panels, keypads), the + engine stays on its own J1939. *NGVA* (NATO Generic Vehicle + Architecture, STANAG 4754) puts Ethernet on top for data and video, + CAN/J1939 stays for the automotive side — close to our maptool + CANopen + split. +* *Connectors*: MIL-DTL-38999, 150–400 € a pair — not for us. Gemini's + "7-pin vetronics pinout" (V+, GND, CAN_H, CAN_L, wake, interlock, + shield) is not a standard we could find; the two extra signals are + still worth having: *a wake line* and *a hardware interlock*. + Dual CAN (A/B on both sides of the hull) is beyond what a car needs. + +What we can borrow: + +* *Silent Watch* — parked for days on battery: every node asleep at + microamps, woken by a key, the ignition / wake line or a CAN wake-up. + Node side: a transceiver with a wake input and INH (TCAN1043 wakes on + any bus activity, WUP; TJA1145 / TCAN1145 also by a selected frame — + partial networking); STM32 in Stop. For later: whether ESPHome and + our CANopen can sleep and wake that way is unknown, and the node PCBs + have to be designed around the chosen transceiver (its wake pin, INH + switching the regulator). maptool's side: a *Sleep* action + (all outputs to their safe state, nodes to NMT stopped / sleep, the + screen off) and what wakes what. +* *Blackout / camp mode* — only our own devices, one key: keypad LEDs to ~2 % in a dim red, + the screen to Night at its lowest, the auxiliary outside lights + (awning, work lights) off and *inhibited* (the door no longer turns the + awning light on) until it's left. A screen profile + a condition on + the outputs, not a new mechanism. The road lights are the car's own + and stay untouched (the military's blackout keeps dim blackout stop + lights too; on a public road it's not ours to switch). +* *Smart fuses (SSPC)*: nothing new — that's the PDM node (dingoPDM and + the like: high-side switches with current sense, trip on a short, reset + over CAN); its current and faults on the switch tiles and load shedding + by battery voltage are already in the virtual switch panel's TODO. +* *Hardware interlock*: a wire that drops the power outputs (winch, + inverter, heater) even with a hung MCU or a dead bus — a node's own + safe state, maptool only shows it. + +*Powering the Pi and the ignition* — two ways: + +. *The Pi on the bus*: a 6-pin Deutsch DT — 12 V, GND, CAN H, CAN L, IGN + and one spare (seen like that on another project); the Pi watches IGN + and shuts itself down cleanly a while after the ignition goes off. +. *The Pi on 12 V only* (the usual way, preferred): the car's CAN is + read by *our gateway node*, which tells "the car is running" from the + car's CAN data or from its own IGN input. The Pi then needs only power + (12 V, GND, possibly IGN — a separate connector, like + https://www.reddit.com/r/raspberry_pi/comments/1codbfw/raspberry_pi_for_automotive_applications_update/[r/raspberry_pi, + "Raspberry Pi for automotive applications"]) and can sit anywhere in + the car. A *HAT with an STM32C5* is its power supervisor: it turns the + Pi on when the car runs or when something on the network needs it + (a node, the tablet), asks it to shut down and cuts its power after, + and measures the power (voltage, current, the battery) — later more. + The HAT also carries the Pi's own CAN (a controller on SPI such as the + MCP2518FD + a transceiver, so maptool keeps its `can0`); the STM32C5 + sits on the same bus as a node of its own and is the Pi's *watchdog*: + it consumes maptool's heartbeat and power-cycles a Pi that hung. + +IGN (or the gateway's "running") is also the simplest wake signal for +the nodes. + +The nodes' side (transceiver, wake pin, PROFET board) belongs in +home-gitops `docs/canopen-nodes.adoc`. + +=== The controller on the Pi's HAT (decided 2026-12-05) + +The outputs' logic leaves maptool for the *STM32C5 on the Pi's HAT*, the +way PDMs (ECUMaster PMU, MaxxECU) keep the keypad and output logic in +themselves rather than on the display. + +* *One owner of every output.* The keypads, the `mcu-lvgl` panel and + maptool only send *requests* (toggle, on, off, a level); the controller + decides, drives the output nodes and sends the outputs' state in a TPDO + that everyone draws from. No two devices write to the same relay. +* *It works with the Pi off.* The HAT's STM32C5 runs whenever there are + 12 V (it's the Pi's power supervisor and watchdog anyway), so the lights + and the pump work while the Pi boots (20–30 s), hangs or is off at camp. +* *The chip*: the same STM32C5A3CGT6 as the nodes (Cortex-M33, 144 MHz, + 1 MB internal flash, two FDCANs, LQFP48) plus the board's 16 MB + external flash. An STM32H was considered and dropped: the controller is + a state machine for a few dozen outputs, an H7 draws far more while the + car stands (the HAT never sleeps fully, Silent Watch), needs a bigger + package and power design, and would be a second MCU family to keep. An + H5 only if the controller ever needs Ethernet. +* *Firmware*: plain Zephyr, not ESPHome (which can't use the external + flash yet). The external flash holds MCUboot's second slot (OTA over CAN + without squeezing the 1 MB), a *black box* — who switched what, faults, + heartbeats lost, the battery voltage — that maptool fetches when it + comes up, so the night at camp can be seen afterwards, the bindings and + scenes with their earlier versions (back to the last good one), and + per-circuit current and on-time statistics. +* *Conditions* come off the bus: speed from the GNSS node, the ignition + from the gateway, the sun computed on the chip; a geofence (the trip's + camp) is a point and a radius sent by maptool. +* *maptool stays* the UI (the switch tiles, `/keypad.html`, + `/sim.html`), the bindings' editor — `bindings.json` written to the + controller (SDO) and kept in its flash — and the screen's own keypad + actions (zoom, pan, menus), which it keeps reading off the bus. Today's + `outputs.rb` stays as the simulator and the reference the firmware is + checked against. +* *A single point of failure*, softened: every relay node has its own safe + state when the controller's heartbeat is lost, and a few key outputs + (the interior light) can have an input of their own on their node. + +Order: maptool stays the controller until the firmware is done. First +the messages are fixed — requests, state, configuration as CANopen +objects — so that maptool uses them now and the STM32 later, with no +change to the other nodes. + == Typography * Planning UI: the system sans; *National Park* (the router-carved