2018-07-12 16:29:32 +02:00
|
|
|
#ifndef FIXEDSLOTSEQUENCE_H_
|
|
|
|
#define FIXEDSLOTSEQUENCE_H_
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
#include <framework/devicehandlers/FixedSequenceSlot.h>
|
2016-06-15 23:48:41 +02:00
|
|
|
#include <framework/objectmanager/SystemObject.h>
|
2020-04-06 11:19:05 +02:00
|
|
|
#include <set>
|
|
|
|
|
|
|
|
using SlotList = std::multiset<FixedSequenceSlot>;
|
|
|
|
using SlotListIter = std::multiset<FixedSequenceSlot>::iterator;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
2020-04-06 11:19:05 +02:00
|
|
|
* @brief This class is the representation of a Polling Sequence Table in software.
|
2016-06-15 23:48:41 +02:00
|
|
|
*
|
2020-05-05 18:56:45 +02:00
|
|
|
* @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 thepolling 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
|
|
|
|
* which device handler shall be executed within a given polling period.
|
|
|
|
* The sequence is then executed by iterating through this slot list.
|
|
|
|
* Handlers are invoking by calling a certain function stored in the handler list.
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2018-07-12 16:29:32 +02:00
|
|
|
class FixedSlotSequence {
|
2016-06-15 23:48:41 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
2020-04-06 11:19:05 +02:00
|
|
|
* @brief The constructor of the FixedSlotSequence object.
|
2016-06-15 23:48:41 +02:00
|
|
|
*
|
2020-04-06 11:19:05 +02:00
|
|
|
* @details The constructor takes two arguments, the period length and the init function.
|
2016-06-15 23:48:41 +02:00
|
|
|
*
|
2020-04-06 11:19:05 +02:00
|
|
|
* @param setLength The period length, expressed in ms.
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2018-07-12 16:29:32 +02:00
|
|
|
FixedSlotSequence(uint32_t setLengthMs);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
2020-04-06 11:19:05 +02:00
|
|
|
* @brief The destructor of the FixedSlotSequence object.
|
2016-06-15 23:48:41 +02:00
|
|
|
*
|
2020-04-06 11:19:05 +02:00
|
|
|
* @details The destructor frees all allocated memory by iterating through the slotList
|
2018-07-12 16:29:32 +02:00
|
|
|
* and deleting all allocated resources.
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2018-07-12 16:29:32 +02:00
|
|
|
virtual ~FixedSlotSequence();
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
2020-04-06 11:19:05 +02:00
|
|
|
* @brief This is a method to add an PollingSlot object to slotList.
|
2016-06-15 23:48:41 +02:00
|
|
|
*
|
2020-04-06 11:19:05 +02:00
|
|
|
* @details Here, a polling slot object is added to the slot list. It is appended
|
2016-06-15 23:48:41 +02:00
|
|
|
* to the end of the list. The list is currently NOT reordered.
|
|
|
|
* Afterwards, the iterator current is set to the beginning of the list.
|
2020-04-06 11:19:05 +02:00
|
|
|
* @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
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2018-07-12 16:29:32 +02:00
|
|
|
void addSlot(object_id_t handlerId, uint32_t setTime, int8_t setSequenceId,
|
|
|
|
PeriodicTaskIF* executingTask);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the current slot shall be executed immediately after the one before.
|
|
|
|
* This allows to distinguish between grouped and not grouped handlers.
|
|
|
|
* @return - @c true if the slot has the same polling time as the previous
|
|
|
|
* - @c false else
|
|
|
|
*/
|
|
|
|
bool slotFollowsImmediately();
|
|
|
|
|
|
|
|
/**
|
2020-05-11 17:20:10 +02:00
|
|
|
* @brief This method returns the time until the next software
|
|
|
|
* component is invoked.
|
2016-06-15 23:48:41 +02:00
|
|
|
*
|
2020-05-11 17:20:10 +02:00
|
|
|
* @details
|
2020-04-06 11:19:05 +02:00
|
|
|
* This method is vitally important for the operation of the PST.
|
|
|
|
* By fetching the polling time of the current slot and that of the
|
|
|
|
* next one (or the first one, if the list end is reached)
|
|
|
|
* it calculates and returns the interval in milliseconds within
|
|
|
|
* which the handler execution shall take place.
|
|
|
|
* If the next slot has the same time as the current one, it is ignored
|
|
|
|
* until a slot with different time or the end of the PST is found.
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2018-07-13 15:56:37 +02:00
|
|
|
uint32_t getIntervalToNextSlotMs();
|
|
|
|
|
|
|
|
/**
|
2020-05-11 17:20:10 +02:00
|
|
|
* @brief This method returns the time difference between the current
|
|
|
|
* slot and the previous slot
|
2018-07-13 15:56:37 +02:00
|
|
|
*
|
2020-05-11 17:20:10 +02:00
|
|
|
* @details
|
|
|
|
* This method is vitally important for the operation of the PST.
|
|
|
|
* By fetching the polling time of the current slot and that of the previous
|
|
|
|
* one (or the last one, if the slot is the first one) it calculates and
|
|
|
|
* returns the interval in milliseconds that the handler execution shall
|
|
|
|
* be delayed.
|
2018-07-13 15:56:37 +02:00
|
|
|
*/
|
|
|
|
uint32_t getIntervalToPreviousSlotMs();
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
2020-04-06 11:19:05 +02:00
|
|
|
* @brief This method returns the length of this FixedSlotSequence instance.
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2018-07-12 16:29:32 +02:00
|
|
|
uint32_t getLengthMs() const;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
2020-05-11 17:20:10 +02:00
|
|
|
* @brief The method to execute the device handler entered in the current
|
|
|
|
* PollingSlot object.
|
2016-06-15 23:48:41 +02:00
|
|
|
*
|
2020-05-11 17:20:10 +02:00
|
|
|
* @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 talkToInterface or its listenToInterface
|
|
|
|
* method is invoked, depending on the isTalking flag of the polling slot.
|
|
|
|
* After execution the iterator current is increased or, by reaching the
|
|
|
|
* end of slotList, reset to the beginning.
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2018-07-12 16:29:32 +02:00
|
|
|
void executeAndAdvance();
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
2020-04-06 11:19:05 +02:00
|
|
|
* @brief An iterator that indicates the current polling slot to execute.
|
2016-06-15 23:48:41 +02:00
|
|
|
*
|
2020-05-11 17:20:10 +02:00
|
|
|
* @details This is an iterator for slotList and always points to the
|
|
|
|
* polling slot which is executed next.
|
2018-07-12 16:29:32 +02:00
|
|
|
*/
|
2020-04-06 11:19:05 +02:00
|
|
|
SlotListIter current;
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2020-05-05 18:55:05 +02:00
|
|
|
/**
|
|
|
|
* Iterate through slotList and check successful creation.
|
|
|
|
* Checks if timing is ok (must be ascending) and if all handlers were found.
|
|
|
|
* @return
|
|
|
|
*/
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t checkSequence() const;
|
2020-05-07 20:06:17 +02:00
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
2020-05-11 17:20:10 +02:00
|
|
|
* @brief This list contains all PollingSlot objects, defining order and
|
|
|
|
* execution time of the device handler objects.
|
2016-06-15 23:48:41 +02:00
|
|
|
*
|
2020-05-11 17:20:10 +02:00
|
|
|
* @details
|
|
|
|
* The slot list is a std:list object that contains all created
|
|
|
|
* PollingSlot instances. They are NOT ordered automatically, so by
|
|
|
|
* adding entries, the correct order needs to be ensured. By iterating
|
|
|
|
* through this list the polling sequence is executed. Two entries with
|
|
|
|
* identical polling times are executed immediately one after another.
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2020-04-06 11:19:05 +02:00
|
|
|
SlotList slotList;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-04-19 21:37:55 +02:00
|
|
|
uint32_t lengthMs;
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
#endif /* FIXEDSLOTSEQUENCE_H_ */
|