Rebuild obu-firmware on Niklas Dathe's microbu-firmware
Replace the vanetza-idf port with his current station firmware (microbu-firmware e4e4bd8: main/, components/microbu_v2x, components/vanetza, external/vanetza) and re-apply the MicrOBU additions, each marked "MicrOBU:" in the sources: - V2X_RX (opcode 0x90): every received ITS message, signed or not, through gn_unwrap.c, because the stack drops unsigned and foreign-root traffic. 0x85 is the spec's RAW_FRAME and 0x86 is reserved. The body is built in v2x_rx.hpp. - Unsigned transmission (geonet.c) for security profile 1 or station security 0, from a random MAC per configuration. - Radio polled from STATION_CONFIGURE on; manual country policy, TX power read-back, static RX buffer, short frames ignored. - Battery guard (battery_policy.hpp): deep sleep below 3.30 V with no phone on USB. - No USB writes without a host; last_frame_ms() for the guard. - 80 KB NVS with the app at 0x20000, 8 MB flash, XIAO ESP32-C5 board, 20 dBm. Remove the old C firmware, the bench listener and the old vanetza-idf copy. Add docs/station-link.tex as revision 2 of the interface reference (V2X_RX, unsigned sending, battery rule, revision history). Add 39 host unit tests (make firmware in test/host) next to the existing chain, replay, fuzz and battery tests, and point tools/station_status_watch.py at the new CONFIRM-based status.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
// Serial transport of the station-internal link over the ESP32-C5 native USB Serial/JTAG port.
|
||||
// Framing is the app's Phase 03 one: [AA][55][type][len LE][payload][crc16 LE] with
|
||||
// CRC-16/CCITT-FALSE over type+len+payload (implementation/station-link/README.md, "Serial").
|
||||
// One writer serialises complete frames. The byte stream never carries plain text: ESP_LOG stays on
|
||||
// UART0 here, or travels as LOG frames with CONFIG_MICROBU_LOG_OVER_LINK.
|
||||
// CRC-16/CCITT-FALSE over type+len+payload (../../docs/station-link.tex, "Serial").
|
||||
// One writer serialises complete frames; ESP_LOG output travels as LOG frames so the byte
|
||||
// stream never mixes text with a binary frame.
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
@@ -14,8 +14,7 @@ namespace microbu::serial {
|
||||
/// @brief Byte buffer type for frame payloads.
|
||||
using Bytes = std::vector<std::uint8_t>;
|
||||
|
||||
/// @brief The type of a frame. Either Link (link protocol), Test (test channel), or Log (ESP_LOG output).
|
||||
enum class FrameType : std::uint8_t { LINK = 0x10, TEST = 0x11, LOG = 0x7F };
|
||||
enum class FrameType : std::uint8_t { LINK = 0x10, LOG = 0x7F };
|
||||
|
||||
constexpr std::size_t maximum_payload = 1536;
|
||||
|
||||
@@ -54,22 +53,23 @@ private:
|
||||
std::uint32_t crc_errors_ = 0, frames_ = 0;
|
||||
};
|
||||
|
||||
struct Counters { std::uint32_t frames = 0, crc_errors = 0, write_failures = 0, not_connected = 0; };
|
||||
struct Counters { std::uint32_t frames = 0, crc_errors = 0, write_failures = 0; };
|
||||
|
||||
/// @brief Installs the USB Serial/JTAG driver and starts the reader task. ESP_LOG goes into LOG frames
|
||||
/// only with CONFIG_MICROBU_LOG_OVER_LINK; on this board it stays on the UART0 console.
|
||||
/// @brief Installs the USB Serial/JTAG driver, starts the reader task and routes ESP_LOG into LOG frames.
|
||||
/// @param on_frame Invoked once per complete, CRC-valid frame.
|
||||
/// @note The handler runs on the reader task; it must only enqueue, never block.
|
||||
void start(const Decoder::Handler& on_frame);
|
||||
/// @brief Writes one complete frame (blocking, mutex-protected). Safe from any task.
|
||||
/// @brief Writes one complete frame (mutex-protected; dropped while the host does not read). Safe from any task.
|
||||
/// @param type Frame type tag.
|
||||
/// @param payload Payload bytes; must not exceed maximum_payload.
|
||||
/// @return false on a full payload, missing driver, lock timeout, or write failure.
|
||||
bool write(FrameType type, const Bytes& payload);
|
||||
/// Queues a complete debug frame if the writer and USB buffer are immediately available.
|
||||
bool try_write(FrameType type, const Bytes& payload);
|
||||
/// @return Current frame/error counters.
|
||||
Counters counters();
|
||||
/// @return esp_timer time in ms (wrapping) at which the last CRC-valid frame arrived from the host,
|
||||
/// 0 if none yet. MicrOBU: app_main pauses BLE advertising while this is recent.
|
||||
/// MicrOBU: milliseconds since boot at which the last valid frame arrived on the native port,
|
||||
/// 0 if none yet. The battery guard reads it to tell a phone on USB (which powers the board).
|
||||
std::uint32_t last_frame_ms();
|
||||
|
||||
} // namespace microbu::serial
|
||||
|
||||
Reference in New Issue
Block a user