Merge pull request 'api-changes' (#18) from api-changes into main

Reviewed-on: https://git.intern.spaceteamaachen.de/ALPAKA/TACOS/pulls/18
Reviewed-by: carlwachter <carlwachter@noreply.git.intern.spaceteamaachen.de>
This commit is contained in:
dario 2024-01-03 09:33:17 +00:00
commit 2494b4f0c1
2 changed files with 97 additions and 0 deletions

64
include/sta/tacos.hpp Normal file
View File

@ -0,0 +1,64 @@
/*
* tacos.hpp
*
* Created on: Jan 2, 2024
* Author: Dario
*/
#ifndef STA_TACOS_HPP
#define STA_TACOS_HPP
#include <sta/tacos/thread.hpp>
#include <sta/tacos/manager.hpp>
#include <sta/tacos/statemachine.hpp>
#include <initializer_list>
#include <type_traits>
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<typename T, typename ... Args>
void addThread(std::list<uint16_t> states, Args ... args)
{
Manager::instance()->registerThread(std::make_shared<T>(args...), states);
}
} // namespace tacos
}
#endif /* STA_TACOS_HPP */

33
src/tacos.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* tacos.cpp
*
* Created on: Jan 2, 2024
* Author: Dario
*/
#include <sta/tacos.hpp>
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);
}
} // namespace tacos
} // namespace sta