F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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
18namespace Fw {
19
20 void FilePacket::EndPacket ::
21 initialize(
22 const U32 sequenceIndex,
23 const CFDP::Checksum& checksum
24 )
25 {
26 this->header.initialize(FilePacket::T_END, sequenceIndex);
27 this->setChecksum(checksum);
28 }
29
30 U32 FilePacket::EndPacket ::
31 bufferSize() const
32 {
33 return this->header.bufferSize() + sizeof(this->checksumValue);
34 }
35
36 SerializeStatus FilePacket::EndPacket ::
37 toBuffer(Buffer& buffer) const
38 {
39 SerialBuffer serialBuffer(
40 buffer.getData(),
41 buffer.getSize()
42 );
43 return this->toSerialBuffer(serialBuffer);
44 }
45
46 void FilePacket::EndPacket ::
47 setChecksum(const CFDP::Checksum& checksum)
48 {
49 this->checksumValue = checksum.getValue();
50 }
51
52
53 void FilePacket::EndPacket ::
54 getChecksum(CFDP::Checksum& checksum) const
55 {
56 CFDP::Checksum c(this->checksumValue);
57 checksum = c;
58 }
59
60 SerializeStatus FilePacket::EndPacket ::
61 fromSerialBuffer(SerialBuffer& serialBuffer)
62 {
63
64 FW_ASSERT(this->header.type == T_END);
65
66 const SerializeStatus status =
67 serialBuffer.deserialize(this->checksumValue);
68
69 return status;
70
71 }
72
73 SerializeStatus FilePacket::EndPacket ::
74 toSerialBuffer(SerialBuffer& serialBuffer) const
75 {
76
77 FW_ASSERT(this->header.type == T_END);
78
79 SerializeStatus status;
80
81 status = this->header.toSerialBuffer(serialBuffer);
82 if (status != FW_SERIALIZE_OK)
83 return status;
84
85 status = serialBuffer.serialize(this->checksumValue);
86 if (status != FW_SERIALIZE_OK)
87 return status;
88
89 return FW_SERIALIZE_OK;
90
91 }
92
93}
#define FW_ASSERT(...)
Definition Assert.hpp:7
Class representing a CFDP checksum.
Definition Checksum.hpp:23
U32 getValue() const
Get the checksum value.
Definition Checksum.cpp:66
U8 * getData() const
Definition Buffer.cpp:60
U32 getSize() const
Definition Buffer.cpp:64
A variable-length serializable buffer.
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
Definition Buffer.cpp:21
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.