feat(state-via-can): state transitions via can are forced to resync state across devices

This commit is contained in:
CarlWachter
2024-06-17 08:54:36 +02:00
committed by carlwachter
parent 69b5091c76
commit d028ecef74
5 changed files with 31 additions and 10 deletions

View File

@@ -64,7 +64,7 @@ namespace sta
return currentState_;
}
void Statemachine::requestStateTransition(uint32_t from, uint32_t to, uint32_t lockout /* = 0 */)
void Statemachine::requestStateTransition(uint32_t from, uint32_t to, uint32_t lockout /* = 0 */, bool force /* = 0 */)
{
StateTransition transition;
transition.from = from;
@@ -72,9 +72,28 @@ namespace sta
transition.event = EventFlags::NORMAL;
transition.lockout = lockout;
// Try to add a state transition request to the queue. Don't wait if another
// thread is already requesting a state change.
queue_.put(transition, 0);
if (force){
// Perform the transition and notify the threads. The event flags are set
// here in order to allow threads to react immediately.
currentState_ = transition.to;
Statemachine::stateChangeEvent.set(transition.event);
Statemachine::stateChangeEvent.clear(EventFlags::ALL);
if (failsafeTimer_.isRunning())
{
failsafeTimer_.stop();
}
// Start the lockout timer if requested.
if (transition.lockout != 0)
{
setLockoutTimer(transition.lockout);
}
}else{
// Try to add a state transition request to the queue. Don't wait if another
// thread is already requesting a state change.
queue_.put(transition, 0);
}
}
void Statemachine::requestTimedStateTransition(uint32_t from, uint32_t to, uint32_t millis, uint32_t lockout /* = 0 */)