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:
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Serial console (Controller B) - line reader + command chain.
|
||||
*
|
||||
* Commands live in their modules (LinkPeer, Ota); this only splits lines and
|
||||
* asks each handler in turn. `help` lists them.
|
||||
*/
|
||||
|
||||
#ifndef CONSOLE_H
|
||||
#define CONSOLE_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace Console {
|
||||
|
||||
typedef bool (*handler_t)(const char* line);
|
||||
|
||||
/** Register up to 8 handlers; each returns true if it consumed the line. */
|
||||
void addHandler(handler_t h);
|
||||
|
||||
/** Non-blocking: read whatever is pending on Serial, dispatch complete lines. */
|
||||
void tick();
|
||||
|
||||
} // namespace Console
|
||||
|
||||
#endif // CONSOLE_H
|
||||
@@ -7,6 +7,10 @@
|
||||
* Channel discovery: A transmits on ESPNOW_CHANNEL unless it is associated to
|
||||
* an access point. B listens on ESPNOW_CHANNEL first and, while it hears
|
||||
* nothing, hops through channels 1..13 until frames arrive, then locks.
|
||||
*
|
||||
* Frames other than DATA/CONFIG (the SECURE envelope from A) are routed to
|
||||
* LinkPeer, and the sender MAC of A's frames is remembered so LinkPeer can
|
||||
* unicast STATUS frames back (sendTo).
|
||||
*/
|
||||
|
||||
#ifndef ESPNOW_RECEIVER_H
|
||||
@@ -31,6 +35,12 @@ bool isReady();
|
||||
uint8_t currentChannel();
|
||||
uint32_t framesReceived();
|
||||
|
||||
/** A's MAC as seen on its last DATA/CONFIG frame. False until A was heard by radio. */
|
||||
bool peerMac(uint8_t out[6]);
|
||||
|
||||
/** Unicast one complete frame to a MAC (peer added on first use, unencrypted). */
|
||||
bool sendTo(const uint8_t mac[6], const uint8_t* frame, size_t len);
|
||||
|
||||
} // namespace EspNowReceiver
|
||||
|
||||
#endif // ESPNOW_RECEIVER_H
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Link Peer Module (Controller B) - the maintenance side of the link to A.
|
||||
*
|
||||
* The data path (DATA/CONFIG frames) is UARTReceiver's. This module owns
|
||||
* everything else on the link, see wiki/pages/controller-b-ota.md:
|
||||
*
|
||||
* - STATUS frames B -> A every LINK_STATUS_PERIOD_MS (ESP-NOW unicast to A's
|
||||
* MAC, learned from the frames A broadcasts): our version, OTA phase, uptime.
|
||||
* - PAIR frames from A, accepted from the UART wire ONLY: the shared key that
|
||||
* protects everything below. Kept in NVS, survives reflashes.
|
||||
* - SECURE frames from A (ESP-NOW unicast, AES-256-GCM under the pairing key):
|
||||
* WIFI_CREDS -> stored in NVS for the OTA module to join with
|
||||
* OTA_CMD -> handed to the OTA module (check / install / rollback)
|
||||
*
|
||||
* Console (`link ...`, `wifi ...`) via Console::handle chain.
|
||||
*/
|
||||
|
||||
#ifndef LINK_PEER_H
|
||||
#define LINK_PEER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "protocol/automotive_data.h"
|
||||
|
||||
namespace LinkPeer {
|
||||
|
||||
/** Load pairing key + Wi-Fi credentials from NVS. Call before the receivers start. */
|
||||
void init();
|
||||
|
||||
/** STATUS transmit + housekeeping. Call from loop(). */
|
||||
void tick();
|
||||
|
||||
/** ESP-NOW frames that are not DATA/CONFIG (EspNowReceiver hands them here). */
|
||||
void onRadioFrame(const uint8_t* mac, const uint8_t* frame, size_t len);
|
||||
|
||||
/** A PAIR payload that arrived on the UART wire (UARTReceiver hands it here). */
|
||||
void onPairFrame(const link_pair_t* p);
|
||||
|
||||
bool isPaired();
|
||||
uint16_t keyFingerprint(); // 0 when unpaired
|
||||
|
||||
/** Stored Wi-Fi credentials (from A). False if none. Never printed. */
|
||||
bool getWifiCredentials(char* ssid, size_t ssid_n, char* pass, size_t pass_n);
|
||||
bool hasWifiCredentials();
|
||||
void forgetWifi();
|
||||
void unpair();
|
||||
|
||||
// ---- OTA module integration ------------------------------------------------
|
||||
|
||||
typedef void (*ota_cmd_handler_t)(uint8_t cmd, uint8_t flags);
|
||||
void setOtaCommandHandler(ota_cmd_handler_t handler);
|
||||
|
||||
/** What the STATUS frame reports about the updater. */
|
||||
void setOtaStatus(uint8_t phase, uint8_t progress, const char* latest, const char* message,
|
||||
bool wifi_joined, bool pending_verify);
|
||||
|
||||
/** Console: `link status | unpair`, `wifi status | forget`. */
|
||||
bool handleCommand(const char* line);
|
||||
|
||||
} // namespace LinkPeer
|
||||
|
||||
#endif // LINK_PEER_H
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* ota_update.h - Controller B pulls its own firmware from this repo's Gitea
|
||||
* releases. Port of Controller A's module (ESP32-S3-Touch-LCD-5B/src/modules/
|
||||
* ota_update.cpp), see wiki/pages/controller-b-ota.md.
|
||||
*
|
||||
* Triggered by A (OTA_CMD inside a SECURE frame, behind A's parking gate and
|
||||
* its Updates screen) or by this console:
|
||||
*
|
||||
* ota status running version, slot, rollback state
|
||||
* ota check join Wi-Fi, ask Gitea for the latest release, leave
|
||||
* ota install [force] join, download, verify, flash idle slot, reboot
|
||||
* ota rollback boot the previous slot
|
||||
*
|
||||
* Safety, same as A:
|
||||
* - refused unless parked: link alive with engine rpm 0 and no shaft speed,
|
||||
* or link silent (ignition off / bench). A has already applied its gate.
|
||||
* - image must match the signed manifest (sha256 + ECDSA P-256 over
|
||||
* "patrol-b|version|sha256"); the idle slot is never activated otherwise.
|
||||
* - a new image must run OTA_CONFIRM_MS before it is marked valid, else the
|
||||
* bootloader falls back to the old slot.
|
||||
*
|
||||
* Wi-Fi: B lives in bare STA mode for ESP-NOW. For a job it joins the network
|
||||
* whose credentials A handed over (LinkPeer), then disconnects again so the
|
||||
* receiver can hop back to A's channel.
|
||||
*/
|
||||
|
||||
#ifndef OTA_UPDATE_H
|
||||
#define OTA_UPDATE_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace Ota {
|
||||
|
||||
/** Log version/slot; flag an unconfirmed new image. Call early in setup(). */
|
||||
void init();
|
||||
|
||||
/** Runs queued jobs, confirms a fresh image after healthy uptime. Call from loop(). */
|
||||
void tick();
|
||||
|
||||
/** LinkPeer hands A's OTA commands here (registered by init()). */
|
||||
void onLinkCommand(uint8_t cmd, uint8_t flags);
|
||||
|
||||
/** Console entry point (`ota ...`). */
|
||||
bool handleCommand(const char* line);
|
||||
|
||||
const char* version();
|
||||
|
||||
} // namespace Ota
|
||||
|
||||
#endif // OTA_UPDATE_H
|
||||
Reference in New Issue
Block a user