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.
64 lines
2.9 KiB
C++
64 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include "link_protocol.hpp"
|
|
#include <cstdint>
|
|
#include <functional>
|
|
|
|
namespace microbu::ble {
|
|
|
|
using Receiver = std::function<void(link::Bytes)>;
|
|
|
|
/// @brief A set of counters for tracking BLE message traffic.
|
|
struct Counters {
|
|
std::uint32_t rx_messages = 0;
|
|
std::uint32_t tx_messages = 0;
|
|
std::uint32_t tx_failed = 0;
|
|
std::uint32_t malformed = 0;
|
|
};
|
|
|
|
/**
|
|
* @brief Starts a simple, bonded BLE GATT peripheral on the NimBLE host.
|
|
* Uses structured ETSI C-ITS Station Service & Characteristics:
|
|
* Service: 0000C175-BA5E-4C17-8000-00805F9B34FB
|
|
* BTP-DATA.request: 0000C176-BA5E-4C17-8000-00805F9B34FB (Write, Authenticated/Encrypted)
|
|
* BTP-DATA.indication: 0000C177-BA5E-4C17-8000-00805F9B34FB (Notify, Authenticated/Encrypted)
|
|
* PoTi Fix Update: 0000C178-BA5E-4C17-8000-00805F9B34FB (Write, Authenticated/Encrypted)
|
|
* Access probe: 0000C179-BA5E-4C17-8000-00805F9B34FB (Empty Read, Authenticated/Encrypted)
|
|
* SF-SAP Identity: 0000C17A-BA5E-4C17-8000-00805F9B34FB (Notify, Authenticated/Encrypted)
|
|
* Station Configure: 0000C17B-BA5E-4C17-8000-00805F9B34FB (Write, Authenticated/Encrypted)
|
|
* Confirm: 0000C17C-BA5E-4C17-8000-00805F9B34FB (Notify, Authenticated/Encrypted)
|
|
*
|
|
* Station-specific compile-time passkey and one pinned owner bond, stored in NVS.
|
|
* Each GATT value carries one message or fragment, up to the negotiated ATT limit.
|
|
* @param receiver Invoked with each decoded station-link message written by the phone.
|
|
* @return false if the NimBLE host or GATT service failed to start.
|
|
*/
|
|
bool start(Receiver receiver);
|
|
|
|
/**
|
|
* @brief Sends one complete station-link message via GATT notification.
|
|
* Dispatches immediately without queuing delay.
|
|
* @param message Encoded station-link message to notify.
|
|
* @return false if not connected/subscribed or the notification could not be sent.
|
|
*/
|
|
bool write(const link::Bytes& message);
|
|
|
|
/// @return true if a phone is connected.
|
|
bool connected();
|
|
/// @brief Pauses (false) or resumes (true) advertising while no phone is connected. The C5 shares one radio
|
|
/// between BLE and ITS-G5: each advertising event leaves the 5.9 GHz receiver deaf, so a board measuring on air
|
|
/// (raw capture over USB) stops advertising (2026-09-29: 2-4 % of the frames missed by the receiving board).
|
|
void set_advertising(bool enabled);
|
|
/// @return Largest link message one notification carries: min(ATT MTU - 3, maximum_message).
|
|
std::size_t max_message();
|
|
/// @return true if the phone has subscribed to notifications.
|
|
bool is_subscribed();
|
|
/// @return Current message/error counters.
|
|
Counters counters();
|
|
/// @return esp_timer time (us) of the last GATT write from the phone, a connection-event anchor; 0 if none.
|
|
std::int64_t last_write_us();
|
|
/// @return Current connection interval in us; 0 if not connected.
|
|
std::uint32_t connection_interval_us();
|
|
|
|
} // namespace microbu::ble
|