Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
BaseStateMachine.h
Go to the documentation of this file.
1#ifndef BASE_STATE_MACHINE_H
2#define BASE_STATE_MACHINE_H
3
4#include <array>
5#include <cstddef>
6#include <cstdint>
7
11
20 public:
21 // Type alias for a function pointer with void return and no args
22 using StateEntryCallback = void (*)();
23
24 static constexpr std::size_t kMaxStateEntryCallbacks = 32;
25
26 explicit BaseStateMachine(FlightState initialState = STATE_UNARMED);
27 virtual ~BaseStateMachine() = default;
28
36 virtual int update(const AccelerationTriplet& accel, const DataPoint& alt) = 0;
37
43 virtual uint8_t getState() const;
44
52 bool registerOnStateEntry(FlightState targetState, StateEntryCallback functionPtr);
53
54 static constexpr std::size_t getMaxStateEntryCallbacks() {
56 }
57
58 protected:
64 bool changeState(FlightState newState);
65
70
71 private:
72 struct StateCallbackRegistration {
73 FlightState state;
74 StateEntryCallback functionPtr;
75 };
76
77 FlightState state_;
78 std::size_t callbackCount_ = 0;
79 std::array<StateCallbackRegistration, kMaxStateEntryCallbacks> onStateEntryCallbacks_{};
80};
81
82#endif
FlightState
Definition States.h:17
@ STATE_UNARMED
Definition States.h:18
virtual ~BaseStateMachine()=default
virtual uint8_t getState() const
Current discrete state identifier.
bool registerOnStateEntry(FlightState targetState, StateEntryCallback functionPtr)
Register a callback to invoke each time a target state is entered.
bool changeState(FlightState newState)
Transition to a new state and trigger registered on-entry callbacks.
static constexpr std::size_t getMaxStateEntryCallbacks()
virtual int update(const AccelerationTriplet &accel, const DataPoint &alt)=0
Advance the state machine with the latest measurements.
void(*)() StateEntryCallback
static constexpr std::size_t kMaxStateEntryCallbacks
FlightState getFlightState() const
Current state as FlightState enum.
BaseStateMachine(FlightState initialState=STATE_UNARMED)
Timestamped float measurement container.
Definition DataPoint.h:11