F´ Flight Software - C/C++ Documentation  devel
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 <FpConfig.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  PRIVATE:
55 
57  U8 m_length;
58 
60  const char *m_value;
61 
62  public:
63 
65  void initialize(
66  const char *const value
67  );
68 
70  U32 bufferSize() const;
71 
73  U32 getLength(void) const {
74  return this->m_length;
75  };
76 
78  const char* getValue(void) const {
79  return this->m_value;
80  };
81 
82  PRIVATE:
83 
85  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
86 
88  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
89 
90  };
91 
93  class Header {
94 
95  friend union FilePacket;
96 
97  PRIVATE:
98 
100  Type m_type;
101 
103  U32 m_sequenceIndex;
104 
105  public:
106 
108  enum { HEADERSIZE = sizeof(U8) + sizeof(U32) };
109 
110  PRIVATE:
111 
113  void initialize(
114  const Type type,
115  const U32 sequenceIndex
116  );
117 
119  U32 bufferSize() const;
120 
122  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
123 
125  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
126 
127  public:
128  Type getType(void) const {
129  return this->m_type;
130  };
131 
132  U32 getSequenceIndex(void) const {
133  return this->m_sequenceIndex;
134  };
135 
136  };
137 
139  struct StartPacket {
140 
141  friend union FilePacket;
142 
143  PRIVATE:
144 
146  Header m_header;
147 
149  U32 m_fileSize;
150 
152  PathName m_sourcePath;
153 
155  PathName m_destinationPath;
156 
157  public:
158 
160  void initialize(
161  const U32 fileSize,
162  const char *const sourcePath,
163  const char *const destinationPath
164  );
165 
167  U32 bufferSize() const;
168 
170  SerializeStatus toBuffer(Buffer& buffer) const;
171 
173  const PathName& getDestinationPath() const {
174  return this->m_destinationPath;
175  };
176 
178  const PathName& getSourcePath() const {
179  return this->m_sourcePath;
180  };
181 
183  U32 getFileSize() const {
184  return this->m_fileSize;
185  };
186  PRIVATE:
187 
189  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
190 
192  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
193 
194  };
195 
197  class DataPacket {
198 
199  friend union FilePacket;
200 
201  PRIVATE:
202 
204  Header m_header;
205 
207  U32 m_byteOffset;
208 
210  U16 m_dataSize;
211 
213  const U8 *m_data;
214 
215  public:
216 
218  enum { HEADERSIZE = Header::HEADERSIZE +
219  sizeof(U32) +
220  sizeof(U16) };
221 
223  void initialize(
224  const U32 sequenceIndex,
225  const U32 byteOffset,
226  const U16 dataSize,
227  const U8 *const data
228  );
229 
231  U32 bufferSize() const;
232 
234  SerializeStatus toBuffer(Buffer& buffer) const;
235 
237  const FilePacket::Header& asHeader() const {
238  return this->m_header;
239  };
240 
242  U32 getByteOffset() const {
243  return this->m_byteOffset;
244  };
245 
247  U32 getDataSize() const {
248  return this->m_dataSize;
249  };
250 
252  const U8* getData() const {
253  return this->m_data;
254  };
255  PRIVATE:
256 
258  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
259 
261  U32 fixedLengthSize() const;
262 
264  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
265 
266  };
267 
269  class EndPacket {
270 
271  friend union FilePacket;
272 
273  PRIVATE:
274 
276  Header m_header;
277 
278  public:
279 
281  void setChecksum(const CFDP::Checksum& checksum);
282 
284  void getChecksum(CFDP::Checksum& checksum) const;
285 
287  U32 bufferSize() const;
288 
290  SerializeStatus toBuffer(Buffer& buffer) const;
291 
293  const FilePacket::Header& asHeader() const {
294  return this->m_header;
295  };
296  public:
297 
299  void initialize(
300  const U32 sequenceIndex,
301  const CFDP::Checksum& checksum
302  );
303 
304  PRIVATE:
305 
307  U32 m_checksumValue;
308 
310  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
311 
313  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
314 
315  };
316 
318  class CancelPacket {
319 
320  friend union FilePacket;
321 
322  PRIVATE:
323 
325  Header m_header;
326 
327  public:
328 
330  void initialize(
331  const U32 sequenceIndex
332  );
333 
335  U32 bufferSize() const;
336 
338  SerializeStatus toBuffer(Buffer& buffer) const;
339 
341  const FilePacket::Header& asHeader() const {
342  return this->m_header;
343  };
344  PRIVATE:
345 
347  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
348 
349  };
350 
351  public:
352 
353  // ----------------------------------------------------------------------
354  // Constructor
355  // ----------------------------------------------------------------------
356 
357  FilePacket() { this->m_header.m_type = T_NONE; }
358 
359  public:
360 
361  // ----------------------------------------------------------------------
362  // Public instance methods
363  // ----------------------------------------------------------------------
364 
367  SerializeStatus fromBuffer(const Buffer& buffer);
368 
371  const Header& asHeader() const;
372 
375  const StartPacket& asStartPacket() const;
376 
379  const DataPacket& asDataPacket() const;
380 
383  const EndPacket& asEndPacket() const;
384 
387  const CancelPacket& asCancelPacket() const;
388 
391  void fromStartPacket(const StartPacket& startPacket);
392 
395  void fromDataPacket(const DataPacket& dataPacket);
396 
399  void fromEndPacket(const EndPacket& endPacket);
400 
403  void fromCancelPacket(const CancelPacket& cancelPacket);
404 
407  U32 bufferSize() const;
408 
411  SerializeStatus toBuffer(Buffer& buffer) const;
412 
413  PRIVATE:
414 
415  // ----------------------------------------------------------------------
416  // Private methods
417  // ----------------------------------------------------------------------
418 
421  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
422 
423  PRIVATE:
424 
425  // ----------------------------------------------------------------------
426  // Private data
427  // ----------------------------------------------------------------------
428 
431  Header m_header;
432 
435  StartPacket m_startPacket;
436 
439  DataPacket m_dataPacket;
440 
443  EndPacket m_endPacket;
444 
447  CancelPacket m_cancelPacket;
448 
449  };
450 
451 }
452 
453 #endif
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
C++-compatible configuration header for fprime configuration.
Class representing a CFDP checksum.
Definition: Checksum.hpp:23
The type of a cancel packet.
Definition: FilePacket.hpp:318
SerializeStatus toBuffer(Buffer &buffer) const
Convert this CancelPacket to a Buffer.
const FilePacket::Header & asHeader() const
Get this as a Header.
Definition: FilePacket.hpp:341
U32 bufferSize() const
Compute the buffer size needed to hold this CancelPacket.
void initialize(const U32 sequenceIndex)
Initialize a cancel packet.
The type of a data packet.
Definition: FilePacket.hpp:197
const FilePacket::Header & asHeader() const
Get this as a Header.
Definition: FilePacket.hpp:237
SerializeStatus toBuffer(Buffer &buffer) const
Convert this DataPacket to a Buffer.
Definition: DataPacket.cpp:43
void initialize(const U32 sequenceIndex, const U32 byteOffset, const U16 dataSize, const U8 *const data)
Initialize a data packet.
Definition: DataPacket.cpp:19
U32 getByteOffset() const
Get the byte offset.
Definition: FilePacket.hpp:242
const U8 * getData() const
Get the data.
Definition: FilePacket.hpp:252
U32 getDataSize() const
Get the data size.
Definition: FilePacket.hpp:247
U32 bufferSize() const
Compute the buffer size needed to hold this DataPacket.
Definition: DataPacket.cpp:33
The type of an end packet.
Definition: FilePacket.hpp:269
U32 bufferSize() const
Compute the buffer size needed to hold this EndPacket.
Definition: EndPacket.cpp:31
void getChecksum(CFDP::Checksum &checksum) const
Get the checksum.
Definition: EndPacket.cpp:54
void initialize(const U32 sequenceIndex, const CFDP::Checksum &checksum)
Initialize an end packet.
Definition: EndPacket.cpp:21
void setChecksum(const CFDP::Checksum &checksum)
Set the checksum.
Definition: EndPacket.cpp:47
const FilePacket::Header & asHeader() const
Get this as a Header.
Definition: FilePacket.hpp:293
SerializeStatus toBuffer(Buffer &buffer) const
Convert this EndPacket to a Buffer.
Definition: EndPacket.cpp:37
The type of a packet header.
Definition: FilePacket.hpp:93
U32 getSequenceIndex(void) const
Definition: FilePacket.hpp:132
Type getType(void) const
Definition: FilePacket.hpp:128
The type of a path name.
Definition: FilePacket.hpp:45
void initialize(const char *const value)
Initialize a PathName.
Definition: PathName.cpp:22
U32 bufferSize() const
Compute the buffer size needed to hold this PathName.
Definition: PathName.cpp:30
const char * getValue(void) const
Get the path name value.
Definition: FilePacket.hpp:78
U32 getLength(void) const
Get the length of the path name value.
Definition: FilePacket.hpp:73
A variable-length serializable buffer.
SerializeStatus
forward declaration for string
The type of a start packet.
Definition: FilePacket.hpp:139
const PathName & getSourcePath() const
Get the source path.
Definition: FilePacket.hpp:178
SerializeStatus toBuffer(Buffer &buffer) const
Convert this StartPacket to a Buffer.
Definition: StartPacket.cpp:42
const PathName & getDestinationPath() const
Get the destination path.
Definition: FilePacket.hpp:173
U32 getFileSize() const
Get the file size.
Definition: FilePacket.hpp:183
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
A file packet.
Definition: FilePacket.hpp:27
SerializeStatus fromBuffer(const Buffer &buffer)
Definition: FilePacket.cpp:23
void fromCancelPacket(const CancelPacket &cancelPacket)
Definition: FilePacket.cpp:90
void fromEndPacket(const EndPacket &endPacket)
Definition: FilePacket.cpp:83
const CancelPacket & asCancelPacket() const
Definition: FilePacket.cpp:62
const StartPacket & asStartPacket() const
Definition: FilePacket.cpp:41
const EndPacket & asEndPacket() const
Definition: FilePacket.cpp:55
void fromDataPacket(const DataPacket &dataPacket)
Definition: FilePacket.cpp:76
Type
Packet type.
Definition: FilePacket.hpp:36
void fromStartPacket(const StartPacket &startPacket)
Definition: FilePacket.cpp:69
const DataPacket & asDataPacket() const
Definition: FilePacket.cpp:48
U32 bufferSize() const
Definition: FilePacket.cpp:97
const Header & asHeader() const
Definition: FilePacket.cpp:35
SerializeStatus toBuffer(Buffer &buffer) const
Definition: FilePacket.cpp:117