fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp

73 lines
2.1 KiB
C++
Raw Normal View History

2021-06-13 16:29:13 +02:00
#include "TcPacketStoredBase.h"
2021-06-14 10:19:01 +02:00
#include "../../../objectmanager/ObjectManager.h"
#include "../../../serviceinterface/ServiceInterface.h"
#include "../../../objectmanager/frameworkObjects.h"
2021-06-13 16:29:13 +02:00
#include <cstring>
StorageManagerIF* TcPacketStoredBase::store = nullptr;
TcPacketStoredBase::TcPacketStoredBase() {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->checkAndSetStore();
}
TcPacketStoredBase::~TcPacketStoredBase() {
}
ReturnValue_t TcPacketStoredBase::getData(const uint8_t ** dataPtr,
2021-06-14 15:14:57 +02:00
size_t* dataSize) {
auto result = this->store->getData(storeAddress, dataPtr, dataSize);
if(result != HasReturnvaluesIF::RETURN_OK) {
2021-06-13 16:29:13 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-06-14 15:14:57 +02:00
sif::warning << "TcPacketStoredBase: Could not get data!" << std::endl;
2021-06-13 16:29:13 +02:00
#else
2021-06-14 15:14:57 +02:00
sif::printWarning("TcPacketStoredBase: Could not get data!\n");
2021-06-13 16:29:13 +02:00
#endif
2021-06-14 15:14:57 +02:00
}
return result;
2021-06-13 16:29:13 +02:00
}
bool TcPacketStoredBase::checkAndSetStore() {
2021-06-14 15:14:57 +02:00
if (this->store == nullptr) {
this->store = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (this->store == nullptr) {
2021-06-13 16:29:13 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-06-14 15:14:57 +02:00
sif::error << "TcPacketStoredBase::TcPacketStoredBase: TC Store not found!"
<< std::endl;
2021-06-13 16:29:13 +02:00
#endif
2021-06-14 15:14:57 +02:00
return false;
}
}
return true;
2021-06-13 16:29:13 +02:00
}
void TcPacketStoredBase::setStoreAddress(store_address_t setAddress) {
this->storeAddress = setAddress;
const uint8_t* tempData = nullptr;
size_t tempSize;
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
if (this->checkAndSetStore()) {
status = this->store->getData(this->storeAddress, &tempData, &tempSize);
}
TcPacketBase* tcPacketBase = this->getPacketBase();
if(tcPacketBase == nullptr) {
return;
}
if (status == StorageManagerIF::RETURN_OK) {
tcPacketBase->setData(tempData);
}
else {
tcPacketBase->setData(nullptr);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
}
store_address_t TcPacketStoredBase::getStoreAddress() {
2021-06-14 15:14:57 +02:00
return this->storeAddress;
2021-06-13 16:29:13 +02:00
}