fsfw/src/fsfw/tmtcpacket/cfdp/CFDPPacketStored.cpp

91 lines
2.8 KiB
C++
Raw Normal View History

2022-07-19 18:13:25 +02:00
#include "fsfw/tmtcpacket/cfdp/CfdpPacketStored.h"
2022-02-02 10:29:30 +01:00
#include "fsfw/objectmanager/ObjectManager.h"
2022-07-19 18:13:25 +02:00
CfdpPacketStored::CfdpPacketStored() : CfdpReader(nullptr) {}
2022-07-19 18:13:25 +02:00
CfdpPacketStored::CfdpPacketStored(store_address_t setAddress) : CfdpReader(nullptr) {
2022-02-02 10:29:30 +01:00
this->setStoreAddress(setAddress);
}
2022-07-19 18:13:25 +02:00
CfdpPacketStored::CfdpPacketStored(const uint8_t* data, size_t size) : CfdpReader(data) {
2022-02-02 10:29:30 +01:00
if (this->getFullSize() != size) {
return;
}
if (this->checkAndSetStore()) {
2022-07-18 10:20:26 +02:00
ReturnValue_t status = STORE->addData(&storeAddress, data, size);
2022-02-02 10:29:30 +01:00
if (status != HasReturnvaluesIF::RETURN_OK) {
2022-07-18 10:20:26 +02:00
this->setData(nullptr, -1, nullptr);
}
2022-02-02 10:29:30 +01:00
const uint8_t* storePtr = nullptr;
// Repoint base data pointer to the data in the store.
2022-07-18 10:20:26 +02:00
STORE->getData(storeAddress, &storePtr, &size);
this->setData(const_cast<uint8_t*>(storePtr), size, nullptr);
2022-02-02 10:29:30 +01:00
}
}
2022-07-19 18:13:25 +02:00
ReturnValue_t CfdpPacketStored::deletePacket() {
2022-07-18 10:20:26 +02:00
ReturnValue_t result = STORE->deleteData(this->storeAddress);
2022-02-02 10:29:30 +01:00
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
// To circumvent size checks
2022-07-18 10:20:26 +02:00
this->setData(nullptr, -1, nullptr);
2022-02-02 10:29:30 +01:00
return result;
}
2022-02-02 10:29:30 +01:00
// CFDPPacket* CFDPPacketStored::getPacketBase() {
// return this;
// }
2022-07-19 18:13:25 +02:00
void CfdpPacketStored::setStoreAddress(store_address_t setAddress) {
2022-02-02 10:29:30 +01:00
this->storeAddress = setAddress;
const uint8_t* tempData = nullptr;
size_t tempSize;
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
if (this->checkAndSetStore()) {
2022-07-18 10:20:26 +02:00
status = STORE->getData(this->storeAddress, &tempData, &tempSize);
2022-02-02 10:29:30 +01:00
}
if (status == StorageManagerIF::RETURN_OK) {
2022-07-18 10:20:26 +02:00
this->setData(const_cast<uint8_t*>(tempData), tempSize, nullptr);
2022-02-02 10:29:30 +01:00
} else {
// To circumvent size checks
2022-07-18 10:20:26 +02:00
this->setData(nullptr, -1, nullptr);
2022-02-02 10:29:30 +01:00
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
}
2022-07-19 18:13:25 +02:00
store_address_t CfdpPacketStored::getStoreAddress() { return this->storeAddress; }
2022-07-19 18:13:25 +02:00
CfdpPacketStored::~CfdpPacketStored() = default;
2022-07-19 18:13:25 +02:00
ReturnValue_t CfdpPacketStored::getData(const uint8_t** dataPtr, size_t* dataSize) {
2022-02-02 10:29:30 +01:00
return HasReturnvaluesIF::RETURN_OK;
}
2022-02-02 10:29:30 +01:00
// ReturnValue_t CFDPPacketStored::setData(const uint8_t *data) {
// return HasReturnvaluesIF::RETURN_OK;
// }
2022-07-19 18:13:25 +02:00
bool CfdpPacketStored::checkAndSetStore() {
2022-07-18 10:20:26 +02:00
if (STORE == nullptr) {
STORE = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (STORE == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::error << "CFDPPacketStored::CFDPPacketStored: TC Store not found!" << std::endl;
#endif
2022-02-02 10:29:30 +01:00
return false;
}
2022-02-02 10:29:30 +01:00
}
return true;
}
2022-07-19 18:13:25 +02:00
bool CfdpPacketStored::isSizeCorrect() {
2022-02-02 10:29:30 +01:00
const uint8_t* temp_data = nullptr;
size_t temp_size;
2022-07-18 10:20:26 +02:00
ReturnValue_t status = STORE->getData(this->storeAddress, &temp_data, &temp_size);
2022-02-02 10:29:30 +01:00
if (status == StorageManagerIF::RETURN_OK) {
if (this->getFullSize() == temp_size) {
return true;
}
2022-02-02 10:29:30 +01:00
}
return false;
}