changed taken over

This commit is contained in:
Robin Müller 2020-09-04 14:49:27 +02:00
parent 9d1f292af0
commit 94b45d7407
2 changed files with 21 additions and 18 deletions

View File

@ -1,8 +1,7 @@
#include "../../tasks/ExecutableObjectIF.h" #include "../../tasks/ExecutableObjectIF.h"
#include "../../serviceinterface/ServiceInterfaceStream.h" #include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../osal/linux/PeriodicPosixTask.h"
#include <errno.h> #include <errno.h>
#include "PeriodicPosixTask.h"
PeriodicPosixTask::PeriodicPosixTask(const char* name_, int priority_, PeriodicPosixTask::PeriodicPosixTask(const char* name_, int priority_,
size_t stackSize_, uint32_t period_, void(deadlineMissedFunc_)()): size_t stackSize_, uint32_t period_, void(deadlineMissedFunc_)()):
@ -26,14 +25,14 @@ ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object) {
ExecutableObjectIF* newObject = objectManager->get<ExecutableObjectIF>( ExecutableObjectIF* newObject = objectManager->get<ExecutableObjectIF>(
object); object);
if (newObject == nullptr) { if (newObject == nullptr) {
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure" sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
"it implements ExecutableObjectIF" << std::endl; << " it implements ExecutableObjectIF!" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
objectList.push_back(newObject); objectList.push_back(newObject);
newObject->setTaskIF(this); newObject->setTaskIF(this);
return newObject->initializeAfterTaskCreation(); return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t PeriodicPosixTask::sleepFor(uint32_t ms) { ReturnValue_t PeriodicPosixTask::sleepFor(uint32_t ms) {
@ -49,27 +48,31 @@ ReturnValue_t PeriodicPosixTask::startTask(void) {
} }
void PeriodicPosixTask::taskFunctionality(void) { void PeriodicPosixTask::taskFunctionality(void) {
if(!started){ if(not started) {
suspend(); suspend();
} }
for (auto const &object: objectList) {
object->initializeAfterTaskCreation();
}
uint64_t lastWakeTime = getCurrentMonotonicTimeMs(); uint64_t lastWakeTime = getCurrentMonotonicTimeMs();
//The task's "infinite" inner loop is entered. //The task's "infinite" inner loop is entered.
while (1) { while (1) {
for (ObjectList::iterator it = objectList.begin(); for (auto const &object: objectList) {
it != objectList.end(); ++it) { object->performOperation();
(*it)->performOperation();
} }
if(!PosixThread::delayUntil(&lastWakeTime,periodMs)){
if(not PosixThread::delayUntil(&lastWakeTime, periodMs)){
char name[20] = {0}; char name[20] = {0};
int status = pthread_getname_np(pthread_self(),name,sizeof(name)); int status = pthread_getname_np(pthread_self(), name, sizeof(name));
if(status == 0){ if(status == 0) {
//sif::error << "PeriodicPosixTask " << name << ": Deadline " sif::error << "PeriodicPosixTask " << name << ": Deadline "
// "missed." << std::endl; "missed." << std::endl;
} }
else { else {
//sif::error << "PeriodicPosixTask X: Deadline missed. " << sif::error << "PeriodicPosixTask X: Deadline missed. " <<
// status << std::endl; status << std::endl;
} }
if (this->deadlineMissedFunc != nullptr) { if (this->deadlineMissedFunc != nullptr) {
this->deadlineMissedFunc(); this->deadlineMissedFunc();

View File

@ -3,7 +3,7 @@
#include "../../tasks/PeriodicTaskIF.h" #include "../../tasks/PeriodicTaskIF.h"
#include "../../objectmanager/ObjectManagerIF.h" #include "../../objectmanager/ObjectManagerIF.h"
#include "../../osal/linux/PosixThread.h" #include "PosixThread.h"
#include "../../tasks/ExecutableObjectIF.h" #include "../../tasks/ExecutableObjectIF.h"
#include <vector> #include <vector>
@ -32,7 +32,7 @@ public:
* The address of the task object is passed as an argument * The address of the task object is passed as an argument
* to the system call. * to the system call.
*/ */
ReturnValue_t startTask(void) override; ReturnValue_t startTask() override;
/** /**
* Adds an object to the list of objects to be executed. * Adds an object to the list of objects to be executed.
* The objects are executed in the order added. * The objects are executed in the order added.