Merge branch 'mueller_framework' into front_branch

This commit is contained in:
Robin Müller 2020-06-26 13:33:19 +02:00
commit 71f997888b
7 changed files with 90 additions and 94 deletions

View File

@ -1,5 +1,5 @@
#ifndef HYBRIDITERATOR_H_ #ifndef FRAMEWORK_CONTAINER_HYBRIDITERATOR_H_
#define HYBRIDITERATOR_H_ #define FRAMEWORK_CONTAINER_HYBRIDITERATOR_H_
#include <framework/container/ArrayList.h> #include <framework/container/ArrayList.h>
#include <framework/container/SinglyLinkedList.h> #include <framework/container/SinglyLinkedList.h>
@ -17,23 +17,23 @@ public:
} }
HybridIterator(LinkedElement<T> *start) : HybridIterator(LinkedElement<T> *start) :
LinkedElement<T>::Iterator(start), value( LinkedElement<T>::Iterator(start), value(start->value),
start->value), linked(true), end(NULL) { linked(true) {
} }
HybridIterator(typename ArrayList<T, count_t>::Iterator start, HybridIterator(typename ArrayList<T, count_t>::Iterator start,
typename ArrayList<T, count_t>::Iterator end) : typename ArrayList<T, count_t>::Iterator end) :
ArrayList<T, count_t>::Iterator(start), value(start.value), linked( ArrayList<T, count_t>::Iterator(start), value(start.value),
false), end(end.value) { linked(false), end(end.value) {
if (value == this->end) { if (value == this->end) {
value = NULL; value = NULL;
} }
} }
HybridIterator(T *firstElement, T *lastElement) : HybridIterator(T *firstElement, T *lastElement) :
ArrayList<T, count_t>::Iterator(firstElement), value(firstElement), linked( ArrayList<T, count_t>::Iterator(firstElement), value(firstElement),
false), end(++lastElement) { linked(false), end(++lastElement) {
if (value == end) { if (value == end) {
value = NULL; value = NULL;
} }
@ -42,17 +42,17 @@ public:
HybridIterator& operator++() { HybridIterator& operator++() {
if (linked) { if (linked) {
LinkedElement<T>::Iterator::operator++(); LinkedElement<T>::Iterator::operator++();
if (LinkedElement<T>::Iterator::value != NULL) { if (LinkedElement<T>::Iterator::value != nullptr) {
value = LinkedElement<T>::Iterator::value->value; value = LinkedElement<T>::Iterator::value->value;
} else { } else {
value = NULL; value = nullptr;
} }
} else { } else {
ArrayList<T, count_t>::Iterator::operator++(); ArrayList<T, count_t>::Iterator::operator++();
value = ArrayList<T, count_t>::Iterator::value; value = ArrayList<T, count_t>::Iterator::value;
if (value == end) { if (value == end) {
value = NULL; value = nullptr;
} }
} }
return *this; return *this;
@ -64,11 +64,11 @@ public:
return tmp; return tmp;
} }
bool operator==(const HybridIterator& other) { bool operator==(const HybridIterator& other) const {
return value == other.value; return value == other.value;
} }
bool operator!=(const HybridIterator& other) { bool operator!=(const HybridIterator& other) const {
return !(*this == other); return !(*this == other);
} }
@ -87,4 +87,4 @@ private:
T *end = nullptr; T *end = nullptr;
}; };
#endif /* HYBRIDITERATOR_H_ */ #endif /* FRAMEWORK_CONTAINER_HYBRIDITERATOR_H_ */

View File

