2020-08-13 20:53:35 +02:00
|
|
|
#include "CCSDSDistributorIF.h"
|
|
|
|
#include "PUSDistributor.h"
|
2020-10-01 13:23:06 +02:00
|
|
|
|
|
|
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "../tmtcpacket/pus/TcPacketStored.h"
|
|
|
|
#include "../tmtcservices/PusVerificationReport.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-10-01 13:23:06 +02:00
|
|
|
PUSDistributor::PUSDistributor(uint16_t setApid, object_id_t setObjectId,
|
|
|
|
object_id_t setPacketSource) :
|
|
|
|
TcDistributor(setObjectId), checker(setApid), verifyChannel(),
|
|
|
|
tcStatus(RETURN_FAILED), packetSource(setPacketSource) {}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-10-01 13:23:06 +02:00
|
|
|
PUSDistributor::~PUSDistributor() {}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-10-01 13:23:06 +02:00
|
|
|
PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() {
|
|
|
|
// sif:: debug << "PUSDistributor::handlePacket received: "
|
|
|
|
// << this->current_packet_id.store_index << ", "
|
|
|
|
// << this->current_packet_id.packet_index << std::endl;
|
|
|
|
TcMqMapIter queueMapIt = this->queueMap.end();
|
2020-10-03 14:19:42 +02:00
|
|
|
if(this->currentPacket == nullptr) {
|
|
|
|
return queueMapIt;
|
|
|
|
}
|
2020-10-01 13:23:06 +02:00
|
|
|
this->currentPacket->setStoreAddress(this->currentMessage.getStorageId());
|
2020-10-03 14:19:42 +02:00
|
|
|
if (currentPacket->getWholeData() != nullptr) {
|
2020-10-01 13:23:06 +02:00
|
|
|
tcStatus = checker.checkPacket(currentPacket);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if(tcStatus != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
sif::debug << "PUSDistributor::handlePacket: Packet format "
|
|
|
|
<< "invalid, code "<< static_cast<int>(tcStatus)
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
uint32_t queue_id = currentPacket->getService();
|
|
|
|
queueMapIt = this->queueMap.find(queue_id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tcStatus = PACKET_LOST;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-10-01 13:23:06 +02:00
|
|
|
if (queueMapIt == this->queueMap.end()) {
|
|
|
|
tcStatus = DESTINATION_NOT_FOUND;
|
|
|
|
#ifdef DEBUG
|
|
|
|
sif::debug << "PUSDistributor::handlePacket: Destination not found, "
|
|
|
|
<< "code "<< static_cast<int>(tcStatus) << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-10-01 13:23:06 +02:00
|
|
|
if (tcStatus != RETURN_OK) {
|
|
|
|
return this->queueMap.end();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return queueMapIt;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ReturnValue_t PUSDistributor::registerService(AcceptsTelecommandsIF* service) {
|
|
|
|
uint16_t serviceId = service->getIdentifier();
|
2020-10-01 13:23:06 +02:00
|
|
|
// sif::info << "Service ID: " << (int)serviceId << std::endl;
|
2016-06-15 23:48:41 +02:00
|
|
|
MessageQueueId_t queue = service->getRequestQueue();
|
2020-10-01 13:23:06 +02:00
|
|
|
auto returnPair = queueMap.emplace(serviceId, queue);
|
|
|
|
if (not returnPair.second) {
|
|
|
|
sif::error << "PUSDistributor::registerService: Service ID already"
|
|
|
|
" exists in map." << std::endl;
|
|
|
|
return SERVICE_ID_ALREADY_EXISTS;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2020-10-01 13:23:06 +02:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueId_t PUSDistributor::getRequestQueue() {
|
2018-07-12 16:29:32 +02:00
|
|
|
return tcQueue->getId();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PUSDistributor::callbackAfterSending(ReturnValue_t queueStatus) {
|
2018-07-12 16:29:32 +02:00
|
|
|
if (queueStatus != RETURN_OK) {
|
|
|
|
tcStatus = queueStatus;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
if (tcStatus != RETURN_OK) {
|
|
|
|
this->verifyChannel.sendFailureReport(TC_VERIFY::ACCEPTANCE_FAILURE,
|
2020-10-01 13:23:06 +02:00
|
|
|
currentPacket, tcStatus);
|
|
|
|
// A failed packet is deleted immediately after reporting,
|
|
|
|
// otherwise it will block memory.
|
|
|
|
currentPacket->deletePacket();
|
2016-06-15 23:48:41 +02:00
|
|
|
return RETURN_FAILED;
|
|
|
|
} else {
|
2018-07-12 16:29:32 +02:00
|
|
|
this->verifyChannel.sendSuccessReport(TC_VERIFY::ACCEPTANCE_SUCCESS,
|
2020-10-01 13:23:06 +02:00
|
|
|
currentPacket);
|
2016-06-15 23:48:41 +02:00
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t PUSDistributor::getIdentifier() {
|
|
|
|
return checker.getApid();
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PUSDistributor::initialize() {
|
2018-07-12 16:29:32 +02:00
|
|
|
CCSDSDistributorIF* ccsdsDistributor =
|
|
|
|
objectManager->get<CCSDSDistributorIF>(packetSource);
|
2020-10-03 14:19:42 +02:00
|
|
|
currentPacket = new TcPacketStored();
|
2020-10-01 13:23:06 +02:00
|
|
|
if (ccsdsDistributor == nullptr) {
|
|
|
|
sif::error << "PUSDistributor::initialize: Packet source invalid."
|
|
|
|
<< " Make sure it exists and implements CCSDSDistributorIF!"
|
|
|
|
<< std::endl;
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
else {
|
2016-06-15 23:48:41 +02:00
|
|
|
return ccsdsDistributor->registerApplication(this);
|
|
|
|
}
|
|
|
|
}
|