F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
22  const U32 sequenceIndex,
23  const CFDP::Checksum& checksum
24  )
25  {
26  this->m_header.initialize(FilePacket::T_END, sequenceIndex);
27  this->setChecksum(checksum);
28  }
29 
31  bufferSize() const
32  {
33  return static_cast<U32>(this->m_header.bufferSize() + sizeof(this->m_checksumValue));
34  }
35 
37  toBuffer(Buffer& buffer) const
38  {
39  SerialBuffer serialBuffer(
40  buffer.getData(),
41  buffer.getSize()
42  );
43  return this->toSerialBuffer(serialBuffer);
44  }
45 
47  setChecksum(const CFDP::Checksum& checksum)
48  {
49  this->m_checksumValue = checksum.getValue();
50  }
51 
52 
54  getChecksum(CFDP::Checksum& checksum) const
55  {
56  CFDP::Checksum c(this->m_checksumValue);
57  checksum = c;
58  }
59 
60  SerializeStatus FilePacket::EndPacket ::
61  fromSerialBuffer(SerialBuffer& serialBuffer)
62  {
63 
64  FW_ASSERT(this->m_header.m_type == T_END);
65 
66  const SerializeStatus status =
67  serialBuffer.deserialize(this->m_checksumValue);
68 
69  return status;
70 
71  }
72 
73  SerializeStatus FilePacket::EndPacket ::
74  toSerialBuffer(SerialBuffer& serialBuffer) const
75  {
76 
77  FW_ASSERT(this->m_header.m_type == T_END);
78 
79  SerializeStatus status;
80 
81  status = this->m_header.toSerialBuffer(serialBuffer);
82  if (status != FW_SERIALIZE_OK) {
83  return status;
84  }
85 
86  status = serialBuffer.serialize(this->m_checksumValue);
87  if (status != FW_SERIALIZE_OK) {
88  return status;
89  }
90 
91  return FW_SERIALIZE_OK;
92 
93  }
94 
95 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
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
U8 * getData() const
Definition: Buffer.cpp:68
U32 getSize() const
Definition: Buffer.cpp:72
U32 bufferSize() const
Compute the buffer size needed to hold this EndPacket.
Definition: EndPacket.cpp:31
void getChecksum(CFDP::Checksum &checksum) const
Get the checksum.
Definition: EndPacket.cpp:54
void initialize(const U32 sequenceIndex, const CFDP::Checksum &checksum)
Initialize an end packet.
Definition: EndPacket.cpp:21
void setChecksum(const CFDP::Checksum &checksum)
Set the checksum.
Definition: EndPacket.cpp:47
SerializeStatus toBuffer(Buffer &buffer) const
Convert this EndPacket to a Buffer.
Definition: EndPacket.cpp:37
A variable-length serializable buffer.
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.