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;
|
|
|
|
|
|
|
|
PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId) :
|
|
|
|
SystemObject(setObjectId), apid(setApid), serviceId(setServiceId), errorParameter1(
|
|
|
|
0), errorParameter2(0), requestQueue(NULL) {
|
|
|
|
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) {
|
2016-06-15 23:48:41 +02:00
|
|
|
TmTcMessage message;
|
|
|
|
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);
|
2019-11-25 00:14:39 +01: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());
|
2019-11-25 00:14:39 +01:00
|
|
|
// info << "Service " << (uint16_t) this->serviceId << ": new packet!" << std::endl;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-04-06 12:38:39 +02:00
|
|
|
ReturnValue_t return_code = this->handleRequest(currentPacket.getSubService());
|
2019-11-25 00:14:39 +01:00
|
|
|
// debug << "Service " << (uint16_t)this->serviceId << ": handleRequest returned: " << (int)return_code << std::endl;
|
2016-06-15 23:48:41 +02:00
|
|
|
if (return_code == RETURN_OK) {
|
|
|
|
this->verifyReporter.sendSuccessReport(
|
|
|
|
TC_VERIFY::COMPLETION_SUCCESS, &this->currentPacket);
|
|
|
|
} else {
|
|
|
|
this->verifyReporter.sendFailureReport(
|
|
|
|
TC_VERIFY::COMPLETION_FAILURE, &this->currentPacket,
|
|
|
|
return_code, 0, errorParameter1, errorParameter2);
|
|
|
|
}
|
|
|
|
this->currentPacket.deletePacket();
|
|
|
|
errorParameter1 = 0;
|
|
|
|
errorParameter2 = 0;
|
2018-07-13 18:28:26 +02:00
|
|
|
} else if (status == MessageQueueIF::EMPTY) {
|
2016-06-15 23:48:41 +02:00
|
|
|
status = RETURN_OK;
|
2019-11-25 00:14:39 +01:00
|
|
|
// debug << "PusService " << (uint16_t)this->serviceId << ": no new packet." << std::endl;
|
2016-06-15 23:48:41 +02:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
error << "PusServiceBase::performOperation: Service "
|
|
|
|
<< (uint16_t) this->serviceId
|
|
|
|
<< ": Error receiving packet. Code: " << std::hex << status
|
|
|
|
<< std::dec << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReturnValue_t return_code = this->performService();
|
|
|
|
if (return_code == RETURN_OK) {
|
|
|
|
return RETURN_OK;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
error << "PusService " << (uint16_t) this->serviceId
|
|
|
|
<< ": performService returned with " << (int16_t) return_code
|
|
|
|
<< std::endl;
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
AcceptsTelemetryIF* dest_service = 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);
|
2016-06-15 23:48:41 +02:00
|
|
|
if ((dest_service != NULL) && (distributor != NULL)) {
|
2018-07-12 16:29:32 +02:00
|
|
|
this->requestQueue->setDefaultDestination(
|
2016-06-15 23:48:41 +02:00
|
|
|
dest_service->getReportReceptionQueue());
|
|
|
|
distributor->registerService(this);
|
|
|
|
return RETURN_OK;
|
|
|
|
} else {
|
|
|
|
error << "PusServiceBase::PusServiceBase: Service "
|
|
|
|
<< (uint32_t) this->serviceId << ": Configuration error."
|
2018-07-12 16:29:32 +02:00
|
|
|
<< " Make sure packetSource and packetDestination are defined correctly" << std::endl;
|
2016-06-15 23:48:41 +02:00
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
}
|