GCC Code Coverage Report


Directory: ./
File: Svc/Ccsds/CfdpManager/Types/EofPdu.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 59 71 83.1%
Functions: 6 6 100.0%
Branches: 31 43 72.1%

Line Branch Exec Source
1 // ======================================================================
2 // \title EofPdu.cpp
3 // \author Brian Campuzano
4 // \brief cpp file for CFDP EOF PDU
5 // ======================================================================
6
7 #include <Fw/Types/Assert.hpp>
8 #include <Svc/Ccsds/CfdpManager/Types/EofPdu.hpp>
9
10 namespace Svc {
11 namespace Ccsds {
12 namespace Cfdp {
13
14 44 void EofPdu::initialize(PduDirection direction,
15 Cfdp::Class::T txmMode,
16 EntityId sourceEid,
17 TransactionSeq transactionSeq,
18 EntityId destEid,
19 ConditionCode conditionCode,
20 U32 checksum,
21 FileSize fileSize) {
22 // Initialize header with PduTypeEnum::END_OF_FILE type
23 44 this->m_header.initialize(PduTypeEnum::END_OF_FILE, direction, txmMode, sourceEid, transactionSeq, destEid);
24
25 44 this->m_conditionCode = conditionCode;
26 44 this->m_checksum = checksum;
27 44 this->m_fileSize = fileSize;
28
29 // Clear TLV list
30 44 this->m_tlvList.clear();
31 44 }
32
33 74 U32 EofPdu::getBufferSize() const {
34 74 U32 size = this->m_header.getBufferSize();
35
36 // Directive code: 1 byte
37 // Condition code: 1 byte
38 // Checksum: 4 bytes (U32)
39 // File size: sizeof(FileSize) bytes
40 74 size += static_cast<U32>(sizeof(U8) + sizeof(U8) + sizeof(U32) + sizeof(FileSize));
41
42 // Add TLV size
43 74 size += this->m_tlvList.getEncodedSize();
44
45 74 return size;
46 }
47
48 41 Fw::SerializeStatus EofPdu::serializeTo(Fw::SerialBufferBase& buffer, Fw::Endianness mode) const {
49 41 return this->toSerialBuffer(buffer);
50 }
51
52 49 Fw::SerializeStatus EofPdu::deserializeFrom(Fw::SerialBufferBase& buffer, Fw::Endianness mode) {
53 // Deserialize header first
54
1/1
✓ Branch 4 taken 49 times.
49 Fw::SerializeStatus status = this->m_header.fromSerialBuffer(buffer);
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49 times.
49 if (status != Fw::FW_SERIALIZE_OK) {
56 return status;
57 }
58
59 // Validate this is a directive PDU (not file data)
60
2/2
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 43 times.
49 if (this->m_header.m_pduType != PduType::PDU_TYPE_DIRECTIVE) {
61 6 return Fw::FW_DESERIALIZE_TYPE_MISMATCH;
62 }
63
64 // Validate directive code
65 43 U8 directiveCode;
66
1/1
✓ Branch 7 taken 43 times.
43 status = buffer.deserializeTo(directiveCode);
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (status != Fw::FW_SERIALIZE_OK) {
68 return status;
69 }
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (directiveCode != static_cast<U8>(FileDirective::FILE_DIRECTIVE_END_OF_FILE)) {
71 return Fw::FW_DESERIALIZE_TYPE_MISMATCH;
72 }
73
74 // Now set the type to PduTypeEnum::END_OF_FILE since we've validated it
75 43 this->m_header.m_type = PduTypeEnum::END_OF_FILE;
76
77 // Deserialize the EOF body
78
1/1
✓ Branch 4 taken 43 times.
43 return this->fromSerialBuffer(buffer);
79 }
80
81 41 Fw::SerializeStatus EofPdu::toSerialBuffer(Fw::SerialBufferBase& serialBuffer) const {
82 41 FW_ASSERT(this->m_header.m_type == PduTypeEnum::END_OF_FILE);
83
84 // Calculate PDU data length (everything after header)
85
2/2
✓ Branch 7 taken 41 times.
✓ Branch 15 taken 41 times.
41 U32 dataLength = this->getBufferSize() - this->m_header.getBufferSize();
86
87 // Update header with data length
88 41 PduHeader headerCopy = this->m_header;
89 41 headerCopy.setPduDataLength(static_cast<U16>(dataLength));
90
91 // Serialize header
92
1/1
✓ Branch 1 taken 41 times.
41 Fw::SerializeStatus status = headerCopy.toSerialBuffer(serialBuffer);
93
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (status != Fw::FW_SERIALIZE_OK) {
94 return status;
95 }
96
97 // Directive code
98 41 U8 directiveCode = static_cast<U8>(FileDirective::FILE_DIRECTIVE_END_OF_FILE);
99
1/1
✓ Branch 7 taken 41 times.
41 status = serialBuffer.serializeFrom(directiveCode);
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (status != Fw::FW_SERIALIZE_OK) {
101 return status;
102 }
103
104 // Condition code (CFDP Blue Book 5.2.6: bits 7-4 = condition code, bits 3-0 = spare/zero)
105 // Note: CFDP uses big-endian bit numbering where bit 0 is MSB
106 41 U8 conditionCode = static_cast<U8>((static_cast<U8>(this->m_conditionCode) & 0x0F) << 4); // Place in upper 4 bits
107
1/1
✓ Branch 7 taken 41 times.
41 status = serialBuffer.serializeFrom(conditionCode);
108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (status != Fw::FW_SERIALIZE_OK) {
109 return status;
110 }
111
112 // Checksum (U32)
113
1/1
✓ Branch 11 taken 41 times.
41 status = serialBuffer.serializeFrom(this->m_checksum);
114
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (status != Fw::FW_SERIALIZE_OK) {
115 return status;
116 }
117
118 // File size (FileSize)
119
1/1
✓ Branch 11 taken 41 times.
41 status = serialBuffer.serializeFrom(this->m_fileSize);
120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (status != Fw::FW_SERIALIZE_OK) {
121 return status;
122 }
123
124 // Serialize TLVs (if any)
125
1/1
✓ Branch 6 taken 41 times.
41 status = this->m_tlvList.toSerialBuffer(serialBuffer);
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (status != Fw::FW_SERIALIZE_OK) {
127 return status;
128 }
129
130 41 return Fw::FW_SERIALIZE_OK;
131 }
132
133 43 Fw::SerializeStatus EofPdu::fromSerialBuffer(Fw::SerialBufferBase& serialBuffer) {
134 43 FW_ASSERT(this->m_header.m_type == PduTypeEnum::END_OF_FILE);
135
136 // Directive code already read by union wrapper
137
138 // Condition code (CFDP Blue Book 5.2.6: bits 7-4 = condition code, bits 3-0 = spare)
139 // Note: CFDP uses big-endian bit numbering where bit 0 is MSB
140 43 U8 conditionCodeVal;
141
1/1
✓ Branch 7 taken 43 times.
43 Fw::SerializeStatus status = serialBuffer.deserializeTo(conditionCodeVal);
142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (status != Fw::FW_SERIALIZE_OK) {
143 return status;
144 }
145 // Extract upper 4 bits (condition code field)
146 43 this->m_conditionCode = static_cast<ConditionCode>((conditionCodeVal >> 4) & 0x0F);
147
148 // Checksum
149
1/1
✓ Branch 10 taken 43 times.
43 status = serialBuffer.deserializeTo(this->m_checksum);
150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (status != Fw::FW_SERIALIZE_OK) {
151 return status;
152 }
153
154 // File size
155
1/1
✓ Branch 10 taken 43 times.
43 status = serialBuffer.deserializeTo(this->m_fileSize);
156
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 42 times.
43 if (status != Fw::FW_SERIALIZE_OK) {
157 1 return status;
158 }
159
160 // Deserialize TLVs (consumes rest of buffer)
161
1/1
✓ Branch 4 taken 42 times.
42 status = this->m_tlvList.fromSerialBuffer(serialBuffer);
162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if (status != Fw::FW_SERIALIZE_OK) {
163 return status;
164 }
165
166 42 return Fw::FW_SERIALIZE_OK;
167 }
168
169 } // namespace Cfdp
170 } // namespace Ccsds
171 } // namespace Svc
172