Controller B OTA: link_peer (STATUS to A, PAIR from the wire, AES-GCM SECURE frames), updater ported from A, console, CI workflow, shared header v2 maintenance frames; wiki + docs
Firmware / build (push) Successful in 2m57s
Firmware / build (push) Successful in 2m57s
This commit is contained in:
@@ -46,14 +46,19 @@ src/
|
||||
espnow_receiver.cpp # ESP-NOW leg: STA mode, channel hopping while silent, feeds processFrame()
|
||||
gauge_outputs.cpp # Patrol gauges: tach on IO7 (hardware-timer ISR), coolant PWM on IO8 (LEDC ch4), NVS-cached config
|
||||
debug_monitor.cpp # shows/hides LVGL perf+mem monitors from A's debug_enabled flag (recorded by the receiver, applied in loop)
|
||||
link_peer.cpp # maintenance side of the link: STATUS to A, PAIR from the wire, SECURE (AES-GCM) frames from A -> Wi-Fi creds / OTA commands
|
||||
ota_update.cpp # pulls this repo's signed Gitea release over Wi-Fi (port of A's module), 'ota' console
|
||||
console.cpp # serial line reader + handler chain ('help', 'link', 'wifi', 'ota')
|
||||
assets/
|
||||
assets.h # LV_FONT_DECLARE / LV_IMG_DECLARE for the files below
|
||||
fonts/ # Ubuntu Light 35 (values) and Ubuntu Bold 110 (gear) - plain LVGL font arrays
|
||||
images/ # 3 status icons x normal/red - plain LVGL image arrays
|
||||
include/
|
||||
config/lv_conf.h # LVGL 8.4.0 config (RGB565, dark theme, 128 KB pool in PSRAM, millis() tick, log off)
|
||||
modules/uart_receiver.h, espnow_receiver.h, gauge_outputs.h, debug_monitor.h
|
||||
config/ota_config.h # FW_VERSION (CI bakes it, "dev" locally), OTA_TARGET "patrol-b", repo URLs, CA roots, signing public key
|
||||
modules/uart_receiver.h, espnow_receiver.h, gauge_outputs.h, debug_monitor.h, link_peer.h, ota_update.h, console.h
|
||||
protocol/automotive_data.h # SHARED packet contract — copied from Controller A, must match its version
|
||||
protocol/link_secure.h # SHARED too: AES-256-GCM envelope for SECURE frames (byte-identical in both repos)
|
||||
```
|
||||
|
||||
**UI**: the single screen is hand-coded in `src/modules/gauge_screen.cpp` (SquareLine Studio was retired on 2026-09-27; `include/ui/` is gone - do not reintroduce a UI generator). The font and icon arrays it uses were kept from the old export, symbol names unchanged, under `src/assets/`. The engine-oil quadrant was dropped the same day: this engine has no oil temperature sensor.
|
||||
@@ -70,12 +75,24 @@ include/
|
||||
|
||||
**DebugMonitor** — `init()`, `setVisible(bool)` (records only; called from the receiver), `tick()` (applies under the LVGL lock; called from loop), `isVisible()`. Driven by the `debug_enabled` byte in each packet, so Controller A's debug toggle controls B's overlays.
|
||||
|
||||
**LinkPeer** (2026-09-27) — `init()` loads the pairing key + A's MAC (NVS `linkpeer`) and the Wi-Fi credentials A handed over (NVS `wifi`, same keys as A's). `onPairFrame()` is called by `UARTReceiver::processFrame()` for `PAIR` frames **from the UART source only**; `onRadioFrame()` by `EspNowReceiver` for every non-DATA/CONFIG frame. Both just fill a one-slot mailbox; `tick()` (loop task) decrypts, checks the sender MAC against the paired A, writes NVS, and sends a `STATUS` frame to A every 5 s or on any phase change (`EspNowReceiver::sendTo()`, A's MAC from its data frames). `setOtaStatus()` / `setOtaCommandHandler()` are the updater's hooks. Nonce replay window of 4 for OTA commands. Console: `link status | unpair`, `wifi status | forget`. The password is never printed.
|
||||
|
||||
**Ota** (2026-09-27) — port of Controller A's `ota_update.cpp`: `ota status | check | install [force] | rollback` and A's `OTA_CMD` land in `startJob()`; the job runs in `tick()` (loop task, blocks the gauges - parked anyway). Gate: link data says rpm 0 and lever P/N/unknown, or the link is silent (A off); credentials present. Joins Wi-Fi only for the job and `WiFi.disconnect(false)` afterwards so the ESP-NOW receiver hops back to A. Manifest signature (ECDSA P-256 over `patrol-b|version|sha256`) checked before download, streamed sha256 checked after, `esp_ota_end()` image check, slot switch, reboot; `verifyRollbackLater()` overridden so the new image stays pending until `tick()` confirms it after `OTA_CONFIRM_MS` (30 s). Progress: `GaugeScreen::setNotice("Updating vX N%")` and a STATUS pumped to A at most once a second from inside the download loop. Never put secrets in source - the repo and its releases are public.
|
||||
|
||||
**Console** — `Console::addHandler()` chain, `tick()` from loop; `help` asks every handler to print its lines.
|
||||
|
||||
### UART packet (shared with Controller A)
|
||||
|
||||
Protocol **v2**: `0xAA | 0x02 | type | length | payload | XOR | 0x55`. DATA (21-byte `automotive_data_t`: lever, target/engaged gear nibbles, rpm, temps, battery, alerts, valid flags) every 200 ms; CONFIG (27-byte `link_config_t`: gauge calibration + alert thresholds) on change and every 5 s. Same frames on UART1 and ESP-NOW. Spec: sibling repo `docs/UART_PROTOCOL.md`. `include/protocol/automotive_data.h` must stay byte-identical to A's; B rejects other versions and counts them.
|
||||
Protocol **v2**: `0xAA | 0x02 | type | length | payload | XOR | 0x55`. DATA (21-byte `automotive_data_t`: lever, target/engaged gear nibbles, rpm, temps, battery, alerts, valid flags) every 200 ms; CONFIG (27-byte `link_config_t`: gauge calibration + alert thresholds) on change and every 5 s. Same frames on UART1 and ESP-NOW. Spec: sibling repo `docs/UART_PROTOCOL.md`. `include/protocol/automotive_data.h` (and `link_secure.h`) must stay byte-identical to A's; B rejects other versions and counts them.
|
||||
|
||||
Since 2026-09-27 the link is two-way for maintenance (`PACKET_VERSION` unchanged, `PACKET_MAX_PAYLOAD` 160): `STATUS` 0x03 B → A (ESP-NOW unicast), `PAIR` 0x04 A → B (**wire only**, the shared key), `SECURE` 0x05 A → B (AES-256-GCM envelope carrying `OTA_CMD` or `WIFI_CREDS`). See `wiki/pages/controller-b-ota.md`.
|
||||
|
||||
Alert thresholds live on A; B turns icons red from the `alerts` bits only. The gear label shows the engaged gear, or the target gear pulsing while `target != engaged`, and turns red on the gear-mismatch alert. `engine_oil_temp` has no source on this engine and stays invalid.
|
||||
|
||||
### Firmware updates (OTA)
|
||||
|
||||
B updates itself from this repo's Gitea releases; A triggers it from Settings → Updates (Controller B card) or B's console does (`ota check`, `ota install`). CI: `.gitea/workflows/firmware.yml` - push to `master` → unsigned pre-release `main-latest`; tag `v*` → signed release (`manifest.txt`, target `patrol-b`), needs the repo secret `BMW_NISSAN_FIRMWARE_SIGNING_KEY` (same key as A's). Release with one push: `git tag -a vX.Y.Z -m "..." && git push --follow-tags origin master`. Version strings ≤ 15 chars. First pairing (`link pair` on A, wire connected) and the procedure: `wiki/pages/controller-b-ota.md`.
|
||||
|
||||
## Hardware-Specific Details
|
||||
|
||||
### GPIO assignments (verified against the Waveshare demo and the pinout photo)
|
||||
@@ -113,6 +130,8 @@ Pins are set in `src/modules/display_init.cpp` and `platformio.ini` (`-DUART_RX_
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- **Building**: start `pio` from PowerShell, not Git Bash - `idf_tools.py` refuses MSYS ("MSys/Mingw is not supported"). The two projects share one PlatformIO penv and one `framework-arduinoespressif32` package dir: the first `pio run` after building the other project reinstalls the core and can fail once with `TypeError: expected str, bytes or os.PathLike object, not NoneType` - run it again. After any build here, run `../ESP32-S3-Touch-LCD-5B/tools/fix_penv_deps.ps1` before building A.
|
||||
|
||||
- **Blank display**: confirm the pin table above (backlight GPIO 20 is the usual culprit), try `cfg.freq_write = 40000000`, toggle `cfg.invert`. A direct LovyanGFX `fillScreen()` before LVGL init separates hardware from LVGL problems.
|
||||
- **`lv_tick_inc() is not called`**: the tick handler lives in `DisplayInit::update()`; make sure `lvglTask` is running.
|
||||
- **Out of memory**: LVGL's 128 KB pool is already in PSRAM (`LV_MEM_POOL_ALLOC` in `lv_conf.h`); raise `LV_MEM_SIZE` there. The two 240×40 draw buffers must stay in internal RAM (SPI DMA).
|
||||
|
||||
Reference in New Issue
Block a user