From 9c167e207460f4889174e2bf7fa264a8e832182c Mon Sep 17 00:00:00 2001 From: dario Date: Tue, 2 Jan 2024 01:03:01 +0100 Subject: [PATCH 1/2] Added a simple API for TACOS --- include/sta/tacos.hpp | 60 +++++++++++++++++++++++++++++++++++++++++++ src/tacos.cpp | 39 ++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 include/sta/tacos.hpp create mode 100644 src/tacos.cpp diff --git a/include/sta/tacos.hpp b/include/sta/tacos.hpp new file mode 100644 index 0000000..fb14a3a --- /dev/null +++ b/include/sta/tacos.hpp @@ -0,0 +1,60 @@ +/* + * tacos.hpp + * + * Created on: Jan 2, 2024 + * Author: Dario + */ + +#ifndef STA_TACOS_HPP +#define STA_TACOS_HPP + +#include +#include +#include + +#include + + +namespace sta +{ + namespace tacos + { + /** + * @brief Get the current state of the TACOS statemachine. + * + * @return uint16_t Returns the state. + */ + uint16_t getState(); + + /** + * @brief Request a state transition. Invalid state transitions will be dismissed. + * + * @param from The start we want to transition from. + * @param to The state we want to transition to. + * @param lockout An optional timer blocking state transition for a given time. + */ + void setState(uint32_t from, uint32_t to, uint32_t lockout = 0); + + /** + * @brief Request a state transition after a given time has passed. Invalid state transitions will be dismissed. + * + * @param from The start we want to transition from. + * @param to The state we want to transition to. + * @param millis The time to wait until the transition is requested. + * @param lockout An optional timer blocking state transition for a given time. Will be active after this transition was executed. + */ + void setStateTimed(uint32_t from, uint32_t to, uint32_t millis, uint32_t lockout = 0); + + /** + * @brief Register a new thread to be run by TACOS. + * + * @tparam T The class of the thread to be created. A subclass of TacosThread. + * @param states A list of states in which the thread should run. + * @param args The constructor arguments for the provided class. + */ + template + void addThread(std::list states, std::initializer_list args); + } // namespace tacos +} + +#endif /* STA_TACOS_HPP */ diff --git a/src/tacos.cpp b/src/tacos.cpp new file mode 100644 index 0000000..ea4a1c4 --- /dev/null +++ b/src/tacos.cpp @@ -0,0 +1,39 @@ +/* + * tacos.cpp + * + * Created on: Jan 2, 2024 + * Author: Dario + */ + +#include + + +namespace sta +{ + namespace tacos + { + uint16_t getState() + { + return Statemachine::instance()->getCurrentState(); + } + + void setState(uint32_t from, uint32_t to, uint32_t lockout /* = 0 */) + { + Statemachine::instance()->requestStateTransition(from, to, lockout); + } + + void setStateTimed(uint32_t from, uint32_t to, uint32_t millis, uint32_t lockout /* = 0 */) + { + Statemachine::instance()->requestTimedStateTransition(from, to, millis, lockout); + } + + template + void addThread(std::list states, std::initializer_list args) + { + Manager::instance()->registerThread(std::make_shared(args), states); + } + } // namespace tacos + +} // namespace sta + + From 74e122699862e7818e51a220dd56049393701c70 Mon Sep 17 00:00:00 2001 From: dario Date: Tue, 2 Jan 2024 01:40:09 +0100 Subject: [PATCH 2/2] Fixed the addThread function --- include/sta/tacos.hpp | 8 ++++++-- src/tacos.cpp | 6 ------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/sta/tacos.hpp b/include/sta/tacos.hpp index fb14a3a..bec1616 100644 --- a/include/sta/tacos.hpp +++ b/include/sta/tacos.hpp @@ -13,6 +13,7 @@ #include #include +#include namespace sta @@ -52,8 +53,11 @@ namespace sta * @param states A list of states in which the thread should run. * @param args The constructor arguments for the provided class. */ - template - void addThread(std::list states, std::initializer_list args); + template + void addThread(std::list states, Args ... args) + { + Manager::instance()->registerThread(std::make_shared(args...), states); + } } // namespace tacos } diff --git a/src/tacos.cpp b/src/tacos.cpp index ea4a1c4..45aa708 100644 --- a/src/tacos.cpp +++ b/src/tacos.cpp @@ -26,12 +26,6 @@ namespace sta { Statemachine::instance()->requestTimedStateTransition(from, to, millis, lockout); } - - template - void addThread(std::list states, std::initializer_list args) - { - Manager::instance()->registerThread(std::make_shared(args), states); - } } // namespace tacos } // namespace sta