F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
16namespace Fw {
17
18 void FilePacket::StartPacket ::
19 initialize(
20 const U32 fileSize,
21 const char *const sourcePath,
22 const char *const destinationPath
23 )
24 {
25 const FilePacket::Header header = { FilePacket::T_START, 0 };
26 this->header = header;
27 this->fileSize = fileSize;
28 this->sourcePath.initialize(sourcePath);
29 this->destinationPath.initialize(destinationPath);
30 }
31
32 U32 FilePacket::StartPacket ::
33 bufferSize() const
34 {
35 return this->header.bufferSize() +
36 sizeof(this->fileSize) +
37 this->sourcePath.bufferSize() +
38 this->destinationPath.bufferSize();
39 }
40
41 SerializeStatus FilePacket::StartPacket ::
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->header.type == T_START);
56
57 {
58 const SerializeStatus status =
59 serialBuffer.deserialize(this->fileSize);
60 if (status != FW_SERIALIZE_OK)
61 return status;
62 }
63
64 {
65 const SerializeStatus status =
66 this->sourcePath.fromSerialBuffer(serialBuffer);
67 if (status != FW_SERIALIZE_OK)
68 return status;
69 }
70
71 {
72 const SerializeStatus status =
73 this->destinationPath.fromSerialBuffer(serialBuffer);
74 if (status != FW_SERIALIZE_OK)
75 return status;
76 }
77
78 return FW_SERIALIZE_OK;
79
80 }
81
82 SerializeStatus FilePacket::StartPacket ::
83 toSerialBuffer(SerialBuffer& serialBuffer) const
84 {
85
86 FW_ASSERT(this->header.type == T_START);
87
88 {
89 const SerializeStatus status =
90 this->header.toSerialBuffer(serialBuffer);
91 if (status != FW_SERIALIZE_OK)
92 return status;
93 }
94
95 {
96 const SerializeStatus status =
97 serialBuffer.serialize(this->fileSize);
98 if (status != FW_SERIALIZE_OK)
99 return status;
100 }
101
102 {
103 const SerializeStatus status =
104 this->sourcePath.toSerialBuffer(serialBuffer);
105 if (status != FW_SERIALIZE_OK)
106 return status;
107 }
108
109 {
110 const SerializeStatus status =
111 this->destinationPath.toSerialBuffer(serialBuffer);
112 if (status != FW_SERIALIZE_OK)
113 return status;
114 }
115
116 return FW_SERIALIZE_OK;
117
118 }
119
120}
#define FW_ASSERT(...)
Definition Assert.hpp:7
U8 * getData() const
Definition Buffer.cpp:60
U32 getSize() const
Definition Buffer.cpp:64
The type of a packet header.
A variable-length serializable buffer.
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
Definition Buffer.cpp:21
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.