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

View File

@ -54,7 +54,7 @@ public:
uint32_t getPeriodMs() const override; uint32_t getPeriodMs() const override;
ReturnValue_t checkAndInitializeSequence() const override; ReturnValue_t checkSequence() const override;
ReturnValue_t sleepFor(uint32_t ms) 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; return HasReturnvaluesIF::RETURN_FAILED;
} }
ReturnValue_t FixedTimeslotTask::checkAndInitializeSequence() const { ReturnValue_t FixedTimeslotTask::checkSequence() const {
return pst.checkSequence(); return pst.checkSequence();
} }
@ -58,6 +58,8 @@ void FixedTimeslotTask::taskFunctionality() {
if (!started) { if (!started) {
suspend(); suspend();
} }
pst.intializeSequenceAfterTaskCreation();
//The start time for the first entry is read. //The start time for the first entry is read.
uint64_t lastWakeTime = getCurrentMonotonicTimeMs(); uint64_t lastWakeTime = getCurrentMonotonicTimeMs();
uint64_t interval = pst.getIntervalToNextSlotMs(); uint64_t interval = pst.getIntervalToNextSlotMs();

View File

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

View File

@ -52,6 +52,7 @@ void PeriodicPosixTask::taskFunctionality(void) {
if(!started){ if(!started){
suspend(); suspend();
} }
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) {

View File

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

View File

@ -27,7 +27,7 @@ public:
* Check whether the sequence is valid and perform all other required * Check whether the sequence is valid and perform all other required
* initialization steps which are needed after task creation * 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_ */ #endif /* FRAMEWORK_TASKS_FIXEDTIMESLOTTASKIF_H_ */