|
STAR
Cal STAR — firmware, DAQ server, and engine design
|
Parses state_transitions.csv and validates state transitions. More...
#include <StateMachine.hpp>
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} |
Parses state_transitions.csv and validates state transitions.
Thread-safe for concurrent reads after load().
Definition at line 43 of file StateMachine.hpp.
| 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_.
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_.
|
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().
|
staticprivate |
Definition at line 18 of file StateMachine.cpp.
References sequencer::ARMED, sequencer::CALIBRATE, sequencer::DEBUG, sequencer::EMERGENCY_ABORT, sequencer::ENGINE_ABORT, sequencer::FIRE, sequencer::FUEL_FILL, sequencer::FUEL_PRESS, sequencer::FUEL_VENT, sequencer::GN2_HIGH_PRESS, sequencer::GN2_HIGH_VENT, sequencer::GN2_LOW_PRESS, sequencer::GN2_VENT, sequencer::GSE_ABORT, sequencer::IDLE, sequencer::OX_FILL, sequencer::OX_PRESS, sequencer::OX_VENT, sequencer::PRESS_STANDBY, sequencer::READY, and sequencer::VENT.
Referenced by fromName().
|
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().
|
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().
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().
|
inline |
Definition at line 106 of file StateMachine.hpp.
References loaded_.
| 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.
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().
|
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().
|
static |
Human-readable name for a State (e.g.
State::FIRE → "Fire").
Definition at line 128 of file StateMachine.cpp.
References sequencer::ARMED, sequencer::CALIBRATE, sequencer::DEBUG, sequencer::EMERGENCY_ABORT, sequencer::ENGINE_ABORT, sequencer::FIRE, sequencer::FUEL_FILL, sequencer::FUEL_PRESS, sequencer::FUEL_VENT, sequencer::GN2_HIGH_PRESS, sequencer::GN2_HIGH_VENT, sequencer::GN2_LOW_PRESS, sequencer::GN2_VENT, sequencer::GSE_ABORT, sequencer::IDLE, sequencer::OX_FILL, sequencer::OX_PRESS, sequencer::OX_VENT, sequencer::PRESS_STANDBY, sequencer::READY, and sequencer::VENT.
Referenced by sequencer::SequencerService::applyConfig(), sequencer::ActuatorCommander::applyForState(), sequencer::SequencerService::doTransitionTo(), fromName(), sequencer::SequencerService::init(), sequencer::ScriptRunner::run(), sequencer::SequencerService::scriptStatusReport(), sequencer::ActuatorCommander::startContinuousLoop(), and stateId().
|
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().
|
private |
Definition at line 112 of file StateMachine.hpp.
Referenced by isLoaded(), and load().
Definition at line 111 of file StateMachine.hpp.
Referenced by allowedBitmask(), allowedFrom(), isAllowed(), and load().