fsfw/src/opt/pus/Service5EventReporting.cpp

105 lines
3.3 KiB
C++
Raw Normal View History

2020-08-13 20:53:35 +02:00
#include "Service5EventReporting.h"
#include "servicepackets/Service5Packets.h"
2020-07-10 14:16:55 +02:00
2021-06-05 19:52:38 +02:00
#include "../serviceinterface/ServiceInterface.h"
#include "../objectmanager/ObjectManager.h"
2020-08-13 20:53:35 +02:00
#include "../events/EventManagerIF.h"
#include "../ipc/QueueFactory.h"
2021-06-14 10:19:01 +02:00
#include "../tmtcpacket/pus/tm/TmPacketStored.h"
2020-07-10 14:16:55 +02:00
Service5EventReporting::Service5EventReporting(object_id_t objectId,
2020-11-09 21:33:09 +01:00
uint16_t apid, uint8_t serviceId, size_t maxNumberReportsPerCycle,
uint32_t messageQueueDepth):
2020-07-10 14:16:55 +02:00
PusServiceBase(objectId, apid, serviceId),
maxNumberReportsPerCycle(maxNumberReportsPerCycle) {
2020-11-09 21:33:09 +01:00
eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth);
2020-07-10 14:16:55 +02:00
}
2021-04-08 22:49:36 +02:00
Service5EventReporting::~Service5EventReporting() {
QueueFactory::instance()->deleteMessageQueue(eventQueue);
}
2020-07-10 14:16:55 +02:00
ReturnValue_t Service5EventReporting::performService() {
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;
}
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
2020-07-10 14:16:55 +02:00
sif::debug << "Service5EventReporting::generateEventReport:"
" Too many events" << std::endl;
#endif
2020-07-10 14:16:55 +02:00
return HasReturnvaluesIF::RETURN_OK;
}
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
2021-04-12 21:53:08 +02:00
TmPacketStoredPusA tmPacket(PusServiceBase::apid, PusServiceBase::serviceId,
2020-07-10 14:16:55 +02:00
message.getSeverity(), packetSubCounter++, &report);
2021-04-13 00:19:09 +02:00
#else
TmPacketStoredPusC tmPacket(PusServiceBase::apid, PusServiceBase::serviceId,
message.getSeverity(), packetSubCounter++, &report);
#endif
2020-07-10 14:16:55 +02: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
2020-07-10 14:16:55 +02:00
sif::debug << "Service5EventReporting::generateEventReport:"
" Could not send TM packet" << std::endl;
#endif
2020-07-10 14:16:55 +02:00
}
return result;
}
ReturnValue_t Service5EventReporting::handleRequest(uint8_t subservice) {
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;
}
}
// 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() {
2021-06-05 19:52:38 +02:00
EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>(
2020-07-10 14:16:55 +02:00
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();
}