@ -16,8 +16,13 @@ public:
class Iterator { class Iterator {
public: public:
LinkedElement<T> *value = nullptr; LinkedElement<T> *value = nullptr;
//! Creates an uninitialized iterator which points to nullptr.
Iterator() {} Iterator() {}
/**
* Initialize iterator at specified linked element.
* @param element
*/
Iterator(LinkedElement<T> *element) : Iterator(LinkedElement<T> *element) :
value(element) { value(element) {
} }
@ -72,6 +77,11 @@ private:
LinkedElement *next; LinkedElement *next;
}; };
/**
* @brief SinglyLinkedList data structure which keeps a pointer to its
* first element to perform all operations.
* @tparam T
*/
template<typename T> template<typename T>
class SinglyLinkedList { class SinglyLinkedList {
public: public:
@ -88,14 +98,19 @@ public:
ElementIterator begin() const { ElementIterator begin() const {
return ElementIterator::Iterator(start); return ElementIterator::Iterator(start);
} }
typename ElementIterator::Iterator end() const {
return ElementIterator::Iterator(); ElementIterator end() const {
LinkedElement<T> *element = start;
while (element != nullptr) {
element = element->getNext();
}
return ElementIterator::Iterator(element);
} }
uint32_t getSize() const { size_t getSize() const {
uint32_t size = 0; size_t size = 0;
LinkedElement<T> *element = start; LinkedElement<T> *element = start;
while (element != NULL) { while (element != nullptr) {
size++; size++;
element = element->getNext(); element = element->getNext();
} }

View File

@ -1,67 +1,48 @@
#include <framework/housekeeping/HousekeepingMessage.h> #include <framework/housekeeping/HousekeepingMessage.h>
#include <cstring> #include <cstring>
HousekeepingMessage::HousekeepingMessage(): CommandMessage() {
}
HousekeepingMessage::~HousekeepingMessage() {} HousekeepingMessage::~HousekeepingMessage() {}
void HousekeepingMessage::setParameter(uint32_t parameter) { void HousekeepingMessage::setHkReportMessage(CommandMessage* message, sid_t sid,
std::memcpy(getData(), &parameter, sizeof(parameter));
}
uint32_t HousekeepingMessage::getParameter() const {
uint32_t parameter;
std::memcpy(&parameter, getData(), sizeof(parameter));
return parameter;
}
void HousekeepingMessage::setHkReportMessage(sid_t sid,
store_address_t storeId) { store_address_t storeId) {
CommandMessage::setCommand(HK_REPORT); message->setCommand(HK_REPORT);
setSid(sid); message->setMessageSize(HK_MESSAGE_SIZE);
setParameter(storeId.raw); setSid(message, sid);
setParameter(message, storeId.raw);
} }
void HousekeepingMessage::setHkDiagnosticsMessage(sid_t sid, void HousekeepingMessage::setHkDiagnosticsMessage(CommandMessage* message,
store_address_t storeId) { sid_t sid, store_address_t storeId) {
CommandMessage::setCommand(DIAGNOSTICS_REPORT); message->setCommand(DIAGNOSTICS_REPORT);
setSid(sid); message->setMessageSize(HK_MESSAGE_SIZE);
setParameter(storeId.raw); setSid(message, sid);
setParameter(message, storeId.raw);
} }
//size_t HousekeepingMessage::getMinimumMessageSize() const { sid_t HousekeepingMessage::getHkReportMessage(const CommandMessage *message,
// return HK_MESSAGE_SIZE; store_address_t *storeIdToSet) {
//} if(storeIdToSet != nullptr) {
*storeIdToSet = getParameter(message);
}
return getSid(message);
}
sid_t HousekeepingMessage::getSid() const { sid_t HousekeepingMessage::getSid(const CommandMessage* message) {
sid_t sid; sid_t sid;
std::memcpy(&sid.raw, CommandMessage::getData(), sizeof(sid.raw)); std::memcpy(&sid.raw, message->getData(), sizeof(sid.raw));
return sid; return sid;
} }
void HousekeepingMessage::setSid(CommandMessage *message, sid_t sid) {
sid_t HousekeepingMessage::getHkReportMessage( std::memcpy(message->getData(), &sid.raw, sizeof(sid.raw));
store_address_t *storeIdToSet) const {
if(storeIdToSet != nullptr) {
*storeIdToSet = getParameter();
}
return getSid();
}
void HousekeepingMessage::setSid(sid_t sid) {
std::memcpy(CommandMessage::getData(), &sid.raw, sizeof(sid.raw));
} }
uint8_t* HousekeepingMessage::getData() { void HousekeepingMessage::setParameter(CommandMessage *message,
return CommandMessage::getData() + sizeof(sid_t); uint32_t parameter) {
message->setParameter3(parameter);
} }
const uint8_t* HousekeepingMessage::getData() const { uint32_t HousekeepingMessage::getParameter(const CommandMessage *message) {
return CommandMessage::getData() + sizeof(sid_t); return message->getParameter3();
}
void HousekeepingMessage::clear() {
// clear IPC store where it is needed.
} }

View File

@ -34,7 +34,7 @@ union sid_t {
* This message is slightly larger than regular command messages to accomodate * This message is slightly larger than regular command messages to accomodate
* the uint64_t structure ID (SID). * the uint64_t structure ID (SID).
*/ */
class HousekeepingMessage : public CommandMessage { class HousekeepingMessage {
public: public:
static constexpr size_t HK_MESSAGE_SIZE = CommandMessageIF::HEADER_SIZE + static constexpr size_t HK_MESSAGE_SIZE = CommandMessageIF::HEADER_SIZE +
@ -45,7 +45,7 @@ public:
* the message data, see CommandMessageIF and getInternalMessage(). * the message data, see CommandMessageIF and getInternalMessage().
* @param message * @param message
*/ */
HousekeepingMessage(); HousekeepingMessage() = delete;
virtual ~HousekeepingMessage(); virtual ~HousekeepingMessage();
static constexpr uint8_t MESSAGE_ID = messagetypes::HOUSEKEEPING; static constexpr uint8_t MESSAGE_ID = messagetypes::HOUSEKEEPING;
@ -94,25 +94,22 @@ public:
static constexpr Command_t MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL = static constexpr Command_t MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL =
MAKE_COMMAND_ID(32); MAKE_COMMAND_ID(32);
static sid_t getSid(const CommandMessage* message);
void setParameter(uint32_t parameter); static void setHkReportMessage(CommandMessage* message, sid_t sid,
uint32_t getParameter() const; store_address_t storeId);
sid_t getSid() const; static void setHkDiagnosticsMessage(CommandMessage* message, sid_t sid,
store_address_t storeId);
void setHkReportMessage(sid_t sid, store_address_t storeId);
void setHkDiagnosticsMessage(sid_t sid, store_address_t storeId);
//! Get the respective SID and store ID. Command ID can be used beforehand //! Get the respective SID and store ID. Command ID can be used beforehand
//! to distinguish between diagnostics and regular HK packets //! to distinguish between diagnostics and regular HK packets
sid_t getHkReportMessage(store_address_t * storeIdToSet) const; static sid_t getHkReportMessage(const CommandMessage* message,
store_address_t * storeIdToSet);
//virtual size_t getMinimumMessageSize() const override;
virtual void clear() override;
private: private:
static void setSid(CommandMessage* message, sid_t sid);
void setSid(sid_t sid); static void setParameter(CommandMessage* message, uint32_t parameter);
static uint32_t getParameter(const CommandMessage* message);
virtual uint8_t* getData() override;
virtual const uint8_t* getData() const override;
}; };

View File

@ -52,6 +52,18 @@ void CommandMessage::setParameter2(uint32_t parameter2) {
sizeof(parameter2)); sizeof(parameter2));
} }
uint32_t CommandMessage::getParameter3() const {
uint32_t parameter3;
std::memcpy(&parameter3, this->getData() + 2 * sizeof(uint32_t),
sizeof(parameter3));
return parameter3;
}
void CommandMessage::setParameter3(uint32_t parameter3) {
std::memcpy(this->getData() + 2 * sizeof(uint32_t), &parameter3,
sizeof(parameter3));
}
size_t CommandMessage::getMinimumMessageSize() const { size_t CommandMessage::getMinimumMessageSize() const {
return MINIMUM_COMMAND_MESSAGE_SIZE; return MINIMUM_COMMAND_MESSAGE_SIZE;
} }

