2021-12-03 15:37:49 +01:00
|
|
|
#include "fsfw/tcdistribution/CFDPDistributor.h"
|
|
|
|
|
|
|
|
#include "fsfw/objectmanager/ObjectManager.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/tcdistribution/CCSDSDistributorIF.h"
|
2022-07-19 18:13:25 +02:00
|
|
|
#include "fsfw/tmtcpacket/cfdp/CfdpPacketStored.h"
|
2021-12-03 15:37:49 +01:00
|
|
|
|
|
|
|
#ifndef FSFW_CFDP_DISTRIBUTOR_DEBUGGING
|
2022-02-02 10:29:30 +01:00
|
|
|
#define FSFW_CFDP_DISTRIBUTOR_DEBUGGING 1
|
2021-12-03 15:37:49 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
CFDPDistributor::CFDPDistributor(uint16_t setApid, object_id_t setObjectId,
|
2022-02-02 10:29:30 +01:00
|
|
|
object_id_t setPacketSource)
|
|
|
|
: TcDistributor(setObjectId),
|
|
|
|
apid(setApid),
|
|
|
|
checker(setApid),
|
|
|
|
tcStatus(RETURN_FAILED),
|
|
|
|
packetSource(setPacketSource) {}
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-07-19 18:13:25 +02:00
|
|
|
CFDPDistributor::~CFDPDistributor() = default;
|
2021-12-03 15:37:49 +01:00
|
|
|
|
|
|
|
CFDPDistributor::TcMqMapIter CFDPDistributor::selectDestination() {
|
|
|
|
#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
store_address_t storeId = this->currentMessage.getStorageId();
|
2021-12-03 15:37:49 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::debug << "CFDPDistributor::handlePacket received: " << storeId.poolIndex << ", "
|
|
|
|
<< storeId.packetIndex << std::endl;
|
2021-12-03 15:37:49 +01:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::printDebug("CFDPDistributor::handlePacket received: %d, %d\n", storeId.poolIndex,
|
|
|
|
storeId.packetIndex);
|
2021-12-03 15:37:49 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2022-07-19 18:13:25 +02:00
|
|
|
auto queueMapIt = this->queueMap.end();
|
2022-02-02 10:29:30 +01:00
|
|
|
if (this->currentPacket == nullptr) {
|
|
|
|
return queueMapIt;
|
|
|
|
}
|
|
|
|
this->currentPacket->setStoreAddress(this->currentMessage.getStorageId());
|
2022-07-19 18:13:25 +02:00
|
|
|
if (currentPacket->getFullData() != nullptr) {
|
2022-07-27 17:00:43 +02:00
|
|
|
tcStatus = checker.checkPacket(*currentPacket, currentPacket->getFullPacketLen());
|
2022-02-02 10:29:30 +01:00
|
|
|
if (tcStatus != HasReturnvaluesIF::RETURN_OK) {
|
2021-12-03 15:37:49 +01:00
|
|
|
#if FSFW_VERBOSE_LEVEL >= 1
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::debug << "CFDPDistributor::handlePacket: Packet format invalid, code "
|
|
|
|
<< static_cast<int>(tcStatus) << std::endl;
|
2021-12-03 15:37:49 +01:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::printDebug("CFDPDistributor::handlePacket: Packet format invalid, code %d\n",
|
|
|
|
static_cast<int>(tcStatus));
|
2021-12-03 15:37:49 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
2022-02-02 10:29:30 +01:00
|
|
|
queueMapIt = this->queueMap.find(0);
|
|
|
|
} else {
|
|
|
|
tcStatus = PACKET_LOST;
|
|
|
|
}
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
if (queueMapIt == this->queueMap.end()) {
|
|
|
|
tcStatus = DESTINATION_NOT_FOUND;
|
2021-12-03 15:37:49 +01:00
|
|
|
#if FSFW_VERBOSE_LEVEL >= 1
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::debug << "CFDPDistributor::handlePacket: Destination not found" << std::endl;
|
2021-12-03 15:37:49 +01:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::printDebug("CFDPDistributor::handlePacket: Destination not found\n");
|
2021-12-03 15:37:49 +01:00
|
|
|
#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */
|
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
if (tcStatus != RETURN_OK) {
|
|
|
|
return this->queueMap.end();
|
|
|
|
} else {
|
|
|
|
return queueMapIt;
|
|
|
|
}
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t CFDPDistributor::registerHandler(AcceptsTelecommandsIF* handler) {
|
2022-02-02 10:29:30 +01:00
|
|
|
uint16_t handlerId =
|
2022-07-28 15:13:27 +02:00
|
|
|
handler->getIdentifier(); // should be 0, because CfdpHandler does not set a set a service-ID
|
2021-12-03 15:37:49 +01:00
|
|
|
#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::info << "CFDPDistributor::registerHandler: Handler ID: " << static_cast<int>(handlerId)
|
|
|
|
<< std::endl;
|
2021-12-03 15:37:49 +01:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::printInfo("CFDPDistributor::registerHandler: Handler ID: %d\n", static_cast<int>(handlerId));
|
2021-12-03 15:37:49 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
MessageQueueId_t queue = handler->getRequestQueue();
|
|
|
|
auto returnPair = queueMap.emplace(handlerId, queue);
|
|
|
|
if (not returnPair.second) {
|
2021-12-03 15:37:49 +01:00
|
|
|
#if FSFW_VERBOSE_LEVEL >= 1
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::error << "CFDPDistributor::registerHandler: Service ID already"
|
|
|
|
" exists in map"
|
|
|
|
<< std::endl;
|
2021-12-03 15:37:49 +01:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::printError("CFDPDistributor::registerHandler: Service ID already exists in map\n");
|
2021-12-03 15:37:49 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
return SERVICE_ID_ALREADY_EXISTS;
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
MessageQueueId_t CFDPDistributor::getRequestQueue() { return tcQueue->getId(); }
|
|
|
|
|
|
|
|
// ReturnValue_t CFDPDistributor::callbackAfterSending(ReturnValue_t queueStatus) {
|
|
|
|
// if (queueStatus != RETURN_OK) {
|
|
|
|
// tcStatus = queueStatus;
|
|
|
|
// }
|
|
|
|
// if (tcStatus != RETURN_OK) {
|
|
|
|
// this->verifyChannel.sendFailureReport(tc_verification::ACCEPTANCE_FAILURE,
|
|
|
|
// currentPacket, tcStatus);
|
|
|
|
// // A failed packet is deleted immediately after reporting,
|
|
|
|
// // otherwise it will block memory.
|
|
|
|
// currentPacket->deletePacket();
|
|
|
|
// return RETURN_FAILED;
|
|
|
|
// } else {
|
|
|
|
// this->verifyChannel.sendSuccessReport(tc_verification::ACCEPTANCE_SUCCESS,
|
|
|
|
// currentPacket);
|
|
|
|
// return RETURN_OK;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
uint16_t CFDPDistributor::getIdentifier() { return this->apid; }
|
2021-12-03 15:37:49 +01:00
|
|
|
|
|
|
|
ReturnValue_t CFDPDistributor::initialize() {
|
2022-07-19 18:13:25 +02:00
|
|
|
currentPacket = new CfdpPacketStored();
|
2022-02-02 10:29:30 +01:00
|
|
|
if (currentPacket == nullptr) {
|
|
|
|
// Should not happen, memory allocation failed!
|
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
|
|
|
|
2022-07-19 18:13:25 +02:00
|
|
|
auto* ccsdsDistributor = ObjectManager::instance()->get<CCSDSDistributorIF>(packetSource);
|
2022-02-02 10:29:30 +01:00
|
|
|
if (ccsdsDistributor == nullptr) {
|
2021-12-03 15:37:49 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::error << "CFDPDistributor::initialize: Packet source invalid" << std::endl;
|
|
|
|
sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl;
|
2021-12-03 15:37:49 +01:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::printError("CFDPDistributor::initialize: Packet source invalid\n");
|
|
|
|
sif::printError("Make sure it exists and implements CCSDSDistributorIF\n");
|
2021-12-03 15:37:49 +01:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
return ccsdsDistributor->registerApplication(this);
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|