hk message continued

This commit is contained in:
Robin Müller 2020-06-14 19:03:28 +02:00
parent 9f69191f23
commit 6ecf1cf534
2 changed files with 64 additions and 21 deletions

View File

@ -3,9 +3,25 @@
HousekeepingMessage::HousekeepingMessage(MessageQueueMessageIF* message): HousekeepingMessage::HousekeepingMessage(MessageQueueMessageIF* message):
CommandMessageBase(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(), &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, void HousekeepingMessage::setHkReportMessage(sid_t sid,
@ -15,32 +31,45 @@ void HousekeepingMessage::setHkReportMessage(sid_t sid,
setParameter(storeId.raw); 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 { size_t HousekeepingMessage::getMinimumMessageSize() const {
return HK_MESSAGE_SIZE; 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 HousekeepingMessage::getSid() const {
sid_t sid; sid_t sid;
std::memcpy(&sid.raw, CommandMessageBase::getData(), sizeof(sid.raw)); std::memcpy(&sid.raw, CommandMessageBase::getData(), sizeof(sid.raw));
return sid; return sid;
} }
uint8_t* HousekeepingMessage::getData() {
return internalMessage->getBuffer() + sizeof(sid_t);
}
void HousekeepingMessage::setParameter(uint32_t parameter) { sid_t HousekeepingMessage::getHkReportMessage(
memcpy(getData(), &parameter, sizeof(parameter)); store_address_t *storeIdToSet) const {
if(storeIdToSet != nullptr) {
*storeIdToSet = getParameter();
}
return getSid();
} }
void HousekeepingMessage::setSid(sid_t sid) { void HousekeepingMessage::setSid(sid_t sid) {
std::memcpy(CommandMessageBase::getData(), &sid.raw, sizeof(sid.raw)); 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.
}

View File

@ -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 { class HousekeepingMessage : public CommandMessageBase {
public: public:
static constexpr size_t HK_MESSAGE_SIZE = sizeof(MessageQueueId_t) static constexpr size_t HK_MESSAGE_SIZE = sizeof(MessageQueueId_t)
+ sizeof(Command_t) + sizeof(sid_t) * sizeof(uint32_t); + sizeof(Command_t) + sizeof(sid_t) * sizeof(uint32_t);
/** /**
* No instances of a message shall be created, instead * The HK message is initialized with a pointer to a message which holds
* a CommandMessage instance is manipulated. * the message data, see CommandMessageIF and getInternalMessage().
* @param message
*/ */
HousekeepingMessage(MessageQueueMessageIF* message); HousekeepingMessage(MessageQueueMessageIF* message);
virtual ~HousekeepingMessage(); virtual ~HousekeepingMessage();
@ -85,18 +93,24 @@ 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);
void setHkReportMessage(sid_t sid, store_address_t storeId);
void setParameter(uint32_t parameter); 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 getMinimumMessageSize() const override;
virtual size_t getMaximumMessageSize() const override; virtual void clear() override;
virtual uint8_t* getData() override;
private: private:
sid_t getSid() const; sid_t getSid() const;
void setSid(sid_t sid); void setSid(sid_t sid);
virtual uint8_t* getData() override;
virtual const uint8_t* getData() const override;
}; };