MasterMacEngine class final
#include <npr/mac/master_mac_engine.hpp>
First PacketRF NPR master MAC implementation.
Scope of this initial master engine is intentionally limited:
- accept and answer CONNECT_REQ,
- keep shared WHO/neighbor observability,
- emit periodic downlink TDMA allocation frames,
- bridge basic IPv4 traffic in both directions.
It does not yet implement:
- lease persistence,
- richer master-side policy beyond the current baseline behavior.
The class keeps these boundaries explicit so the first master slice stays readable and testable while still fitting the role-neutral IMacEngine contract used by NprRuntime.
Base classes
- class IMacEngine
- Thin role-neutral MAC boundary used by
NprRuntime.
Public functions
- auto allocation_age_us(uint64_t now_us) const -> uint64_t override
- Returns allocation age for diagnostics.
- auto client_id() const -> uint8_t override
- Returns current local client ID, if assigned by the active role.
- auto connected() const -> bool override
- Master reports connected while actively running downlink scheduling/tx.
- auto consume_ipv4_downlink_packet() -> bool override
- Releases the front downlink IPv4 packet after successful handoff.
- auto enqueue_ipv4_uplink_packet(const uint8_t* packet, size_t packet_size) -> bool override
- Queues one host IPv4 packet for uplink.
- auto init(const MacInitParams& params) -> bool override
- Initializes engine with role-neutral runtime context.
- void log_signaling_stats_periodic(uint64_t now_us) override
- Emits periodic role-specific signaling diagnostics.
- auto network_config_snapshot(NprNetworkConfig* out) const -> bool override
- Copies current role-specific effective network config snapshot.
- auto on_slot_burst_plan_result(const MacSlotBurstPlanResult& plan) -> MacSlotBurstPlanAction override
- Classifies burst-planner output into runtime action.
- auto on_slot_burst_tx_result(const MacSlotBurstTxFeedback& feedback) -> bool override
- Applies PHY TX result to MAC state and returns whether burst should continue.
- void on_tx_failure() override
- Notifies MAC about failed frame transmission.
- void on_tx_success(SlotTxFrameKind kind, uint64_t now_us) override
- Notifies MAC about successful frame transmission.
- void on_unslotted_tx_result(MacUnslottedAction action, bool sent, uint64_t now_us) override
- Feeds unslotted transmission result back to MAC state.
- auto peek_ipv4_downlink_packet(uint8_t* out, size_t out_capacity, size_t* out_size) const -> bool override
- Copies the current front downlink IPv4 packet without releasing ownership.
- auto plan_slot_burst_tx(const MacSlotBurstPlanInput& in, MacSlotBurstPlanResult* out) -> bool override
- Plans one step of slotted burst utilization.
- auto plan_unslotted_tx(uint64_t now_us, MacUnslottedAction action, MacUnslottedTxPlan* out) -> bool override
- Emits role-specific unslotted signaling frame when needed.
- auto process_received_packet(const uint8_t* packet, size_t packet_size, uint64_t packet_time_us, bool local_rssi_valid, uint8_t local_rssi, MacRxProcessResult* out) -> bool override
- Processes one decoded-on-air packet and updates MAC state.
- void reset(uint64_t now_us) override
- Resets dynamic MAC state while keeping static configuration.
- auto should_continue_slot_burst(uint32_t sent_in_slot, uint64_t now_us, const SlotTxTimeBudget& slot_budget) const -> bool override
- Returns whether MAC policy allows another frame in current slot burst.
- auto slot_budget_us() const -> uint32_t override
- Returns current slot budget in microseconds.
- auto sync_age_us(uint64_t now_us) const -> uint64_t override
- Returns sync age for diagnostics.
- void tick(const MacTickInput& input, MacTickPlan* out_plan) override
- Computes one-step MAC execution plan for runtime.
- auto who_cache_snapshot(SignalingWhoEntry* out_entries, size_t max_entries) const -> size_t override
- Copies current role-neutral WHO/neighbor cache entries for external observers.
Function documentation
bool npr:: rf:: MasterMacEngine:: connected() const override
Master reports connected while actively running downlink scheduling/tx.
In idle RX-only sleep (no clients, timeout elapsed) it reports disconnected.
bool npr:: rf:: MasterMacEngine:: network_config_snapshot(NprNetworkConfig* out) const override
Copies current role-specific effective network config snapshot.
Current slave MAC returns CONNECT_ACK-derived client assignment state. Engines that do not expose an equivalent snapshot may return false.
bool npr:: rf:: MasterMacEngine:: peek_ipv4_downlink_packet(uint8_t* out,
size_t out_capacity,
size_t* out_size) const override
Copies the current front downlink IPv4 packet without releasing ownership.
Runtime uses this two-phase handoff to keep the packet in MAC-owned storage until the next queue boundary accepts it.
size_t npr:: rf:: MasterMacEngine:: who_cache_snapshot(SignalingWhoEntry* out_entries,
size_t max_entries) const override
Copies current role-neutral WHO/neighbor cache entries for external observers.
Both slave and master implementations should expose the same observability model here whenever practical.