fsfw/tmtcservices/PusServiceBase.cpp

134 lines
4.3 KiB
C++
Raw Normal View History

2020-08-13 20:53:35 +02:00
#include "PusServiceBase.h"
2020-12-14 21:30:39 +01:00
#include "AcceptsTelemetryIF.h"
2020-08-13 20:53:35 +02:00
#include "PusVerificationReport.h"
#include "TmTcMessage.h"
2020-12-14 21:30:39 +01:00
2021-06-05 19:52:38 +02:00
#include "../objectmanager/ObjectManager.h"
#include "../serviceinterface/ServiceInterface.h"
2020-12-14 21:30:39 +01:00
#include "../tcdistribution/PUSDistributorIF.h"
2020-08-13 20:53:35 +02:00
#include "../ipc/QueueFactory.h"
object_id_t PusServiceBase::packetSource = 0;
object_id_t PusServiceBase::packetDestination = 0;
2020-06-10 20:49:30 +02:00
PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid,
uint8_t setServiceId) :
SystemObject(setObjectId), apid(setApid), serviceId(setServiceId) {
requestQueue = QueueFactory::instance()->
createMessageQueue(PUS_SERVICE_MAX_RECEPTION);
}
PusServiceBase::~PusServiceBase() {
QueueFactory::instance()->deleteMessageQueue(requestQueue);
}
ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) {
2020-06-10 20:49:30 +02:00
handleRequestQueue();
ReturnValue_t result = this->performService();
if (result != RETURN_OK) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-06-10 20:49:30 +02:00
sif::error << "PusService " << (uint16_t) this->serviceId
<< ": performService returned with " << (int16_t) result
<< std::endl;
#endif
2020-06-10 20:49:30 +02:00
return RETURN_FAILED;
}
return RETURN_OK;
}
2020-06-29 16:57:00 +02:00
void PusServiceBase::setTaskIF(PeriodicTaskIF* taskHandle) {
this->taskHandle = taskHandle;
}
2020-06-10 20:49:30 +02:00
void PusServiceBase::handleRequestQueue() {
TmTcMessage message;
2020-06-10 20:49:30 +02:00
ReturnValue_t result = RETURN_FAILED;
for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) {
ReturnValue_t status = this->requestQueue->receiveMessage(&message);
2020-12-14 21:30:39 +01:00
// if(status != MessageQueueIF::EMPTY) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-12-14 21:30:39 +01:00
// sif::debug << "PusServiceBase::performOperation: Receiving from "
// << "MQ ID: " << std::hex << "0x" << std::setw(8)
// << std::setfill('0') << this->requestQueue->getId()
// << std::dec << " returned: " << status << std::setfill(' ')
// << std::endl;
#endif
2020-12-14 21:30:39 +01:00
// }
if (status == RETURN_OK) {
this->currentPacket.setStoreAddress(message.getStorageId());
2020-06-10 20:49:30 +02:00
//info << "Service " << (uint16_t) this->serviceId <<
// ": new packet!" << std::endl;
2020-06-10 20:49:30 +02:00
result = this->handleRequest(currentPacket.getSubService());
2020-06-10 20:28:44 +02:00
2020-06-10 20:49:30 +02:00
// debug << "Service " << (uint16_t)this->serviceId <<
// ": handleRequest returned: " << (int)return_code << std::endl;
if (result == RETURN_OK) {
this->verifyReporter.sendSuccessReport(
2020-12-14 21:30:39 +01:00
tc_verification::COMPLETION_SUCCESS, &this->currentPacket);
2020-06-10 20:49:30 +02:00
}
else {
this->verifyReporter.sendFailureReport(
2020-12-14 21:30:39 +01:00
tc_verification::COMPLETION_FAILURE, &this->currentPacket,
2020-06-10 20:49:30 +02:00
result, 0, errorParameter1, errorParameter2);
}
this->currentPacket.deletePacket();
errorParameter1 = 0;
errorParameter2 = 0;
2020-06-10 20:49:30 +02:00
}
else if (status == MessageQueueIF::EMPTY) {
status = RETURN_OK;
2020-06-10 20:49:30 +02:00
// debug << "PusService " << (uint16_t)this->serviceId <<
// ": no new packet." << std::endl;
break;
2020-06-10 20:49:30 +02:00
}
else {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PusServiceBase::performOperation: Service "
2020-12-14 21:30:39 +01:00
<< this->serviceId << ": Error receiving packet. Code: "
<< std::hex << status << std::dec << std::endl;
#endif
}
}
}
uint16_t PusServiceBase::getIdentifier() {
return this->serviceId;
}
MessageQueueId_t PusServiceBase::getRequestQueue() {
return this->requestQueue->getId();
}
ReturnValue_t PusServiceBase::initialize() {
ReturnValue_t result = SystemObject::initialize();
if (result != RETURN_OK) {
return result;
}
2021-06-05 19:52:38 +02:00
AcceptsTelemetryIF* destService = ObjectManager::instance()->get<AcceptsTelemetryIF>(
packetDestination);
2021-06-05 19:52:38 +02:00
PUSDistributorIF* distributor = ObjectManager::instance()->get<PUSDistributorIF>(
packetSource);
2020-12-14 21:30:39 +01:00
if (destService == nullptr or distributor == nullptr) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PusServiceBase::PusServiceBase: Service "
2020-12-14 21:30:39 +01:00
<< this->serviceId << ": Configuration error. Make sure "
<< "packetSource and packetDestination are defined correctly"
<< std::endl;
#endif
2020-12-14 21:30:39 +01:00
return ObjectManagerIF::CHILD_INIT_FAILED;
}
2020-12-14 21:30:39 +01:00
this->requestQueue->setDefaultDestination(
destService->getReportReceptionQueue());
distributor->registerService(this);
return HasReturnvaluesIF::RETURN_OK;
}
2020-06-29 16:57:00 +02:00
ReturnValue_t PusServiceBase::initializeAfterTaskCreation() {
// If task parameters, for example task frequency are required, this
// function should be overriden and the system object task IF can
// be used to get those parameters.
return HasReturnvaluesIF::RETURN_OK;
}