replaced std::list by std::set for fixedSlotSequen

This commit is contained in:
Robin Müller 2020-03-24 00:22:17 +01:00
parent f7b7e10d05
commit 7e8d92f956
7 changed files with 95 additions and 94 deletions

View File

@ -69,6 +69,12 @@ class StorageManagerIF;
*
* Other important virtual methods with a default implementation
* are the getTransitionDelayMs() function and the getSwitches() function.
* Please ensure that getSwitches() returns DeviceHandlerIF::NO_SWITCHES if
* power switches are not implemented yet. Otherwise, the device handler will
* not transition to MODE_ON, even if setMode(MODE_ON) is called.
* If a transition to MODE_ON is desired without commanding, override the
* intialize() function and call setMode(_MODE_START_UP) before calling
* DeviceHandlerBase::initialize().
*
* @ingroup devices
*/
@ -349,7 +355,7 @@ protected:
* @param[out] numberOfSwitches length of returned array
* @return
* - @c RETURN_OK if the parameters were set
* - @c RETURN_FAILED if no switches exist
* - @c NO_SWITCH or any other returnvalue if no switches exist
*/
virtual ReturnValue_t getSwitches(const uint8_t **switches,
uint8_t *numberOfSwitches);

View File

@ -7,33 +7,11 @@
#include <framework/modes/HasModesIF.h>
#include <framework/ipc/MessageQueueSenderIF.h>
#if __cplusplus >= 201703L
#include <array>
#include <variant>
#endif
/**
* Physical address type
*/
typedef uint32_t address_t;
///**
// * This type safe union cold be used if C++17 or newer is used to transfer
// * comIF settings to the communication interface object.
// */
//
//#if __cplusplus >= 201703L
//using comParameterArray_t = std::array<uint8_t, 4>;
//using comParameters_t = std::variant<store_address_t, comParameterArray_t>;
//#else
//using comParameters_t = union comParameters {
// comParameters() = default;
// comParameters(uint32_t initValue): storeIdRaw(initValue) {}
// uint32_t storeIdRaw;
// uint8_t comParameter[4];
// };
//#endif
/**
* This is the Interface used to communicate with a device handler.
*

View File

@ -19,29 +19,34 @@ class PeriodicTaskIF;
*/
class FixedSequenceSlot {
public:
FixedSequenceSlot( object_id_t handlerId, uint32_t setTimeMs, int8_t setSequenceId, PeriodicTaskIF* executingTask );
FixedSequenceSlot( object_id_t handlerId, uint32_t setTimeMs,
int8_t setSequenceId, PeriodicTaskIF* executingTask );
virtual ~FixedSequenceSlot();
/**
* \brief \c handler identifies which device handler object is executed in this slot.
* @brief Handler identifies which device handler object is executed in this slot.
*/
ExecutableObjectIF* handler;
/**
* \brief This attribute defines when a device handler object is executed.
* @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, which is ensured by automated calculation
* from a database.
* @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;
/**
* \brief This value defines the type of device communication.
*
* \details The state of this value decides what communication routine is called in the PST executable or the device handler object.
* \details The state of this value decides what communication routine is
* called in the PST executable or the device handler object.
*/
uint8_t opcode;
bool operator <(const FixedSequenceSlot & fixedSequenceSlot) const {
return pollingTimeMs < fixedSequenceSlot.pollingTimeMs;
}
};

View File

