moved store failure to separate function

This commit is contained in:
Robin Müller 2021-10-05 12:47:30 +02:00
parent 91f43d00a2
commit 2124f36e36
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 94 additions and 94 deletions

View File

@ -5,71 +5,71 @@
#include <cstring> #include <cstring>
TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress) : TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress):
TmPacketStoredBase(setAddress), TmPacketPusA(nullptr){ TmPacketStoredBase(setAddress), TmPacketPusA(nullptr){
} }
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter, const uint8_t *data, uint8_t subservice, uint8_t packetSubcounter, const uint8_t *data,
uint32_t size, const uint8_t *headerData, uint32_t headerSize) : uint32_t size, const uint8_t *headerData, uint32_t headerSize):
TmPacketPusA(nullptr) { TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) { if (not TmPacketStoredBase::checkAndSetStore()) {
return; return;
} }
uint8_t *pData = nullptr; uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + size + headerSize; size_t sizeToReserve = getPacketMinimumSize() + size + headerSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
sizeToReserve, &pData); sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) { if (returnValue != store->RETURN_OK) {
handleStoreFailure("A", returnValue, sizeToReserve); handleStoreFailure("A", returnValue, sizeToReserve);
return; return;
} }
setData(pData); setData(pData);
initializeTmPacket(apid, service, subservice, packetSubcounter); initializeTmPacket(apid, service, subservice, packetSubcounter);
memcpy(getSourceData(), headerData, headerSize); memcpy(getSourceData(), headerData, headerSize);
memcpy(getSourceData() + headerSize, data, size); memcpy(getSourceData() + headerSize, data, size);
setPacketDataLength( setPacketDataLength(
size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
} }
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content, uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content,
SerializeIF *header) : SerializeIF *header) :
TmPacketPusA(nullptr) { TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) { if (not TmPacketStoredBase::checkAndSetStore()) {
return; return;
} }
size_t sourceDataSize = 0; size_t sourceDataSize = 0;
if (content != nullptr) { if (content != nullptr) {
sourceDataSize += content->getSerializedSize(); sourceDataSize += content->getSerializedSize();
} }
if (header != nullptr) { if (header != nullptr) {
sourceDataSize += header->getSerializedSize(); sourceDataSize += header->getSerializedSize();
} }
uint8_t *pData = nullptr; uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize; size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
sizeToReserve, &pData); sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) { if (returnValue != store->RETURN_OK) {
handleStoreFailure("A", returnValue, sizeToReserve); handleStoreFailure("A", returnValue, sizeToReserve);
return; return;
} }
setData(pData); setData(pData);
initializeTmPacket(apid, service, subservice, packetSubcounter); initializeTmPacket(apid, service, subservice, packetSubcounter);
uint8_t *putDataHere = getSourceData(); uint8_t *putDataHere = getSourceData();
size_t size = 0; size_t size = 0;
if (header != nullptr) { if (header != nullptr) {
header->serialize(&putDataHere, &size, sourceDataSize, header->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
} }
if (content != nullptr) { if (content != nullptr) {
content->serialize(&putDataHere, &size, sourceDataSize, content->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
} }
setPacketDataLength(sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); setPacketDataLength(sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
} }
uint8_t* TmPacketStoredPusA::getAllTmData() { uint8_t* TmPacketStoredPusA::getAllTmData() {

View File

@ -15,46 +15,46 @@
* packets in a store with the help of a storeAddress. * packets in a store with the help of a storeAddress.
* @ingroup tmtcpackets * @ingroup tmtcpackets
*/ */
class TmPacketStoredPusA : class TmPacketStoredPusA:
public TmPacketStoredBase, public TmPacketStoredBase,
public TmPacketPusA { public TmPacketPusA {
public: public:
/** /**
* This is a default constructor which does not set the data pointer. * This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store. * However, it does try to set the packet store.
*/ */
TmPacketStoredPusA( store_address_t setAddress ); TmPacketStoredPusA( store_address_t setAddress );
/** /**
* With this constructor, new space is allocated in the packet store and * With this constructor, new space is allocated in the packet store and
* a new PUS Telemetry Packet is created there. * a new PUS Telemetry Packet is created there.
* Packet Application Data passed in data is copied into the packet. * Packet Application Data passed in data is copied into the packet.
* The Application data is passed in two parts, first a header, then a * The Application data is passed in two parts, first a header, then a
* data field. This allows building a Telemetry Packet from two separate * data field. This allows building a Telemetry Packet from two separate
* data sources. * data sources.
* @param apid Sets the packet's APID field. * @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field. * @param service Sets the packet's Service ID field.
* This specifies the source service. * This specifies the source service.
* @param subservice Sets the packet's Service Subtype field. * @param subservice Sets the packet's Service Subtype field.
* This specifies the source sub-service. * This specifies the source sub-service.
* @param packet_counter Sets the Packet counter field of this packet * @param packet_counter Sets the Packet counter field of this packet
* @param data The payload data to be copied to the * @param data The payload data to be copied to the
* Application Data Field * Application Data Field
* @param size The amount of data to be copied. * @param size The amount of data to be copied.
* @param headerData The header Data of the Application field, * @param headerData The header Data of the Application field,
* will be copied in front of data * will be copied in front of data
* @param headerSize The size of the headerDataF * @param headerSize The size of the headerDataF
*/ */
TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice, TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packet_counter = 0, const uint8_t* data = nullptr, uint8_t packet_counter = 0, const uint8_t* data = nullptr,
uint32_t size = 0, const uint8_t* headerData = nullptr, uint32_t size = 0, const uint8_t* headerData = nullptr,
uint32_t headerSize = 0); uint32_t headerSize = 0);
/** /**
* Another ctor to directly pass structured content and header data to the * Another ctor to directly pass structured content and header data to the
* packet to avoid additional buffers. * packet to avoid additional buffers.
*/ */
TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice, TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packet_counter, SerializeIF* content, uint8_t packet_counter, SerializeIF* content,
SerializeIF* header = nullptr); SerializeIF* header = nullptr);
uint8_t* getAllTmData() override; uint8_t* getAllTmData() override;
void setDataPointer(const uint8_t* newPointer) override; void setDataPointer(const uint8_t* newPointer) override;