2022-05-18 14:32:35 +02:00
|
|
|
#include "PeriodicTaskBase.h"
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
2022-05-19 00:44:34 +02:00
|
|
|
#include "fsfw/objectmanager/ObjectManager.h"
|
|
|
|
#include "fsfw/serviceinterface.h"
|
|
|
|
|
2022-05-18 15:42:18 +02:00
|
|
|
PeriodicTaskBase::PeriodicTaskBase(TaskPeriod period_, TaskDeadlineMissedFunction dlmFunc_)
|
2022-05-19 00:44:34 +02:00
|
|
|
: period(period_), dlmFunc(dlmFunc_) {
|
|
|
|
// Hints at configuration error
|
|
|
|
if (PeriodicTaskBase::getPeriodMs() <= 1) {
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
sif::warning << "Passed task period 0 or smaller than 1 ms" << std::endl;
|
|
|
|
#else
|
|
|
|
sif::printWarning("Passed task period 0 or smaller than 1ms\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2022-05-18 14:32:35 +02:00
|
|
|
|
2022-05-18 15:42:18 +02:00
|
|
|
uint32_t PeriodicTaskBase::getPeriodMs() const { return static_cast<uint32_t>(period * 1000); }
|
2022-05-18 14:32:35 +02:00
|
|
|
|
2022-05-18 15:42:18 +02:00
|
|
|
bool PeriodicTaskBase::isEmpty() const { return objectList.empty(); }
|
2022-05-18 14:32:35 +02:00
|
|
|
|
2022-05-30 12:20:05 +02:00
|
|
|
ReturnValue_t PeriodicTaskBase::addComponent(object_id_t object) { return addComponent(object, 0); }
|
|
|
|
|
|
|
|
ReturnValue_t PeriodicTaskBase::addComponent(ExecutableObjectIF* object) {
|
|
|
|
return addComponent(object, 0);
|
|
|
|
}
|
|
|
|
|
2022-05-18 14:32:35 +02:00
|
|
|
ReturnValue_t PeriodicTaskBase::initObjsAfterTaskCreation() {
|
2022-05-30 11:00:43 +02:00
|
|
|
std::set<ExecutableObjectIF*> uniqueObjects;
|
2022-08-16 01:08:26 +02:00
|
|
|
ReturnValue_t status = returnvalue::OK;
|
2022-05-18 14:32:35 +02:00
|
|
|
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();
|
2022-08-16 01:08:26 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-05-18 14:32:35 +02:00
|
|
|
count++;
|
|
|
|
status = result;
|
|
|
|
}
|
|
|
|
uniqueObjects.emplace(obj.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count > 0) {
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PeriodicTaskBase::addComponent(object_id_t object, uint8_t opCode) {
|
2022-05-19 00:44:34 +02:00
|
|
|
auto* newObject = ObjectManager::instance()->get<ExecutableObjectIF>(object);
|
2022-05-18 14:32:35 +02:00
|
|
|
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
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-05-18 14:32:35 +02:00
|
|
|
}
|
|
|
|
objectList.push_back({object, opCode});
|
|
|
|
object->setTaskIF(this);
|
|
|
|
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::OK;
|
2022-05-18 14:32:35 +02:00
|
|
|
}
|