F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/FPrimeBasicTypes.hpp>
21 
22 // Forward declaration for UTs
23 namespace Svc {
24 class FileUplinkTester;
25 class FileDownlinkTester;
26 } // namespace Svc
27 
28 namespace Fw {
29 
33 union FilePacket {
34  public:
35  // ----------------------------------------------------------------------
36  // Types
37  // ----------------------------------------------------------------------
38 
40  typedef enum { T_START = 0, T_DATA = 1, T_END = 2, T_CANCEL = 3, T_NONE = 255 } Type;
41 
43  class PathName {
44  friend union FilePacket;
46  friend class Svc::FileUplinkTester;
47 
48  public:
50  enum { MAX_LENGTH = 255 };
51 
52  private:
54  U8 m_length;
55 
57  const char* m_value;
58 
59  public:
61  void initialize(const char* const value
62  );
63 
65  U32 bufferSize() const;
66 
68  U32 getLength(void) const { return this->m_length; };
69 
71  const char* getValue(void) const { return this->m_value; };
72 
73  private:
75  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
76 
78  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
79  };
80 
82  class Header {
83  friend union FilePacket;
84  friend class FilePacketTester;
86  friend class Svc::FileUplinkTester;
87 
88  private:
90  Type m_type;
91 
93  U32 m_sequenceIndex;
94 
95  public:
97  enum { HEADERSIZE = sizeof(U8) + sizeof(U32) };
98 
99  private:
101  void initialize(const Type type,
102  const U32 sequenceIndex
103  );
104 
106  U32 bufferSize() const;
107 
109  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
110 
112  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
113 
114  public:
115  Type getType(void) const { return this->m_type; };
116 
117  U32 getSequenceIndex(void) const { return this->m_sequenceIndex; };
118  };
119 
121  struct StartPacket {
122  friend union FilePacket;
123 
124  private:
126  Header m_header;
127 
129  U32 m_fileSize;
130 
132  PathName m_sourcePath;
133 
135  PathName m_destinationPath;
136 
137  public:
139  void initialize(const U32 fileSize,
140  const char* const sourcePath,
141  const char* const destinationPath
142  );
143 
145  U32 bufferSize() const;
146 
148  SerializeStatus toBuffer(Buffer& buffer) const;
149 
151  const FilePacket::Header& asHeader() const { return this->m_header; };
152 
154  const PathName& getDestinationPath() const { return this->m_destinationPath; };
155 
157  const PathName& getSourcePath() const { return this->m_sourcePath; };
158 
160  U32 getFileSize() const { return this->m_fileSize; };
161 
162  private:
164  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
165 
167  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
168  };
169 
171  class DataPacket {
172  friend union FilePacket;
174  friend class Svc::FileUplinkTester;
175 
176  private:
178  Header m_header;
179 
181  U32 m_byteOffset;
182 
184  U16 m_dataSize;
185 
187  const U8* m_data;
188 
189  public:
191  enum { HEADERSIZE = Header::HEADERSIZE + sizeof(U32) + sizeof(U16) };
192 
194  void initialize(const U32 sequenceIndex,
195  const U32 byteOffset,
196  const U16 dataSize,
197  const U8* const data
198  );
199 
201  U32 bufferSize() const;
202 
204  SerializeStatus toBuffer(Buffer& buffer) const;
205 
207  const FilePacket::Header& asHeader() const { return this->m_header; };
208 
210  U32 getByteOffset() const { return this->m_byteOffset; };
211 
213  U32 getDataSize() const { return this->m_dataSize; };
214 
216  const U8* getData() const { return this->m_data; };
217 
218  private:
220  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
221 
223  U32 fixedLengthSize() const;
224 
226  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
227  };
228 
230  class EndPacket {
231  friend union FilePacket;
233  friend class Svc::FileUplinkTester;
234 
235  private:
237  Header m_header;
238 
239  public:
241  void setChecksum(const CFDP::Checksum& checksum);
242 
244  void getChecksum(CFDP::Checksum& checksum) const;
245 
247  U32 bufferSize() const;
248 
250  SerializeStatus toBuffer(Buffer& buffer) const;
251 
253  const FilePacket::Header& asHeader() const { return this->m_header; };
254 
255  public:
257  void initialize(const U32 sequenceIndex,
258  const CFDP::Checksum& checksum
259  );
260 
261  private:
263  U32 m_checksumValue;
264 
266  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
267 
269  SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
270  };
271 
273  class CancelPacket {
274  friend union FilePacket;
276  friend class Svc::FileUplinkTester;
277 
278  private:
280  Header m_header;
281 
282  public:
284  void initialize(const U32 sequenceIndex
285  );
286 
288  U32 bufferSize() const;
289 
291  SerializeStatus toBuffer(Buffer& buffer) const;
292 
294  const FilePacket::Header& asHeader() const { return this->m_header; };
295 
296  private:
298  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
299  };
300 
301  public:
302  // ----------------------------------------------------------------------
303  // Constructor
304  // ----------------------------------------------------------------------
305 
306  FilePacket() { this->m_header.m_type = T_NONE; }
307 
308  public:
309  // ----------------------------------------------------------------------
310  // Public instance methods
311  // ----------------------------------------------------------------------
312 
315  SerializeStatus fromBuffer(const Buffer& buffer);
316 
319  const Header& asHeader() const;
320 
323  const StartPacket& asStartPacket() const;
324 
327  const DataPacket& asDataPacket() const;
328 
331  const EndPacket& asEndPacket() const;
332 
335  const CancelPacket& asCancelPacket() const;
336 
339  void fromStartPacket(const StartPacket& startPacket);
340 
343  void fromDataPacket(const DataPacket& dataPacket);
344 
347  void fromEndPacket(const EndPacket& endPacket);
348 
351  void fromCancelPacket(const CancelPacket& cancelPacket);
352 
355  U32 bufferSize() const;
356 
359  SerializeStatus toBuffer(Buffer& buffer) const;
360 
361  private:
362  // ----------------------------------------------------------------------
363  // Private methods
364  // ----------------------------------------------------------------------
365 
368  SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
369 
370  private:
371  // ----------------------------------------------------------------------
372  // Private data
373  // ----------------------------------------------------------------------
374 
377  Header m_header;
378 
381  StartPacket m_startPacket;
382 
385  DataPacket m_dataPacket;
386 
389  EndPacket m_endPacket;
390 
393  CancelPacket m_cancelPacket;
394 };
395 
396 } // namespace Fw
397 
398 #endif
const U8 * getData() const
Get the data.
Definition: FilePacket.hpp:216
friend class Svc::FileUplinkTester
Definition: FilePacket.hpp:86
U32 bufferSize() const
Compute the buffer size needed to hold this EndPacket.
Definition: EndPacket.cpp:25
void fromCancelPacket(const CancelPacket &cancelPacket)
Definition: FilePacket.cpp:68
A variable-length serializable buffer.
friend class Svc::FileDownlinkTester
Definition: FilePacket.hpp:85
void fromDataPacket(const DataPacket &dataPacket)
Definition: FilePacket.cpp:58
SerializeStatus toBuffer(Buffer &buffer) const
Convert this DataPacket to a Buffer.
Definition: DataPacket.cpp:33
U32 bufferSize() const
Compute the buffer size needed to hold this CancelPacket.
void setChecksum(const CFDP::Checksum &checksum)
Set the checksum.
Definition: EndPacket.cpp:34
U32 bufferSize() const
Compute the buffer size needed to hold this StartPacket.
Definition: StartPacket.cpp:27
The type of a cancel packet.
Definition: FilePacket.hpp:273
const FilePacket::Header & asHeader() const
Get this as a Header.
Definition: FilePacket.hpp:207
friend class Svc::FileUplinkTester
Definition: FilePacket.hpp:46
void fromEndPacket(const EndPacket &endPacket)
Definition: FilePacket.cpp:63
U32 getByteOffset() const
Get the byte offset.
Definition: FilePacket.hpp:210
const FilePacket::Header & asHeader() const
Get this as a Header.
Definition: FilePacket.hpp:253
The type of a data packet.
Definition: FilePacket.hpp:171
friend class Svc::FileDownlinkTester
Definition: FilePacket.hpp:45
const DataPacket & asDataPacket() const
Definition: FilePacket.cpp:38
U32 getFileSize() const
Get the file size.
Definition: FilePacket.hpp:160
void getChecksum(CFDP::Checksum &checksum) const
Get the checksum.
Definition: EndPacket.cpp:38
Type
Packet type.
Definition: FilePacket.hpp:40
void fromStartPacket(const StartPacket &startPacket)
Definition: FilePacket.cpp:53
U32 getDataSize() const
Get the data size.
Definition: FilePacket.hpp:213
SerializeStatus toBuffer(Buffer &buffer) const
Definition: FilePacket.cpp:91
Type getType(void) const
Definition: FilePacket.hpp:115
const FilePacket::Header & asHeader() const
Get this as a Header.
Definition: FilePacket.hpp:294
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 EndPacket to a Buffer.
Definition: EndPacket.cpp:29
const char * getValue(void) const
Get the path name value.
Definition: FilePacket.hpp:71
Class representing a 32-bit checksum as mandated by the CCSDS File Delivery Protocol.
Definition: Checksum.hpp:53
const PathName & getDestinationPath() const
Get the destination path.
Definition: FilePacket.hpp:154
U32 bufferSize() const
Definition: FilePacket.cpp:73
friend class Svc::FileUplinkTester
Definition: FilePacket.hpp:276
const Header & asHeader() const
Definition: FilePacket.cpp:29
friend class Svc::FileDownlinkTester
Definition: FilePacket.hpp:275
SerializeStatus toBuffer(Buffer &buffer) const
Convert this StartPacket to a Buffer.
Definition: StartPacket.cpp:32
friend class Svc::FileDownlinkTester
Definition: FilePacket.hpp:232
friend class Svc::FileUplinkTester
Definition: FilePacket.hpp:233
The type of a start packet.
Definition: FilePacket.hpp:121
U32 bufferSize() const
Compute the buffer size needed to hold this DataPacket.
Definition: DataPacket.cpp:28
const StartPacket & asStartPacket() const
Definition: FilePacket.cpp:33
U32 getLength(void) const
Get the length of the path name value.
Definition: FilePacket.hpp:68
The type of a packet header.
Definition: FilePacket.hpp:82
const FilePacket::Header & asHeader() const
Get this as a Header.
Definition: FilePacket.hpp:151
const EndPacket & asEndPacket() const
Definition: FilePacket.cpp:43
U32 bufferSize() const
Compute the buffer size needed to hold this PathName.
Definition: PathName.cpp:27
The type of a path name.
Definition: FilePacket.hpp:43
friend class Svc::FileUplinkTester
Definition: FilePacket.hpp:174
void initialize(const U32 fileSize, const char *const sourcePath, const char *const destinationPath)
Initialize a StartPacket with sequence number 0.
Definition: StartPacket.cpp:18
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
SerializeStatus fromBuffer(const Buffer &buffer)
Definition: FilePacket.cpp:22
friend class Svc::FileDownlinkTester
Definition: FilePacket.hpp:173
SerializeStatus toBuffer(Buffer &buffer) const
Convert this CancelPacket to a Buffer.
friend class FilePacketTester
Definition: FilePacket.hpp:84
RateGroupDivider component implementation.
A file packet.
Definition: FilePacket.hpp:33
void initialize(const U32 sequenceIndex, const U32 byteOffset, const U16 dataSize, const U8 *const data)
Initialize a data packet.
Definition: DataPacket.cpp:18
Implementation of malloc based allocator.
U32 getSequenceIndex(void) const
Definition: FilePacket.hpp:117
void initialize(const U32 sequenceIndex, const CFDP::Checksum &checksum)
Initialize an end packet.
Definition: EndPacket.cpp:20
void initialize(const U32 sequenceIndex)
Initialize a cancel packet.
const PathName & getSourcePath() const
Get the source path.
Definition: FilePacket.hpp:157
The type of an end packet.
Definition: FilePacket.hpp:230
const CancelPacket & asCancelPacket() const
Definition: FilePacket.cpp:48