F´ Flight Software - C/C++ Documentation NASA-v1.6.0
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 public:
55
58
60 const char *value;
61
62 public:
63
65 void initialize(
66 const char *const value
67 );
68
70 U32 bufferSize() 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() 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
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() 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
163
164 friend union FilePacket;
165
166 public:
167
170
173
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() const;
198
200 SerializeStatus toBuffer(Buffer& buffer) const;
201
202 PRIVATE:
203
205 SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
206
208 U32 fixedLengthSize() 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() 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
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() 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() { 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() const;
309
312 const StartPacket& asStartPacket() const;
313
316 const DataPacket& asDataPacket() const;
317
320 const EndPacket& asEndPacket() const;
321
324 const CancelPacket& asCancelPacket() 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() 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
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.
SerializeStatus toBuffer(Buffer &buffer) const
Convert this CancelPacket to a Buffer.
Header header
The packet header.
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.
Header header
The packet header.
U32 byteOffset
The byte offset of the packet data into the destination file.
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.
U16 dataSize
The size of the file data in the packet.
const U8 * data
Pointer to the file data.
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
void getChecksum(CFDP::Checksum &checksum) const
Get the checksum.
Definition EndPacket.cpp:54
Header header
The packet header.
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 sequenceIndex
The sequence index.
Type type
The packet type.
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 * value
Pointer to the path value.
A variable-length serializable buffer.
Definition Buffer.cpp:21
SerializeStatus
forward declaration for string
The type of a start packet.
SerializeStatus toBuffer(Buffer &buffer) const
Convert this StartPacket to a Buffer.
Header header
The packet header.
PathName sourcePath
The source path.
U32 bufferSize() const
Compute the buffer size needed to hold this StartPacket.
U32 fileSize
The file size.
void initialize(const U32 fileSize, const char *const sourcePath, const char *const destinationPath)
Initialize a StartPacket with sequence number 0.
PathName destinationPath
The destination 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