13 #include <condition_variable>
26 template<
template<
class>
class Wrapper,
typename Tuple>
29 template<
template<
class>
class Wrapper,
typename... Ts>
31 using type = std::tuple<typename Wrapper<Ts>::type...>;
34 template<
template<
class>
class Wrapper,
typename Tuple>
38 template<
typename T,
typename Tuple>
43 using type = std::tuple<T>;
46 template<
typename T,
typename... Ts>
50 using type = std::conditional_t<!(std::is_same_v<T, Ts> || ...),
55 template<
typename T,
typename Tuple>
60 template<
typename Ts,
typename Us>
65 template<
typename... Us>
67 using type = std::tuple<Us...>;
72 template<
typename T,
typename... Ts,
typename... Us>
80 template<
typename Ts,
typename Us = std::tuple<>>
89 template<
typename Tuple>
92 template<
typename... Ts>
94 using type = std::variant<Ts...>;
98 template<
typename Tuple>
112 template<
typename From,
typename Event,
typename To>
119 template<
typename From,
122 typename Action = void (*)(),
123 typename Guard =
bool (*)()>
135 template<
typename From,
137 typename Guard = bool (*)(void),
138 typename Action =
void (*)(void)>
143 template<
typename Tuple,
typename... Ts>
148 template<
typename Tuple>
154 template<
typename Tuple,
typename First,
typename... Rest>
165 template<
typename... Ts>
168 template<
typename... Ts>
173 template<
typename... Ts>
180 template<
typename From,
182 typename TransitionsTuple,
188 template<
typename Transition,
typename From,
typename Event>
191 template<
typename From,
198 Event> : std::true_type {};
201 template<
typename From,
typename Event,
typename... Transitions,
size_t Index>
205 std::tuple<Transitions...>,
207 std::enable_if_t<(Index < sizeof...(Transitions))>> {
209 std::tuple_element_t<Index, std::tuple<Transitions...>>;
210 static constexpr
bool match =
213 using type =
typename std::conditional_t<
218 std::tuple<Transitions...>,
223 template<
typename From,
typename Event,
typename... Transitions,
size_t Index>
227 std::tuple<Transitions...>,
229 std::enable_if_t<!(Index < sizeof...(Transitions))>> {
234 template<
typename From,
typename Event,
typename Transitions>
240 template<
typename From,
typename Event,
typename Transitions>
245 template<
typename State,
typename Event,
typename Transitions>
247 !std::is_same_v<typename TransitionMap<State, Event, Transitions>::type,
251 template<
typename T,
typename Event,
typename =
void>
254 template<
typename T,
typename Event>
257 std::void_t<std::disjunction<
258 std::is_invocable<decltype(&T::exit), T>,
259 std::is_invocable<decltype(&T::exit), T, T&>,
260 std::is_invocable<decltype(&T::exit), T, Event>>>>
263 template<
typename T,
typename Event>
267 template<
typename T,
typename Event,
typename =
void>
270 template<
typename T,
typename Event>
273 std::void_t<std::disjunction<
274 std::is_invocable<decltype(&T::entry), T>,
275 std::is_invocable<decltype(&T::entry), T&>,
276 std::is_invocable<decltype(&T::entry), T, Event>>>>
279 template<
typename T,
typename Event>
283 template<
typename T,
typename Event,
typename =
void>
286 template<
typename T,
typename Event>
289 std::void_t<std::disjunction<
290 std::is_invocable<decltype(&T::guard), T>,
291 std::is_invocable<decltype(&T::guard), T&>,
292 std::is_invocable<decltype(&T::guard), T, Event>>>>
295 template<
typename T,
typename Event>
299 template<
typename T,
typename Event,
typename =
void>
302 template<
typename T,
typename Event>
305 std::void_t<std::disjunction<
306 std::is_invocable<decltype(&T::action), T>,
307 std::is_invocable<decltype(&T::action), T&>,
308 std::is_invocable<decltype(&T::action), T, Event>>>>
311 template<
typename T,
typename Event>
315 template<
typename,
typename = std::
void_t<>>
330 template<
typename State,
333 typename = std::void_t<>>
336 template<
typename State,
typename Event,
typename Context>
341 std::void_t<decltype(std::declval<State>().handle(std::declval<Context&>(),
342 std::declval<Event>()))>>
346 template<
typename State,
typename Event,
typename Context>
351 template<
typename,
typename = std::
void_t<>>
355 struct is_hsm_trait<T, std::void_t<decltype(T::is_hsm)>> : std::true_type {};
366 std::conjunction_v<has_transitions<T>, std::negation<is_hsm_trait<T>>>;
368 template<
typename T,
typename =
void>
379 template<
typename T,
typename transitions =
typename T::transitions>
391 template<
typename Event>
396 [
this, &e](
auto* state) {
397 using State = std::decay_t<decltype(*state)>;
399 bool handled =
false;
402 handled = state->handle(std::forward<Event>(e));
412 this->handle_transition<transition>(
413 state,
static_cast<Event&&
>(e));
422 template<
typename Event,
typename State>
424 if constexpr (has_entry_v<State, Event>) {
425 if constexpr (std::is_invocable_v<decltype(&State::entry),
429 state->entry(
static_cast<T&
>(*
this), std::forward<Event>(e));
430 }
else if constexpr (std::is_invocable_v<decltype(&State::entry),
433 state->entry(
static_cast<T&
>(*
this));
434 }
else if constexpr (std::is_invocable_v<decltype(&State::entry),
441 template<
typename Event,
typename State>
443 if constexpr (has_exit_v<State, Event>) {
444 if constexpr (std::is_invocable_v<decltype(&State::exit),
448 state->exit(
static_cast<T&
>(*
this), std::forward<Event>(e));
449 }
else if constexpr (std::is_invocable_v<decltype(&State::exit),
452 state->exit(
static_cast<T&
>(*
this));
453 }
else if constexpr (std::is_invocable_v<decltype(&State::exit),
460 template<
typename Tn,
461 typename Event =
typename Tn::event,
462 typename State =
typename Tn::from>
464 if constexpr (has_guard_v<State, Event>) {
465 if constexpr (std::is_invocable_v<decltype(&State::guard),
469 return state->guard(
static_cast<T&
>(*
this),
470 std::forward<Event>(e));
471 }
else if constexpr (std::is_invocable_v<decltype(&State::guard),
474 return state->guard(
static_cast<T&
>(*
this));
475 }
else if constexpr (std::is_invocable_v<decltype(&State::guard),
477 return state->guard();
484 template<
typename Tn,
485 typename Event =
typename Tn::event,
486 typename State =
typename Tn::from>
488 if constexpr (has_action_v<State, Event>) {
489 if constexpr (std::is_invocable_v<decltype(&State::action),
493 state->action(
static_cast<T&
>(*
this), std::forward<Event>(e));
494 }
else if constexpr (std::is_invocable_v<decltype(&State::action),
497 state->action(
static_cast<T&
>(*
this));
498 }
else if constexpr (std::is_invocable_v<decltype(&State::action),
505 template<
typename transition,
506 typename State =
typename transition::from,
507 typename Event =
typename transition::event>
508 std::enable_if_t<!has_handle_method_v<State, Event, T>,
void>
511 if (!this->check_guard<transition>(std::forward<Event>(e), state)) {
515 this->
template exit<Event, State>(std::forward<Event>(e), state);
518 this->perform_action<transition>(std::forward<Event>(e), state);
520 using to =
typename transition::to;
525 this->
template entry<Event, to>(std::forward<Event>(e),
529 template<
typename transition,
530 typename State =
typename transition::from,
531 typename Event =
typename transition::event>
532 std::enable_if_t<has_handle_method_v<State, Event, T>,
void>
536 if (!state->handle(
static_cast<T&
>(*
this), std::forward<Event>(e))) {
540 using to =
typename transition::to;
545 this->
template entry<Event, to>(std::forward<Event>(e),
549 template<
typename State>
559 template<
typename T,
typename =
void>
563 struct make_hsm<T, std::enable_if_t<!is_state_trait_v<T>>> {
574 using event =
typename T::event;
575 using to =
typename T::to;
590 template<
typename... Ts>
593 template<
typename... Ts>
595 using type = std::tuple<wrap_transition_t<Ts>...>;
598 template<
typename... Ts>
603 template<
typename T,
template<
typename>
class Policy =
make_hsm_t>
612 template<
typename Event>
614 return HsmType::handle(e);
619 return HsmType::handle(e);
627 struct make_hsm<T, std::enable_if_t<is_state_trait_v<T>>> {
635 template<
typename... Hsms>
640 template<
typename Event>
642 std::apply([e](
auto&... hsm) { (hsm.entry(e), ...); },
hsms_);
645 template<
typename Event>
647 std::apply([e](
auto&... hsm) { (hsm.exit(e), ...); },
hsms_);
650 template<
typename Event>
652 return std::apply([e](
auto&... hsm) {
return (hsm.handle(e) && ...); },
661 template<
typename Event,
typename LockType,
typename ConditionVarType>
670 std::unique_lock<LockType> lock(eventQueueMutex_);
671 cvEventAvailable_.wait(
672 lock, [
this] {
return (!this->
empty() || this->interrupt_); });
685 std::lock_guard<LockType> lock(eventQueueMutex_);
687 cvEventAvailable_.notify_all();
692 cvEventAvailable_.notify_all();
700 bool empty() {
return push_index_ == pop_index_; }
706 pop_index_ = (pop_index_ + 1) % data_.size();
711 if ((push_index_ + 1) % data_.size() != pop_index_) {
712 data_[push_index_] = e;
713 push_index_ = (push_index_ + 1) % data_.size();
720 LockType eventQueueMutex_;
721 ConditionVarType cvEventAvailable_;
723 size_t push_index_{ 0 };
724 size_t pop_index_{ 0 };
725 std::array<Event, 50> data_;
735 this->mutex = xSemaphoreCreateMutex();
740 vSemaphoreDelete(this->mutex);
745 xSemaphoreTake(this->mutex, portMAX_DELAY);
750 return xSemaphoreTake(this->mutex, 0) == pdTRUE;
755 xSemaphoreGive(this->mutex);
762 SemaphoreHandle_t mutex;
768 : semaphore_(xSemaphoreCreateBinary())
771 xSemaphoreTake(semaphore_, 0);
776 template<
typename Lock>
779 UBaseType_t oldISRState = taskENTER_CRITICAL_FROM_ISR();
781 taskEXIT_CRITICAL_FROM_ISR(oldISRState);
785 xSemaphoreTake(semaphore_, portMAX_DELAY);
788 oldISRState = taskENTER_CRITICAL_FROM_ISR();
790 taskEXIT_CRITICAL_FROM_ISR(oldISRState);
797 if (waitersCount_ > 0) {
798 xSemaphoreGive(semaphore_);
803 while (waitersCount_ > 0) {
804 xSemaphoreGive(semaphore_);
806 vTaskDelay(pdMS_TO_TICKS(10));
811 SemaphoreHandle_t semaphore_;
812 volatile UBaseType_t waitersCount_;
819 using rep = duration::rep;
825 TickType_t ticks = xTaskGetTickCount();
828 auto durationSinceEpoch =
829 std::chrono::milliseconds(ticks * (1000 / configTICK_RATE_HZ));
834 template<
typename Event>
837 template<
typename HsmType,
typename Events>
847 xTaskCreate(
reinterpret_cast<TaskFunction_t
>(
taskCallback),
848 "ThreadedPolicyTask",
849 configMINIMAL_STACK_SIZE,
886 std::visit([
this](
auto const& e) {
return this->handle(e); },
894 template<
typename Event>
895 using EventQueue = EventQueueT<Event, std::mutex, std::condition_variable_any>;
899 struct AccurateClock {
900 using duration = std::chrono::nanoseconds;
901 using period = duration::period;
902 using rep = duration::rep;
903 using time_point = std::chrono::time_point<AccurateClock>;
905 static constexpr
bool is_steady =
true;
907 static time_point now() noexcept {
909 clock_gettime(CLOCK_MONOTONIC, &ts);
910 auto durationSinceEpoch = std::chrono::seconds(ts.tv_sec) +
911 std::chrono::nanoseconds(ts.tv_nsec);
912 return time_point(duration(durationSinceEpoch));
919 template<
typename HsmType,
typename =
void>
922 template<
typename Transition>
925 template<
typename TransitionsTuple>
929 template<
typename... Transitions>
931 using type = decltype(std::tuple_cat(
942 template<
typename Transition>
944 using Event = std::tuple<typename Transition::event>;
953 template<
typename HsmType>
955 std::enable_if_t<has_transitions_v<HsmType>>> {
961 template<
typename HsmType>
963 std::enable_if_t<!has_transitions_v<HsmType>>> {
968 template<
typename HsmType>
973 template<
typename Context,
template<
typename>
class Policy =
make_hsm_t>
976 using HsmType =
typename Policy<Context>::type;
981 Event const& nextEvent = eventQueue_.next_event();
985 [
this](
auto&& e) ->
bool {
return HsmType::handle(e); }, nextEvent);
989 eventQueue_.add_event(std::forward<Event>(event));
998 template<
typename Context,
template<
typename>
class Policy =
make_hsm_t>
999 struct ThreadedExecutionPolicy : Policy<Context> {
1023 eventQueue_.add_event(std::forward<Event>(event));
1035 std::visit([
this](
auto const& e) {
return this->handle(e); },
1047 template<
typename LockType,
typename ConditionVarType>
1050 std::unique_lock<std::mutex> lock(smBusyMutex_);
1056 std::unique_lock<std::mutex> lock(smBusyMutex_);
1057 cv_.wait(lock, [
this] {
return this->notified_ ==
true; });
1062 LockType smBusyMutex_;
1063 ConditionVarType cv_;
1070 if (cb !=
nullptr) {
1076 for (
auto const& cb : cbs_) {
1082 std::vector<std::function<void()>> cbs_;
1085 #ifdef __FREE_RTOS__
1098 template<
typename Observer,
1102 :
public Policy<Context>
1106 using HsmType::interrupt_;
1107 using HsmType::process_event;
1108 using HsmType::smThread_;
1125 template<
typename Context>
1130 template<
typename Clock = std::chrono::steady_clock,
1131 typename Duration =
typename Clock::duration>
1144 auto now = Clock::now();
1146 return std::chrono::duration_cast<Duration>(interval);
1149 template<
typename ToDuration = Duration>
1151 auto now = Clock::now();
1152 if constexpr (std::is_same<ToDuration, Duration>::value) {
1153 return std::chrono::duration_cast<Duration>(now - since);
1155 return std::chrono::duration_cast<ToDuration>(now - since);
1159 template<
typename ToDuration>
1161 return std::chrono::duration_cast<ToDuration>(
elapsed());
1174 template<
typename Clock = std::chrono::steady_clock,
1175 typename Duration =
typename Clock::duration>
1184 auto now = Clock::now();
1186 this->start_time_ = now;
1187 return std::chrono::duration_cast<Duration>(
interval);
1195 template<
typename Clock = AccurateClock,
1196 typename Duration =
typename Clock::duration>
1209 std::chrono::duration_cast<std::chrono::seconds>(remaining).count();
1211 std::chrono::duration_cast<std::chrono::nanoseconds>(remaining)
1214 struct timespec remaining_ts;
1215 while (nanosleep(&ts, &remaining_ts) == EINTR) {
1237 struct sched_param param;
1239 if (pthread_setschedparam(pthread_self(), SCHED_RR, ¶m) != 0) {
1240 perror(
"pthread_setschedparam");
1247 CPU_SET(cpu, &cpuset);
1250 if (pthread_setaffinity_np(
1251 pthread_self(),
sizeof(cpu_set_t), &cpuset) != 0) {
1252 perror(
"sched_setaffinity");
1256 if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
1257 perror(
"mlockall failed");
1261 template<
typename Fn>
1263 return std::thread([
this, fn] {
1271 return std::move(t);
1280 template<
typename Context,
1281 template<
typename>
class Policy = ThreadedExecutionPolicy>
1287 using HsmType::interrupt_;
1288 using HsmType::process_event;
1289 using HsmType::smThread_;
1303 template<
typename Context,
1306 std::chrono::milliseconds>>
1313 using HsmType::interrupt_;
1314 using HsmType::send_event;
1317 PeriodicTimer::start();
1322 PeriodicTimer::wait();
1345 template<
typename Context,
1348 std::chrono::milliseconds>>
1357 using HsmType::interrupt_;
1358 using HsmType::process_event;
1359 using HsmType::send_event;
1360 using HsmType::smThread_;
1363 PeriodicTimer::start();
1372 PeriodicTimer::wait();
1395 template<
typename... Hsms>
1400 template<
typename Event>
1402 std::apply([e](
auto&... hsm) { (hsm.entry(e), ...); },
hsms_);
1405 template<
typename Event>
1407 std::apply([e](
auto&... hsm) { (hsm.exit(e), ...); },
hsms_);
1410 template<
typename Event>
1414 [e](
auto&... hsm) { (hsm.send_event(e), ...); },
1421 std::apply([](
auto&... hsm) { (hsm.tick(), ...); },
hsms_);
Definition: tsm_impl.h:765
void notify_all()
Definition: tsm_impl.h:802
void notify_one()
Definition: tsm_impl.h:796
FreeRTOSConditionVariable()
Definition: tsm_impl.h:767
void wait(Lock &lock)
Definition: tsm_impl.h:777
~FreeRTOSConditionVariable()
Definition: tsm_impl.h:774
Definition: tsm_impl.h:731
FreeRTOSMutex()
Definition: tsm_impl.h:733
void lock()
Definition: tsm_impl.h:743
void unlock()
Definition: tsm_impl.h:753
bool try_lock()
Definition: tsm_impl.h:748
~FreeRTOSMutex()
Definition: tsm_impl.h:738
SemaphoreHandle_t native_handle()
Definition: tsm_impl.h:759
Definition: tsm_impl.h:838
TaskHandle_t smTaskHandle
Definition: tsm_impl.h:868
std::thread smThread_
Definition: tsm_impl.h:1027
static void StepTask(void *pvParameters)
Definition: tsm_impl.h:872
ThreadedExecutionPolicy()
Definition: tsm_impl.h:844
TaskCallback taskCallback
Definition: tsm_impl.h:867
EventQueue eventQueue
Definition: tsm_impl.h:869
BaseType_t interrupt_
Definition: tsm_impl.h:870
void stop()
Definition: tsm_impl.h:1012
void process_event()
Definition: tsm_impl.h:883
void start()
Definition: tsm_impl.h:1004
void send_event(Event &&event)
Definition: tsm_impl.h:1022
void send_event(const Event &event)
Definition: tsm_impl.h:864
void step()
Definition: tsm_impl.h:877
virtual ~ThreadedExecutionPolicy()
Definition: tsm_impl.h:855
void(*)(ThreadedExecutionPolicy *) TaskCallback
Definition: tsm_impl.h:842
typename Policy< Context >::type HsmType
Definition: tsm_impl.h:1001
EventQueue< Event > eventQueue_
Definition: tsm_impl.h:1028
tuple_to_variant_t< Events > Event
Definition: tsm_impl.h:840
typename is_hsm_trait< T >::type is_hsm_trait_t
Definition: tsm_impl.h:358
typename wrap_transitions< Ts... >::type wrap_transitions_t
Definition: tsm_impl.h:599
constexpr bool has_guard_v
Definition: tsm_impl.h:296
typename append_unique_impl< T, Tuple >::type append_unique
Definition: tsm_impl.h:56
constexpr bool has_transitions_v
Definition: tsm_impl.h:326
constexpr bool has_entry_v
Definition: tsm_impl.h:280
typename wrap_type_impl< Wrapper, Tuple >::type wrap_type
Definition: tsm_impl.h:35
constexpr bool has_handle_method_v
Definition: tsm_impl.h:347
constexpr bool has_action_v
Definition: tsm_impl.h:312
typename unique_tuple< Ts >::type unique_tuple_t
Definition: tsm_impl.h:86
typename make_hsm< T >::type make_hsm_t
Definition: tsm_impl.h:568
typename has_transitions< T >::type has_transitions_t
Definition: tsm_impl.h:323
constexpr bool has_exit_v
Definition: tsm_impl.h:264
constexpr int MaxEvents
Definition: tsm_impl.h:729
constexpr bool is_clocked_hsm_v
Definition: tsm_impl.h:376
typename tuple_to_variant_impl< Tuple >::type tuple_to_variant_t
Definition: tsm_impl.h:99
typename get_states< Ts... >::type get_states_t
Definition: tsm_impl.h:174
constexpr bool is_hsm_trait_v
Definition: tsm_impl.h:361
typename wrap_transition< T >::type wrap_transition_t
Definition: tsm_impl.h:588
constexpr bool is_state_trait_v
Definition: tsm_impl.h:365
typename TransitionMap< From, Event, Transitions >::type find_transition_t
Definition: tsm_impl.h:242
unique_tuple_t< typename get_events_from_hsm< HsmType >::type > get_events_t
Definition: tsm_impl.h:970
constexpr bool has_valid_transition_v
Definition: tsm_impl.h:246
typename make_concurrent_hsm< Policy, Ts... >::type make_concurrent_hsm_t
Definition: tsm_impl.h:1436
Definition: tsm_impl.h:113
To to
Definition: tsm_impl.h:116
From from
Definition: tsm_impl.h:114
Definition: tsm_impl.h:1048
void notify()
Definition: tsm_impl.h:1049
void wait()
Definition: tsm_impl.h:1055
Definition: tsm_impl.h:1068
void add_callback(std::function< void()> &&cb)
Definition: tsm_impl.h:1069
void notify()
Definition: tsm_impl.h:1075
Definition: tsm_impl.h:131
int ticks_
Definition: tsm_impl.h:132
Definition: tsm_impl.h:604
bool handle(ClockTickEvent &e)
Definition: tsm_impl.h:617
bool handle(Event e=Event())
Definition: tsm_impl.h:613
bool tick()
Definition: tsm_impl.h:610
ClockTickEvent tick_event_
Definition: tsm_impl.h:621
typename Policy< T >::type HsmType
Definition: tsm_impl.h:606
Definition: tsm_impl.h:140
Definition: tsm_impl.h:1396
void tick()
Definition: tsm_impl.h:1420
void send_event(Event &&e)
Definition: tsm_impl.h:1411
void exit(Event &&e)
Definition: tsm_impl.h:1406
static constexpr bool is_hsm
Definition: tsm_impl.h:1397
std::tuple< Hsms... > hsms_
Definition: tsm_impl.h:1424
void entry(Event e=Event())
Definition: tsm_impl.h:1401
Definition: tsm_impl.h:662
Event const & front()
Definition: tsm_impl.h:702
virtual ~EventQueueT()
Definition: tsm_impl.h:665
bool empty()
Definition: tsm_impl.h:700
void add_event(Event &&e)
Definition: tsm_impl.h:681
Event next_event()
Definition: tsm_impl.h:669
void stop()
Definition: tsm_impl.h:690
bool interrupted()
Definition: tsm_impl.h:697
bool push_back(Event const &e)
Definition: tsm_impl.h:710
void pop_front()
Definition: tsm_impl.h:704
Definition: tsm_impl.h:102
Definition: tsm_impl.h:816
std::chrono::time_point< FreeRTOSClock > time_point
Definition: tsm_impl.h:820
static constexpr bool is_steady
Definition: tsm_impl.h:822
std::chrono::milliseconds duration
Definition: tsm_impl.h:817
duration::rep rep
Definition: tsm_impl.h:819
static time_point now() noexcept
Definition: tsm_impl.h:824
duration::period period
Definition: tsm_impl.h:818
Definition: tsm_impl.h:380
void entry(Event &&e, State *state) noexcept
Definition: tsm_impl.h:423
void current_state()
Definition: tsm_impl.h:550
States states_
Definition: tsm_impl.h:554
tuple_to_variant_t< wrap_type< std::add_pointer, States > > current_state_
Definition: tsm_impl.h:556
std::enable_if_t< has_handle_method_v< State, Event, T >, void > handle_transition(State *state, Event &&e)
Definition: tsm_impl.h:533
Hsm()
Definition: tsm_impl.h:387
bool check_guard(Event &&e, State *state)
Definition: tsm_impl.h:463
void exit(Event &&e, State *state) noexcept
Definition: tsm_impl.h:442
std::enable_if_t<!has_handle_method_v< State, Event, T >, void > handle_transition(typename transition::from *state, Event &&e)
Definition: tsm_impl.h:509
static constexpr bool is_hsm
Definition: tsm_impl.h:381
transitions transitions_
Definition: tsm_impl.h:555
void perform_action(Event &&e, State *state)
Definition: tsm_impl.h:487
Hsm< T, transitions > type
Definition: tsm_impl.h:382
get_states_t< transitions > States
Definition: tsm_impl.h:385
bool handle(Event &&e)
Definition: tsm_impl.h:392
typename std::tuple_element_t< 0, transitions >::from initial_state
Definition: tsm_impl.h:384
Definition: tsm_impl.h:1176
Duration interval()
Definition: tsm_impl.h:1179
Definition: tsm_impl.h:636
void entry(Event e=Event())
Definition: tsm_impl.h:641
void exit(Event e=Event())
Definition: tsm_impl.h:646
bool handle(Event e=Event())
Definition: tsm_impl.h:651
std::tuple< Hsms... > hsms_
Definition: tsm_impl.h:656
static constexpr bool is_hsm
Definition: tsm_impl.h:637
Definition: tsm_impl.h:1309
PeriodicTimer TimerType
Definition: tsm_impl.h:1312
std::thread eventThread_
Definition: tsm_impl.h:1340
ClockTickEvent tick_event_
Definition: tsm_impl.h:1341
virtual ~PeriodicExecutionPolicy()
Definition: tsm_impl.h:1335
int get_ticks()
Definition: tsm_impl.h:1337
void stop()
Definition: tsm_impl.h:1329
void start()
Definition: tsm_impl.h:1316
typename Policy< Context >::type HsmType
Definition: tsm_impl.h:1311
Definition: tsm_impl.h:1197
void start()
Definition: tsm_impl.h:1200
Duration get_period() const
Definition: tsm_impl.h:1222
void wait()
Definition: tsm_impl.h:1202
Duration period_
Definition: tsm_impl.h:1225
PeriodicSleepTimer(Duration period=Duration(1))
Definition: tsm_impl.h:1198
Definition: tsm_impl.h:1229
void config_realtime_thread()
Definition: tsm_impl.h:1235
RealtimeConfigurator()=default
std::thread make_real_time(std::thread &&t)
Definition: tsm_impl.h:1269
int PROCESS_PRIORITY
Definition: tsm_impl.h:1275
std::thread real_time_thread(Fn fn)
Definition: tsm_impl.h:1262
RealtimeConfigurator(int priority, std::array< int, 4 > affinity)
Definition: tsm_impl.h:1231
std::array< int, 4 > CPU_AFFINITY
Definition: tsm_impl.h:1276
Definition: tsm_impl.h:1284
virtual ~RealtimeExecutionPolicy()=default
typename Policy< Context >::type HsmType
Definition: tsm_impl.h:1286
void start()
Definition: tsm_impl.h:1291
Definition: tsm_impl.h:1352
void start()
Definition: tsm_impl.h:1362
virtual ~RealtimePeriodicExecutionPolicy()
Definition: tsm_impl.h:1385
typename Policy< Context >::type HsmType
Definition: tsm_impl.h:1356
void stop()
Definition: tsm_impl.h:1379
PeriodicTimer TimerType
Definition: tsm_impl.h:1355
int get_ticks()
Definition: tsm_impl.h:1387
ClockTickEvent tick_event_
Definition: tsm_impl.h:1391
std::thread eventThread_
Definition: tsm_impl.h:1390
Definition: tsm_impl.h:974
typename Policy< Context >::type HsmType
Definition: tsm_impl.h:976
tuple_to_variant_t< get_events_t< HsmType > > Event
Definition: tsm_impl.h:977
void send_event(Event &&event)
Definition: tsm_impl.h:988
bool step()
Definition: tsm_impl.h:979
Definition: tsm_impl.h:1103
virtual ~ThreadedExecWithObserver()=default
typename Policy< Context >::type HsmType
Definition: tsm_impl.h:1105
void start()
Definition: tsm_impl.h:1110
Helper to implement a Timed Execution Policy.
Definition: tsm_impl.h:1132
void stop()
Definition: tsm_impl.h:1166
void start()
Definition: tsm_impl.h:1135
Clock ClockType
Definition: tsm_impl.h:1133
Duration DurationType
Definition: tsm_impl.h:1134
Duration elapsed(ToDuration since) const
Definition: tsm_impl.h:1150
bool started_
Definition: tsm_impl.h:1170
void reset()
Definition: tsm_impl.h:1165
ToDuration elapsed() const
Definition: tsm_impl.h:1160
Clock::time_point start_time_
Definition: tsm_impl.h:1169
bool started() const
Definition: tsm_impl.h:1164
Duration elapsed() const
Definition: tsm_impl.h:1140
Definition: tsm_impl.h:235
typename transition_map_helper< From, Event, Transitions >::type type
Definition: tsm_impl.h:236
Definition: tsm_impl.h:124
Action action
Definition: tsm_impl.h:125
Guard guard
Definition: tsm_impl.h:126
decltype(std::tuple_cat(typename get_events_from_transition< Transitions >::type{}...)) type
Definition: tsm_impl.h:932
std::tuple<> type
Definition: tsm_impl.h:938
Definition: tsm_impl.h:926
std::conditional_t<!(std::is_same_v< T, Ts >||...), std::tuple< Ts..., T >, std::tuple< Ts... > > type
Definition: tsm_impl.h:52
std::tuple< T > type
Definition: tsm_impl.h:43
Definition: tsm_impl.h:39
typename HsmType::transitions Transitions
Definition: tsm_impl.h:956
typename aggregate_events< Transitions >::type type
Definition: tsm_impl.h:957
std::tuple<> type
Definition: tsm_impl.h:964
Definition: tsm_impl.h:920
Definition: tsm_impl.h:943
typename get_events_from_hsm< typename Transition::to >::type ToEvents
Definition: tsm_impl.h:948
typename get_events_from_hsm< typename Transition::from >::type FromEvents
Definition: tsm_impl.h:946
decltype(std::tuple_cat(Event{}, FromEvents{}, ToEvents{})) type
Definition: tsm_impl.h:949
std::tuple< typename Transition::event > Event
Definition: tsm_impl.h:944
typename get_states_impl< std::tuple<>, Ts... >::type type
Definition: tsm_impl.h:170
typename get_states_impl< to_states, Rest... >::type type
Definition: tsm_impl.h:162
append_unique< typename First::from, Tuple > from_states
Definition: tsm_impl.h:157
append_unique< typename First::to, from_states > to_states
Definition: tsm_impl.h:159
Tuple type
Definition: tsm_impl.h:150
Definition: tsm_impl.h:144
Definition: tsm_impl.h:166
Definition: tsm_impl.h:300
Definition: tsm_impl.h:268
Definition: tsm_impl.h:252
Definition: tsm_impl.h:284
Definition: tsm_impl.h:334
Definition: tsm_impl.h:316
Definition: tsm_impl.h:369
Definition: tsm_impl.h:352
Definition: tsm_impl.h:189
Definition: tsm_impl.h:1430
wrap_transitions_t< typename T::transitions > transitions
Definition: tsm_impl.h:629
T type
Definition: tsm_impl.h:564
Definition: tsm_impl.h:560
typename std::conditional_t< match, CurrentTransition, typename transition_map_helper< From, Event, std::tuple< Transitions... >, Index+1 >::type > type
Definition: tsm_impl.h:219
std::tuple_element_t< Index, std::tuple< Transitions... > > CurrentTransition
Definition: tsm_impl.h:209
void type
Definition: tsm_impl.h:230
Definition: tsm_impl.h:185
std::variant< Ts... > type
Definition: tsm_impl.h:94
Definition: tsm_impl.h:90
typename unique_tuple_impl< std::tuple< Ts... >, append_unique< T, std::tuple< Us... > >>::type type
Definition: tsm_impl.h:76
std::tuple< Us... > type
Definition: tsm_impl.h:67
Definition: tsm_impl.h:61
Definition: tsm_impl.h:81
typename unique_tuple_impl< Ts, Us >::type type
Definition: tsm_impl.h:82
Definition: tsm_impl.h:572
typename T::from from
Definition: tsm_impl.h:573
typename T::to to
Definition: tsm_impl.h:575
typename T::guard guard
Definition: tsm_impl.h:577
typename T::action action
Definition: tsm_impl.h:576
std::conditional_t< is_state_trait_v< from >, make_hsm_t< from >, from > wrap_from
Definition: tsm_impl.h:580
std::conditional_t< is_state_trait_v< to >, make_hsm_t< to >, to > wrap_to
Definition: tsm_impl.h:582
std::tuple< wrap_transition_t< Ts >... > type
Definition: tsm_impl.h:595
Definition: tsm_impl.h:591
std::tuple< typename Wrapper< Ts >::type... > type
Definition: tsm_impl.h:31
Definition: tsm_impl.h:27
Definition: tsm_impl.h:105
T type
Definition: tsm_impl.h:106