From 6ecf1cf534b1eaf45be731263a241b629fa3d937 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 14 Jun 2020 19:03:28 +0200 Subject: [PATCH] hk message continued --- housekeeping/HousekeepingMessage.cpp | 57 +++++++++++++++++++++------- housekeeping/HousekeepingMessage.h | 28 ++++++++++---- 2 files changed, 64 insertions(+), 21 deletions(-) diff --git a/housekeeping/HousekeepingMessage.cpp b/housekeeping/HousekeepingMessage.cpp index 6dd1a711..d47fb92a 100644 --- a/housekeeping/HousekeepingMessage.cpp +++ b/housekeeping/HousekeepingMessage.cpp @@ -3,9 +3,25 @@ HousekeepingMessage::HousekeepingMessage(MessageQueueMessageIF* message): CommandMessageBase(message) { + if(message->getMaximumMessageSize() < HK_MESSAGE_SIZE) { + sif::error << "CommandMessage::ComandMessage: Passed message buffer" + " can not hold minimum "<< HK_MESSAGE_SIZE + << " bytes!" << std::endl; + return; + } + message->setMessageSize(HK_MESSAGE_SIZE); } -HousekeepingMessage::~HousekeepingMessage() { +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, @@ -15,32 +31,45 @@ void HousekeepingMessage::setHkReportMessage(sid_t sid, setParameter(storeId.raw); } +void HousekeepingMessage::setHkDiagnosticsMessage(sid_t sid, + store_address_t storeId) { + CommandMessageBase::setCommand(DIAGNOSTICS_REPORT); + setSid(sid); + setParameter(storeId.raw); +} + size_t HousekeepingMessage::getMinimumMessageSize() const { return HK_MESSAGE_SIZE; } -size_t HousekeepingMessage::getMaximumMessageSize() const { - return MessageQueueMessage::MAX_MESSAGE_SIZE; -} - -void HousekeepingMessage::clear() { - // clear IPC store where it is needed. -} - sid_t HousekeepingMessage::getSid() const { sid_t sid; std::memcpy(&sid.raw, CommandMessageBase::getData(), sizeof(sid.raw)); return sid; } -uint8_t* HousekeepingMessage::getData() { - return internalMessage->getBuffer() + sizeof(sid_t); -} -void HousekeepingMessage::setParameter(uint32_t parameter) { - memcpy(getData(), ¶meter, sizeof(parameter)); +sid_t HousekeepingMessage::getHkReportMessage( + store_address_t *storeIdToSet) const { + if(storeIdToSet != nullptr) { + *storeIdToSet = getParameter(); + } + return getSid(); } void HousekeepingMessage::setSid(sid_t sid) { std::memcpy(CommandMessageBase::getData(), &sid.raw, sizeof(sid.raw)); } + + +uint8_t* HousekeepingMessage::getData() { + return CommandMessageBase::getData() + sizeof(sid_t); +} + +const uint8_t* HousekeepingMessage::getData() const { + return CommandMessageBase::getData() + sizeof(sid_t); +} + +void HousekeepingMessage::clear() { + // clear IPC store where it is needed. +} diff --git a/housekeeping/HousekeepingMessage.h b/housekeeping/HousekeepingMessage.h index 4e9d4553..c5e31fda 100644 --- a/housekeeping/HousekeepingMessage.h +++ b/housekeeping/HousekeepingMessage.h @@ -27,14 +27,22 @@ union sid_t { }; +/** + * @brief Special command message type for housekeeping messages + * @details + * This message is slightly larger than regular command messages to accomodate + * the uint64_t structure ID (SID). + */ class HousekeepingMessage : public CommandMessageBase { public: static constexpr size_t HK_MESSAGE_SIZE = sizeof(MessageQueueId_t) + sizeof(Command_t) + sizeof(sid_t) * sizeof(uint32_t); + /** - * No instances of a message shall be created, instead - * a CommandMessage instance is manipulated. + * The HK message is initialized with a pointer to a message which holds + * the message data, see CommandMessageIF and getInternalMessage(). + * @param message */ HousekeepingMessage(MessageQueueMessageIF* message); virtual ~HousekeepingMessage(); @@ -85,18 +93,24 @@ public: static constexpr Command_t MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL = MAKE_COMMAND_ID(32); - void setHkReportMessage(sid_t sid, store_address_t storeId); void setParameter(uint32_t parameter); + uint32_t getParameter() const; + + 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; - virtual void clear() override; virtual size_t getMinimumMessageSize() const override; - virtual size_t getMaximumMessageSize() const override; - - virtual uint8_t* getData() override; + virtual void clear() override; private: sid_t getSid() const; void setSid(sid_t sid); + + virtual uint8_t* getData() override; + virtual const uint8_t* getData() const override; };