@ -2,22 +2,23 @@
#include <framework/serviceinterface/ServiceInterfaceStream.h>
FixedSlotSequence::FixedSlotSequence(uint32_t setLengthMs) :
lengthMs(setLengthMs) {
slotLengthMs(setLengthMs) {
current = slotList.begin();
}
FixedSlotSequence::~FixedSlotSequence() {
std::list<FixedSequenceSlot*>::iterator slotIt;
//Iterate through slotList and delete all entries.
slotIt = this->slotList.begin();
while (slotIt != this->slotList.end()) {
delete (*slotIt);
slotIt++;
}
// This should call the destructor on each list entry.
slotList.clear();
// SlotListIter slotListIter = this->slotList.begin();
// //Iterate through slotList and delete all entries.
// while (slotListIter != this->slotList.end()) {
// delete (*slotIt);
// slotIt++;
// }
}
void FixedSlotSequence::executeAndAdvance() {
(*this->current)->handler->performOperation((*this->current)->opcode);
current->handler->performOperation(current->opcode);
// if (returnValue != RETURN_OK) {
// this->sendErrorMessage( returnValue );
// }
@ -31,53 +32,50 @@ void FixedSlotSequence::executeAndAdvance() {
uint32_t FixedSlotSequence::getIntervalToNextSlotMs() {
uint32_t oldTime;
std::list<FixedSequenceSlot*>::iterator it;
it = current;
SlotListIter slotListIter = current;
// Get the pollingTimeMs of the current slot object.
oldTime = (*it)->pollingTimeMs;
oldTime = slotListIter->pollingTimeMs;
// Advance to the next object.
it++;
slotListIter++;
// Find the next interval which is not 0.
while (it != slotList.end()) {
if (oldTime != (*it)->pollingTimeMs) {
return (*it)->pollingTimeMs - oldTime;
while (slotListIter != slotList.end()) {
if (oldTime != slotListIter->pollingTimeMs) {
return slotListIter->pollingTimeMs - oldTime;
} else {
it++;
slotListIter++;
}
}
// If the list end is reached (this is definitely an interval != 0),
// the interval is calculated by subtracting the remaining time of the PST
// and adding the start time of the first handler in the list.
it = slotList.begin();
return lengthMs - oldTime + (*it)->pollingTimeMs;
slotListIter = slotList.begin();
return slotLengthMs - oldTime + slotListIter->pollingTimeMs;
}
uint32_t FixedSlotSequence::getIntervalToPreviousSlotMs() {
uint32_t currentTime;
std::list<FixedSequenceSlot*>::iterator it;
it = current;
SlotListIter slotListIter = current;
// Get the pollingTimeMs of the current slot object.
currentTime = (*it)->pollingTimeMs;
currentTime = slotListIter->pollingTimeMs;
//if it is the first slot, calculate difference to last slot
if (it == slotList.begin()){
return lengthMs - (*(--slotList.end()))->pollingTimeMs + currentTime;
if (slotListIter == slotList.begin()){
return slotLengthMs - (--slotList.end())->pollingTimeMs + currentTime;
}
// get previous slot
it--;
slotListIter--;
return currentTime - (*it)->pollingTimeMs;
return currentTime - slotListIter->pollingTimeMs;
}
bool FixedSlotSequence::slotFollowsImmediately() {
uint32_t currentTime = (*current)->pollingTimeMs;
std::list<FixedSequenceSlot*>::iterator it;
it = this->current;
uint32_t currentTime = current->pollingTimeMs;
SlotListIter fixedSequenceIter = this->current;
// Get the pollingTimeMs of the current slot object.
if (it == slotList.begin())
if (fixedSequenceIter == slotList.begin())
return false;
it--;
if ((*it)->pollingTimeMs == currentTime) {
fixedSequenceIter--;
if (fixedSequenceIter->pollingTimeMs == currentTime) {
return true;
} else {
return false;
@ -85,29 +83,30 @@ bool FixedSlotSequence::slotFollowsImmediately() {
}
uint32_t FixedSlotSequence::getLengthMs() const {
return this->lengthMs;
return this->slotLengthMs;
}
ReturnValue_t FixedSlotSequence::checkSequence() const {
//Iterate through slotList and check successful creation. Checks if timing is ok (must be ascending) and if all handlers were found.
// Iterate through slotList and check successful creation.
// Checks if timing is ok (must be ascending) and if all handlers were found.
auto slotIt = slotList.begin();
uint32_t count = 0;
uint32_t time = 0;
while (slotIt != slotList.end()) {
if ((*slotIt)->handler == NULL) {
if (slotIt->handler == NULL) {
error << "FixedSlotSequene::initialize: ObjectId does not exist!"
<< std::endl;
count++;
} else if ((*slotIt)->pollingTimeMs < time) {
} else if (slotIt->pollingTimeMs < time) {
error << "FixedSlotSequence::initialize: Time: "
<< (*slotIt)->pollingTimeMs
<< slotIt->pollingTimeMs
<< " is smaller than previous with " << time << std::endl;
count++;
} else {
//All ok, print slot.
// (*slotIt)->print();
// All ok, print slot.
// (*slotIt)->print();
}
time = (*slotIt)->pollingTimeMs;
time = slotIt->pollingTimeMs;
slotIt++;
}
if (count > 0) {
@ -118,8 +117,7 @@ ReturnValue_t FixedSlotSequence::checkSequence() const {
void FixedSlotSequence::addSlot(object_id_t componentId, uint32_t slotTimeMs,
int8_t executionStep, PeriodicTaskIF* executingTask) {
this->slotList.push_back(
new FixedSequenceSlot(componentId, slotTimeMs, executionStep,
executingTask));
this->slotList.insert(FixedSequenceSlot(componentId, slotTimeMs, executionStep,
executingTask));
this->current = slotList.begin();
}

View File

@ -4,11 +4,15 @@
#include <framework/devicehandlers/FixedSequenceSlot.h>
#include <framework/objectmanager/SystemObject.h>
#include <list>
#include <set>
using SlotList = std::set<FixedSequenceSlot>;
using SlotListIter = std::set<FixedSequenceSlot>::iterator;
/**
* \brief This class is the representation of a Polling Sequence Table in software.
* @brief This class is the representation of a Polling Sequence Table in software.
*
* \details The FixedSlotSequence object maintains the dynamic execution of device handler objects.
* @details The FixedSlotSequence object maintains the dynamic execution of device handler objects.
* The main idea is to create a list of device handlers, to announce all handlers to the
* polling sequence and to maintain a list of polling slot objects. This slot list represents the
* Polling Sequence Table in software. Each polling slot contains information to indicate when and
@ -19,29 +23,37 @@
class FixedSlotSequence {
public:
/**
* \brief The constructor of the FixedSlotSequence object.
* @brief The constructor of the FixedSlotSequence object.
*
* \details The constructor takes two arguments, the period length and the init function.
* @details The constructor takes two arguments, the period length and the init function.
*
* \param setLength The period length, expressed in ms.
* @param setLength The period length, expressed in ms.
*/
FixedSlotSequence(uint32_t setLengthMs);
/**
* \brief The destructor of the FixedSlotSequence object.
* @brief The destructor of the FixedSlotSequence object.
*
* \details The destructor frees all allocated memory by iterating through the slotList
* @details The destructor frees all allocated memory by iterating through the slotList
* and deleting all allocated resources.
*/
virtual ~FixedSlotSequence();
/**
* \brief This is a method to add an PollingSlot object to slotList.
* @brief This is a method to add an PollingSlot object to slotList.
*
* \details Here, a polling slot object is added to the slot list. It is appended
* @details Here, a polling slot object is added to the slot list. It is appended
* to the end of the list. The list is currently NOT reordered.
* Afterwards, the iterator current is set to the beginning of the list.
* @param Object ID of the object to add
* @param setTime Value between (0 to 1) * slotLengthMs, when a FixedTimeslotTask
* will be called inside the slot period.
* @param setSequenceId ID which can be used to distinguish
* different task operations
* @param
* @param
*/
void addSlot(object_id_t handlerId, uint32_t setTime, int8_t setSequenceId,
PeriodicTaskIF* executingTask);
@ -75,12 +87,12 @@ public:
uint32_t getIntervalToPreviousSlotMs();
/**
* \brief This method returns the length of this FixedSlotSequence instance.
* @brief This method returns the length of this FixedSlotSequence instance.
*/
uint32_t getLengthMs() const;
/**
* \brief The method to execute the device handler entered in the current OPUSPollingSlot object.
* \brief The method to execute the device handler entered in the current PollingSlot object.
*
* \details Within this method the device handler object to be executed is chosen by looking up the
* handler address of the current slot in the handlerMap. Either the device handler's
@ -91,17 +103,17 @@ public:
void executeAndAdvance();
/**
* \brief An iterator that indicates the current polling slot to execute.
* @brief An iterator that indicates the current polling slot to execute.
*
* \details This is an iterator for slotList and always points to the polling slot which is executed next.
* @details This is an iterator for slotList and always points to the polling slot which is executed next.
*/
std::list<FixedSequenceSlot*>::iterator current;
SlotListIter current;
ReturnValue_t checkSequence() const;
virtual ReturnValue_t checkSequence() const;
protected:
/**
* \brief This list contains all OPUSPollingSlot objects, defining order and execution time of the
* @brief This list contains all PollingSlot objects, defining order and execution time of the
* device handler objects.
*
* @details The slot list is a std:list object that contains all created PollingSlot instances.
@ -109,9 +121,9 @@ protected:
* By iterating through this list the polling sequence is executed. Two entries with identical
* polling times are executed immediately one after another.
*/
std::list<FixedSequenceSlot*> slotList;
SlotList slotList;
uint32_t lengthMs;
uint32_t slotLengthMs;
};
#endif /* FIXEDSLOTSEQUENCE_H_ */

View File

@ -80,10 +80,10 @@ ReturnValue_t FixedTimeslotTask::checkSequence() const {
void FixedTimeslotTask::taskFunctionality() {
// A local iterator for the Polling Sequence Table is created to find the start time for the first entry.
std::list<FixedSequenceSlot*>::iterator it = pst.current;
SlotListIter slotListIter = pst.current;
//The start time for the first entry is read.
uint32_t intervalMs = (*it)->pollingTimeMs;
uint32_t intervalMs = slotListIter->pollingTimeMs;
TickType_t interval = pdMS_TO_TICKS(intervalMs);
TickType_t xLastWakeTime;

View File

@ -5,11 +5,13 @@
#include <framework/tasks/PeriodicTaskIF.h>
/**
* Following the same principle as the base class IF. This is the interface for a Fixed timeslot task
* @brief Following the same principle as the base class IF.
* This is the interface for a Fixed timeslot task
*/
class FixedTimeslotTaskIF : public PeriodicTaskIF {
public:
virtual ~FixedTimeslotTaskIF() {}
virtual ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) = 0;
virtual ReturnValue_t checkSequence() const = 0;
};