new initializeSequence func

This commit is contained in:
Robin Müller 2020-08-27 14:42:10 +02:00
parent 790e0399b7
commit 1dfdd65662
8 changed files with 45 additions and 20 deletions

View File

@ -78,8 +78,8 @@ uint32_t FixedTimeslotTask::getPeriodMs() const {
return pst.getLengthMs();
}
ReturnValue_t FixedTimeslotTask::checkAndInitializeSequence() const {
return pst.checkAndInitializeSequence();
ReturnValue_t FixedTimeslotTask::checkSequence() const {
return pst.checkSequence();
}
void FixedTimeslotTask::taskFunctionality() {
@ -87,6 +87,8 @@ void FixedTimeslotTask::taskFunctionality() {
// start time for the first entry.
auto slotListIter = pst.current;
pst.intializeSequenceAfterTaskCreation();
//The start time for the first entry is read.
uint32_t intervalMs = slotListIter->pollingTimeMs;
TickType_t interval = pdMS_TO_TICKS(intervalMs);

View File

@ -54,7 +54,7 @@ public:
uint32_t getPeriodMs() const override;
ReturnValue_t checkAndInitializeSequence() const override;
ReturnValue_t checkSequence() const override;
ReturnValue_t sleepFor(uint32_t ms) override;

View File

@ -49,7 +49,7 @@ ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
return HasReturnvaluesIF::RETURN_FAILED;
}
ReturnValue_t FixedTimeslotTask::checkAndInitializeSequence() const {
ReturnValue_t FixedTimeslotTask::checkSequence() const {
return pst.checkSequence();
}
@ -58,6 +58,8 @@ void FixedTimeslotTask::taskFunctionality() {
if (!started) {
suspend();
}
pst.intializeSequenceAfterTaskCreation();
//The start time for the first entry is read.
uint64_t lastWakeTime = getCurrentMonotonicTimeMs();
uint64_t interval = pst.getIntervalToNextSlotMs();

View File

@ -33,7 +33,7 @@ public:
virtual ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs,
int8_t executionStep);
virtual ReturnValue_t checkAndInitializeSequence() const;
virtual ReturnValue_t checkSequence() const;
/**
* This static function can be used as #deadlineMissedFunc.

View File

@ -52,6 +52,7 @@ void PeriodicPosixTask::taskFunctionality(void) {
if(!started){
suspend();
}
uint64_t lastWakeTime = getCurrentMonotonicTimeMs();
//The task's "infinite" inner loop is entered.
while (1) {

View File

@ -81,13 +81,20 @@ uint32_t FixedSlotSequence::getLengthMs() const {
return this->lengthMs;
}
ReturnValue_t FixedSlotSequence::checkAndInitializeSequence() const {
void FixedSlotSequence::addSlot(object_id_t componentId, uint32_t slotTimeMs,
int8_t executionStep, ExecutableObjectIF* executableObject,
PeriodicTaskIF* executingTask) {
this->slotList.insert(FixedSequenceSlot(componentId, slotTimeMs,
executionStep, executableObject, executingTask));
this->current = slotList.begin();
}
ReturnValue_t FixedSlotSequence::checkSequence() const {
if(slotList.empty()) {
sif::error << "Fixed Slot Sequence: Slot list is empty!" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
std::set<ExecutableObjectIF*> uniqueObjects;
uint32_t count = 0;
uint32_t time = 0;
for(const auto& slot: slotList) {
@ -106,11 +113,7 @@ ReturnValue_t FixedSlotSequence::checkAndInitializeSequence() const {
//sif::info << std::dec << slotIt->pollingTimeMs << std::endl;
}
time = slot.pollingTimeMs;
// Ensure that each unique object is initialized once.
if(uniqueObjects.find(slot.executableObject) == uniqueObjects.end()) {
slot.executableObject->initializeAfterTaskCreation();
uniqueObjects.emplace(slot.executableObject);
}
}
//sif::info << "Number of elements in slot list: "
// << slotList.size() << std::endl;
@ -120,10 +123,25 @@ ReturnValue_t FixedSlotSequence::checkAndInitializeSequence() const {
return HasReturnvaluesIF::RETURN_OK;
}
void FixedSlotSequence::addSlot(object_id_t componentId, uint32_t slotTimeMs,
int8_t executionStep, ExecutableObjectIF* executableObject,
PeriodicTaskIF* executingTask) {
this->slotList.insert(FixedSequenceSlot(componentId, slotTimeMs,
executionStep, executableObject, executingTask));
this->current = slotList.begin();
ReturnValue_t FixedSlotSequence::intializeSequenceAfterTaskCreation() const {
std::set<ExecutableObjectIF*> uniqueObjects;
uint32_t count = 0;
for(const auto& slot: slotList) {
// Ensure that each unique object is initialized once.
if(uniqueObjects.find(slot.executableObject) == uniqueObjects.end()) {
ReturnValue_t result =
slot.executableObject->initializeAfterTaskCreation();
if(result != HasReturnvaluesIF::RETURN_OK) {
count++;
}
uniqueObjects.emplace(slot.executableObject);
}
}
if (count > 0) {
sif::error << "FixedSlotSequence::intializeSequenceAfterTaskCreation:"
"Counted " << count << " failed initializations!" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -132,7 +132,9 @@ public:
* creation.
* @return
*/
ReturnValue_t checkAndInitializeSequence() const;
ReturnValue_t checkSequence() const;
ReturnValue_t intializeSequenceAfterTaskCreation() const;
protected:

View File

@ -27,7 +27,7 @@ public:
* Check whether the sequence is valid and perform all other required
* initialization steps which are needed after task creation
*/
virtual ReturnValue_t checkAndInitializeSequence() const = 0;
virtual ReturnValue_t checkSequence() const = 0;
};
#endif /* FRAMEWORK_TASKS_FIXEDTIMESLOTTASKIF_H_ */