Files
MicrOBU/obu-firmware/main/tx_policy.hpp
T

35 lines
1.7 KiB
C++
Raw Normal View History

#pragma once
// Transmission timing policy of the micrOBU. Honest functions only: no clock, no radio, no global state.
#include <cstdint>
#include <optional>
#include <span>
namespace microbu::tx_policy {
/// @brief Span of the BLE connection interval, as time since the last GATT write from the phone
/// (the host's view of a connection event), in microseconds: [start_us, end_us).
struct PhaseWindow {
std::int64_t start_us = 0;
std::int64_t end_us = 0;
};
/// @brief Hand-off phases at which an ITS-G5 frame collides with a BLE connection event and is dropped by
/// the ESP32-C5's coexistence arbitration. Measured per connection interval on the bench (2026-09-25).
/// @param interval_us Current BLE connection interval.
/// @return The windows; empty for an interval without calibration.
std::span<const PhaseWindow> guard_windows(std::int64_t interval_us);
/// @brief How long to hold a frame so that its hand-off to the driver leaves every guard window.
/// @param since_anchor_us Time since the last GATT write (>= 0).
/// @param interval_us Current BLE connection interval (> 0).
/// @return Delay in microseconds; 0 outside the windows or for an interval without calibration.
std::int64_t guard_delay_us(std::int64_t since_anchor_us, std::int64_t interval_us);
/// @brief A request generated more than one packet lifetime ago is stale: a BLE write delayed in the link
/// @param generated_at_us ITS time at which the phone generated the request.
/// @param now_us Current ITS time of the station.
/// @param lifetime_us Maximum packet lifetime (1 s for a VAM, TS 103 300-3 Table 4).
bool is_stale(std::int64_t generated_at_us, std::int64_t now_us, std::int64_t lifetime_us);
} // namespace microbu::tx_policy