/* * tacos.hpp * * Created on: Jan 2, 2024 * Author: Dario */ #ifndef STA_TACOS_HPP #define STA_TACOS_HPP #include #include #include #include #include #include /** * @defgroup tacos_api TACOS API * @brief Functions and classes that are used to interact with TACOS. * * @details This module contains all functions and classes that are used to interact with TACOS. It is the only module that should be used in user code. */ namespace sta { namespace tacos { /** * @brief Get the current state of the TACOS statemachine. * * @return uint16_t Returns the state. * * @ingroup tacos_api */ 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. * @param force If true, the state transition will be executed regardless of the current state. * * @ingroup tacos_api */ void setState(uint32_t from, uint32_t to, uint32_t lockout = 0, bool force = false); /** * @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. * * @ingroup tacos_api */ 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. * * @ingroup tacos_api */ template std::shared_ptr addThread(std::set states, Args ... args) { std::shared_ptr thread_ptr = std::make_shared(args...); Manager::instance()->registerThread(thread_ptr, states); return thread_ptr; } #ifdef STA_TACOS_CAN_BUS_ENABLED /** * @brief Queue a message to be sent over the CAN bus. * * @param msg The message to be sent. * @param timeout The time to wait for the message to be sent. * * @return bool True if the message was sent successfully. * * @ingroup tacos_api */ bool queueCanBusMsg(CanSysMsg & msg, uint32_t timeout); /** * @brief Publish a state transition message to the CAN bus. * * @param from The state 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. * * @return bool True if the message was sent successfully. * * @ingroup tacos_api */ bool publishState(uint32_t from, uint32_t to, uint32_t lockout = 0); #endif // STA_TACOS_CAN_BUS_ENABLED } // namespace tacos } #endif /* STA_TACOS_HPP */