fsfw/src/fsfw/cfdp/pdu/HeaderDeserializer.h
Robin Mueller 5907f8ee9d
Added CFDP packet stack
This PR adds the packet stack for the CCSDS File Delivery Protocol.
It also refactors the existing TMTC infastructure to allow sending
of CFDP packets to the CCSDS handlers.

This includes the whole PDU (Protocol Data Unit) stack:

- File Data PDUs

and all file directive PDUs

- ACK PDU
- NAK PDU
- Metadata PDU
- Finished PDU
- Prompt PDU
- Keep Alive PDU
- EOF PDU

The PR includes a full set of unittests for the packet stack
with a coverage of 90+ %.

The refactoring of the existing TMTC infastructure includes non-ideal
solutions like diamond inheritance.
Avoiding this solution would require refactoring the packet stack.
This would be a good idea anyway because the existing stack is tightly
coupled to the FSFW, making reuse more difficult if only the stack is
planned to be used without the store functionalities etc.

The PDU implementation provided here is only weakly coupled to the FSFW,
only using components like returnvalues or the Serialization modules.
There are dedicated serializers and deserializers, which also helps in
creating small focused modules which are easy to test.

Some of the modules here were provied by Matthias Tompert.
2021-12-03 15:37:49 +01:00

94 lines
3.0 KiB
C++

#ifndef FSFW_SRC_FSFW_CFDP_PDU_HEADERDESERIALIZER_H_
#define FSFW_SRC_FSFW_CFDP_PDU_HEADERDESERIALIZER_H_
#include "PduConfig.h"
#include "PduHeaderIF.h"
#include "fsfw/serialize/SerializeIF.h"
#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h"
#include <cstdint>
#include <cstddef>
struct PduHeaderFixedStruct {
uint8_t firstByte;
uint8_t pduDataFieldLenH;
uint8_t pduDataFieldLenL;
uint8_t fourthByte;
uint8_t variableFieldsStart;
};
/**
* @brief This class is used to deserialize a PDU header from raw memory.
* @details
* This is a zero-copy implementation and #parseData needs to be called to ensure the data is
* valid.
*/
class HeaderDeserializer:
public RedirectableDataPointerIF,
public PduHeaderIF {
public:
/**
* Initialize a PDU header from raw data. This is a zero-copy implementation and #parseData
* needs to be called to ensure the data is valid
* @param pduBuf
* @param maxSize
*/
HeaderDeserializer(const uint8_t* pduBuf, size_t maxSize);
/**
* This needs to be called before accessing the PDU fields to avoid segmentation faults.
* @return
* - RETURN_OK on parse success
* - RETURN_FAILED Invalid raw data
* - SerializeIF::BUFFER_TOO_SHORT if buffer is shorter than expected
*/
virtual ReturnValue_t parseData();
size_t getHeaderSize() const;
size_t getPduDataFieldLen() const override;
size_t getWholePduSize() const override;
cfdp::PduType getPduType() const override;
cfdp::Direction getDirection() const override;
cfdp::TransmissionModes getTransmissionMode() const override;
bool getCrcFlag() const override;
bool getLargeFileFlag() const override;
cfdp::SegmentationControl getSegmentationControl() const override;
cfdp::WidthInBytes getLenEntityIds() const override;
cfdp::WidthInBytes getLenSeqNum() const override;
cfdp::SegmentMetadataFlag getSegmentMetadataFlag() const override;
bool hasSegmentMetadataFlag() const override;
void getSourceId(cfdp::EntityId& sourceId) const override;
void getDestId(cfdp::EntityId& destId) const override;
void getTransactionSeqNum(cfdp::TransactionSeqNum& seqNum) const override;
ReturnValue_t deserResult = HasReturnvaluesIF::RETURN_OK;
/**
* Can also be used to reset the pointer to a nullptr, but the getter functions will not
* perform nullptr checks!
* @param dataPtr
* @param maxSize
* @param args
* @return
*/
ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize,
void* args = nullptr) override;
size_t getMaxSize() const;
protected:
PduHeaderFixedStruct* fixedHeader = nullptr;
const uint8_t* rawPtr = nullptr;
size_t maxSize = 0;
private:
void assignVarLenField(cfdp::VarLenField* field, cfdp::WidthInBytes width,
void* sourcePtr) const;
void* sourceIdRaw = nullptr;
void* seqNumRaw = nullptr;
void* destIdRaw = nullptr;
};
#endif /* FSFW_SRC_FSFW_CFDP_PDU_HEADERDESERIALIZER_H_ */