From 7f3607c3d998fb4473fd7b35b3ddf9ebff7b1dbb Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 24 Jun 2020 02:00:26 +0200 Subject: [PATCH 1/6] hk service fixed --- housekeeping/HousekeepingMessage.cpp | 66 ++++++++++------------------ housekeeping/HousekeepingMessage.h | 27 +++++------- ipc/CommandMessage.cpp | 12 +++++ ipc/CommandMessage.h | 14 ++---- 4 files changed, 50 insertions(+), 69 deletions(-) diff --git a/housekeeping/HousekeepingMessage.cpp b/housekeeping/HousekeepingMessage.cpp index 0d0f9860..64b07c17 100644 --- a/housekeeping/HousekeepingMessage.cpp +++ b/housekeeping/HousekeepingMessage.cpp @@ -1,67 +1,47 @@ #include #include -HousekeepingMessage::HousekeepingMessage(): CommandMessage() { -} - HousekeepingMessage::~HousekeepingMessage() {} -void HousekeepingMessage::setParameter(uint32_t parameter) { - std::memcpy(getData(), ¶meter, sizeof(parameter)); -} - -uint32_t HousekeepingMessage::getParameter() const { - uint32_t parameter; - std::memcpy(¶meter, getData(), sizeof(parameter)); - return parameter; -} - -void HousekeepingMessage::setHkReportMessage(sid_t sid, +void HousekeepingMessage::setHkReportMessage(CommandMessage* message, sid_t sid, store_address_t storeId) { - CommandMessage::setCommand(HK_REPORT); - setSid(sid); - setParameter(storeId.raw); + message->setCommand(HK_REPORT); + message->setMessageSize(HK_MESSAGE_SIZE); + setSid(message, sid); + message->setParameter(storeId.raw); } -void HousekeepingMessage::setHkDiagnosticsMessage(sid_t sid, - store_address_t storeId) { - CommandMessage::setCommand(DIAGNOSTICS_REPORT); - setSid(sid); - setParameter(storeId.raw); +void HousekeepingMessage::setHkDiagnosticsMessage(CommandMessage* message, + sid_t sid, store_address_t storeId) { + message->setCommand(DIAGNOSTICS_REPORT); + setSid(message, sid); + setParameter(message, storeId.raw); } - -//size_t HousekeepingMessage::getMinimumMessageSize() const { -// return HK_MESSAGE_SIZE; -//} - -sid_t HousekeepingMessage::getSid() const { +sid_t HousekeepingMessage::getSid(const CommandMessage* message) { sid_t sid; - std::memcpy(&sid.raw, CommandMessage::getData(), sizeof(sid.raw)); + std::memcpy(&sid.raw, message->getData(), sizeof(sid.raw)); return sid; } -sid_t HousekeepingMessage::getHkReportMessage( - store_address_t *storeIdToSet) const { +sid_t HousekeepingMessage::getHkReportMessage(const CommandMessage *message, + store_address_t *storeIdToSet) { if(storeIdToSet != nullptr) { - *storeIdToSet = getParameter(); + *storeIdToSet = getParameter(message); } - return getSid(); + return getSid(message); } -void HousekeepingMessage::setSid(sid_t sid) { - std::memcpy(CommandMessage::getData(), &sid.raw, sizeof(sid.raw)); +void HousekeepingMessage::setSid(CommandMessage *message, sid_t sid) { + std::memcpy(message->getData(), &sid.raw, sizeof(sid.raw)); } -uint8_t* HousekeepingMessage::getData() { - return CommandMessage::getData() + sizeof(sid_t); +void HousekeepingMessage::setParameter(CommandMessage *message, + uint32_t parameter) { + message->setParameter3(parameter); } -const uint8_t* HousekeepingMessage::getData() const { - return CommandMessage::getData() + sizeof(sid_t); -} - -void HousekeepingMessage::clear() { - // clear IPC store where it is needed. +uint32_t HousekeepingMessage::getParameter(const CommandMessage *message) { + return message->getParameter3(); } diff --git a/housekeeping/HousekeepingMessage.h b/housekeeping/HousekeepingMessage.h index 8958201e..e2a69805 100644 --- a/housekeeping/HousekeepingMessage.h +++ b/housekeeping/HousekeepingMessage.h @@ -34,7 +34,7 @@ union sid_t { * This message is slightly larger than regular command messages to accomodate * the uint64_t structure ID (SID). */ -class HousekeepingMessage : public CommandMessage { +class HousekeepingMessage { public: static constexpr size_t HK_MESSAGE_SIZE = CommandMessageIF::HEADER_SIZE + @@ -45,7 +45,7 @@ public: * the message data, see CommandMessageIF and getInternalMessage(). * @param message */ - HousekeepingMessage(); + HousekeepingMessage() = delete; virtual ~HousekeepingMessage(); static constexpr uint8_t MESSAGE_ID = messagetypes::HOUSEKEEPING; @@ -94,25 +94,22 @@ public: static constexpr Command_t MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL = MAKE_COMMAND_ID(32); + static sid_t getSid(const CommandMessage* message); - void setParameter(uint32_t parameter); - uint32_t getParameter() const; - sid_t getSid() const; + static void setHkReportMessage(CommandMessage* message, sid_t sid, + store_address_t storeId); + 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 //! 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: - - void setSid(sid_t sid); - - virtual uint8_t* getData() override; - virtual const uint8_t* getData() const override; + static void setSid(CommandMessage* message, sid_t sid); + static void setParameter(CommandMessage* message, uint32_t parameter); + static uint32_t getParameter(const CommandMessage* message); }; diff --git a/ipc/CommandMessage.cpp b/ipc/CommandMessage.cpp index 2b0c34d5..e1d4dfae 100644 --- a/ipc/CommandMessage.cpp +++ b/ipc/CommandMessage.cpp @@ -52,6 +52,18 @@ void CommandMessage::setParameter2(uint32_t parameter2) { sizeof(parameter2)); } +uint32_t CommandMessage::getParameter3() const { + uint32_t parameter3; + std::memcpy(¶meter3, this->getData() + 2 * sizeof(uint32_t), + sizeof(parameter3)); + return parameter3; +} + +void CommandMessage::setParameter3(uint32_t parameter3) { + std::memcpy(this->getData() + 2 * sizeof(uint32_t), ¶meter3, + sizeof(parameter3)); +} + size_t CommandMessage::getMinimumMessageSize() const { return MINIMUM_COMMAND_MESSAGE_SIZE; } diff --git a/ipc/CommandMessage.h b/ipc/CommandMessage.h index 53df1c08..021fa49a 100644 --- a/ipc/CommandMessage.h +++ b/ipc/CommandMessage.h @@ -66,29 +66,21 @@ public: virtual uint8_t* getData() override; virtual const uint8_t* getData() const override; + /** * Get the first parameter of the message * @return the first Parameter of the message */ uint32_t getParameter() const; - /** * Set the first parameter of the message * @param the first parameter of the message */ void setParameter(uint32_t parameter1); - - /** - * Get the second parameter of the message - * @return the second Parameter of the message - */ uint32_t getParameter2() const; - - /** - * Set the second parameter of the message - * @param the second parameter of the message - */ void setParameter2(uint32_t parameter2); + uint32_t getParameter3() const; + void setParameter3(uint32_t parameter3); /** * check if a message was cleared From 6f2bb4125d7e4cd9baaf812c3dcd118883f65e71 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 24 Jun 2020 02:02:57 +0200 Subject: [PATCH 2/6] bugfix --- housekeeping/HousekeepingMessage.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/housekeeping/HousekeepingMessage.cpp b/housekeeping/HousekeepingMessage.cpp index 64b07c17..2335f03d 100644 --- a/housekeeping/HousekeepingMessage.cpp +++ b/housekeeping/HousekeepingMessage.cpp @@ -8,21 +8,16 @@ void HousekeepingMessage::setHkReportMessage(CommandMessage* message, sid_t sid, message->setCommand(HK_REPORT); message->setMessageSize(HK_MESSAGE_SIZE); setSid(message, sid); - message->setParameter(storeId.raw); + setParameter(message, storeId.raw); } void HousekeepingMessage::setHkDiagnosticsMessage(CommandMessage* message, sid_t sid, store_address_t storeId) { message->setCommand(DIAGNOSTICS_REPORT); + message->setMessageSize(HK_MESSAGE_SIZE); setSid(message, sid); setParameter(message, storeId.raw); } -sid_t HousekeepingMessage::getSid(const CommandMessage* message) { - sid_t sid; - std::memcpy(&sid.raw, message->getData(), sizeof(sid.raw)); - return sid; -} - sid_t HousekeepingMessage::getHkReportMessage(const CommandMessage *message, store_address_t *storeIdToSet) { @@ -32,6 +27,12 @@ sid_t HousekeepingMessage::getHkReportMessage(const CommandMessage *message, return getSid(message); } +sid_t HousekeepingMessage::getSid(const CommandMessage* message) { + sid_t sid; + std::memcpy(&sid.raw, message->getData(), sizeof(sid.raw)); + return sid; +} + void HousekeepingMessage::setSid(CommandMessage *message, sid_t sid) { std::memcpy(message->getData(), &sid.raw, sizeof(sid.raw)); } From 8d633bf1278e473a23ab67ee86458771a5c45bc2 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 24 Jun 2020 11:40:48 +0200 Subject: [PATCH 3/6] took over changed for singly linked list --- container/SinglyLinkedList.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/container/SinglyLinkedList.h b/container/SinglyLinkedList.h index 3c0078fc..a78a1467 100644 --- a/container/SinglyLinkedList.h +++ b/container/SinglyLinkedList.h @@ -88,14 +88,15 @@ public: ElementIterator begin() const { return ElementIterator::Iterator(start); } - typename ElementIterator::Iterator end() const { + + ElementIterator end() const { return ElementIterator::Iterator(); } - uint32_t getSize() const { - uint32_t size = 0; + size_t getSize() const { + size_t size = 0; LinkedElement *element = start; - while (element != NULL) { + while (element != nullptr) { size++; element = element->getNext(); } From 0c32a964529105b611b600938c84df647f8fa0cf Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 24 Jun 2020 11:54:41 +0200 Subject: [PATCH 4/6] some more singly linked list improvements --- container/SinglyLinkedList.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/container/SinglyLinkedList.h b/container/SinglyLinkedList.h index a78a1467..85a92e6a 100644 --- a/container/SinglyLinkedList.h +++ b/container/SinglyLinkedList.h @@ -16,8 +16,13 @@ public: class Iterator { public: LinkedElement *value = nullptr; + //! Creates an uninitialized iterator which points to nullptr. Iterator() {} + /** + * Initialize iterator at specified linked element. + * @param element + */ Iterator(LinkedElement *element) : value(element) { } @@ -72,6 +77,11 @@ private: LinkedElement *next; }; +/** + * @brief SinglyLinkedList data structure which keeps a pointer to its + * first element to perform all operations. + * @tparam T + */ template class SinglyLinkedList { public: @@ -90,7 +100,11 @@ public: } ElementIterator end() const { - return ElementIterator::Iterator(); + LinkedElement *element = start; + while (element != nullptr) { + element = element->getNext(); + } + return ElementIterator::Iterator(element); } size_t getSize() const { From 08f25370f3505ebf39f26166b2bf5a4000c28461 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 24 Jun 2020 12:03:52 +0200 Subject: [PATCH 5/6] moved typedefs into namespace --- tasks/FixedSlotSequence.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tasks/FixedSlotSequence.h b/tasks/FixedSlotSequence.h index 7de1884c..61883658 100644 --- a/tasks/FixedSlotSequence.h +++ b/tasks/FixedSlotSequence.h @@ -6,9 +6,6 @@ #include -using SlotList = std::multiset; -using SlotListIter = std::multiset::iterator; - /** * @brief This class is the representation of a Polling Sequence Table in software. * @details @@ -27,6 +24,8 @@ using SlotListIter = std::multiset::iterator; */ class FixedSlotSequence { public: + using SlotList = std::multiset; + using SlotListIter = std::multiset::iterator; /** * @brief The constructor of the FixedSlotSequence object. From ba5b8bd682e1e3e36612a9c8974a4b27c8bf1151 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 26 Jun 2020 13:28:58 +0200 Subject: [PATCH 6/6] hybrid iter update --- container/HybridIterator.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/container/HybridIterator.h b/container/HybridIterator.h index db1ce4bc..f2fd6b28 100644 --- a/container/HybridIterator.h +++ b/container/HybridIterator.h @@ -1,5 +1,5 @@ -#ifndef HYBRIDITERATOR_H_ -#define HYBRIDITERATOR_H_ +#ifndef FRAMEWORK_CONTAINER_HYBRIDITERATOR_H_ +#define FRAMEWORK_CONTAINER_HYBRIDITERATOR_H_ #include #include @@ -17,23 +17,23 @@ public: } HybridIterator(LinkedElement *start) : - LinkedElement::Iterator(start), value( - start->value), linked(true), end(NULL) { + LinkedElement::Iterator(start), value(start->value), + linked(true) { } HybridIterator(typename ArrayList::Iterator start, typename ArrayList::Iterator end) : - ArrayList::Iterator(start), value(start.value), linked( - false), end(end.value) { + ArrayList::Iterator(start), value(start.value), + linked(false), end(end.value) { if (value == this->end) { value = NULL; } } HybridIterator(T *firstElement, T *lastElement) : - ArrayList::Iterator(firstElement), value(firstElement), linked( - false), end(++lastElement) { + ArrayList::Iterator(firstElement), value(firstElement), + linked(false), end(++lastElement) { if (value == end) { value = NULL; } @@ -42,17 +42,17 @@ public: HybridIterator& operator++() { if (linked) { LinkedElement::Iterator::operator++(); - if (LinkedElement::Iterator::value != NULL) { + if (LinkedElement::Iterator::value != nullptr) { value = LinkedElement::Iterator::value->value; } else { - value = NULL; + value = nullptr; } } else { ArrayList::Iterator::operator++(); value = ArrayList::Iterator::value; if (value == end) { - value = NULL; + value = nullptr; } } return *this; @@ -64,11 +64,11 @@ public: return tmp; } - bool operator==(const HybridIterator& other) { + bool operator==(const HybridIterator& other) const { return value == other.value; } - bool operator!=(const HybridIterator& other) { + bool operator!=(const HybridIterator& other) const { return !(*this == other); } @@ -87,4 +87,4 @@ private: T *end = nullptr; }; -#endif /* HYBRIDITERATOR_H_ */ +#endif /* FRAMEWORK_CONTAINER_HYBRIDITERATOR_H_ */