F´ Flight Software - C/C++ Documentation
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 
18 void FilePacket::StartPacket ::initialize(const U32 fileSize,
19  const char* const sourcePath,
20  const char* const destinationPath) {
21  this->m_header.initialize(FilePacket::T_START, 0);
22  this->m_fileSize = fileSize;
23  this->m_sourcePath.initialize(sourcePath);
24  this->m_destinationPath.initialize(destinationPath);
25 }
26 
28  return static_cast<U32>(this->m_header.bufferSize() + sizeof(this->m_fileSize) + this->m_sourcePath.bufferSize() +
29  this->m_destinationPath.bufferSize());
30 }
31 
33  SerialBuffer serialBuffer(buffer.getData(), buffer.getSize());
34  return this->toSerialBuffer(serialBuffer);
35 }
36 
37 SerializeStatus FilePacket::StartPacket ::fromSerialBuffer(SerialBuffer& serialBuffer) {
38  FW_ASSERT(this->m_header.m_type == T_START);
39 
40  {
41  const SerializeStatus status = serialBuffer.deserialize(this->m_fileSize);
42 
43  if (status != FW_SERIALIZE_OK) {
44  return status;
45  }
46  }
47 
48  {
49  const SerializeStatus status = this->m_sourcePath.fromSerialBuffer(serialBuffer);
50 
51  if (status != FW_SERIALIZE_OK) {
52  return status;
53  }
54  }
55 
56  {
57  const SerializeStatus status = this->m_destinationPath.fromSerialBuffer(serialBuffer);
58 
59  if (status != FW_SERIALIZE_OK) {
60  return status;
61  }
62  }
63 
64  return FW_SERIALIZE_OK;
65 }
66 
67 SerializeStatus FilePacket::StartPacket ::toSerialBuffer(SerialBuffer& serialBuffer) const {
68  FW_ASSERT(this->m_header.m_type == T_START);
69 
70  {
71  const SerializeStatus status = this->m_header.toSerialBuffer(serialBuffer);
72 
73  if (status != FW_SERIALIZE_OK) {
74  return status;
75  }
76  }
77 
78  {
79  const SerializeStatus status = serialBuffer.serialize(this->m_fileSize);
80 
81  if (status != FW_SERIALIZE_OK) {
82  return status;
83  }
84  }
85 
86  {
87  const SerializeStatus status = this->m_sourcePath.toSerialBuffer(serialBuffer);
88 
89  if (status != FW_SERIALIZE_OK) {
90  return status;
91  }
92  }
93 
94  {
95  const SerializeStatus status = this->m_destinationPath.toSerialBuffer(serialBuffer);
96 
97  if (status != FW_SERIALIZE_OK) {
98  return status;
99  }
100  }
101 
102  return FW_SERIALIZE_OK;
103 }
104 
105 } // namespace Fw
Serialization/Deserialization operation was successful.
A variable-length serializable buffer.
U32 bufferSize() const
Compute the buffer size needed to hold this StartPacket.
Definition: StartPacket.cpp:27
U8 * getData() const
Definition: Buffer.cpp:56
void initialize(const char *const value)
Initialize a PathName.
Definition: PathName.cpp:21
SerializeStatus
forward declaration for string
SerializeStatus toBuffer(Buffer &buffer) const
Convert this StartPacket to a Buffer.
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:18
FwSizeType getSize() const
Definition: Buffer.cpp:60
SerializeStatus deserialize(U8 &val)
#define FW_ASSERT(...)
Definition: Assert.hpp:14