fsfw/src/fsfw/tcdistribution/CCSDSDistributor.cpp

114 lines
4.0 KiB
C++
Raw Normal View History

2021-07-13 20:22:54 +02:00
#include "fsfw/tcdistribution/CCSDSDistributor.h"
2020-10-01 13:23:06 +02:00
2021-07-13 20:22:54 +02:00
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
2022-07-20 11:43:16 +02:00
#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h"
2022-07-27 17:13:42 +02:00
#define CCSDS_DISTRIBUTOR_DEBUGGING 0
2021-04-07 12:09:06 +02:00
2022-07-27 17:00:43 +02:00
CCSDSDistributor::CCSDSDistributor(uint16_t setDefaultApid, object_id_t setObjectId,
CcsdsPacketCheckIF* packetChecker)
: TcDistributor(setObjectId), defaultApid(setDefaultApid), packetChecker(packetChecker) {}
CCSDSDistributor::~CCSDSDistributor() = default;
2020-10-01 13:23:06 +02:00
TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() {
2021-04-07 12:09:06 +02:00
#if CCSDS_DISTRIBUTOR_DEBUGGING == 1
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::debug << "CCSDSDistributor::selectDestination received: "
<< this->currentMessage.getStorageId().poolIndex << ", "
<< this->currentMessage.getStorageId().packetIndex << std::endl;
2021-04-07 12:09:06 +02:00
#else
2022-02-02 10:29:30 +01:00
sif::printDebug("CCSDSDistributor::selectDestination received: %d, %d\n",
currentMessage.getStorageId().poolIndex,
currentMessage.getStorageId().packetIndex);
2021-04-07 12:09:06 +02:00
#endif
#endif
2022-02-02 10:29:30 +01:00
const uint8_t* packet = nullptr;
size_t size = 0;
2022-07-27 17:00:43 +02:00
ReturnValue_t result = tcStore->getData(currentMessage.getStorageId(), &packet, &size);
2022-08-16 01:08:26 +02:00
if (result != returnvalue::OK) {
2021-04-07 12:09:06 +02:00
#if FSFW_VERBOSE_LEVEL >= 1
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::error << "CCSDSDistributor::selectDestination: Getting data from"
" store failed!"
<< std::endl;
2021-04-07 12:09:06 +02:00
#else
2022-02-02 10:29:30 +01:00
sif::printError(
"CCSDSDistributor::selectDestination: Getting data from"
" store failed!\n");
2021-04-07 12:09:06 +02:00
#endif
#endif
return queueMap.end();
2022-02-02 10:29:30 +01:00
}
2022-07-19 18:13:25 +02:00
SpacePacketReader currentPacket(packet, size);
2022-07-27 17:00:43 +02:00
result = packetChecker->checkPacket(currentPacket, size);
2022-08-16 01:08:26 +02:00
if (result != returnvalue::OK) {
2022-07-27 17:00:43 +02:00
}
2021-04-07 12:09:06 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1 && CCSDS_DISTRIBUTOR_DEBUGGING == 1
2022-07-27 17:00:43 +02:00
sif::info << "CCSDSDistributor::selectDestination has packet with APID 0x" << std::hex
<< currentPacket.getApid() << std::dec << std::endl;
#endif
2022-07-18 10:20:26 +02:00
auto position = this->queueMap.find(currentPacket.getApid());
2022-02-02 10:29:30 +01:00
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.
2022-07-27 17:00:43 +02:00
return queueMap.find(this->defaultApid);
2022-02-02 10:29:30 +01:00
}
}
2022-09-14 20:21:03 +02:00
MessageQueueId_t CCSDSDistributor::getRequestQueue() const { return tcQueue->getId(); }
2022-02-02 10:29:30 +01:00
ReturnValue_t CCSDSDistributor::registerApplication(AcceptsTelecommandsIF* application) {
2022-08-16 01:08:26 +02:00
ReturnValue_t returnValue = returnvalue::OK;
2022-02-02 10:29:30 +01:00
auto insertPair =
this->queueMap.emplace(application->getIdentifier(), application->getRequestQueue());
if (not insertPair.second) {
2022-08-16 01:08:26 +02:00
returnValue = returnvalue::FAILED;
2022-02-02 10:29:30 +01:00
}
return returnValue;
}
2022-02-02 10:29:30 +01:00
ReturnValue_t CCSDSDistributor::registerApplication(uint16_t apid, MessageQueueId_t id) {
2022-08-16 01:08:26 +02:00
ReturnValue_t returnValue = returnvalue::OK;
2022-02-02 10:29:30 +01:00
auto insertPair = this->queueMap.emplace(apid, id);
if (not insertPair.second) {
2022-08-16 01:08:26 +02:00
returnValue = returnvalue::FAILED;
2022-02-02 10:29:30 +01:00
}
return returnValue;
}
2022-09-14 20:21:03 +02:00
uint32_t CCSDSDistributor::getIdentifier() const { return 0; }
ReturnValue_t CCSDSDistributor::initialize() {
2022-07-27 17:00:43 +02:00
if (packetChecker == nullptr) {
packetChecker = new CcsdsPacketChecker(ccsds::PacketType::TC);
}
2022-02-02 10:29:30 +01:00
ReturnValue_t status = this->TcDistributor::initialize();
this->tcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (this->tcStore == nullptr) {
2021-04-07 12:09:06 +02:00
#if FSFW_VERBOSE_LEVEL >= 1
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::error << "CCSDSDistributor::initialize: Could not initialize"
" TC store!"
<< std::endl;
2021-04-07 12:09:06 +02:00
#else
2022-02-02 10:29:30 +01:00
sif::printError(
"CCSDSDistributor::initialize: Could not initialize"
" TC store!\n");
2021-04-07 12:09:06 +02:00
#endif
#endif
2022-08-16 01:08:26 +02:00
status = returnvalue::FAILED;
2022-02-02 10:29:30 +01:00
}
return status;
}
2022-02-02 10:29:30 +01:00
ReturnValue_t CCSDSDistributor::callbackAfterSending(ReturnValue_t queueStatus) {
2022-08-16 01:08:26 +02:00
if (queueStatus != returnvalue::OK) {
2022-02-02 10:29:30 +01:00
tcStore->deleteData(currentMessage.getStorageId());
}
2022-08-16 01:08:26 +02:00
return returnvalue::OK;
}