2016-06-15 23:48:41 +02:00
|
|
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
|
|
|
#include <framework/tcdistribution/CCSDSDistributorIF.h>
|
|
|
|
#include <framework/tcdistribution/PUSDistributor.h>
|
|
|
|
#include <framework/tmtcpacket/pus/TcPacketStored.h>
|
|
|
|
#include <framework/tmtcservices/PusVerificationReport.h>
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
PUSDistributor::PUSDistributor(uint16_t setApid, object_id_t setObjectId, object_id_t setPacketSource) :
|
|
|
|
TcDistributor(setObjectId), checker(setApid), verifyChannel(), currentPacket(), tcStatus(
|
|
|
|
RETURN_FAILED), packetSource(setPacketSource) {
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PUSDistributor::~PUSDistributor() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator_t PUSDistributor::selectDestination() {
|
2020-06-17 08:35:58 +02:00
|
|
|
sif::debug << "PUSDistributor::handlePacket received "<<std::endl;// << this->currentPacket.store_index << ", " << this->current_packet_id.packet_index << std::endl;
|
2016-06-15 23:48:41 +02:00
|
|
|
iterator_t queueMapIt = this->queueMap.end();
|
2018-07-12 16:29:32 +02:00
|
|
|
this->currentPacket.setStoreAddress(this->currentMessage.getStorageId());
|
|
|
|
if (currentPacket.getWholeData() != NULL) {
|
|
|
|
tcStatus = checker.checkPacket(¤tPacket);
|
2016-06-15 23:48:41 +02:00
|
|
|
// info << "PUSDistributor::handlePacket: packetCheck returned with " << (int)tc_status << std::endl;
|
2018-07-12 16:29:32 +02:00
|
|
|
uint32_t queue_id = currentPacket.getService();
|
|
|
|
queueMapIt = this->queueMap.find(queue_id);
|
2016-06-15 23:48:41 +02:00
|
|
|
} else {
|
2018-07-12 16:29:32 +02:00
|
|
|
tcStatus = PACKET_LOST;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
if (queueMapIt == this->queueMap.end()) {
|
|
|
|
tcStatus = DESTINATION_NOT_FOUND;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
if (tcStatus != RETURN_OK) {
|
2020-04-23 19:13:18 +02:00
|
|
|
sif::debug << "PUSDistributor::handlePacket: error with " << (int) tcStatus
|
2018-07-12 16:29:32 +02:00
|
|
|
<< std::endl;
|
2016-06-15 23:48:41 +02:00
|
|
|
return this->queueMap.end();
|
|
|
|
} else {
|
|
|
|
return queueMapIt;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//uint16_t PUSDistributor::createDestination( uint8_t service_id, uint8_t subservice_id ) {
|
|
|
|
// return ( service_id << 8 ) + subservice_id;
|
|
|
|
//}
|
|
|
|
|
|
|
|
ReturnValue_t PUSDistributor::registerService(AcceptsTelecommandsIF* service) {
|
|
|
|
ReturnValue_t returnValue = RETURN_OK;
|
|
|
|
bool errorCode = true;
|
|
|
|
uint16_t serviceId = service->getIdentifier();
|
|
|
|
MessageQueueId_t queue = service->getRequestQueue();
|
2018-07-12 16:29:32 +02:00
|
|
|
errorCode = this->queueMap.insert(
|
|
|
|
std::pair<uint32_t, MessageQueueId_t>(serviceId, queue)).second;
|
|
|
|
if (errorCode == false) {
|
2018-07-13 18:28:26 +02:00
|
|
|
//TODO Return Code
|
|
|
|
returnValue = MessageQueueIF::NO_QUEUE;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
¤tPacket, tcStatus);
|
2016-06-15 23:48:41 +02:00
|
|
|
//A failed packet is deleted immediately after reporting, otherwise it will block memory.
|
2018-07-12 16:29:32 +02:00
|
|
|
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,
|
|
|
|
¤tPacket);
|
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);
|
2016-06-15 23:48:41 +02:00
|
|
|
if (ccsdsDistributor == NULL) {
|
|
|
|
return RETURN_FAILED;
|
|
|
|
} else {
|
|
|
|
return ccsdsDistributor->registerApplication(this);
|
|
|
|
}
|
|
|
|
}
|