2020-10-28 02:20:12 +01:00
|
|
|
#include "TcPacketStored.h"
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "../../objectmanager/ObjectManagerIF.h"
|
|
|
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
2020-10-28 02:20:12 +01:00
|
|
|
|
2020-05-18 16:41:37 +02:00
|
|
|
#include <cstring>
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-10-28 02:20:12 +01:00
|
|
|
StorageManagerIF* TcPacketStored::store = nullptr;
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
TcPacketStored::TcPacketStored(store_address_t setAddress) :
|
2020-05-18 16:41:37 +02:00
|
|
|
TcPacketBase(nullptr), storeAddress(setAddress) {
|
2020-10-28 02:20:12 +01:00
|
|
|
setStoreAddress(storeAddress);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2020-10-28 02:20:12 +01:00
|
|
|
TcPacketStored::TcPacketStored(uint16_t apid, uint8_t service,
|
|
|
|
uint8_t subservice, uint8_t sequenceCount, const uint8_t* data,
|
|
|
|
size_t size, uint8_t ack) :
|
2020-05-18 16:41:37 +02:00
|
|
|
TcPacketBase(nullptr) {
|
2016-06-15 23:48:41 +02:00
|
|
|
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
2020-10-28 02:20:12 +01:00
|
|
|
if (not this->checkAndSetStore()) {
|
2018-07-12 16:29:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-10-28 02:20:12 +01:00
|
|
|
uint8_t* pData = nullptr;
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t returnValue = this->store->getFreeElement(&this->storeAddress,
|
2020-10-28 02:20:12 +01:00
|
|
|
(TC_PACKET_MIN_SIZE + size), &pData);
|
2018-07-12 16:29:32 +02:00
|
|
|
if (returnValue != this->store->RETURN_OK) {
|
2021-01-03 13:58:18 +01:00
|
|
|
#if CPP_OSTREAM_ENABLED == 1
|
2020-05-19 20:29:37 +02:00
|
|
|
sif::warning << "TcPacketStored: Could not get free element from store!"
|
|
|
|
<< std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2018-07-12 16:29:32 +02:00
|
|
|
return;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2020-10-28 02:20:12 +01:00
|
|
|
this->setData(pData);
|
|
|
|
initializeTcPacket(apid, sequenceCount, ack, service, subservice);
|
2020-05-19 18:55:13 +02:00
|
|
|
memcpy(&tcData->appData, data, size);
|
2018-07-12 16:29:32 +02:00
|
|
|
this->setPacketDataLength(
|
|
|
|
size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
|
|
|
|
this->setErrorControl();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2020-05-19 20:29:37 +02:00
|
|
|
ReturnValue_t TcPacketStored::getData(const uint8_t ** dataPtr,
|
|
|
|
size_t* dataSize) {
|
|
|
|
auto result = this->store->getData(storeAddress, dataPtr, dataSize);
|
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
2021-01-03 13:58:18 +01:00
|
|
|
#if CPP_OSTREAM_ENABLED == 1
|
2020-05-19 20:29:37 +02:00
|
|
|
sif::warning << "TcPacketStored: Could not get data!" << std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2020-05-19 20:29:37 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-10-28 02:20:12 +01:00
|
|
|
TcPacketStored::TcPacketStored(): TcPacketBase(nullptr) {
|
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;
|
2020-10-28 02:20:12 +01:00
|
|
|
this->setData(nullptr);
|
2018-07-12 16:29:32 +02:00
|
|
|
return result;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TcPacketStored::checkAndSetStore() {
|
2020-10-28 02:20:12 +01:00
|
|
|
if (this->store == nullptr) {
|
2018-07-12 16:29:32 +02:00
|
|
|
this->store = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
2020-10-28 02:20:12 +01:00
|
|
|
if (this->store == nullptr) {
|
2021-01-03 13:58:18 +01:00
|
|
|
#if CPP_OSTREAM_ENABLED == 1
|
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;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2016-06-15 23:48:41 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TcPacketStored::setStoreAddress(store_address_t setAddress) {
|
|
|
|
this->storeAddress = setAddress;
|
2020-10-28 02:20:12 +01:00
|
|
|
const uint8_t* tempData = nullptr;
|
2020-05-18 16:41:37 +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()) {
|
2020-10-28 02:20:12 +01:00
|
|
|
status = this->store->getData(this->storeAddress, &tempData,
|
2018-07-12 16:29:32 +02:00
|
|
|
&temp_size);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
if (status == StorageManagerIF::RETURN_OK) {
|
2020-10-28 02:20:12 +01:00
|
|
|
this->setData(tempData);
|
2016-06-15 23:48:41 +02:00
|
|
|
} else {
|
2020-10-28 02:20:12 +01:00
|
|
|
this->setData(nullptr);
|
2016-06-15 23:48:41 +02:00
|
|
|
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
store_address_t TcPacketStored::getStoreAddress() {
|
|
|
|
return this->storeAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TcPacketStored::isSizeCorrect() {
|
2020-10-28 02:20:12 +01:00
|
|
|
const uint8_t* temp_data = nullptr;
|
2020-05-18 16:41:37 +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;
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-10-28 02:20:12 +01:00
|
|
|
this->setData(nullptr);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|