2016-06-15 23:48:41 +02:00
|
|
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
|
|
|
#include <framework/tcdistribution/PUSDistributorIF.h>
|
|
|
|
#include <framework/tmtcservices/AcceptsTelemetryIF.h>
|
|
|
|
#include <framework/tmtcservices/PusServiceBase.h>
|
|
|
|
#include <framework/tmtcservices/PusVerificationReport.h>
|
|
|
|
#include <framework/tmtcservices/TmTcMessage.h>
|
2018-07-12 16:29:32 +02:00
|
|
|
#include <framework/ipc/QueueFactory.h>
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
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);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PusServiceBase::~PusServiceBase() {
|
2018-07-12 16:29:32 +02:00
|
|
|
QueueFactory::instance()->deleteMessageQueue(requestQueue);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
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) {
|
|
|
|
sif::error << "PusService " << (uint16_t) this->serviceId
|
|
|
|
<< ": performService returned with " << (int16_t) result
|
|
|
|
<< std::endl;
|
|
|
|
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() {
|
2016-06-15 23:48:41 +02:00
|
|
|
TmTcMessage message;
|
2020-06-10 20:49:30 +02:00
|
|
|
ReturnValue_t result = RETURN_FAILED;
|
2016-06-15 23:48:41 +02:00
|
|
|
for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) {
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t status = this->requestQueue->receiveMessage(&message);
|
2020-06-10 20:49:30 +02:00
|
|
|
// debug << "PusServiceBase::performOperation: Receiving from MQ ID: "
|
|
|
|
// << std::hex << this->requestQueue.getId()
|
|
|
|
// << std::dec << " returned: " << status << std::endl;
|
2016-06-15 23:48:41 +02: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;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
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) {
|
2016-06-15 23:48:41 +02:00
|
|
|
this->verifyReporter.sendSuccessReport(
|
|
|
|
TC_VERIFY::COMPLETION_SUCCESS, &this->currentPacket);
|
2020-06-10 20:49:30 +02:00
|
|
|
}
|
|
|
|
else {
|
2016-06-15 23:48:41 +02:00
|
|
|
this->verifyReporter.sendFailureReport(
|
|
|
|
TC_VERIFY::COMPLETION_FAILURE, &this->currentPacket,
|
2020-06-10 20:49:30 +02:00
|
|
|
result, 0, errorParameter1, errorParameter2);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
this->currentPacket.deletePacket();
|
|
|
|
errorParameter1 = 0;
|
|
|
|
errorParameter2 = 0;
|
2020-06-10 20:49:30 +02:00
|
|
|
}
|
|
|
|
else if (status == MessageQueueIF::EMPTY) {
|
2016-06-15 23:48:41 +02:00
|
|
|
status = RETURN_OK;
|
2020-06-10 20:49:30 +02:00
|
|
|
// debug << "PusService " << (uint16_t)this->serviceId <<
|
|
|
|
// ": no new packet." << std::endl;
|
2016-06-15 23:48:41 +02:00
|
|
|
break;
|
2020-06-10 20:49:30 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-04-23 19:13:18 +02:00
|
|
|
sif::error << "PusServiceBase::performOperation: Service "
|
2016-06-15 23:48:41 +02:00
|
|
|
<< (uint16_t) this->serviceId
|
|
|
|
<< ": Error receiving packet. Code: " << std::hex << status
|
|
|
|
<< std::dec << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t PusServiceBase::getIdentifier() {
|
|
|
|
return this->serviceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueId_t PusServiceBase::getRequestQueue() {
|
2018-07-12 16:29:32 +02:00
|
|
|
return this->requestQueue->getId();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PusServiceBase::initialize() {
|
|
|
|
ReturnValue_t result = SystemObject::initialize();
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2020-06-10 20:49:30 +02:00
|
|
|
AcceptsTelemetryIF* destService = objectManager->get<AcceptsTelemetryIF>(
|
2018-07-12 16:29:32 +02:00
|
|
|
packetDestination);
|
2016-06-15 23:48:41 +02:00
|
|
|
PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>(
|
2018-07-12 16:29:32 +02:00
|
|
|
packetSource);
|
2020-06-10 20:49:30 +02:00
|
|
|
if ((destService != nullptr) && (distributor != nullptr)) {
|
2018-07-12 16:29:32 +02:00
|
|
|
this->requestQueue->setDefaultDestination(
|
2020-06-10 20:49:30 +02:00
|
|
|
destService->getReportReceptionQueue());
|
2016-06-15 23:48:41 +02:00
|
|
|
distributor->registerService(this);
|
|
|
|
return RETURN_OK;
|
2020-06-10 20:49:30 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-04-23 19:13:18 +02:00
|
|
|
sif::error << "PusServiceBase::PusServiceBase: Service "
|
2016-06-15 23:48:41 +02:00
|
|
|
<< (uint32_t) this->serviceId << ": Configuration error."
|
2020-06-10 20:49:30 +02:00
|
|
|
<< " Make sure packetSource and packetDestination are defined "
|
|
|
|
"correctly" << std::endl;
|
2016-06-15 23:48:41 +02:00
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|