2016-06-15 23:48:41 +02:00
|
|
|
#include <framework/objectmanager/ObjectManagerIF.h>
|
|
|
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
|
|
|
#include <framework/tmtcpacket/pus/TcPacketStored.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
TcPacketStored::TcPacketStored(store_address_t setAddress) :
|
|
|
|
TcPacketBase(NULL), storeAddress(setAddress) {
|
|
|
|
this->setStoreAddress(this->storeAddress);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
TcPacketStored::TcPacketStored(uint16_t apid, uint8_t ack, uint8_t service,
|
|
|
|
uint8_t subservice, uint8_t sequence_count, const uint8_t* data,
|
|
|
|
uint32_t size) :
|
|
|
|
TcPacketBase(NULL) {
|
2016-06-15 23:48:41 +02:00
|
|
|
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
2018-07-12 16:29:32 +02:00
|
|
|
if (!this->checkAndSetStore()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t* p_data = NULL;
|
|
|
|
ReturnValue_t returnValue = this->store->getFreeElement(&this->storeAddress,
|
|
|
|
(TC_PACKET_MIN_SIZE + size), &p_data);
|
|
|
|
if (returnValue != this->store->RETURN_OK) {
|
|
|
|
return;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
this->setData(p_data);
|
|
|
|
initializeTcPacket(apid, sequence_count, ack, service, subservice);
|
|
|
|
memcpy(&tcData->data, data, size);
|
|
|
|
this->setPacketDataLength(
|
|
|
|
size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
|
|
|
|
this->setErrorControl();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
TcPacketStored::TcPacketStored() :
|
|
|
|
TcPacketBase(NULL) {
|
2016-06-15 23:48:41 +02:00
|
|
|
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
|
|
|
this->checkAndSetStore();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t TcPacketStored::deletePacket() {
|
|
|
|
ReturnValue_t result = this->store->deleteData(this->storeAddress);
|
2016-06-15 23:48:41 +02:00
|
|
|
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
2018-07-12 16:29:32 +02:00
|
|
|
this->setData( NULL);
|
|
|
|
return result;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TcPacketStored::checkAndSetStore() {
|
|
|
|
if (this->store == NULL) {
|
2018-07-12 16:29:32 +02:00
|
|
|
this->store = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
|
|
|
if (this->store == NULL) {
|
2020-04-23 19:13:18 +02:00
|
|
|
sif::error << "TcPacketStored::TcPacketStored: TC Store not found!"
|
2018-07-12 16:29:32 +02:00
|
|
|
<< std::endl;
|
2016-06-15 23:48:41 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TcPacketStored::setStoreAddress(store_address_t setAddress) {
|
|
|
|
this->storeAddress = setAddress;
|
|
|
|
const uint8_t* temp_data = NULL;
|
2020-05-04 16:53:04 +02:00
|
|
|
size_t temp_size;
|
2016-06-15 23:48:41 +02:00
|
|
|
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
|
2018-07-12 16:29:32 +02:00
|
|
|
if (this->checkAndSetStore()) {
|
|
|
|
status = this->store->getData(this->storeAddress, &temp_data,
|
|
|
|
&temp_size);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
if (status == StorageManagerIF::RETURN_OK) {
|
|
|
|
this->setData(temp_data);
|
|
|
|
} else {
|
|
|
|
this->setData(NULL);
|
|
|
|
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
store_address_t TcPacketStored::getStoreAddress() {
|
|
|
|
return this->storeAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TcPacketStored::isSizeCorrect() {
|
|
|
|
const uint8_t* temp_data = NULL;
|
2020-05-04 16:53:04 +02:00
|
|
|
size_t temp_size;
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data,
|
|
|
|
&temp_size);
|
2016-06-15 23:48:41 +02:00
|
|
|
if (status == StorageManagerIF::RETURN_OK) {
|
2018-07-12 16:29:32 +02:00
|
|
|
if (this->getFullSize() == temp_size) {
|
2016-06-15 23:48:41 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
StorageManagerIF* TcPacketStored::store = NULL;
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
TcPacketStored::TcPacketStored(const uint8_t* data, uint32_t size) :
|
|
|
|
TcPacketBase(data) {
|
2016-06-15 23:48:41 +02:00
|
|
|
if (getFullSize() != size) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
if (this->checkAndSetStore()) {
|
2016-06-15 23:48:41 +02:00
|
|
|
ReturnValue_t status = store->addData(&storeAddress, data, size);
|
|
|
|
if (status != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
this->setData(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|