2021-07-13 20:58:45 +02:00
|
|
|
#include "fsfw/pus/Service5EventReporting.h"
|
2020-07-10 14:16:55 +02:00
|
|
|
|
2021-07-13 20:58:45 +02:00
|
|
|
#include "fsfw/events/EventManagerIF.h"
|
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/objectmanager/ObjectManager.h"
|
|
|
|
#include "fsfw/pus/servicepackets/Service5Packets.h"
|
|
|
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
2022-07-21 13:48:58 +02:00
|
|
|
#include "fsfw/tmtcservices/tmHelpers.h"
|
2020-07-10 14:16:55 +02:00
|
|
|
|
2022-07-26 16:49:46 +02:00
|
|
|
Service5EventReporting::Service5EventReporting(PsbParams params, size_t maxNumberReportsPerCycle,
|
2022-02-02 10:29:30 +01:00
|
|
|
uint32_t messageQueueDepth)
|
2022-07-26 16:49:46 +02:00
|
|
|
: PusServiceBase(params),
|
|
|
|
storeHelper(params.apid),
|
|
|
|
tmHelper(params.serviceId, storeHelper, sendHelper),
|
2022-02-02 10:29:30 +01:00
|
|
|
maxNumberReportsPerCycle(maxNumberReportsPerCycle) {
|
2022-08-15 11:38:52 +02:00
|
|
|
auto mqArgs = MqArgs(getObjectId(), static_cast<void*>(this));
|
2022-08-01 11:00:36 +02:00
|
|
|
psbParams.name = "PUS 5 Event Reporting";
|
2022-09-16 11:10:35 +02:00
|
|
|
eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth,
|
|
|
|
MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
|
2020-07-10 14:16:55 +02:00
|
|
|
}
|
|
|
|
|
2021-04-08 22:49:36 +02:00
|
|
|
Service5EventReporting::~Service5EventReporting() {
|
2022-02-02 10:29:30 +01:00
|
|
|
QueueFactory::instance()->deleteMessageQueue(eventQueue);
|
2021-04-08 22:49:36 +02:00
|
|
|
}
|
2020-07-10 14:16:55 +02:00
|
|
|
|
|
|
|
ReturnValue_t Service5EventReporting::performService() {
|
2022-02-02 10:29:30 +01:00
|
|
|
EventMessage message;
|
2022-08-16 01:08:26 +02:00
|
|
|
ReturnValue_t status = returnvalue::OK;
|
2022-02-02 10:29:30 +01:00
|
|
|
for (uint8_t counter = 0; counter < maxNumberReportsPerCycle; counter++) {
|
|
|
|
// Receive messages even if reporting is disabled for now.
|
|
|
|
status = eventQueue->receiveMessage(&message);
|
|
|
|
if (status == MessageQueueIF::EMPTY) {
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::OK;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
2020-07-10 14:16:55 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
if (enableEventReport) {
|
|
|
|
status = generateEventReport(message);
|
2022-08-16 01:08:26 +02:00
|
|
|
if (status != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::OK;
|
2020-07-10 14:16:55 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) {
|
|
|
|
EventReport report(message.getEventId(), message.getReporter(), message.getParameter1(),
|
|
|
|
message.getParameter2());
|
2022-07-26 16:49:46 +02:00
|
|
|
storeHelper.preparePacket(psbParams.serviceId, message.getSeverity(), tmHelper.sendCounter);
|
2022-07-25 11:26:45 +02:00
|
|
|
storeHelper.setSourceDataSerializable(report);
|
2022-07-26 11:09:57 +02:00
|
|
|
ReturnValue_t result = tmHelper.storeAndSendTmPacket();
|
2022-08-16 01:08:26 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::warning << "Service5EventReporting::generateEventReport: "
|
|
|
|
"Could not send TM packet"
|
|
|
|
<< std::endl;
|
2021-10-07 10:39:16 +02:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::printWarning(
|
|
|
|
"Service5EventReporting::generateEventReport: "
|
|
|
|
"Could not send TM packet\n");
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
return result;
|
2020-07-10 14:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t Service5EventReporting::handleRequest(uint8_t subservice) {
|
2022-02-02 10:29:30 +01:00
|
|
|
switch (subservice) {
|
|
|
|
case Subservice::ENABLE: {
|
|
|
|
enableEventReport = true;
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::OK;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
case Subservice::DISABLE: {
|
|
|
|
enableEventReport = false;
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::OK;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return AcceptsTelecommandsIF::INVALID_SUBSERVICE;
|
|
|
|
}
|
2020-07-10 14:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// In addition to the default PUSServiceBase initialization, this service needs
|
|
|
|
// to be registered to the event manager to listen for events.
|
|
|
|
ReturnValue_t Service5EventReporting::initialize() {
|
2022-07-20 22:21:15 +02:00
|
|
|
ReturnValue_t result = PusServiceBase::initialize();
|
2022-08-16 01:08:26 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-07-20 22:21:15 +02:00
|
|
|
return result;
|
|
|
|
}
|
2022-05-20 11:09:03 +02:00
|
|
|
auto* manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);
|
2022-02-22 20:08:19 +01:00
|
|
|
if (manager == nullptr) {
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
// register Service 5 as listener for events
|
2022-07-20 22:21:15 +02:00
|
|
|
result = manager->registerListener(eventQueue->getId(), true);
|
2022-08-16 01:08:26 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return result;
|
|
|
|
}
|
2022-07-20 22:21:15 +02:00
|
|
|
initializeTmHelpers(sendHelper, storeHelper);
|
2022-07-21 11:34:11 +02:00
|
|
|
return result;
|
2020-07-10 14:16:55 +02:00
|
|
|
}
|