fsfw/src/fsfw/tcdistribution/CcsdsUnpacker.cpp

58 lines
2.0 KiB
C++
Raw Normal View History

#include "CcsdsUnpacker.h"
2022-07-29 16:32:50 +02:00
#include "fsfw/tmtcservices/TmTcMessage.h"
CcsdsUnpacker::CcsdsUnpacker(MessageQueueIF& msgQueue, AcceptsTelecommandsIF& receiver,
StorageManagerIF& sourceStore)
2022-08-01 17:16:37 +02:00
: sourceStore(sourceStore), msgQueue(msgQueue), receiver(receiver) {
2022-07-29 16:32:50 +02:00
msgQueue.setDefaultDestination(receiver.getRequestQueue());
}
ReturnValue_t CcsdsUnpacker::performOperation(uint8_t operationCode) {
TmTcMessage msg;
ReturnValue_t result;
2022-08-01 17:16:37 +02:00
for (result = msgQueue.receiveMessage(&msg); result == HasReturnvaluesIF::RETURN_OK;
2022-07-29 16:32:50 +02:00
result = msgQueue.receiveMessage(&msg)) {
auto resultPair = sourceStore.getData(msg.getStorageId());
2022-08-01 17:16:37 +02:00
if (resultPair.first != HasReturnvaluesIF::RETURN_OK) {
2022-07-29 16:32:50 +02:00
continue;
}
2022-08-01 17:16:37 +02:00
if (resultPair.second.size() < 6) {
2022-07-29 16:32:50 +02:00
// TODO: This is a config error. Does it make sense to forward the message?
result = msgQueue.sendToDefault(&msg);
2022-08-01 17:16:37 +02:00
if (result != HasReturnvaluesIF::RETURN_OK) {
2022-07-29 16:32:50 +02:00
}
continue;
}
StorageManagerIF* tgtStore;
2022-08-01 17:16:37 +02:00
if (targetStore != nullptr) {
2022-07-29 16:32:50 +02:00
tgtStore = targetStore;
} else {
tgtStore = &sourceStore;
}
store_address_t newId;
uint8_t* ptr;
result = tgtStore->getFreeElement(&newId, resultPair.second.size(), &ptr);
2022-08-01 17:16:37 +02:00
if (result != HasReturnvaluesIF::RETURN_OK) {
2022-07-29 16:32:50 +02:00
// TODO: Implement error handling
}
std::memcpy(ptr, resultPair.second.data() + 6, resultPair.second.size() - 6);
result = sourceStore.deleteData(msg.getStorageId());
2022-08-01 17:16:37 +02:00
if (result != HasReturnvaluesIF::RETURN_OK) {
2022-07-29 16:32:50 +02:00
// TODO: Implement error handling (though this really should not happen)
}
TmTcMessage newMsg(newId);
result = msgQueue.sendToDefault(&newMsg);
2022-08-01 17:16:37 +02:00
if (result != HasReturnvaluesIF::RETURN_OK) {
2022-07-29 16:32:50 +02:00
}
}
return result;
}
2022-07-29 16:32:50 +02:00
void CcsdsUnpacker::setDifferentTargetStore(StorageManagerIF& otherTargetStore) {
targetStore = &otherTargetStore;
}
2022-08-01 14:23:52 +02:00
uint32_t CcsdsUnpacker::getIdentifier() const { return 0; }
MessageQueueId_t CcsdsUnpacker::getRequestQueue() const { return 0; }