fsfw/src/fsfw/tcdistribution/CCSDSDistributor.cpp
Robin Mueller 5907f8ee9d
Added CFDP packet stack
This PR adds the packet stack for the CCSDS File Delivery Protocol.
It also refactors the existing TMTC infastructure to allow sending
of CFDP packets to the CCSDS handlers.

This includes the whole PDU (Protocol Data Unit) stack:

- File Data PDUs

and all file directive PDUs

- ACK PDU
- NAK PDU
- Metadata PDU
- Finished PDU
- Prompt PDU
- Keep Alive PDU
- EOF PDU

The PR includes a full set of unittests for the packet stack
with a coverage of 90+ %.

The refactoring of the existing TMTC infastructure includes non-ideal
solutions like diamond inheritance.
Avoiding this solution would require refactoring the packet stack.
This would be a good idea anyway because the existing stack is tightly
coupled to the FSFW, making reuse more difficult if only the stack is
planned to be used without the store functionalities etc.

The PDU implementation provided here is only weakly coupled to the FSFW,
only using components like returnvalues or the Serialization modules.
There are dedicated serializers and deserializers, which also helps in
creating small focused modules which are easy to test.

Some of the modules here were provied by Matthias Tompert.
2021-12-03 15:37:49 +01:00

113 lines
3.7 KiB
C++

#include "fsfw/tcdistribution/CCSDSDistributor.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#define CCSDS_DISTRIBUTOR_DEBUGGING 0
CCSDSDistributor::CCSDSDistributor(uint16_t setDefaultApid,
object_id_t setObjectId):
TcDistributor(setObjectId), defaultApid( setDefaultApid ) {
}
CCSDSDistributor::~CCSDSDistributor() {}
TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() {
#if CCSDS_DISTRIBUTOR_DEBUGGING == 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "CCSDSDistributor::selectDestination received: " <<
this->currentMessage.getStorageId().poolIndex << ", " <<
this->currentMessage.getStorageId().packetIndex << std::endl;
#else
sif::printDebug("CCSDSDistributor::selectDestination received: %d, %d\n",
currentMessage.getStorageId().poolIndex, currentMessage.getStorageId().packetIndex);
#endif
#endif
const uint8_t* packet = nullptr;
size_t size = 0;
ReturnValue_t result = this->tcStore->getData(currentMessage.getStorageId(),
&packet, &size );
if(result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "CCSDSDistributor::selectDestination: Getting data from"
" store failed!" << std::endl;
#else
sif::printError("CCSDSDistributor::selectDestination: Getting data from"
" store failed!\n");
#endif
#endif
}
SpacePacketBase currentPacket(packet);
#if FSFW_CPP_OSTREAM_ENABLED == 1 && CCSDS_DISTRIBUTOR_DEBUGGING == 1
sif::info << "CCSDSDistributor::selectDestination has packet with APID " << std::hex <<
currentPacket.getAPID() << std::dec << std::endl;
#endif
TcMqMapIter position = this->queueMap.find(currentPacket.getAPID());
if ( position != this->queueMap.end() ) {
return position;
} else {
//The APID was not found. Forward packet to main SW-APID anyway to
// create acceptance failure report.
return this->queueMap.find( this->defaultApid );
}
}
MessageQueueId_t CCSDSDistributor::getRequestQueue() {
return tcQueue->getId();
}
ReturnValue_t CCSDSDistributor::registerApplication(
AcceptsTelecommandsIF* application) {
ReturnValue_t returnValue = RETURN_OK;
auto insertPair = this->queueMap.emplace(application->getIdentifier(),
application->getRequestQueue());
if(not insertPair.second) {
returnValue = RETURN_FAILED;
}
return returnValue;
}
ReturnValue_t CCSDSDistributor::registerApplication(uint16_t apid,
MessageQueueId_t id) {
ReturnValue_t returnValue = RETURN_OK;
auto insertPair = this->queueMap.emplace(apid, id);
if(not insertPair.second) {
returnValue = RETURN_FAILED;
}
return returnValue;
}
uint16_t CCSDSDistributor::getIdentifier() {
return 0;
}
ReturnValue_t CCSDSDistributor::initialize() {
ReturnValue_t status = this->TcDistributor::initialize();
this->tcStore = ObjectManager::instance()->get<StorageManagerIF>( objects::TC_STORE );
if (this->tcStore == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "CCSDSDistributor::initialize: Could not initialize"
" TC store!" << std::endl;
#else
sif::printError("CCSDSDistributor::initialize: Could not initialize"
" TC store!\n");
#endif
#endif
status = RETURN_FAILED;
}
return status;
}
ReturnValue_t CCSDSDistributor::callbackAfterSending(
ReturnValue_t queueStatus) {
if (queueStatus != RETURN_OK) {
tcStore->deleteData(currentMessage.getStorageId());
}
return RETURN_OK;
}