hk service fixed

This commit is contained in:
Robin Müller 2020-06-24 02:00:26 +02:00
parent bb9f606ffd
commit 7f3607c3d9
4 changed files with 50 additions and 69 deletions

View File

@ -1,67 +1,47 @@
#include <framework/housekeeping/HousekeepingMessage.h>
#include <cstring>
HousekeepingMessage::HousekeepingMessage(): CommandMessage() {
}
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(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();
}

View File

@ -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);
};

View File

@ -52,6 +52,18 @@ void CommandMessage::setParameter2(uint32_t 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 {
return MINIMUM_COMMAND_MESSAGE_SIZE;
}

View File

@ -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