F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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
22namespace Fw {
23
27 union FilePacket {
28
29 public:
30
31 // ----------------------------------------------------------------------
32 // Types
33 // ----------------------------------------------------------------------
34
36 typedef enum {
38 T_DATA = 1,
39 T_END = 2,
41 T_NONE = 255
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
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
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
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
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
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
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
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:30
C++-compatible configuration header for fprime configuration.
Class representing a 32-bit checksum as mandated by the CCSDS File Delivery Protocol.
Definition Checksum.hpp:53
The type of a cancel packet.
const FilePacket::Header & asHeader() const
Get this as a Header.
SerializeStatus toBuffer(Buffer &buffer) const
Convert this CancelPacket to a Buffer.
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.
SerializeStatus toBuffer(Buffer &buffer) const
Convert this DataPacket to a Buffer.
void initialize(const U32 sequenceIndex, const U32 byteOffset, const U16 dataSize, const U8 *const data)
Initialize a data packet.
const FilePacket::Header & asHeader() const
Get this as a Header.
U32 getByteOffset() const
Get the byte offset.
const U8 * getData() const
Get the data.
U32 getDataSize() const
Get the data size.
U32 bufferSize() const
Compute the buffer size needed to hold this DataPacket.
The type of an end packet.
U32 bufferSize() const
Compute the buffer size needed to hold this EndPacket.
Definition EndPacket.cpp:31
const FilePacket::Header & asHeader() const
Get this as a Header.
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
SerializeStatus toBuffer(Buffer &buffer) const
Convert this EndPacket to a Buffer.
Definition EndPacket.cpp:37
The type of a packet header.
U32 getSequenceIndex(void) const
Type getType(void) const
The type of a path name.
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.
U32 getLength(void) const
Get the length of the path name value.
A variable-length serializable buffer.
SerializeStatus
forward declaration for string
The type of a start packet.
SerializeStatus toBuffer(Buffer &buffer) const
Convert this StartPacket to a Buffer.
const PathName & getDestinationPath() const
Get the destination path.
U32 getFileSize() const
Get the file size.
U32 bufferSize() const
Compute the buffer size needed to hold this StartPacket.
void initialize(const U32 fileSize, const char *const sourcePath, const char *const destinationPath)
Initialize a StartPacket with sequence number 0.
const PathName & getSourcePath() const
Get the source path.
A file packet.
SerializeStatus fromBuffer(const Buffer &buffer)
void fromCancelPacket(const CancelPacket &cancelPacket)
void fromEndPacket(const EndPacket &endPacket)
const CancelPacket & asCancelPacket() const
const StartPacket & asStartPacket() const
const EndPacket & asEndPacket() const
void fromDataPacket(const DataPacket &dataPacket)
Type
Packet type.
void fromStartPacket(const StartPacket &startPacket)
const DataPacket & asDataPacket() const
U32 bufferSize() const
const Header & asHeader() const
SerializeStatus toBuffer(Buffer &buffer) const