TC 11 Tweaks EIVE #90
@ -16,7 +16,7 @@ elseif(FSFW_OSAL MATCHES "host")
|
||||
|
||||
else()
|
||||
|
||||
message(WARNING "The OS_FSFW variable was not set. Assuming host OS..")
|
||||
message(WARNING "${MSG_PREFIX} The FSFW_OSAL variable was not set. Assuming host OS..")
|
||||
# Not set. Assumuing this is a host build, try to determine host OS
|
||||
if(WIN32)
|
||||
add_subdirectory(host)
|
||||
|
@ -133,7 +133,7 @@ ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotT
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t FixedTimeslotTask::checkSequence() const { return pollingSeqTable.checkSequence(); }
|
||||
ReturnValue_t FixedTimeslotTask::checkSequence() { return pollingSeqTable.checkSequence(); }
|
||||
|
||||
uint32_t FixedTimeslotTask::getPeriodMs() const { return period * 1000; }
|
||||
|
||||
@ -176,3 +176,5 @@ bool FixedTimeslotTask::delayForInterval(chron_ms* previousWakeTimeMs, const chr
|
||||
(*previousWakeTimeMs) = currentStartTime;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FixedTimeslotTask::isEmpty() const { return pollingSeqTable.isEmpty(); }
|
||||
|
@ -59,12 +59,14 @@ class FixedTimeslotTask : public FixedTimeslotTaskIF {
|
||||
*/
|
||||
ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep);
|
||||
|
||||
ReturnValue_t checkSequence() const override;
|
||||
ReturnValue_t checkSequence() override;
|
||||
|
||||
uint32_t getPeriodMs() const;
|
||||
|
||||
ReturnValue_t sleepFor(uint32_t ms);
|
||||
|
||||
bool isEmpty() const override;
|
||||
|
||||
protected:
|
||||
using chron_ms = std::chrono::milliseconds;
|
||||
|
||||
|
@ -156,3 +156,5 @@ bool PeriodicTask::delayForInterval(chron_ms* previousWakeTimeMs, const chron_ms
|
||||
(*previousWakeTimeMs) = currentStartTime;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PeriodicTask::isEmpty() const { return objectList.empty(); }
|
||||
|
@ -73,6 +73,7 @@ class PeriodicTask : public PeriodicTaskIF {
|
||||
|
||||
ReturnValue_t sleepFor(uint32_t ms);
|
||||
|
||||
bool isEmpty() const override;
|
||||
protected:
|
||||
using chron_ms = std::chrono::milliseconds;
|
||||
bool started;
|
||||
|
@ -8,12 +8,10 @@
|
||||
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||
|
||||
PeriodicPosixTask::PeriodicPosixTask(const char* name_, int priority_, size_t stackSize_,
|
||||
uint32_t period_, void(deadlineMissedFunc_)())
|
||||
uint32_t period_, TaskDeadlineMissedFunction dlMissedFunc_)
|
||||
: PosixThread(name_, priority_, stackSize_),
|
||||
objectList(),
|
||||
started(false),
|
||||
periodMs(period_),
|
||||
deadlineMissedFunc(deadlineMissedFunc_) {}
|
||||
PeriodicTaskBase(period_, dlMissedFunc_),
|
||||
started(false) {}
|
||||
|
||||
PeriodicPosixTask::~PeriodicPosixTask() {
|
||||
// Not Implemented
|
||||
@ -27,31 +25,8 @@ void* PeriodicPosixTask::taskEntryPoint(void* arg) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object, uint8_t opCode) {
|
||||
ExecutableObjectIF* newObject = ObjectManager::instance()->get<ExecutableObjectIF>(object);
|
||||
return addComponent(newObject, opCode);
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicPosixTask::addComponent(ExecutableObjectIF* object, uint8_t opCode) {
|
||||
if (object == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
|
||||
<< " it implements ExecutableObjectIF!" << std::endl;
|
||||
#else
|
||||
sif::printError(
|
||||
"PeriodicTask::addComponent: Invalid object. Make sure it "
|
||||
"implements ExecutableObjectIF!\n");
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
objectList.push_back({object, opCode});
|
||||
object->setTaskIF(this);
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicPosixTask::sleepFor(uint32_t ms) {
|
||||
return PosixThread::sleep((uint64_t)ms * 1000000);
|
||||
return PosixThread::sleep(static_cast<uint64_t>(ms * 1000000));
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicPosixTask::startTask(void) {
|
||||
@ -84,27 +59,3 @@ void PeriodicPosixTask::taskFunctionality(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t PeriodicPosixTask::getPeriodMs() const { return periodMs; }
|
||||
|
||||
bool PeriodicPosixTask::isEmpty() const { return objectList.empty(); }
|
||||
|
||||
ReturnValue_t PeriodicPosixTask::initObjsAfterTaskCreation() {
|
||||
std::multiset<ExecutableObjectIF*> uniqueObjects;
|
||||
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
|
||||
uint32_t count = 0;
|
||||
for (const auto& obj : objectList) {
|
||||
// Ensure that each unique object is initialized once.
|
||||
if (uniqueObjects.find(obj.first) == uniqueObjects.end()) {
|
||||
ReturnValue_t result = obj.first->initializeAfterTaskCreation();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
count++;
|
||||
status = result;
|
||||
}
|
||||
uniqueObjects.emplace(obj.first);
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
@ -1,14 +1,17 @@
|
||||
#ifndef FRAMEWORK_OSAL_LINUX_PERIODICPOSIXTASK_H_
|
||||
#define FRAMEWORK_OSAL_LINUX_PERIODICPOSIXTASK_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../tasks/ExecutableObjectIF.h"
|
||||
#include "../../tasks/PeriodicTaskIF.h"
|
||||
#include "PosixThread.h"
|
||||
|
||||
class PeriodicPosixTask : public PosixThread, public PeriodicTaskIF {
|
||||
#include <vector>
|
||||
|
||||
#include "fsfw/objectmanager/ObjectManagerIF.h"
|
||||
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||
#include "fsfw/tasks/PeriodicTaskIF.h"
|
||||
#include "fsfw/tasks/PeriodicTaskBase.h"
|
||||
|
||||
|
||||
class PeriodicPosixTask : public PosixThread, public PeriodicTaskBase {
|
||||
public:
|
||||
/**
|
||||
* Create a generic periodic task.
|
||||
@ -34,48 +37,16 @@ class PeriodicPosixTask : public PosixThread, public PeriodicTaskIF {
|
||||
* to the system call.
|
||||
*/
|
||||
ReturnValue_t startTask() override;
|
||||
/**
|
||||
* Adds an object to the list of objects to be executed.
|
||||
* The objects are executed in the order added.
|
||||
* @param object Id of the object to add.
|
||||
* @return RETURN_OK on success, RETURN_FAILED if the object could not be added.
|
||||
*/
|
||||
ReturnValue_t addComponent(object_id_t object, uint8_t opCode) override;
|
||||
|
||||
/**
|
||||
* Adds an object to the list of objects to be executed.
|
||||
* The objects are executed in the order added.
|
||||
* @param object pointer to the object to add.
|
||||
* @return RETURN_OK on success, RETURN_FAILED if the object could not be added.
|
||||
*/
|
||||
ReturnValue_t addComponent(ExecutableObjectIF* object, uint8_t opCode) override;
|
||||
|
||||
uint32_t getPeriodMs() const override;
|
||||
|
||||
ReturnValue_t sleepFor(uint32_t ms) override;
|
||||
|
||||
ReturnValue_t initObjsAfterTaskCreation();
|
||||
|
||||
bool isEmpty() const override;
|
||||
|
||||
private:
|
||||
//! Typedef for the List of objects. Will contain the objects to execute and their respective
|
||||
//! op codes
|
||||
using ObjectList = std::vector<std::pair<ExecutableObjectIF*, uint8_t>>;
|
||||
/**
|
||||
* @brief This attribute holds a list of objects to be executed.
|
||||
*/
|
||||
ObjectList objectList;
|
||||
|
||||
/**
|
||||
* @brief Flag to indicate that the task was started and is allowed to run
|
||||
*/
|
||||
bool started;
|
||||
|
||||
/**
|
||||
* @brief Period of the task in milliseconds
|
||||
*/
|
||||
uint32_t periodMs;
|
||||
/**
|
||||
* @brief The function containing the actual functionality of the task.
|
||||
* @details The method sets and starts
|
||||
@ -92,14 +63,6 @@ class PeriodicPosixTask : public PosixThread, public PeriodicTaskIF {
|
||||
* of the child class. Needs a valid pointer to the derived class.
|
||||
*/
|
||||
static void* taskEntryPoint(void* arg);
|
||||
/**
|
||||
* @brief The pointer to the deadline-missed function.
|
||||
* @details This pointer stores the function that is executed if the task's deadline is missed.
|
||||
* So, each may react individually on a timing failure. The pointer may be
|
||||
* NULL, then nothing happens on missing the deadline. The deadline is equal to the next execution
|
||||
* of the periodic task.
|
||||
*/
|
||||
void (*deadlineMissedFunc)();
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_LINUX_PERIODICPOSIXTASK_H_ */
|
||||
|
@ -1,2 +1,3 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE FixedSequenceSlot.cpp
|
||||
FixedSlotSequence.cpp)
|
||||
FixedSlotSequence.cpp
|
||||
PeriodicTaskBase.cpp)
|
||||
|
57
src/fsfw/tasks/PeriodicTaskBase.cpp
Normal file
57
src/fsfw/tasks/PeriodicTaskBase.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include <fsfw/objectmanager/ObjectManager.h>
|
||||
#include "PeriodicTaskBase.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
PeriodicTaskBase::PeriodicTaskBase(uint32_t periodMs_,
|
||||
TaskDeadlineMissedFunction deadlineMissedFunc_)
|
||||
: periodMs(periodMs_), deadlineMissedFunc(deadlineMissedFunc_) {}
|
||||
|
||||
uint32_t PeriodicTaskBase::getPeriodMs() const { return periodMs; }
|
||||
|
||||
bool PeriodicTaskBase::isEmpty() const {
|
||||
return objectList.empty();
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicTaskBase::initObjsAfterTaskCreation() {
|
||||
std::multiset<ExecutableObjectIF*> uniqueObjects;
|
||||
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
|
||||
uint32_t count = 0;
|
||||
for (const auto& obj : objectList) {
|
||||
// Ensure that each unique object is initialized once.
|
||||
if (uniqueObjects.find(obj.first) == uniqueObjects.end()) {
|
||||
ReturnValue_t result = obj.first->initializeAfterTaskCreation();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
count++;
|
||||
status = result;
|
||||
}
|
||||
uniqueObjects.emplace(obj.first);
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicTaskBase::addComponent(object_id_t object, uint8_t opCode) {
|
||||
ExecutableObjectIF* newObject = ObjectManager::instance()->get<ExecutableObjectIF>(object);
|
||||
return addComponent(newObject, opCode);
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicTaskBase::addComponent(ExecutableObjectIF* object, uint8_t opCode) {
|
||||
if (object == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
|
||||
<< " it implements ExecutableObjectIF!" << std::endl;
|
||||
#else
|
||||
sif::printError(
|
||||
"PeriodicTask::addComponent: Invalid object. Make sure it "
|
||||
"implements ExecutableObjectIF!\n");
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
objectList.push_back({object, opCode});
|
||||
object->setTaskIF(this);
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
51
src/fsfw/tasks/PeriodicTaskBase.h
Normal file
51
src/fsfw/tasks/PeriodicTaskBase.h
Normal file
@ -0,0 +1,51 @@
|
||||
#ifndef FSFW_SRC_FSFW_TASKS_PERIODICTASKBASE_H_
|
||||
#define FSFW_SRC_FSFW_TASKS_PERIODICTASKBASE_H_
|
||||
|
||||
#include "fsfw/tasks/PeriodicTaskIF.h"
|
||||
#include "fsfw/tasks/definitions.h"
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
class ExecutableObjectIF;
|
||||
|
||||
class PeriodicTaskBase: public PeriodicTaskIF {
|
||||
public:
|
||||
PeriodicTaskBase(uint32_t periodMs, TaskDeadlineMissedFunction deadlineMissedFunc = nullptr);
|
||||
|
||||
ReturnValue_t addComponent(object_id_t object, uint8_t opCode) override;
|
||||
ReturnValue_t addComponent(ExecutableObjectIF* object, uint8_t opCode) override;
|
||||
|
||||
uint32_t getPeriodMs() const override;
|
||||
|
||||
bool isEmpty() const override;
|
||||
|
||||
ReturnValue_t initObjsAfterTaskCreation();
|
||||
|
||||
protected:
|
||||
|
||||
//! Typedef for the List of objects. Will contain the objects to execute and their respective
|
||||
//! operation codes
|
||||
using ObjectList = std::vector<std::pair<ExecutableObjectIF*, uint8_t>>;
|
||||
/**
|
||||
* @brief This attribute holds a list of objects to be executed.
|
||||
*/
|
||||
ObjectList objectList;
|
||||
|
||||
/**
|
||||
* @brief Period of the task in milliseconds
|
||||
*/
|
||||
uint32_t periodMs;
|
||||
|
||||
/**
|
||||
* @brief The pointer to the deadline-missed function.
|
||||
* @details This pointer stores the function that is executed if the task's deadline is missed.
|
||||
* So, each may react individually on a timing failure. The pointer may be
|
||||
* NULL, then nothing happens on missing the deadline. The deadline is equal to the next execution
|
||||
* of the periodic task.
|
||||
*/
|
||||
TaskDeadlineMissedFunction deadlineMissedFunc = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_SRC_FSFW_TASKS_PERIODICTASKBASE_H_ */
|
@ -1,11 +1,10 @@
|
||||
#ifndef FRAMEWORK_TASK_PERIODICTASKIF_H_
|
||||
#define FRAMEWORK_TASK_PERIODICTASKIF_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include "fsfw/objectmanager/SystemObjectIF.h"
|
||||
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||
|
||||
#include "../objectmanager/SystemObjectIF.h"
|
||||
#include "../timemanager/Clock.h"
|
||||
class ExecutableObjectIF;
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* New version of TaskIF
|
||||
@ -26,20 +25,21 @@ class PeriodicTaskIF {
|
||||
virtual ReturnValue_t startTask() = 0;
|
||||
|
||||
/**
|
||||
* Add a component (object) to a periodic task.
|
||||
* @param object
|
||||
* Add an object to the task. The object needs to implement ExecutableObjectIF
|
||||
* @return
|
||||
* Adds an object to the list of objects to be executed.
|
||||
* The objects are executed in the order added. The object needs to implement
|
||||
* ExecutableObjectIF
|
||||
* @param object Id of the object to add.
|
||||
* @return RETURN_OK on success, RETURN_FAILED if the object could not be added.
|
||||
*/
|
||||
virtual ReturnValue_t addComponent(object_id_t object, uint8_t opCode = 0) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an object to a periodic task.
|
||||
* @param object
|
||||
* Add an object to the task.
|
||||
* @return
|
||||
* Adds an object to the list of objects to be executed.
|
||||
* The objects are executed in the order added.
|
||||
* @param object pointer to the object to add.
|
||||
* @return RETURN_OK on success, RETURN_FAILED if the object could not be added.
|
||||
*/
|
||||
virtual ReturnValue_t addComponent(ExecutableObjectIF* object, uint8_t opCode = 0) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <cstdlib>
|
||||
|
||||
#include "FixedTimeslotTaskIF.h"
|
||||
#include "Typedef.h"
|
||||
#include "definitions.h"
|
||||
|
||||
/**
|
||||
* Singleton Class that produces Tasks.
|
||||
|
@ -1,13 +0,0 @@
|
||||
#ifndef FSFW_TASKS_TYPEDEF_H_
|
||||
#define FSFW_TASKS_TYPEDEF_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
typedef const char* TaskName;
|
||||
typedef uint32_t TaskPriority;
|
||||
typedef size_t TaskStackSize;
|
||||
typedef double TaskPeriod;
|
||||
typedef void (*TaskDeadlineMissedFunction)();
|
||||
|
||||
#endif /* FSFW_TASKS_TYPEDEF_H_ */
|
13
src/fsfw/tasks/definitions.h
Normal file
13
src/fsfw/tasks/definitions.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef FSFW_TASKS_TYPEDEF_H_
|
||||
#define FSFW_TASKS_TYPEDEF_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
using TaskName = const char*;
|
||||
using TaskPriority = uint32_t;
|
||||
using TaskStackSize = size_t;
|
||||
using TaskPeriod = double;
|
||||
using TaskDeadlineMissedFunction = void (*)();
|
||||
|
||||
#endif /* FSFW_TASKS_TYPEDEF_H_ */
|
Loading…
Reference in New Issue
Block a user