| 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 | 33 | 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 | 33 | this->m_header.initialize(PduTypeEnum::END_OF_FILE, direction, txmMode, sourceEid, transactionSeq, destEid); | |
| 24 | |||
| 25 | 33 | this->m_conditionCode = conditionCode; | |
| 26 | 33 | this->m_checksum = checksum; | |
| 27 | 33 | this->m_fileSize = fileSize; | |
| 28 | |||
| 29 | // Clear TLV list | ||
| 30 | 33 | this->m_tlvList.clear(); | |
| 31 | 33 | } | |
| 32 | |||
| 33 | 63 | U32 EofPdu::getBufferSize() const { | |
| 34 | 63 | 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 | 63 | size += static_cast<U32>(sizeof(U8) + sizeof(U8) + sizeof(U32) + sizeof(FileSize)); | |
| 41 | |||
| 42 | // Add TLV size | ||
| 43 | 63 | size += this->m_tlvList.getEncodedSize(); | |
| 44 | |||
| 45 | 63 | return size; | |
| 46 | } | ||
| 47 | |||
| 48 | 33 | Fw::SerializeStatus EofPdu::serializeTo(Fw::SerialBufferBase& buffer, Fw::Endianness mode) const { | |
| 49 | 33 | return this->toSerialBuffer(buffer); | |
| 50 | } | ||
| 51 | |||
| 52 | 41 | Fw::SerializeStatus EofPdu::deserializeFrom(Fw::SerialBufferBase& buffer, Fw::Endianness mode) { | |
| 53 | // Deserialize header first | ||
| 54 |
1/1✓ Branch 4 taken 41 times.
|
41 | Fw::SerializeStatus status = this->m_header.fromSerialBuffer(buffer); |
| 55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
|
41 | 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 35 times.
|
41 | 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 | 35 | U8 directiveCode; | |
| 66 |
1/1✓ Branch 7 taken 35 times.
|
35 | status = buffer.deserializeTo(directiveCode); |
| 67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
|
35 | if (status != Fw::FW_SERIALIZE_OK) { |
| 68 | ✗ | return status; | |
| 69 | } | ||
| 70 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
|
35 | 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 | 35 | this->m_header.m_type = PduTypeEnum::END_OF_FILE; | |
| 76 | |||
| 77 | // Deserialize the EOF body | ||
| 78 |
1/1✓ Branch 4 taken 35 times.
|
35 | return this->fromSerialBuffer(buffer); |
| 79 | } | ||
| 80 | |||
| 81 | 33 | Fw::SerializeStatus EofPdu::toSerialBuffer(Fw::SerialBufferBase& serialBuffer) const { | |
| 82 | 33 | 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 33 times.
✓ Branch 15 taken 33 times.
|
33 | U32 dataLength = this->getBufferSize() - this->m_header.getBufferSize(); |
| 86 | |||
| 87 | // Update header with data length | ||
| 88 | 33 | PduHeader headerCopy = this->m_header; | |
| 89 | 33 | headerCopy.setPduDataLength(static_cast<U16>(dataLength)); | |
| 90 | |||
| 91 | // Serialize header | ||
| 92 |
1/1✓ Branch 1 taken 33 times.
|
33 | Fw::SerializeStatus status = headerCopy.toSerialBuffer(serialBuffer); |
| 93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
|
33 | if (status != Fw::FW_SERIALIZE_OK) { |
| 94 | ✗ | return status; | |
| 95 | } | ||
| 96 | |||
| 97 | // Directive code | ||
| 98 | 33 | U8 directiveCode = static_cast<U8>(FileDirective::FILE_DIRECTIVE_END_OF_FILE); | |
| 99 |
1/1✓ Branch 7 taken 33 times.
|
33 | status = serialBuffer.serializeFrom(directiveCode); |
| 100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
|
33 | 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 | 33 | U8 conditionCode = static_cast<U8>((static_cast<U8>(this->m_conditionCode) & 0x0F) << 4); // Place in upper 4 bits | |
| 107 |
1/1✓ Branch 7 taken 33 times.
|
33 | status = serialBuffer.serializeFrom(conditionCode); |
| 108 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
|
33 | if (status != Fw::FW_SERIALIZE_OK) { |
| 109 | ✗ | return status; | |
| 110 | } | ||
| 111 | |||
| 112 | // Checksum (U32) | ||
| 113 |
1/1✓ Branch 11 taken 33 times.
|
33 | status = serialBuffer.serializeFrom(this->m_checksum); |
| 114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
|
33 | if (status != Fw::FW_SERIALIZE_OK) { |
| 115 | ✗ | return status; | |
| 116 | } | ||
| 117 | |||
| 118 | // File size (FileSize) | ||
| 119 |
1/1✓ Branch 11 taken 33 times.
|
33 | status = serialBuffer.serializeFrom(this->m_fileSize); |
| 120 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
|
33 | if (status != Fw::FW_SERIALIZE_OK) { |
| 121 | ✗ | return status; | |
| 122 | } | ||
| 123 | |||
| 124 | // Serialize TLVs (if any) | ||
| 125 |
1/1✓ Branch 6 taken 33 times.
|
33 | status = this->m_tlvList.toSerialBuffer(serialBuffer); |
| 126 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
|
33 | if (status != Fw::FW_SERIALIZE_OK) { |
| 127 | ✗ | return status; | |
| 128 | } | ||
| 129 | |||
| 130 | 33 | return Fw::FW_SERIALIZE_OK; | |
| 131 | } | ||
| 132 | |||
| 133 | 35 | Fw::SerializeStatus EofPdu::fromSerialBuffer(Fw::SerialBufferBase& serialBuffer) { | |
| 134 | 35 | 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 | 35 | U8 conditionCodeVal; | |
| 141 |
1/1✓ Branch 7 taken 35 times.
|
35 | Fw::SerializeStatus status = serialBuffer.deserializeTo(conditionCodeVal); |
| 142 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
|
35 | if (status != Fw::FW_SERIALIZE_OK) { |
| 143 | ✗ | return status; | |
| 144 | } | ||
| 145 | // Extract upper 4 bits (condition code field) | ||
| 146 | 35 | this->m_conditionCode = static_cast<ConditionCode>((conditionCodeVal >> 4) & 0x0F); | |
| 147 | |||
| 148 | // Checksum | ||
| 149 |
1/1✓ Branch 10 taken 35 times.
|
35 | status = serialBuffer.deserializeTo(this->m_checksum); |
| 150 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
|
35 | if (status != Fw::FW_SERIALIZE_OK) { |
| 151 | ✗ | return status; | |
| 152 | } | ||
| 153 | |||
| 154 | // File size | ||
| 155 |
1/1✓ Branch 10 taken 35 times.
|
35 | status = serialBuffer.deserializeTo(this->m_fileSize); |
| 156 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 34 times.
|
35 | 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 34 times.
|
34 | status = this->m_tlvList.fromSerialBuffer(serialBuffer); |
| 162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
|
34 | if (status != Fw::FW_SERIALIZE_OK) { |
| 163 | ✗ | return status; | |
| 164 | } | ||
| 165 | |||
| 166 | 34 | return Fw::FW_SERIALIZE_OK; | |
| 167 | } | ||
| 168 | |||
| 169 | } // namespace Cfdp | ||
| 170 | } // namespace Ccsds | ||
| 171 | } // namespace Svc | ||
| 172 |