srv3 received reply now
This commit is contained in:
@ -3,13 +3,14 @@
|
||||
#include <cstddef>
|
||||
|
||||
FixedSequenceSlot::FixedSequenceSlot(object_id_t handlerId, uint32_t setTime,
|
||||
int8_t setSequenceId, PeriodicTaskIF* executingTask) :
|
||||
int8_t setSequenceId, ExecutableObjectIF* executableObject,
|
||||
PeriodicTaskIF* executingTask) :
|
||||
pollingTimeMs(setTime), opcode(setSequenceId) {
|
||||
handler = objectManager->get<ExecutableObjectIF>(handlerId);
|
||||
if(executingTask != nullptr) {
|
||||
handler->setTaskIF(executingTask);
|
||||
}
|
||||
handler->initializeAfterTaskCreation();
|
||||
if(executableObject == nullptr) {
|
||||
return;
|
||||
}
|
||||
this->executableObject = executableObject;
|
||||
this->executableObject->setTaskIF(executingTask);
|
||||
}
|
||||
|
||||
FixedSequenceSlot::~FixedSequenceSlot() {}
|
||||
|
@ -16,21 +16,23 @@ class PeriodicTaskIF;
|
||||
class FixedSequenceSlot {
|
||||
public:
|
||||
FixedSequenceSlot( object_id_t handlerId, uint32_t setTimeMs,
|
||||
int8_t setSequenceId, PeriodicTaskIF* executingTask );
|
||||
int8_t setSequenceId, ExecutableObjectIF* executableObject,
|
||||
PeriodicTaskIF* executingTask);
|
||||
virtual ~FixedSequenceSlot();
|
||||
|
||||
/**
|
||||
* @brief Handler identifies which device handler object is executed in this slot.
|
||||
* @brief Handler identifies which object is executed in this slot.
|
||||
*/
|
||||
ExecutableObjectIF* handler = nullptr;
|
||||
ExecutableObjectIF* executableObject = nullptr;
|
||||
|
||||
/**
|
||||
* @brief This attribute defines when a device handler object is executed.
|
||||
*
|
||||
* @details The pollingTime attribute identifies the time the handler is executed in ms.
|
||||
* It must be smaller than the period length of the polling sequence.
|
||||
* @details
|
||||
* The pollingTime attribute identifies the time the handler is
|
||||
* executed in ms. It must be smaller than the period length of the
|
||||
* polling sequence.
|
||||
*/
|
||||
uint32_t pollingTimeMs;
|
||||
uint32_t pollingTimeMs;
|
||||
|
||||
/**
|
||||
* @brief This value defines the type of device communication.
|
||||
|
@ -13,7 +13,7 @@ FixedSlotSequence::~FixedSlotSequence() {
|
||||
}
|
||||
|
||||
void FixedSlotSequence::executeAndAdvance() {
|
||||
current->handler->performOperation(current->opcode);
|
||||
current->executableObject->performOperation(current->opcode);
|
||||
// if (returnValue != RETURN_OK) {
|
||||
// this->sendErrorMessage( returnValue );
|
||||
// }
|
||||
@ -81,34 +81,38 @@ uint32_t FixedSlotSequence::getLengthMs() const {
|
||||
return this->lengthMs;
|
||||
}
|
||||
|
||||
ReturnValue_t FixedSlotSequence::checkSequence() const {
|
||||
ReturnValue_t FixedSlotSequence::checkAndInitializeSequence() const {
|
||||
if(slotList.empty()) {
|
||||
sif::error << "Fixed Slot Sequence: Slot list is empty!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
auto slotIt = slotList.begin();
|
||||
std::set<ExecutableObjectIF*> uniqueObjects;
|
||||
uint32_t count = 0;
|
||||
uint32_t time = 0;
|
||||
while (slotIt != slotList.end()) {
|
||||
if (slotIt->handler == nullptr) {
|
||||
sif::error << "FixedSlotSequene::initialize: ObjectId does not exist!"
|
||||
<< std::endl;
|
||||
for(const auto& slot: slotList) {
|
||||
if (slot.executableObject == nullptr) {
|
||||
count++;
|
||||
} else if (slotIt->pollingTimeMs < time) {
|
||||
sif::error << "FixedSlotSequence::initialize: Time: "
|
||||
<< slotIt->pollingTimeMs
|
||||
<< " is smaller than previous with " << time << std::endl;
|
||||
count++;
|
||||
} else {
|
||||
// All ok, print slot.
|
||||
//info << "Current slot polling time: " << std::endl;
|
||||
//info << std::dec << slotIt->pollingTimeMs << std::endl;
|
||||
}
|
||||
time = slotIt->pollingTimeMs;
|
||||
slotIt++;
|
||||
else if (slot.pollingTimeMs < time) {
|
||||
sif::error << "FixedSlotSequence::initialize: Time: "
|
||||
<< slot.pollingTimeMs << " is smaller than previous with "
|
||||
<< time << std::endl;
|
||||
count++;
|
||||
}
|
||||
else {
|
||||
// All ok, print slot.
|
||||
//sif::info << "Current slot polling time: " << std::endl;
|
||||
//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);
|
||||
}
|
||||
}
|
||||
//info << "Number of elements in slot list: "
|
||||
//sif::info << "Number of elements in slot list: "
|
||||
// << slotList.size() << std::endl;
|
||||
if (count > 0) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
@ -117,8 +121,9 @@ ReturnValue_t FixedSlotSequence::checkSequence() const {
|
||||
}
|
||||
|
||||
void FixedSlotSequence::addSlot(object_id_t componentId, uint32_t slotTimeMs,
|
||||
int8_t executionStep, PeriodicTaskIF* executingTask) {
|
||||
this->slotList.insert(FixedSequenceSlot(componentId, slotTimeMs, executionStep,
|
||||
executingTask));
|
||||
this->current = slotList.begin();
|
||||
int8_t executionStep, ExecutableObjectIF* executableObject,
|
||||
PeriodicTaskIF* executingTask) {
|
||||
this->slotList.insert(FixedSequenceSlot(componentId, slotTimeMs,
|
||||
executionStep, executableObject, executingTask));
|
||||
this->current = slotList.begin();
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
* @param
|
||||
*/
|
||||
void addSlot(object_id_t handlerId, uint32_t setTime, int8_t setSequenceId,
|
||||
PeriodicTaskIF* executingTask);
|
||||
ExecutableObjectIF* executableObject, PeriodicTaskIF* executingTask);
|
||||
|
||||
/**
|
||||
* Checks if the current slot shall be executed immediately after the one before.
|
||||
@ -125,11 +125,14 @@ public:
|
||||
SlotListIter current;
|
||||
|
||||
/**
|
||||
* Iterate through slotList and check successful creation.
|
||||
* @brief Check and initialize slot list.
|
||||
* @details
|
||||
* Checks if timing is ok (must be ascending) and if all handlers were found.
|
||||
* Also calls any initialization steps which are required after task
|
||||
* creation.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t checkSequence() const;
|
||||
ReturnValue_t checkAndInitializeSequence() const;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -22,8 +22,12 @@ public:
|
||||
*/
|
||||
virtual ReturnValue_t addSlot(object_id_t componentId,
|
||||
uint32_t slotTimeMs, int8_t executionStep) = 0;
|
||||
/** Check whether the sequence is valid */
|
||||
virtual ReturnValue_t checkSequence() const = 0;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_FIXEDTIMESLOTTASKIF_H_ */
|
||||
|
Reference in New Issue
Block a user