View File

@ -66,29 +66,21 @@ public:
virtual uint8_t* getData() override; virtual uint8_t* getData() override;
virtual const uint8_t* getData() const override; virtual const uint8_t* getData() const override;
/** /**
* Get the first parameter of the message * Get the first parameter of the message
* @return the first Parameter of the message * @return the first Parameter of the message
*/ */
uint32_t getParameter() const; uint32_t getParameter() const;
/** /**
* Set the first parameter of the message * Set the first parameter of the message
* @param the first parameter of the message * @param the first parameter of the message
*/ */
void setParameter(uint32_t parameter1); void setParameter(uint32_t parameter1);
/**
* Get the second parameter of the message
* @return the second Parameter of the message
*/
uint32_t getParameter2() const; uint32_t getParameter2() const;
/**
* Set the second parameter of the message
* @param the second parameter of the message
*/
void setParameter2(uint32_t parameter2); void setParameter2(uint32_t parameter2);
uint32_t getParameter3() const;
void setParameter3(uint32_t parameter3);
/** /**
* check if a message was cleared * check if a message was cleared

View File

@ -6,9 +6,6 @@
#include <set> #include <set>
using SlotList = std::multiset<FixedSequenceSlot>;
using SlotListIter = std::multiset<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 * @details
@ -27,6 +24,8 @@ using SlotListIter = std::multiset<FixedSequenceSlot>::iterator;
*/ */
class FixedSlotSequence { class FixedSlotSequence {
public: public:
using SlotList = std::multiset<FixedSequenceSlot>;
using SlotListIter = std::multiset<FixedSequenceSlot>::iterator;
/** /**
* @brief The constructor of the FixedSlotSequence object. * @brief The constructor of the FixedSlotSequence object.