fsfw/src/fsfw/pus/Service5EventReporting.cpp

102 lines
3.7 KiB
C++
Raw Normal View History

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"
2021-07-13 20:58:45 +02:00
#include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h"
2020-07-10 14:16:55 +02:00
2022-02-02 10:29:30 +01:00
Service5EventReporting::Service5EventReporting(object_id_t objectId, uint16_t apid,
uint8_t serviceId, size_t maxNumberReportsPerCycle,
uint32_t messageQueueDepth)
: PusServiceBase(objectId, apid, serviceId),
maxNumberReportsPerCycle(maxNumberReportsPerCycle) {
2022-02-19 16:14:02 +01:00
auto mqArgs = MqArgs(objectId, static_cast<void*>(this));
2022-02-22 10:17:56 +01: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;
ReturnValue_t status = RETURN_OK;
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) {
return HasReturnvaluesIF::RETURN_OK;
}
2020-07-10 14:16:55 +02:00
2022-02-02 10:29:30 +01:00
if (enableEventReport) {
status = generateEventReport(message);
if (status != HasReturnvaluesIF::RETURN_OK) {
return status;
}
}
}
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: Too many events" << std::endl;
#endif
2022-02-02 10:29:30 +01:00
return HasReturnvaluesIF::RETURN_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());
2021-04-13 00:19:09 +02:00
#if FSFW_USE_PUS_C_TELEMETRY == 0
2022-02-02 10:29:30 +01:00
TmPacketStoredPusA tmPacket(PusServiceBase::apid, PusServiceBase::serviceId,
message.getSeverity(), packetSubCounter++, &report);
2021-04-13 00:19:09 +02:00
#else
2022-02-02 10:29:30 +01:00
TmPacketStoredPusC tmPacket(PusServiceBase::apid, PusServiceBase::serviceId,
message.getSeverity(), packetSubCounter++, &report);
2021-04-13 00:19:09 +02:00
#endif
2022-02-02 10:29:30 +01:00
ReturnValue_t result =
tmPacket.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId());
if (result != HasReturnvaluesIF::RETURN_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");
#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;
return HasReturnvaluesIF::RETURN_OK;
}
case Subservice::DISABLE: {
enableEventReport = false;
return HasReturnvaluesIF::RETURN_OK;
}
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-02-02 10:29:30 +01:00
EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);
if (manager == NULL) {
return RETURN_FAILED;
}
// register Service 5 as listener for events
ReturnValue_t result = manager->registerListener(eventQueue->getId(), true);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return PusServiceBase::initialize();
2020-07-10 14:16:55 +02:00
}