GCC Code Coverage Report


Directory: ./
File: Types/PduHeader.hpp
Date: 2026-09-03 22:13:22
Exec Total Coverage
Lines: 0 8 0.0%
Functions: 0 8 0.0%
Branches: 0 0 -%

Line Branch Exec Source
1 // ======================================================================
2 // \title PduHeader.hpp
3 // \author Brian Campuzano
4 // \brief hpp file for CFDP PDU Header
5 // ======================================================================
6
7 #ifndef Svc_Ccsds_Cfdp_PduHeader_HPP
8 #define Svc_Ccsds_Cfdp_PduHeader_HPP
9
10 #include <Fw/Buffer/Buffer.hpp>
11 #include <Fw/FPrimeBasicTypes.hpp>
12 #include <Fw/Types/Serializable.hpp>
13 #include <Svc/Ccsds/CfdpManager/Types/ClassEnumAc.hpp>
14 #include <Svc/Ccsds/CfdpManager/Types/PduTypeEnumEnumAc.hpp>
15 #include <config/EntityIdAliasAc.hpp>
16 #include <config/TransactionSeqAliasAc.hpp>
17
18 namespace Svc {
19 namespace Ccsds {
20 namespace Cfdp {
21
22 // CFDP PDU Type
23 enum class PduType : U8 {
24 PDU_TYPE_DIRECTIVE = 0, // File directive PDU
25 PDU_TYPE_FILE_DATA = 1 // File data PDU
26 };
27
28 // CFDP PduDirection
29 enum class PduDirection : U8 {
30 DIRECTION_TOWARD_RECEIVER = 0, // Toward file receiver
31 DIRECTION_TOWARD_SENDER = 1 // Toward file sender
32 };
33
34 // CFDP CRC Flag
35 enum class CrcFlag : U8 {
36 CRC_NOT_PRESENT = 0, // CRC not present
37 CRC_PRESENT = 1 // CRC present
38 };
39
40 // CFDP Large File Flag
41 enum class LargeFileFlag : U8 {
42 LARGE_FILE_32_BIT = 0, // 32-bit file size
43 LARGE_FILE_64_BIT = 1 // 64-bit file size
44 };
45
46 //! The type of a PDU header (common to all PDUs)
47 class PduHeader {
48 private:
49 //! PDU type (derived from directive code or file data flag)
50 PduTypeEnum::T m_type;
51
52 //! CFDP version (should be 1)
53 U8 m_version;
54
55 //! PDU type
56 PduType m_pduType;
57
58 //! PduDirection
59 PduDirection m_direction;
60
61 //! Transmission mode
62 Cfdp::Class::T m_class;
63
64 //! CRC flag
65 CrcFlag m_crcFlag;
66
67 //! Large file flag
68 LargeFileFlag m_largeFileFlag;
69
70 //! Segmentation control
71 U8 m_segmentationControl;
72
73 //! Segment metadata flag
74 U8 m_segmentMetadataFlag;
75
76 //! PDU data length (excluding header)
77 U16 m_pduDataLength;
78
79 //! Source entity ID
80 EntityId m_sourceEid;
81
82 //! Transaction sequence number
83 TransactionSeq m_transactionSeq;
84
85 //! Destination entity ID
86 EntityId m_destEid;
87
88 public:
89 //! Header size (variable due to EID/TSN lengths)
90 enum { MIN_HEADERSIZE = 7 }; // Minimum fixed portion
91
92 //! Initialize a PDU header
93 void initialize(PduTypeEnum::T type,
94 PduDirection direction,
95 Cfdp::Class::T txmMode,
96 EntityId sourceEid,
97 TransactionSeq transactionSeq,
98 EntityId destEid);
99
100 //! Compute the buffer size needed to hold this Header
101 U32 getBufferSize() const;
102
103 //! Calculate the number of bytes needed to encode a value
104 //! @param value The value to encode
105 //! @return Number of bytes needed (1, 2, 4, or 8)
106 static U8 getValueEncodedSize(U64 value);
107
108 //! Initialize this Header from a SerialBufferBase
109 Fw::SerializeStatus fromSerialBuffer(Fw::SerialBufferBase& serialBuffer);
110
111 //! Write this Header to a SerialBufferBase
112 Fw::SerializeStatus toSerialBuffer(Fw::SerialBufferBase& serialBuffer) const;
113
114 //! Get the PDU type
115 PduTypeEnum::T getType() const { return this->m_type; }
116
117 //! Get the direction
118 PduDirection getDirection() const { return this->m_direction; }
119
120 //! Get the transmission mode
121 Cfdp::Class::T getTxmMode() const { return this->m_class; }
122
123 //! Get the source entity ID
124 EntityId getSourceEid() const { return this->m_sourceEid; }
125
126 //! Get the transaction sequence number
127 TransactionSeq getTransactionSeq() const { return this->m_transactionSeq; }
128
129 //! Get the destination entity ID
130 EntityId getDestEid() const { return this->m_destEid; }
131
132 //! Get PDU data length
133 U16 getPduDataLength() const { return this->m_pduDataLength; }
134
135 //! Set PDU data length (used during encoding)
136 void setPduDataLength(U16 length) { this->m_pduDataLength = length; }
137
138 //! Get the large file flag
139 LargeFileFlag getLargeFileFlag() const { return this->m_largeFileFlag; }
140
141 //! Check if segment metadata is present
142 bool hasSegmentMetadata() const { return this->m_segmentMetadataFlag != 0; }
143
144 //! Set the large file flag (used for testing and configuration)
145 void setLargeFileFlag(LargeFileFlag flag) { this->m_largeFileFlag = flag; }
146
147 //! Allow PDU classes to access private members
148 friend class MetadataPdu;
149 friend class FileDataPdu;
150 friend class EofPdu;
151 friend class FinPdu;
152 friend class AckPdu;
153 friend class NakPdu;
154 };
155
156 //! Peek at the PDU type from a buffer without consuming it
157 //! @param buffer The buffer containing the PDU
158 //! @return The PDU type, or NONE if the buffer is invalid
159 PduTypeEnum::T peekPduType(const Fw::Buffer& buffer);
160
161 } // namespace Cfdp
162 } // namespace Ccsds
163 } // namespace Svc
164
165 #endif // Svc_Ccsds_Cfdp_PduHeader_HPP
166