2022-11-02 10:26:45 +01:00
|
|
|
#include "TmFunnelBase.h"
|
|
|
|
|
2022-12-19 14:40:27 +01:00
|
|
|
#include <fsfw/tmtcservices/TmTcMessage.h>
|
|
|
|
|
2022-11-02 10:26:45 +01:00
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
|
|
|
|
2023-02-08 17:43:43 +01:00
|
|
|
TmFunnelBase::TmFunnelBase(FunnelCfg cfg)
|
|
|
|
: SystemObject(cfg.objectId), tmStore(cfg.tmStore), ipcStore(cfg.ipcStore) {
|
|
|
|
tmQueue = QueueFactory::instance()->createMessageQueue(cfg.tmMsgDepth);
|
2022-11-02 10:26:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TmFunnelBase::~TmFunnelBase() { QueueFactory::instance()->deleteMessageQueue(tmQueue); }
|
|
|
|
|
|
|
|
MessageQueueId_t TmFunnelBase::getReportReceptionQueue(uint8_t virtualChannel) const {
|
|
|
|
return tmQueue->getId();
|
|
|
|
}
|
|
|
|
|
2023-02-07 17:18:13 +01:00
|
|
|
void TmFunnelBase::addDestination(const char *name, const AcceptsTelemetryIF &downlinkDestination,
|
|
|
|
uint8_t vcid) {
|
2022-11-02 10:26:45 +01:00
|
|
|
auto queueId = downlinkDestination.getReportReceptionQueue(vcid);
|
2023-02-07 17:18:13 +01:00
|
|
|
destinations.emplace_back(name, queueId, vcid);
|
2022-11-02 10:26:45 +01:00
|
|
|
}
|
2022-12-19 14:40:27 +01:00
|
|
|
|
|
|
|
ReturnValue_t TmFunnelBase::sendPacketToDestinations(store_address_t origStoreId,
|
|
|
|
TmTcMessage &message,
|
|
|
|
const uint8_t *packetData, size_t size) {
|
2023-02-24 19:19:42 +01:00
|
|
|
ReturnValue_t result = returnvalue::OK;
|
2022-12-19 14:40:27 +01:00
|
|
|
for (unsigned int idx = 0; idx < destinations.size(); idx++) {
|
2023-02-08 17:43:43 +01:00
|
|
|
const auto &dest = destinations[idx];
|
2022-12-19 14:40:27 +01:00
|
|
|
if (destinations.size() > 1) {
|
|
|
|
if (idx < destinations.size() - 1) {
|
|
|
|
// Create copy of data to ensure each TM recipient has its own copy. That way, we don't need
|
|
|
|
// to bother with send order and where the data is deleted.
|
|
|
|
store_address_t storeId;
|
|
|
|
result = tmStore.addData(&storeId, packetData, size);
|
|
|
|
if (result == returnvalue::OK) {
|
|
|
|
message.setStorageId(storeId);
|
|
|
|
} else {
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
sif::error << "PusTmFunnel::handlePacket: Store too full to create data copy"
|
|
|
|
<< std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
message.setStorageId(origStoreId);
|
|
|
|
}
|
|
|
|
}
|
2023-02-08 17:43:43 +01:00
|
|
|
result = tmQueue->sendMessage(dest.queueId, &message);
|
2022-12-19 14:40:27 +01:00
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
sif::error << "PusTmFunnel::handlePacket: Error sending TM to downlink handler" << std::endl;
|
|
|
|
#endif
|
|
|
|
tmStore.deleteData(message.getStorageId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|