fsfw/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp

79 lines
2.7 KiB
C++
Raw Normal View History

2021-07-13 21:02:53 +02:00
#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h"
2021-06-13 16:29:13 +02:00
#include <cstring>
2022-02-02 10:29:30 +01:00
#include "fsfw/serviceinterface/ServiceInterface.h"
TcPacketStoredPus::TcPacketStoredPus(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t sequenceCount, const uint8_t* data, size_t size,
uint8_t ack)
: TcPacketPus(nullptr) {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not this->checkAndSetStore()) {
return;
}
uint8_t* pData = nullptr;
ReturnValue_t returnValue =
2022-05-20 08:59:06 +02:00
this->STORE->getFreeElement(&this->storeAddress, (TC_PACKET_MIN_SIZE + size), &pData);
if (returnValue != this->STORE->RETURN_OK) {
2021-06-13 16:29:13 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::warning << "TcPacketStoredBase: Could not get free element from store!" << std::endl;
2021-06-13 16:29:13 +02:00
#endif
2022-02-02 10:29:30 +01:00
return;
}
this->setData(pData, TC_PACKET_MIN_SIZE + size);
2021-10-05 13:13:36 +02:00
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
2022-02-02 10:29:30 +01:00
pus::PusVersion pusVersion = pus::PusVersion::PUS_C_VERSION;
2021-10-05 13:13:36 +02:00
#else
2022-02-02 10:29:30 +01:00
pus::PusVersion pusVersion = pus::PusVersion::PUS_A_VERSION;
2021-10-05 13:13:36 +02:00
#endif
2022-02-02 10:29:30 +01:00
initializeTcPacket(apid, sequenceCount, ack, service, subservice, pusVersion);
std::memcpy(&tcData->appData, data, size);
this->setPacketDataLength(size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
this->setErrorControl();
2021-06-13 16:29:13 +02:00
}
2022-02-02 10:29:30 +01:00
TcPacketStoredPus::TcPacketStoredPus() : TcPacketStoredBase(), TcPacketPus(nullptr) {}
2021-06-13 16:29:13 +02:00
2022-02-02 10:29:30 +01:00
TcPacketStoredPus::TcPacketStoredPus(store_address_t setAddress) : TcPacketPus(nullptr) {
TcPacketStoredBase::setStoreAddress(setAddress, this);
2021-06-13 16:29:13 +02:00
}
2022-02-02 10:29:30 +01:00
TcPacketStoredPus::TcPacketStoredPus(const uint8_t* data, size_t size) : TcPacketPus(data) {
if (this->getFullSize() != size) {
return;
}
if (this->checkAndSetStore()) {
2022-05-20 08:59:06 +02:00
ReturnValue_t status = STORE->addData(&storeAddress, data, size);
2022-02-02 10:29:30 +01:00
if (status != HasReturnvaluesIF::RETURN_OK) {
this->setData(nullptr, size);
2021-06-13 16:29:13 +02:00
}
2022-02-02 10:29:30 +01:00
const uint8_t* storePtr = nullptr;
// Repoint base data pointer to the data in the store.
2022-05-20 08:59:06 +02:00
STORE->getData(storeAddress, &storePtr, &size);
2022-02-02 10:29:30 +01:00
this->setData(const_cast<uint8_t*>(storePtr), size);
}
2021-06-13 16:29:13 +02:00
}
2021-06-14 10:19:01 +02:00
ReturnValue_t TcPacketStoredPus::deletePacket() {
2022-05-20 08:59:06 +02:00
ReturnValue_t result = this->STORE->deleteData(this->storeAddress);
2022-02-02 10:29:30 +01:00
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
// To circumvent size checks
this->setData(nullptr, -1);
return result;
2021-06-13 16:29:13 +02:00
}
2022-02-02 10:29:30 +01:00
TcPacketPusBase* TcPacketStoredPus::getPacketBase() { return this; }
2021-06-13 16:29:13 +02:00
2021-06-14 10:19:01 +02:00
bool TcPacketStoredPus::isSizeCorrect() {
2022-02-02 10:29:30 +01:00
const uint8_t* temp_data = nullptr;
size_t temp_size;
2022-05-20 08:59:06 +02:00
ReturnValue_t status = this->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;
2021-06-13 16:29:13 +02:00
}
2022-02-02 10:29:30 +01:00
}
return false;
2021-06-13 16:29:13 +02:00
}