fsfw-example-common/example/test/FsfwReaderTask.cpp

55 lines
2.1 KiB
C++
Raw Normal View History

2021-06-08 13:35:49 +02:00
#include "FsfwReaderTask.h"
2022-05-05 20:55:28 +02:00
#include <OBSWConfig.h>
2021-06-08 13:35:49 +02:00
#include <fsfw/datapool/PoolReadGuard.h>
#include <fsfw/serviceinterface/ServiceInterface.h>
#include <fsfw/tasks/TaskFactory.h>
#include <fsfw/timemanager/Stopwatch.h>
2022-05-05 20:55:28 +02:00
FsfwReaderTask::FsfwReaderTask(object_id_t objectId, bool enablePrintout)
: SystemObject(objectId),
printoutEnabled(enablePrintout),
opDivider(10),
readSet(this->getObjectId(), gp_id_t(objects::TEST_DUMMY_1, FsfwDemoSet::PoolIds::VARIABLE),
gp_id_t(objects::TEST_DUMMY_2, FsfwDemoSet::PoolIds::VARIABLE),
gp_id_t(objects::TEST_DUMMY_3, FsfwDemoSet::PoolIds::VARIABLE)) {
/* Special protection for set reading because each variable is read from a different pool */
readSet.setReadCommitProtectionBehaviour(true);
2021-06-08 13:35:49 +02:00
}
2022-05-05 20:55:28 +02:00
FsfwReaderTask::~FsfwReaderTask() {}
2021-06-08 13:35:49 +02:00
ReturnValue_t FsfwReaderTask::initializeAfterTaskCreation() {
2022-05-05 20:55:28 +02:00
/* Give other task some time to set up local data pools. */
TaskFactory::delayTask(20);
return HasReturnvaluesIF::RETURN_OK;
2021-06-08 13:35:49 +02:00
}
ReturnValue_t FsfwReaderTask::performOperation(uint8_t operationCode) {
2022-05-05 20:55:28 +02:00
PoolReadGuard readHelper(&readSet);
2021-06-08 13:35:49 +02:00
2022-05-05 20:55:28 +02:00
uint32_t variable1 = readSet.variable1.value;
uint32_t variable2 = readSet.variable2.value;
uint32_t variable3 = readSet.variable3.value;
2021-06-08 13:35:49 +02:00
#if OBSW_VERBOSE_LEVEL >= 1
2022-05-05 20:55:28 +02:00
if (opDivider.checkAndIncrement() and printoutEnabled) {
2021-06-08 13:35:49 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-05-05 20:55:28 +02:00
sif::info << "FsfwPeriodicTask::performOperation: Reading variables." << std::endl;
sif::info << "Variable read from demo object 1: " << variable1 << std::endl;
sif::info << "Variable read from demo object 2: " << variable2 << std::endl;
sif::info << "Variable read from demo object 3: " << variable3 << std::endl;
2021-06-08 13:35:49 +02:00
#else
2022-05-05 20:55:28 +02:00
sif::printInfo("FsfwPeriodicTask::performOperation: Reading variables.\n\r");
sif::printInfo("Variable read from demo object 1: %d\n\r", variable1);
sif::printInfo("Variable read from demo object 2: %d\n\r", variable2);
sif::printInfo("Variable read from demo object 3: %d\n\r", variable3);
2021-06-08 13:35:49 +02:00
#endif
2022-05-05 20:55:28 +02:00
}
2021-06-08 13:35:49 +02:00
#else
2022-05-05 20:55:28 +02:00
if (variable1 and variable2 and variable3) {
};
2021-06-08 13:35:49 +02:00
#endif
2022-05-05 20:55:28 +02:00
return HasReturnvaluesIF::RETURN_OK;
2021-06-08 13:35:49 +02:00
}