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