fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp

78 lines
2.5 KiB
C++
Raw Normal View History

2021-06-14 10:19:01 +02:00
#include "TcPacketStoredPus.h"
2021-06-13 16:29:13 +02:00
#include <cstring>
2021-06-14 10:19:01 +02:00
TcPacketStoredPus::TcPacketStoredPus(uint16_t apid, uint8_t service,
2021-06-13 16:29:13 +02:00
uint8_t subservice, uint8_t sequenceCount, const uint8_t* data,
size_t size, uint8_t ack) :
2021-06-14 10:19:01 +02:00
TcPacketPus(nullptr) {
2021-06-13 16:29:13 +02:00
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not this->checkAndSetStore()) {
return;
}
uint8_t* pData = nullptr;
ReturnValue_t returnValue = this->store->getFreeElement(&this->storeAddress,
(TC_PACKET_MIN_SIZE + size), &pData);
if (returnValue != this->store->RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TcPacketStoredBase: Could not get free element from store!"
<< std::endl;
#endif
return;
}
this->setData(pData);
initializeTcPacket(apid, sequenceCount, ack, service, subservice);
std::memcpy(&tcData->appData, data, size);
this->setPacketDataLength(
size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
this->setErrorControl();
}
2021-06-14 10:19:01 +02:00
TcPacketStoredPus::TcPacketStoredPus(): TcPacketStoredBase(), TcPacketPus(nullptr) {
2021-06-13 16:29:13 +02:00
}
2021-06-14 10:19:01 +02:00
TcPacketStoredPus::TcPacketStoredPus(store_address_t setAddress): TcPacketPus(nullptr) {
2021-06-13 16:29:13 +02:00
TcPacketStoredBase::setStoreAddress(setAddress);
}
2021-06-14 10:19:01 +02:00
TcPacketStoredPus::TcPacketStoredPus(const uint8_t* data, size_t size): TcPacketPus(data) {
2021-06-13 16:29:13 +02:00
if (this->getFullSize() != size) {
return;
}
if (this->checkAndSetStore()) {
ReturnValue_t status = store->addData(&storeAddress, data, size);
if (status != HasReturnvaluesIF::RETURN_OK) {
this->setData(nullptr);
}
const uint8_t* storePtr = nullptr;
// Repoint base data pointer to the data in the store.
store->getData(storeAddress, &storePtr, &size);
this->setData(storePtr);
}
}
2021-06-14 10:19:01 +02:00
ReturnValue_t TcPacketStoredPus::deletePacket() {
2021-06-13 16:29:13 +02:00
ReturnValue_t result = this->store->deleteData(this->storeAddress);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->setData(nullptr);
return result;
}
2021-06-14 10:19:01 +02:00
TcPacketBase* TcPacketStoredPus::getPacketBase() {
2021-06-13 16:29:13 +02:00
return this;
}
2021-06-14 10:19:01 +02:00
bool TcPacketStoredPus::isSizeCorrect() {
2021-06-13 16:29:13 +02:00
const uint8_t* temp_data = nullptr;
size_t temp_size;
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data,
&temp_size);
if (status == StorageManagerIF::RETURN_OK) {
if (this->getFullSize() == temp_size) {
return true;
}
}
return false;
}