STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
sequencer::AbortBroadcaster Class Reference

Sends ABORT / ABORT_DONE / CLEAR_ABORT UDP broadcast packets (PacketHeader only — 6 bytes) to the configured broadcast address and port. More...

#include <AbortBroadcaster.hpp>

Collaboration diagram for sequencer::AbortBroadcaster:
[legend]

Classes

struct  dest_addr_

Public Member Functions

 AbortBroadcaster (uint16_t port=5005, uint32_t abort_done_delay_ms=3000)
 ~AbortBroadcaster ()
bool configure (const std::string &broadcast_ip, uint16_t port, uint32_t done_delay_ms, const std::string &bind_address)
 Adopt the destination and source NIC from config.
void triggerAbort ()
 Send ABORT broadcast and schedule ABORT_DONE after abort_done_delay_ms.
void sendClearAbort ()
 Send CLEAR_ABORT broadcast (called when leaving abort states).

Private Member Functions

void sendPacket (uint8_t packet_type)
void waitAndSendAbortDone ()

Private Attributes

uint16_t port_
uint32_t abort_done_delay_ms_
std::string dest_ip_ {"255.255.255.255"}
std::string bind_address_ {"0.0.0.0"}
std::atomic< bool > done_thread_running_ {false}
std::thread done_thread_
std::mutex done_thread_mutex_

Static Private Attributes

static constexpr int kBroadcastRepeats = 4
 How many times each broadcast is repeated, and the gap between repeats.
static constexpr int kBroadcastGapUs = 2000

Detailed Description

Sends ABORT / ABORT_DONE / CLEAR_ABORT UDP broadcast packets (PacketHeader only — 6 bytes) to the configured broadcast address and port.

On abort entry:

  1. sendAbort() — fires immediately
  2. scheduleAbortDone() — fires ABORT_DONE after abort_done_delay_ms

Thread-safe.

Definition at line 23 of file AbortBroadcaster.hpp.

Constructor & Destructor Documentation

◆ AbortBroadcaster()

sequencer::AbortBroadcaster::AbortBroadcaster ( uint16_t port = 5005,
uint32_t abort_done_delay_ms = 3000 )
explicit

Definition at line 31 of file AbortBroadcaster.cpp.

References abort_done_delay_ms_, port, and port_.

◆ ~AbortBroadcaster()

sequencer::AbortBroadcaster::~AbortBroadcaster ( )

Definition at line 66 of file AbortBroadcaster.cpp.

References done_thread_, done_thread_mutex_, done_thread_running_, and lk.

Member Function Documentation

◆ configure()

bool sequencer::AbortBroadcaster::configure ( const std::string & broadcast_ip,
uint16_t port,
uint32_t done_delay_ms,
const std::string & bind_address )

Adopt the destination and source NIC from config.

Call once, before anything can abort.

This class used to be default-constructed and never told anything: port 5005 by ctor default, destination hardcoded to the limited broadcast 255.255.255.255, source interface left to the kernel. Every other sender in the system takes its destination from config, and a limited broadcast is the one destination that does not resolve to a single route — so on a host with more than one NIC all four repeats could leave on the wrong wire together.

Parameters
broadcast_ipSubnet-directed broadcast for the board LAN, e.g. 192.168.2.255.
portBoard listen port.
done_delay_msDelay before ABORT_DONE.
bind_addressLocal address to send from, or "0.0.0.0" to leave unpinned.
Returns
false if broadcast_ip is not a valid IPv4 address (caller should fail startup).

Definition at line 36 of file AbortBroadcaster.cpp.

References abort_done_delay_ms_, bind_address_, dest_ip_, port, and port_.

◆ sendClearAbort()

void sequencer::AbortBroadcaster::sendClearAbort ( )

Send CLEAR_ABORT broadcast (called when leaving abort states).

Definition at line 175 of file AbortBroadcaster.cpp.

References daq::CLEAR_ABORT, and sendPacket().

◆ sendPacket()

void sequencer::AbortBroadcaster::sendPacket ( uint8_t packet_type)
private

◆ triggerAbort()

void sequencer::AbortBroadcaster::triggerAbort ( )

Send ABORT broadcast and schedule ABORT_DONE after abort_done_delay_ms.

Definition at line 137 of file AbortBroadcaster.cpp.

References daq::ABORT, done_thread_, done_thread_mutex_, done_thread_running_, lk, sendPacket(), and waitAndSendAbortDone().

◆ waitAndSendAbortDone()

void sequencer::AbortBroadcaster::waitAndSendAbortDone ( )
private

Member Data Documentation

◆ abort_done_delay_ms_

uint32_t sequencer::AbortBroadcaster::abort_done_delay_ms_
private

Definition at line 54 of file AbortBroadcaster.hpp.

Referenced by AbortBroadcaster(), configure(), and waitAndSendAbortDone().

◆ bind_address_

std::string sequencer::AbortBroadcaster::bind_address_ {"0.0.0.0"}
private

Definition at line 59 of file AbortBroadcaster.hpp.

Referenced by configure(), and sendPacket().

◆ dest_ip_

std::string sequencer::AbortBroadcaster::dest_ip_ {"255.255.255.255"}
private

Definition at line 58 of file AbortBroadcaster.hpp.

Referenced by configure(), and sendPacket().

◆ done_thread_

std::thread sequencer::AbortBroadcaster::done_thread_
private

Definition at line 61 of file AbortBroadcaster.hpp.

Referenced by triggerAbort(), and ~AbortBroadcaster().

◆ done_thread_mutex_

std::mutex sequencer::AbortBroadcaster::done_thread_mutex_
private

Definition at line 67 of file AbortBroadcaster.hpp.

Referenced by triggerAbort(), and ~AbortBroadcaster().

◆ done_thread_running_

std::atomic<bool> sequencer::AbortBroadcaster::done_thread_running_ {false}
private

Definition at line 60 of file AbortBroadcaster.hpp.

Referenced by triggerAbort(), waitAndSendAbortDone(), and ~AbortBroadcaster().

◆ kBroadcastGapUs

int sequencer::AbortBroadcaster::kBroadcastGapUs = 2000
staticconstexprprivate

Definition at line 75 of file AbortBroadcaster.hpp.

Referenced by sendPacket().

◆ kBroadcastRepeats

int sequencer::AbortBroadcaster::kBroadcastRepeats = 4
staticconstexprprivate

How many times each broadcast is repeated, and the gap between repeats.

A single UDP datagram is not a delivery guarantee: one dropped frame on a congested field network and no board hears the abort. ActuatorCommander::sendBatch already sends ordinary state changes 3x for exactly this reason — the abort path must not be weaker than the routine one.

Definition at line 74 of file AbortBroadcaster.hpp.

Referenced by sendPacket().

◆ port_

uint16_t sequencer::AbortBroadcaster::port_
private

Definition at line 53 of file AbortBroadcaster.hpp.

Referenced by AbortBroadcaster(), configure(), and sendPacket().


The documentation for this class was generated from the following files: