2021-07-13 20:58:45 +02:00
|
|
|
#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h"
|
2021-06-13 16:29:13 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
#include <cstring>
|
|
|
|
|
2021-07-13 20:58:45 +02:00
|
|
|
#include "fsfw/objectmanager/ObjectManager.h"
|
|
|
|
#include "fsfw/objectmanager/frameworkObjects.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
2021-06-13 16:29:13 +02:00
|
|
|
|
2022-05-20 08:59:06 +02:00
|
|
|
StorageManagerIF* TcPacketStoredBase::STORE = nullptr;
|
2021-06-13 16:29:13 +02:00
|
|
|
|
|
|
|
TcPacketStoredBase::TcPacketStoredBase() {
|
2022-02-02 10:29:30 +01:00
|
|
|
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
2022-05-20 08:59:06 +02:00
|
|
|
TcPacketStoredBase::checkAndSetStore();
|
2021-06-13 16:29:13 +02:00
|
|
|
}
|
|
|
|
|
2022-05-20 08:59:06 +02:00
|
|
|
TcPacketStoredBase::~TcPacketStoredBase() = default;
|
2021-06-13 16:29:13 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t TcPacketStoredBase::getData(const uint8_t** dataPtr, size_t* dataSize) {
|
2022-05-20 08:59:06 +02:00
|
|
|
auto result = TcPacketStoredBase::STORE->getData(storeAddress, dataPtr, dataSize);
|
2022-02-02 10:29:30 +01:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
2021-06-13 16:29:13 +02:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-05-20 08:59:06 +02:00
|
|
|
sif::warning << "TcPacketStoredBase: Could not get data" << std::endl;
|
2021-06-13 16:29:13 +02:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::printWarning("TcPacketStoredBase: Could not get data!\n");
|
2021-06-13 16:29:13 +02:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
return result;
|
2021-06-13 16:29:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TcPacketStoredBase::checkAndSetStore() {
|
2022-05-20 08:59:06 +02:00
|
|
|
if (TcPacketStoredBase::STORE == nullptr) {
|
|
|
|
TcPacketStoredBase::STORE = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
|
|
|
|
if (TcPacketStoredBase::STORE == nullptr) {
|
2021-06-13 16:29:13 +02:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-05-20 08:59:06 +02:00
|
|
|
sif::error << "TcPacketStoredBase::TcPacketStoredBase: TC Store not found" << std::endl;
|
|
|
|
#else
|
|
|
|
sif::printError("TcPacketStoredBase::TcPacketStoredBase: TC Store not found\n");
|
2021-06-13 16:29:13 +02:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
return false;
|
2021-06-14 15:14:57 +02:00
|
|
|
}
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
return true;
|
2021-06-13 16:29:13 +02:00
|
|
|
}
|
|
|
|
|
2021-12-03 15:37:49 +01:00
|
|
|
void TcPacketStoredBase::setStoreAddress(store_address_t setAddress,
|
2022-02-02 10:29:30 +01:00
|
|
|
RedirectableDataPointerIF* packet) {
|
|
|
|
this->storeAddress = setAddress;
|
|
|
|
const uint8_t* tempData = nullptr;
|
|
|
|
size_t tempSize;
|
|
|
|
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
|
|
|
|
if (this->checkAndSetStore()) {
|
2022-05-20 08:59:06 +02:00
|
|
|
status = TcPacketStoredBase::STORE->getData(this->storeAddress, &tempData, &tempSize);
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status == StorageManagerIF::RETURN_OK) {
|
|
|
|
packet->setData(const_cast<uint8_t*>(tempData), tempSize);
|
|
|
|
} else {
|
|
|
|
packet->setData(nullptr, -1);
|
|
|
|
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
|
|
|
}
|
2021-06-13 16:29:13 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
store_address_t TcPacketStoredBase::getStoreAddress() { return this->storeAddress; }
|