fsfw/src/fsfw/cfdp/CfdpDistributor.cpp

56 lines
1.7 KiB
C++
Raw Normal View History

2022-08-03 18:14:49 +02:00
#include "CfdpDistributor.h"
#include "fsfw/tcdistribution/definitions.h"
2022-08-08 17:53:42 +02:00
CfdpDistributor::CfdpDistributor(CfdpDistribCfg cfg)
2022-08-08 12:31:19 +02:00
: TcDistributorBase(cfg.objectId, cfg.tcQueue), cfg(cfg) {}
2022-08-03 18:14:49 +02:00
ReturnValue_t CfdpDistributor::registerTcDestination(const cfdp::EntityId& address,
AcceptsTelecommandsIF& tcDest) {
for (const auto& dest : tcDestinations) {
if (dest.id == address) {
2022-08-22 16:35:53 +02:00
return returnvalue::FAILED;
2022-08-03 18:14:49 +02:00
}
}
tcDestinations.emplace_back(address, tcDest.getName(), tcDest.getRequestQueue());
2022-08-22 16:35:53 +02:00
return returnvalue::OK;
2022-08-03 18:14:49 +02:00
}
ReturnValue_t CfdpDistributor::selectDestination(MessageQueueId_t& destId) {
auto accessorPair = cfg.tcStore.getData(currentMessage.getStorageId());
2022-08-22 16:35:53 +02:00
if (accessorPair.first != returnvalue::OK) {
2022-08-03 18:14:49 +02:00
return accessorPair.first;
}
2022-09-08 11:08:40 +02:00
ReturnValue_t result =
pduReader.setReadOnlyData(accessorPair.second.data(), accessorPair.second.size());
2022-08-22 16:35:53 +02:00
if (result != returnvalue::OK) {
2022-08-03 18:14:49 +02:00
return result;
}
result = pduReader.parseData();
2022-08-22 16:35:53 +02:00
if (result != returnvalue::OK) {
2022-08-03 18:14:49 +02:00
return result;
}
cfdp::EntityId foundId;
pduReader.getDestId(foundId);
bool destFound = false;
for (const auto& dest : tcDestinations) {
if (dest.id == foundId) {
destId = dest.queueId;
destFound = true;
}
}
if (not destFound) {
// TODO: Warning and event?
return tmtcdistrib::NO_DESTINATION_FOUND;
2022-08-03 18:14:49 +02:00
}
// Packet was forwarded successfully, so do not delete it.
accessorPair.second.release();
2022-08-22 16:35:53 +02:00
return returnvalue::OK;
2022-08-03 18:14:49 +02:00
}
2022-08-08 17:53:42 +02:00
const char* CfdpDistributor::getName() const { return "CFDP Distributor"; }
2022-08-03 18:14:49 +02:00
uint32_t CfdpDistributor::getIdentifier() const { return 0; }
MessageQueueId_t CfdpDistributor::getRequestQueue() const { return tcQueue->getId(); }