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.deserializeTo(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  if (serialBuffer.getDeserializeSizeLeft() != 0) {
66  }
67 
68  return FW_SERIALIZE_OK;
69 }
70 
71 SerializeStatus FilePacket::StartPacket ::toSerialBuffer(SerialBuffer& serialBuffer) const {
72  FW_ASSERT(this->m_header.m_type == T_START);
73 
74  {
75  const SerializeStatus status = this->m_header.toSerialBuffer(serialBuffer);
76 
77  if (status != FW_SERIALIZE_OK) {
78  return status;
79  }
80  }
81 
82  {
83  const SerializeStatus status = serialBuffer.serializeFrom(this->m_fileSize);
84 
85  if (status != FW_SERIALIZE_OK) {
86  return status;
87  }
88  }
89 
90  {
91  const SerializeStatus status = this->m_sourcePath.toSerialBuffer(serialBuffer);
92 
93  if (status != FW_SERIALIZE_OK) {
94  return status;
95  }
96  }
97 
98  {
99  const SerializeStatus status = this->m_destinationPath.toSerialBuffer(serialBuffer);
100 
101  if (status != FW_SERIALIZE_OK) {
102  return status;
103  }
104  }
105 
106  return FW_SERIALIZE_OK;
107 }
108 
109 } // 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
SerializeStatus deserializeTo(U8 &val, Endianness mode=Endianness::BIG) override
Deserialize an 8-bit unsigned integer value.
U8 * getData() const
Definition: Buffer.cpp:82
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
Data was left in the buffer, but not enough to deserialize.
Serializable::SizeType getDeserializeSizeLeft() const override
Get remaining deserialization buffer size.
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:90
Implementation of malloc based allocator.
#define FW_ASSERT(...)
Definition: Assert.hpp:14