fsfw/housekeeping/HousekeepingMessage.cpp

233 lines
6.7 KiB
C++
Raw Permalink Normal View History

2020-10-01 12:05:24 +02:00
#include "HousekeepingMessage.h"
2020-12-03 13:00:04 +01:00
2021-06-05 19:52:38 +02:00
#include "../objectmanager/ObjectManager.h"
2020-10-01 12:05:24 +02:00
#include <cstring>
HousekeepingMessage::~HousekeepingMessage() {}
void HousekeepingMessage::setHkReportReply(CommandMessage* message, sid_t sid,
store_address_t storeId) {
message->setCommand(HK_REPORT);
message->setMessageSize(HK_MESSAGE_SIZE);
setSid(message, sid);
message->setParameter3(storeId.raw);
}
void HousekeepingMessage::setHkDiagnosticsReply(CommandMessage* message,
sid_t sid, store_address_t storeId) {
message->setCommand(DIAGNOSTICS_REPORT);
message->setMessageSize(HK_MESSAGE_SIZE);
setSid(message, sid);
message->setParameter3(storeId.raw);
}
sid_t HousekeepingMessage::getHkDataReply(const CommandMessage *message,
store_address_t *storeIdToSet) {
if(storeIdToSet != nullptr) {
*storeIdToSet = message->getParameter3();
}
return getSid(message);
}
void HousekeepingMessage::setToggleReportingCommand(CommandMessage *message,
sid_t sid, bool enableReporting, bool isDiagnostics) {
if(isDiagnostics) {
if(enableReporting) {
message->setCommand(ENABLE_PERIODIC_DIAGNOSTICS_GENERATION);
}
else {
message->setCommand(DISABLE_PERIODIC_DIAGNOSTICS_GENERATION);
}
}
else {
if(enableReporting) {
message->setCommand(ENABLE_PERIODIC_HK_REPORT_GENERATION);
}
else {
message->setCommand(DISABLE_PERIODIC_HK_REPORT_GENERATION);
}
}
setSid(message, sid);
}
void HousekeepingMessage::setStructureReportingCommand(CommandMessage *command,
sid_t sid, bool isDiagnostics) {
if(isDiagnostics) {
command->setCommand(REPORT_DIAGNOSTICS_REPORT_STRUCTURES);
}
else {
command->setCommand(REPORT_HK_REPORT_STRUCTURES);
}
setSid(command, sid);
}
void HousekeepingMessage::setOneShotReportCommand(CommandMessage *command,
sid_t sid, bool isDiagnostics) {
if(isDiagnostics) {
command->setCommand(GENERATE_ONE_DIAGNOSTICS_REPORT);
}
else {
command->setCommand(GENERATE_ONE_PARAMETER_REPORT);
}
setSid(command, sid);
}
void HousekeepingMessage::setCollectionIntervalModificationCommand(
CommandMessage *command, sid_t sid, float collectionInterval,
bool isDiagnostics) {
if(isDiagnostics) {
command->setCommand(MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL);
}
else {
command->setCommand(MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL);
}
2021-03-10 21:17:08 +01:00
/* Raw storage of the float in the message. Do not use setParameter3, does
implicit conversion to integer type! */
std::memcpy(command->getData() + 2 * sizeof(uint32_t), &collectionInterval,
sizeof(collectionInterval));
2020-10-01 12:05:24 +02:00
setSid(command, sid);
}
sid_t HousekeepingMessage::getCollectionIntervalModificationCommand(
const CommandMessage* command, float* newCollectionInterval) {
2021-03-10 21:17:08 +01:00
2020-10-01 12:05:24 +02:00
if(newCollectionInterval != nullptr) {
2021-03-10 21:17:08 +01:00
std::memcpy(newCollectionInterval, command->getData() + 2 * sizeof(uint32_t),
sizeof(*newCollectionInterval));
2020-10-01 12:05:24 +02:00
}
return getSid(command);
}
void HousekeepingMessage::setHkRequestSuccessReply(CommandMessage *reply,
sid_t sid) {
setSid(reply, sid);
reply->setCommand(HK_REQUEST_SUCCESS);
}
void HousekeepingMessage::setHkRequestFailureReply(CommandMessage *reply,
sid_t sid, ReturnValue_t error) {
setSid(reply, sid);
reply->setCommand(HK_REQUEST_FAILURE);
reply->setParameter3(error);
}
sid_t HousekeepingMessage::getHkRequestFailureReply(const CommandMessage *reply,
ReturnValue_t *error) {
if(error != nullptr) {
*error = reply->getParameter3();
}
return getSid(reply);
}
sid_t HousekeepingMessage::getSid(const CommandMessage* message) {
sid_t sid;
std::memcpy(&sid.raw, message->getData(), sizeof(sid.raw));
return sid;
}
2021-02-04 01:31:46 +01:00
gp_id_t HousekeepingMessage::getGpid(const CommandMessage* message) {
gp_id_t globalPoolId;
std::memcpy(&globalPoolId.raw, message->getData(), sizeof(globalPoolId.raw));
return globalPoolId;
2020-10-01 12:05:24 +02:00
}
void HousekeepingMessage::setHkStuctureReportReply(CommandMessage *reply,
sid_t sid, store_address_t storeId) {
reply->setCommand(HK_DEFINITIONS_REPORT);
setSid(reply, sid);
reply->setParameter3(storeId.raw);
}
void HousekeepingMessage::setDiagnosticsStuctureReportReply(
CommandMessage *reply, sid_t sid, store_address_t storeId) {
reply->setCommand(DIAGNOSTICS_DEFINITION_REPORT);
setSid(reply, sid);
reply->setParameter3(storeId.raw);
}
void HousekeepingMessage::clear(CommandMessage* message) {
switch(message->getCommand()) {
case(HK_REPORT):
case(DIAGNOSTICS_REPORT):
case(HK_DEFINITIONS_REPORT):
case(DIAGNOSTICS_DEFINITION_REPORT):
case(UPDATE_SNAPSHOT_SET):
case(UPDATE_SNAPSHOT_VARIABLE): {
2020-10-01 12:05:24 +02:00
store_address_t storeId;
getHkDataReply(message, &storeId);
2021-06-05 19:52:38 +02:00
StorageManagerIF *ipcStore = ObjectManager::instance()->get<StorageManagerIF>(
2020-10-01 12:05:24 +02:00
objects::IPC_STORE);
if (ipcStore != nullptr) {
ipcStore->deleteData(storeId);
}
}
}
message->setCommand(CommandMessage::CMD_NONE);
}
2020-12-03 13:00:04 +01:00
void HousekeepingMessage::setUpdateNotificationSetCommand(
CommandMessage *command, sid_t sid) {
command->setCommand(UPDATE_NOTIFICATION_SET);
setSid(command, sid);
}
void HousekeepingMessage::setUpdateNotificationVariableCommand(
2021-02-04 01:31:46 +01:00
CommandMessage *command, gp_id_t globalPoolId) {
2020-12-03 13:00:04 +01:00
command->setCommand(UPDATE_NOTIFICATION_VARIABLE);
2021-02-04 01:31:46 +01:00
setGpid(command, globalPoolId);
2020-12-03 13:00:04 +01:00
}
void HousekeepingMessage::setUpdateSnapshotSetCommand(CommandMessage *command,
sid_t sid, store_address_t storeId) {
2021-01-25 00:55:27 +01:00
command->setCommand(UPDATE_SNAPSHOT_SET);
2020-12-03 13:00:04 +01:00
setSid(command, sid);
command->setParameter3(storeId.raw);
}
void HousekeepingMessage::setUpdateSnapshotVariableCommand(
2021-02-04 01:31:46 +01:00
CommandMessage *command, gp_id_t globalPoolId, store_address_t storeId) {
2020-12-03 13:00:04 +01:00
command->setCommand(UPDATE_SNAPSHOT_VARIABLE);
2021-02-04 01:31:46 +01:00
setGpid(command, globalPoolId);
2020-12-03 13:00:04 +01:00
command->setParameter3(storeId.raw);
}
sid_t HousekeepingMessage::getUpdateNotificationSetCommand(
const CommandMessage *command) {
return getSid(command);
}
2021-02-04 01:31:46 +01:00
gp_id_t HousekeepingMessage::getUpdateNotificationVariableCommand(
2020-12-03 13:00:04 +01:00
const CommandMessage *command) {
2021-02-04 01:31:46 +01:00
return getGpid(command);
2020-12-03 13:00:04 +01:00
}
sid_t HousekeepingMessage::getUpdateSnapshotSetCommand(
const CommandMessage *command, store_address_t *storeId) {
if(storeId != nullptr) {
*storeId = command->getParameter3();
}
return getSid(command);
}
2021-02-04 01:31:46 +01:00
gp_id_t HousekeepingMessage::getUpdateSnapshotVariableCommand(
2020-12-03 13:00:04 +01:00
const CommandMessage *command, store_address_t *storeId) {
if(storeId != nullptr) {
*storeId = command->getParameter3();
}
2021-02-04 01:31:46 +01:00
return getGpid(command);
}
void HousekeepingMessage::setSid(CommandMessage *message, sid_t sid) {
std::memcpy(message->getData(), &sid.raw, sizeof(sid.raw));
}
void HousekeepingMessage::setGpid(CommandMessage *message, gp_id_t globalPoolId) {
std::memcpy(message->getData(), &globalPoolId.raw, sizeof(globalPoolId.raw));
2020-12-03 13:00:04 +01:00
}