fsfw/src/fsfw/monitoring/LimitViolationReporter.cpp

55 lines
1.8 KiB
C++
Raw Normal View History

2021-07-13 20:58:45 +02:00
#include "fsfw/monitoring/LimitViolationReporter.h"
2022-02-02 10:29:30 +01:00
2021-07-13 20:58:45 +02:00
#include "fsfw/monitoring/MonitoringIF.h"
#include "fsfw/monitoring/ReceivesMonitoringReportsIF.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serialize/SerializeAdapter.h"
ReturnValue_t LimitViolationReporter::sendLimitViolationReport(const SerializeIF* data) {
2022-02-02 10:29:30 +01:00
ReturnValue_t result = checkClassLoaded();
2022-08-16 01:08:26 +02:00
if (result != returnvalue::OK) {
2022-02-02 10:29:30 +01:00
return result;
}
store_address_t storeId;
uint8_t* dataTarget = nullptr;
size_t maxSize = data->getSerializedSize();
if (maxSize > MonitoringIF::VIOLATION_REPORT_MAX_SIZE) {
return MonitoringIF::INVALID_SIZE;
}
result = ipcStore->getFreeElement(&storeId, maxSize, &dataTarget);
2022-08-16 01:08:26 +02:00
if (result != returnvalue::OK) {
2022-02-02 10:29:30 +01:00
return result;
}
size_t size = 0;
result = data->serialize(&dataTarget, &size, maxSize, SerializeIF::Endianness::BIG);
2022-08-16 01:08:26 +02:00
if (result != returnvalue::OK) {
2022-02-02 10:29:30 +01:00
return result;
}
CommandMessage report;
MonitoringMessage::setLimitViolationReport(&report, storeId);
return MessageQueueSenderIF::sendMessage(reportQueue, &report);
}
ReturnValue_t LimitViolationReporter::checkClassLoaded() {
2022-02-02 10:29:30 +01:00
if (reportQueue == 0) {
ReceivesMonitoringReportsIF* receiver =
ObjectManager::instance()->get<ReceivesMonitoringReportsIF>(reportingTarget);
if (receiver == nullptr) {
return ObjectManagerIF::NOT_FOUND;
}
reportQueue = receiver->getCommandQueue();
}
if (ipcStore == nullptr) {
ipcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
if (ipcStore == nullptr) {
2022-08-16 01:08:26 +02:00
return returnvalue::FAILED;
2022-02-02 10:29:30 +01:00
}
}
2022-08-16 01:08:26 +02:00
return returnvalue::OK;
}
2022-02-02 10:29:30 +01:00
// Lazy initialization.
MessageQueueId_t LimitViolationReporter::reportQueue = 0;
2021-06-05 19:52:38 +02:00
StorageManagerIF* LimitViolationReporter::ipcStore = nullptr;
object_id_t LimitViolationReporter::reportingTarget = 0;