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

Parses state_transitions.csv and validates state transitions. More...

#include <StateMachine.hpp>

Collaboration diagram for sequencer::StateMachine:
[legend]

Public Member Functions

bool load (const std::string &csv_path)
 Load from a state_transitions.csv file.
bool isAllowed (State from, State to) const
 Returns true if transitioning from→to is allowed.
std::vector< State > allowedFrom (State state) const
 Returns the list of states reachable from the given state.
uint32_t allowedBitmask (State state) const
 Returns a bitmask where bit N is set if state N is reachable from the given state.
bool isLoaded () const

Static Public Member Functions

static void loadStatesFromConfig (const std::string &config_content)
 Adopt the [[states]] entries from a config as the source of truth for state names and semantics.
static bool isAbort (State s)
 True if the state carries the abort semantics (config is_abort, else the built-in trio).
static State bootState ()
 The state to boot into (config is_boot, else Idle).
static State fromName (const std::string &name)
 Translate a CSV name (e.g.
static std::string name (State s)
 Human-readable name for a State (e.g.
static uint8_t stateId (const std::string &name)
 Numeric id for a state name, or 255 if unknown.

Static Private Member Functions

static const std::map< std::string, State > & csvStateMap ()

Private Attributes

std::map< State, std::set< State > > transitions_
bool loaded_ {false}

Detailed Description

Parses state_transitions.csv and validates state transitions.

Thread-safe for concurrent reads after load().

Definition at line 43 of file StateMachine.hpp.

Member Function Documentation

◆ allowedBitmask()

uint32_t sequencer::StateMachine::allowedBitmask ( State state) const

Returns a bitmask where bit N is set if state N is reachable from the given state.

Used for the [0x50, 0x00] Elodin VTable payload.

Definition at line 325 of file StateMachine.cpp.

References state, and transitions_.

◆ allowedFrom()

std::vector< State > sequencer::StateMachine::allowedFrom ( State state) const

Returns the list of states reachable from the given state.

In debug mode, returns all known states.

Definition at line 315 of file StateMachine.cpp.

References result, state, and transitions_.

◆ bootState()

State sequencer::StateMachine::bootState ( )
static

The state to boot into (config is_boot, else Idle).

Definition at line 109 of file StateMachine.cpp.

References sequencer::IDLE.

Referenced by sequencer::SequencerService::init().

◆ csvStateMap()

◆ fromName()

State sequencer::StateMachine::fromName ( const std::string & name)
static

Translate a CSV name (e.g.

"Emergency Abort") to a State.

Definition at line 184 of file StateMachine.cpp.

References csvStateMap(), name(), and sequencer::UNKNOWN.

Referenced by sequencer::SequencerService::applyConfig(), load(), sequencer::load_dynamic_states(), main(), stateId(), and sequencer::SequencerService::transitionTo().

◆ isAbort()

bool sequencer::StateMachine::isAbort ( State s)
static

True if the state carries the abort semantics (config is_abort, else the built-in trio).

Definition at line 99 of file StateMachine.cpp.

References sequencer::EMERGENCY_ABORT, sequencer::ENGINE_ABORT, and sequencer::GSE_ABORT.

Referenced by sequencer::SequencerService::isAbortState().

◆ isAllowed()

bool sequencer::StateMachine::isAllowed ( State from,
State to ) const

Returns true if transitioning from→to is allowed.

In debug mode, always returns true.

Definition at line 308 of file StateMachine.cpp.

References transitions_.

Referenced by sequencer::load_dynamic_states(), and main().

◆ isLoaded()

bool sequencer::StateMachine::isLoaded ( ) const
inline

Definition at line 106 of file StateMachine.hpp.

References loaded_.

◆ load()

bool sequencer::StateMachine::load ( const std::string & csv_path)

Load from a state_transitions.csv file.

Tries the given path, then a set of fallback paths.

Returns
true on success.

Definition at line 222 of file StateMachine.cpp.

References fromName(), loaded_, transitions_, sequencer::trimCell(), and sequencer::UNKNOWN.

Referenced by engine.layerx.measurements.MeasurementStore::get(), and main().

◆ loadStatesFromConfig()

void sequencer::StateMachine::loadStatesFromConfig ( const std::string & config_content)
static

Adopt the [[states]] entries from a config as the source of truth for state names and semantics.

This is an OVERRIDE LAYER, deliberately: anything the config does not mention keeps its built-in name and behaviour. The state list was duplicated in eight places across C++, the shared TS types, the backend and six frontend label maps, several already disagreeing (the top bar rendered GSE Abort and Emergency Abort as "STATE 18"/"STATE 19"). Config becomes the one place to edit, without a partial or missing [[states]] being able to erase the machine's knowledge of its own states.

id is a stable key, not an ordering: it is written into Elodin run history as a raw u8 with no name table beside it, so an id must keep meaning the same state. Reordering, renaming, adding and removing are all fine; reusing an id for a different state is not.

Definition at line 72 of file StateMachine.cpp.

References fsw::config::load_from_string(), and sequencer::anonymous_namespace{StateMachine.cpp}::ConfigStates::names.

Referenced by sequencer::SequencerService::applyConfig(), main(), and main().

◆ name()

◆ stateId()

uint8_t sequencer::StateMachine::stateId ( const std::string & name)
inlinestatic

Numeric id for a state name, or 255 if unknown.

Lets a service that only needs the id (e.g. the controller's PWM gate) avoid carrying its own copy of the enum.

Definition at line 101 of file StateMachine.hpp.

References fromName(), and name().

Referenced by main().

Member Data Documentation

◆ loaded_

bool sequencer::StateMachine::loaded_ {false}
private

Definition at line 112 of file StateMachine.hpp.

Referenced by isLoaded(), and load().

◆ transitions_

std::map<State, std::set<State> > sequencer::StateMachine::transitions_
private

Definition at line 111 of file StateMachine.hpp.

Referenced by allowedBitmask(), allowedFrom(), isAllowed(), and load().


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