F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
FilePacket.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title FilePacket.hpp
3 // \author bocchino
4 // \brief hpp file for FilePacket
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 #ifndef Fw_FilePacket_HPP
14 #define Fw_FilePacket_HPP
15 
17 #include <Fw/Buffer/Buffer.hpp>
18 #include <Fw/Types/BasicTypes.hpp>
21 
22 namespace Fw {
23 
27  union FilePacket {
28 
29  public:
30 
31  // ----------------------------------------------------------------------
32  // Types
33  // ----------------------------------------------------------------------
34 
36  typedef enum {
37  T_START = 0,
38  T_DATA = 1,
39  T_END = 2,
40  T_CANCEL = 3,
41  T_NONE = 255
42  } Type;
43 
45  class PathName {
46 
47  friend union FilePacket;
48 
49  public:
50 
52  enum { MAX_LENGTH = 255 };
53 
54  public:
55 
58 
60  const char *value;
61 
62  public:
63 
65  void initialize(
66  const char *const value
67  );
68 
70  U32 bufferSize(void) const;
71 
72  PRIVATE:
73 
75  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
76 
78  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
79 
80  };
81 
83  class Header {
84 
85  friend union FilePacket;
86 
87  public:
88 
91 
94 
96  enum { HEADERSIZE = sizeof(U8) + sizeof(U32) };
97 
98  PRIVATE:
99 
101  void initialize(
102  const Type type,
103  const U32 sequenceIndex
104  );
105 
107  U32 bufferSize(void) const;
108 
110  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
111 
113  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
114 
115  };
116 
118  struct StartPacket {
119 
120  friend union FilePacket;
121 
122  public:
123 
126 
128  U32 fileSize;
129 
132 
135 
136  public:
137 
139  void initialize(
140  const U32 fileSize,
141  const char *const sourcePath,
142  const char *const destinationPath
143  );
144 
146  U32 bufferSize(void) const;
147 
149  SerializeStatus toBuffer(Buffer& buffer) const;
150 
151  PRIVATE:
152 
154  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
155 
157  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
158 
159  };
160 
162  class DataPacket {
163 
164  friend union FilePacket;
165 
166  public:
167 
170 
173 
175  U16 dataSize;
176 
178  const U8 *data;
179 
182  sizeof(U32) +
183  sizeof(U16) };
184 
185 
186  public:
187 
189  void initialize(
190  const U32 sequenceIndex,
191  const U32 byteOffset,
192  const U16 dataSize,
193  const U8 *const data
194  );
195 
197  U32 bufferSize(void) const;
198 
200  SerializeStatus toBuffer(Buffer& buffer) const;
201 
202  PRIVATE:
203 
205  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
206 
208  U32 fixedLengthSize(void) const;
209 
211  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
212 
213  };
214 
216  class EndPacket {
217 
218  friend union FilePacket;
219 
220  public:
221 
224 
226  void setChecksum(const CFDP::Checksum& checksum);
227 
229  void getChecksum(CFDP::Checksum& checksum) const;
230 
232  U32 bufferSize(void) const;
233 
235  SerializeStatus toBuffer(Buffer& buffer) const;
236 
237  public:
238 
240  void initialize(
241  const U32 sequenceIndex,
242  const CFDP::Checksum& checksum
243  );
244 
245  PRIVATE:
246 
248  U32 checksumValue;
249 
251  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
252 
254  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
255 
256  };
257 
259  class CancelPacket {
260 
261  friend union FilePacket;
262 
263  public:
264 
267 
268  public:
269 
271  void initialize(
272  const U32 sequenceIndex
273  );
274 
276  U32 bufferSize(void) const;
277 
279  SerializeStatus toBuffer(Buffer& buffer) const;
280 
281  PRIVATE:
282 
284  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
285 
286  };
287 
288  public:
289 
290  // ----------------------------------------------------------------------
291  // Constructor
292  // ----------------------------------------------------------------------
293 
294  FilePacket(void) { this->header.type = T_NONE; }
295 
296  public:
297 
298  // ----------------------------------------------------------------------
299  // Public instance methods
300  // ----------------------------------------------------------------------
301 
304  SerializeStatus fromBuffer(const Buffer& buffer);
305 
308  const Header& asHeader(void) const;
309 
312  const StartPacket& asStartPacket(void) const;
313 
316  const DataPacket& asDataPacket(void) const;
317 
320  const EndPacket& asEndPacket(void) const;
321 
324  const CancelPacket& asCancelPacket(void) const;
325 
328  void fromStartPacket(const StartPacket& startPacket);
329 
332  void fromDataPacket(const DataPacket& dataPacket);
333 
336  void fromEndPacket(const EndPacket& endPacket);
337 
340  void fromCancelPacket(const CancelPacket& cancelPacket);
341 
344  U32 bufferSize(void) const;
345 
348  SerializeStatus toBuffer(Buffer& buffer) const;
349 
350  PRIVATE:
351 
352  // ----------------------------------------------------------------------
353  // Private methods
354  // ----------------------------------------------------------------------
355 
358  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
359 
360  PRIVATE:
361 
362  // ----------------------------------------------------------------------
363  // Private data
364  // ----------------------------------------------------------------------
365 
368  Header header;
369 
372  StartPacket startPacket;
373 
376  DataPacket dataPacket;
377 
380  EndPacket endPacket;
381 
384  CancelPacket cancelPacket;
385 
386  };
387 
388 }
389 
390 #endif
Fw::FilePacket::DataPacket::bufferSize
U32 bufferSize(void) const
Compute the buffer size needed to hold this DataPacket.
Definition: DataPacket.cpp:33
Fw::FilePacket::EndPacket::bufferSize
U32 bufferSize(void) const
Compute the buffer size needed to hold this EndPacket.
Definition: EndPacket.cpp:31
Fw::FilePacket::StartPacket::fileSize
U32 fileSize
The file size.
Definition: FilePacket.hpp:128
Fw::FilePacket::DataPacket::header
Header header
The packet header.
Definition: FilePacket.hpp:169
Fw::SerialBuffer
A variable-length serializable buffer.
Definition: SerialBuffer.hpp:24
Fw::FilePacket::CancelPacket::header
Header header
The packet header.
Definition: FilePacket.hpp:266
Fw::FilePacket::asHeader
const Header & asHeader(void) const
Definition: FilePacket.cpp:35
Fw::FilePacket::DataPacket::initialize
void initialize(const U32 sequenceIndex, const U32 byteOffset, const U16 dataSize, const U8 *const data)
Initialize a data packet.
Definition: DataPacket.cpp:19
Fw::FilePacket::DataPacket::HEADERSIZE
@ HEADERSIZE
Definition: FilePacket.hpp:181
Fw::SerializeStatus
SerializeStatus
forward declaration for string
Definition: Serializable.hpp:14
Serializable.hpp
Fw::FilePacket::toBuffer
SerializeStatus toBuffer(Buffer &buffer) const
Definition: FilePacket.cpp:117
Fw::FilePacket::asEndPacket
const EndPacket & asEndPacket(void) const
Definition: FilePacket.cpp:55
Fw::FilePacket::PathName::initialize
void initialize(const char *const value)
Initialize a PathName.
Definition: PathName.cpp:21
Fw::FilePacket::CancelPacket
The type of a cancel packet.
Definition: FilePacket.hpp:259
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Fw::FilePacket::StartPacket
The type of a start packet.
Definition: FilePacket.hpp:118
Buffer.hpp
Fw::FilePacket::asStartPacket
const StartPacket & asStartPacket(void) const
Definition: FilePacket.cpp:41
Fw::FilePacket::PathName::MAX_LENGTH
@ MAX_LENGTH
Definition: FilePacket.hpp:52
Fw::FilePacket::DataPacket
The type of a data packet.
Definition: FilePacket.hpp:162
Fw::FilePacket::fromDataPacket
void fromDataPacket(const DataPacket &dataPacket)
Definition: FilePacket.cpp:76
Fw::FilePacket::Header
The type of a packet header.
Definition: FilePacket.hpp:83
Fw::Buffer
Definition: Buffer.hpp:43
Fw::FilePacket::T_CANCEL
@ T_CANCEL
Definition: FilePacket.hpp:40
Fw::FilePacket::EndPacket
The type of an end packet.
Definition: FilePacket.hpp:216
Fw::FilePacket::EndPacket::initialize
void initialize(const U32 sequenceIndex, const CFDP::Checksum &checksum)
Initialize an end packet.
Definition: EndPacket.cpp:21
Fw::FilePacket::Header::HEADERSIZE
@ HEADERSIZE
Definition: FilePacket.hpp:96
Fw::FilePacket::EndPacket::header
Header header
The packet header.
Definition: FilePacket.hpp:223
Fw::FilePacket
A file packet.
Definition: FilePacket.hpp:27
Fw::FilePacket::T_NONE
@ T_NONE
Definition: FilePacket.hpp:41
Fw::FilePacket::bufferSize
U32 bufferSize(void) const
Definition: FilePacket.cpp:97
SerialBuffer.hpp
Fw::FilePacket::StartPacket::sourcePath
PathName sourcePath
The source path.
Definition: FilePacket.hpp:131
Fw::FilePacket::fromStartPacket
void fromStartPacket(const StartPacket &startPacket)
Definition: FilePacket.cpp:69
Fw::FilePacket::EndPacket::setChecksum
void setChecksum(const CFDP::Checksum &checksum)
Set the checksum.
Definition: EndPacket.cpp:47
Fw::FilePacket::PathName::length
U8 length
The length.
Definition: FilePacket.hpp:57
Fw::FilePacket::T_START
@ T_START
Definition: FilePacket.hpp:37
Fw::FilePacket::EndPacket::getChecksum
void getChecksum(CFDP::Checksum &checksum) const
Get the checksum.
Definition: EndPacket.cpp:54
Fw::FilePacket::Header::sequenceIndex
U32 sequenceIndex
The sequence index.
Definition: FilePacket.hpp:93
Fw::FilePacket::Type
Type
Packet type.
Definition: FilePacket.hpp:36
Fw::FilePacket::StartPacket::header
Header header
The packet header.
Definition: FilePacket.hpp:125
Fw::FilePacket::StartPacket::bufferSize
U32 bufferSize(void) const
Compute the buffer size needed to hold this StartPacket.
Definition: StartPacket.cpp:33
CFDP::Checksum
Class representing a CFDP checksum.
Definition: Checksum.hpp:23
Fw::FilePacket::DataPacket::byteOffset
U32 byteOffset
The byte offset of the packet data into the destination file.
Definition: FilePacket.hpp:172
Fw::FilePacket::asDataPacket
const DataPacket & asDataPacket(void) const
Definition: FilePacket.cpp:48
Fw::FilePacket::FilePacket
FilePacket(void)
Definition: FilePacket.hpp:294
Fw::FilePacket::asCancelPacket
const CancelPacket & asCancelPacket(void) const
Definition: FilePacket.cpp:62
Fw::FilePacket::PathName::value
const char * value
Pointer to the path value.
Definition: FilePacket.hpp:60
Fw::FilePacket::StartPacket::toBuffer
SerializeStatus toBuffer(Buffer &buffer) const
Convert this StartPacket to a Buffer.
Definition: StartPacket.cpp:42
Fw::FilePacket::PathName
The type of a path name.
Definition: FilePacket.hpp:45
Fw::FilePacket::StartPacket::destinationPath
PathName destinationPath
The destination path.
Definition: FilePacket.hpp:134
Fw::FilePacket::PathName::bufferSize
U32 bufferSize(void) const
Compute the buffer size needed to hold this PathName.
Definition: PathName.cpp:29
Fw::FilePacket::fromEndPacket
void fromEndPacket(const EndPacket &endPacket)
Definition: FilePacket.cpp:83
Fw::FilePacket::CancelPacket::toBuffer
SerializeStatus toBuffer(Buffer &buffer) const
Convert this CancelPacket to a Buffer.
Definition: CancelPacket.cpp:31
Fw::FilePacket::T_END
@ T_END
Definition: FilePacket.hpp:39
Checksum.hpp
Fw::FilePacket::EndPacket::toBuffer
SerializeStatus toBuffer(Buffer &buffer) const
Convert this EndPacket to a Buffer.
Definition: EndPacket.cpp:37
Fw::FilePacket::CancelPacket::initialize
void initialize(const U32 sequenceIndex)
Initialize a cancel packet.
Definition: CancelPacket.cpp:19
BasicTypes.hpp
Declares ISF basic types.
Fw::FilePacket::DataPacket::data
const U8 * data
Pointer to the file data.
Definition: FilePacket.hpp:178
Fw::FilePacket::fromBuffer
SerializeStatus fromBuffer(const Buffer &buffer)
Definition: FilePacket.cpp:23
Fw::FilePacket::Header::type
Type type
The packet type.
Definition: FilePacket.hpp:90
Fw::FilePacket::StartPacket::initialize
void initialize(const U32 fileSize, const char *const sourcePath, const char *const destinationPath)
Initialize a StartPacket with sequence number 0.
Definition: StartPacket.cpp:19
Fw::FilePacket::CancelPacket::bufferSize
U32 bufferSize(void) const
Compute the buffer size needed to hold this CancelPacket.
Definition: CancelPacket.cpp:25
Fw::FilePacket::T_DATA
@ T_DATA
Definition: FilePacket.hpp:38
Fw::FilePacket::DataPacket::toBuffer
SerializeStatus toBuffer(Buffer &buffer) const
Convert this DataPacket to a Buffer.
Definition: DataPacket.cpp:43
Fw
Definition: Buffer.cpp:21
Fw::FilePacket::DataPacket::dataSize
U16 dataSize
The size of the file data in the packet.
Definition: FilePacket.hpp:175
Fw::FilePacket::fromCancelPacket
void fromCancelPacket(const CancelPacket &cancelPacket)
Definition: FilePacket.cpp:90