F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
StartPacket.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title StartPacket.cpp
3 // \author bocchino
4 // \brief cpp file for FilePacket::StartPacket
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 
14 #include <Fw/Types/Assert.hpp>
15 
16 namespace Fw {
17 
20  const U32 fileSize,
21  const char *const sourcePath,
22  const char *const destinationPath
23  )
24  {
25  this->m_header.initialize(FilePacket::T_START, 0);
26  this->m_fileSize = fileSize;
27  this->m_sourcePath.initialize(sourcePath);
28  this->m_destinationPath.initialize(destinationPath);
29  }
30 
32  bufferSize() const
33  {
34  return static_cast<U32>(
35  this->m_header.bufferSize() +
36  sizeof(this->m_fileSize) +
37  this->m_sourcePath.bufferSize() +
38  this->m_destinationPath.bufferSize());
39  }
40 
42  toBuffer(Buffer& buffer) const
43  {
44  SerialBuffer serialBuffer(
45  buffer.getData(),
46  buffer.getSize()
47  );
48  return this->toSerialBuffer(serialBuffer);
49  }
50 
51  SerializeStatus FilePacket::StartPacket ::
52  fromSerialBuffer(SerialBuffer& serialBuffer)
53  {
54 
55  FW_ASSERT(this->m_header.m_type == T_START);
56 
57  {
58  const SerializeStatus status =
59  serialBuffer.deserialize(this->m_fileSize);
60 
61  if (status != FW_SERIALIZE_OK) {
62  return status;
63  }
64  }
65 
66  {
67  const SerializeStatus status =
68  this->m_sourcePath.fromSerialBuffer(serialBuffer);
69 
70  if (status != FW_SERIALIZE_OK) {
71  return status;
72  }
73  }
74 
75  {
76  const SerializeStatus status =
77  this->m_destinationPath.fromSerialBuffer(serialBuffer);
78 
79  if (status != FW_SERIALIZE_OK) {
80  return status;
81  }
82  }
83 
84  return FW_SERIALIZE_OK;
85 
86  }
87 
88  SerializeStatus FilePacket::StartPacket ::
89  toSerialBuffer(SerialBuffer& serialBuffer) const
90  {
91 
92  FW_ASSERT(this->m_header.m_type == T_START);
93 
94  {
95  const SerializeStatus status =
96  this->m_header.toSerialBuffer(serialBuffer);
97 
98  if (status != FW_SERIALIZE_OK) {
99  return status;
100  }
101  }
102 
103  {
104  const SerializeStatus status =
105  serialBuffer.serialize(this->m_fileSize);
106 
107  if (status != FW_SERIALIZE_OK) {
108  return status;
109  }
110  }
111 
112  {
113  const SerializeStatus status =
114  this->m_sourcePath.toSerialBuffer(serialBuffer);
115 
116  if (status != FW_SERIALIZE_OK) {
117  return status;
118  }
119  }
120 
121  {
122  const SerializeStatus status =
123  this->m_destinationPath.toSerialBuffer(serialBuffer);
124 
125  if (status != FW_SERIALIZE_OK) {
126  return status;
127  }
128  }
129 
130  return FW_SERIALIZE_OK;
131 
132  }
133 
134 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
U8 * getData() const
Definition: Buffer.cpp:68
U32 getSize() const
Definition: Buffer.cpp:72
void initialize(const char *const value)
Initialize a PathName.
Definition: PathName.cpp:22
A variable-length serializable buffer.
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
SerializeStatus toBuffer(Buffer &buffer) const
Convert this StartPacket to a Buffer.
Definition: StartPacket.cpp:42
U32 bufferSize() const
Compute the buffer size needed to hold this StartPacket.
Definition: StartPacket.cpp:32
void initialize(const U32 fileSize, const char *const sourcePath, const char *const destinationPath)
Initialize a StartPacket with sequence number 0.
Definition: StartPacket.cpp:19