GCC Code Coverage Report


Directory: Svc/Ccsds/CfdpManager/
File: Types/FinPdu.cpp
Date: 2026-09-03 21:16:27
Exec Total Coverage
Lines: 58 67 86.6%
Functions: 6 6 100.0%
Branches: 22 31 71.0%

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