F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
EndPacket.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title EndPacket.cpp
3 // \author bocchino
4 // \brief cpp file for FilePacket::EndPacket
5 //
6 // \copyright
7 // Copyright 2009-2016, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
13 #include <cstring>
14 
16 #include <Fw/Types/Assert.hpp>
17 
18 namespace Fw {
19 
20 void FilePacket::EndPacket ::initialize(const U32 sequenceIndex, const CFDP::Checksum& checksum) {
21  this->m_header.initialize(FilePacket::T_END, sequenceIndex);
22  this->setChecksum(checksum);
23 }
24 
26  return static_cast<U32>(this->m_header.bufferSize() + sizeof(this->m_checksumValue));
27 }
28 
30  SerialBuffer serialBuffer(buffer.getData(), buffer.getSize());
31  return this->toSerialBuffer(serialBuffer);
32 }
33 
35  this->m_checksumValue = checksum.getValue();
36 }
37 
39  CFDP::Checksum c(this->m_checksumValue);
40  checksum = c;
41 }
42 
43 SerializeStatus FilePacket::EndPacket ::fromSerialBuffer(SerialBuffer& serialBuffer) {
44  FW_ASSERT(this->m_header.m_type == T_END);
45 
46  const SerializeStatus status = serialBuffer.deserialize(this->m_checksumValue);
47 
48  return status;
49 }
50 
51 SerializeStatus FilePacket::EndPacket ::toSerialBuffer(SerialBuffer& serialBuffer) const {
52  FW_ASSERT(this->m_header.m_type == T_END);
53 
54  SerializeStatus status;
55 
56  status = this->m_header.toSerialBuffer(serialBuffer);
57  if (status != FW_SERIALIZE_OK) {
58  return status;
59  }
60 
61  status = serialBuffer.serialize(this->m_checksumValue);
62  if (status != FW_SERIALIZE_OK) {
63  return status;
64  }
65 
66  return FW_SERIALIZE_OK;
67 }
68 
69 } // namespace Fw
Serialization/Deserialization operation was successful.
U32 bufferSize() const
Compute the buffer size needed to hold this EndPacket.
Definition: EndPacket.cpp:25
A variable-length serializable buffer.
void setChecksum(const CFDP::Checksum &checksum)
Set the checksum.
Definition: EndPacket.cpp:34
SerializeStatus serialize(U8 val)
U8 * getData() const
Definition: Buffer.cpp:56
void getChecksum(CFDP::Checksum &checksum) const
Get the checksum.
Definition: EndPacket.cpp:38
SerializeStatus
forward declaration for string
SerializeStatus toBuffer(Buffer &buffer) const
Convert this EndPacket to a Buffer.
Definition: EndPacket.cpp:29
Class representing a 32-bit checksum as mandated by the CCSDS File Delivery Protocol.
Definition: Checksum.hpp:53
U32 getValue() const
Get the checksum value.
Definition: Checksum.cpp:66
FwSizeType getSize() const
Definition: Buffer.cpp:60
SerializeStatus deserialize(U8 &val)
void initialize(const U32 sequenceIndex, const CFDP::Checksum &checksum)
Initialize an end packet.
Definition: EndPacket.cpp:20
#define FW_ASSERT(...)
Definition: Assert.hpp:14