GCC Code Coverage Report


Directory: Fw/FilePacket/
File: FilePacket.hpp
Date: 2026-09-03 21:14:53
Exec Total Coverage
Lines: 15 15 100.0%
Functions: 15 15 100.0%
Branches: 1 2 50.0%

Line Branch Exec Source
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
16 #include <CFDP/Checksum/Checksum.hpp>
17 #include <Fw/Buffer/Buffer.hpp>
18 #include <Fw/FPrimeBasicTypes.hpp>
19 #include <Fw/Types/SerialBuffer.hpp>
20 #include <Fw/Types/Serializable.hpp>
21
22 // Forward declaration for UTs
23 namespace Svc {
24 class FileUplinkTester;
25 class FileDownlinkTester;
26 } // namespace Svc
27
28 namespace Fw {
29
30 //! \class FilePacket
31 //! \brief A file packet
32 //!
33 union FilePacket {
34 public:
35 // ----------------------------------------------------------------------
36 // Types
37 // ----------------------------------------------------------------------
38
39 //! Packet type
40 typedef enum { T_START = 0, T_DATA = 1, T_END = 2, T_CANCEL = 3, T_NONE = 255 } Type;
41
42 //! The type of a path name
43 class PathName {
44 friend union FilePacket;
45 friend class Svc::FileDownlinkTester;
46 friend class Svc::FileUplinkTester;
47
48 public:
49 //! The maximum length of a path name
50 enum { MAX_LENGTH = 255 };
51
52 private:
53 //! The length
54 U8 m_length;
55
56 //! Pointer to the path value
57 const char* m_value;
58
59 public:
60 //! Initialize a PathName
61 void initialize(const char* const value //! The path value
62 );
63
64 //! Compute the buffer size needed to hold this PathName
65 U32 bufferSize() const;
66
67 //! Get the length of the path name value
68 8 U32 getLength(void) const { return this->m_length; };
69
70 //! Get the path name value
71 4 const char* getValue(void) const { return this->m_value; };
72
73 private:
74 //! Initialize this PathName from a SerialBuffer
75 SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
76
77 //! Write this PathName to a SerialBuffer
78 SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
79 };
80
81 //! The type of a packet header
82 class Header {
83 friend union FilePacket;
84 friend class FilePacketTester;
85 friend class Svc::FileDownlinkTester;
86 friend class Svc::FileUplinkTester;
87
88 private:
89 //! The packet type
90 Type m_type;
91
92 //! The sequence index
93 U32 m_sequenceIndex;
94
95 public:
96 //! Header size
97 enum { HEADERSIZE = sizeof(U8) + sizeof(U32) };
98
99 private:
100 //! Initialize a file packet header
101 void initialize(const Type type, //!< The packet type
102 const U32 sequenceIndex //!< The sequence index
103 );
104
105 //! Compute the buffer size needed to hold this Header
106 U32 bufferSize() const;
107
108 //! Initialize this Header from a SerialBuffer
109 SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
110
111 //! Write this Header to a SerialBuffer
112 SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
113
114 public:
115
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 Type getType(void) const { return this->m_type; };
116
117 10 U32 getSequenceIndex(void) const { return this->m_sequenceIndex; };
118 };
119
120 //! The type of a start packet
121 struct StartPacket {
122 friend union FilePacket;
123
124 private:
125 //! The packet header
126 Header m_header;
127
128 //! The file size
129 U32 m_fileSize;
130
131 //! The source path
132 PathName m_sourcePath;
133
134 //! The destination path
135 PathName m_destinationPath;
136
137 public:
138 //! Initialize a StartPacket with sequence number 0
139 void initialize(const U32 fileSize, //!< The file size
140 const char* const sourcePath, //!< The source path
141 const char* const destinationPath //!< The destination path
142 );
143
144 //! Compute the buffer size needed to hold this StartPacket
145 U32 bufferSize() const;
146
147 //! Convert this StartPacket to a Buffer
148 SerializeStatus toBuffer(Buffer& buffer) const;
149
150 //! Get this as a Header
151 2 const FilePacket::Header& asHeader() const { return this->m_header; };
152
153 //! Get the destination path
154 2 const PathName& getDestinationPath() const { return this->m_destinationPath; };
155
156 //! Get the source path
157 2 const PathName& getSourcePath() const { return this->m_sourcePath; };
158
159 //! Get the file size
160 2 U32 getFileSize() const { return this->m_fileSize; };
161
162 private:
163 //! Initialize this StartPacket from a SerialBuffer
164 SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
165
166 //! Write this StartPacket to a SerialBuffer
167 SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
168 };
169
170 //! The type of a data packet
171 class DataPacket {
172 friend union FilePacket;
173 friend class Svc::FileDownlinkTester;
174 friend class Svc::FileUplinkTester;
175
176 private:
177 //! The packet header
178 Header m_header;
179
180 //! The byte offset of the packet data into the destination file
181 U32 m_byteOffset;
182
183 //! The size of the file data in the packet
184 U16 m_dataSize;
185
186 //! Pointer to the file data
187 const U8* m_data;
188
189 public:
190 //! header size
191 enum { HEADERSIZE = Header::HEADERSIZE + sizeof(U32) + sizeof(U16) };
192
193 //! Initialize a data packet
194 void initialize(const U32 sequenceIndex, //!< The sequence index
195 const U32 byteOffset, //!< The byte offset
196 const U16 dataSize, //!< The data size
197 const U8* const data //!< The file data
198 );
199
200 //! Compute the buffer size needed to hold this DataPacket
201 U32 bufferSize() const;
202
203 //! Convert this DataPacket to a Buffer
204 SerializeStatus toBuffer(Buffer& buffer) const;
205
206 //! Get this as a Header
207 2 const FilePacket::Header& asHeader() const { return this->m_header; };
208
209 //! Get the byte offset
210 2 U32 getByteOffset() const { return this->m_byteOffset; };
211
212 //! Get the data size
213 2 U32 getDataSize() const { return this->m_dataSize; };
214
215 //! Get the data
216 2 const U8* getData() const { return this->m_data; };
217
218 private:
219 //! Initialize this DataPacket from a SerialBuffer
220 SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
221
222 //! Compute the fixed-length data size of a StartPacket
223 U32 fixedLengthSize() const;
224
225 //! Write this DataPacket to a SerialBuffer
226 SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
227 };
228
229 //! The type of an end packet
230 class EndPacket {
231 friend union FilePacket;
232 friend class Svc::FileDownlinkTester;
233 friend class Svc::FileUplinkTester;
234
235 private:
236 //! The packet header
237 Header m_header;
238
239 public:
240 //! Set the checksum
241 void setChecksum(const CFDP::Checksum& checksum);
242
243 //! Get the checksum
244 void getChecksum(CFDP::Checksum& checksum) const;
245
246 //! Compute the buffer size needed to hold this EndPacket
247 U32 bufferSize() const;
248
249 //! Convert this EndPacket to a Buffer
250 SerializeStatus toBuffer(Buffer& buffer) const;
251
252 //! Get this as a Header
253 2 const FilePacket::Header& asHeader() const { return this->m_header; };
254
255 public:
256 //! Initialize an end packet
257 void initialize(const U32 sequenceIndex, //!< The sequence index
258 const CFDP::Checksum& checksum //!< The checksum
259 );
260
261 private:
262 //! The checksum
263 U32 m_checksumValue;
264
265 //! Initialize this EndPacket from a SerialBuffer
266 SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
267
268 //! Write this EndPacket to a SerialBuffer
269 SerializeStatus toSerialBuffer(SerialBuffer& serialBuffer) const;
270 };
271
272 //! The type of a cancel packet
273 class CancelPacket {
274 friend union FilePacket;
275 friend class Svc::FileDownlinkTester;
276 friend class Svc::FileUplinkTester;
277
278 private:
279 //! The packet header
280 Header m_header;
281
282 public:
283 //! Initialize a cancel packet
284 void initialize(const U32 sequenceIndex //!< The sequence index
285 );
286
287 //! Compute the buffer size needed to hold this CancelPacket
288 U32 bufferSize() const;
289
290 //! Convert this CancelPacket to a Buffer
291 SerializeStatus toBuffer(Buffer& buffer) const;
292
293 //! Get this as a Header
294 2 const FilePacket::Header& asHeader() const { return this->m_header; };
295
296 private:
297 //! Initialize this CancelPacket from a SerialBuffer
298 SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
299 };
300
301 public:
302 // ----------------------------------------------------------------------
303 // Constructor
304 // ----------------------------------------------------------------------
305
306 4 FilePacket() { this->m_header.m_type = T_NONE; }
307
308 public:
309 // ----------------------------------------------------------------------
310 // Public instance methods
311 // ----------------------------------------------------------------------
312
313 //! Initialize this from a Buffer
314 //!
315 SerializeStatus fromBuffer(const Buffer& buffer);
316
317 //! Get this as a Header
318 //!
319 const Header& asHeader() const;
320
321 //! Get this as a StartPacket
322 //!
323 const StartPacket& asStartPacket() const;
324
325 //! Get this as a DataPacket
326 //!
327 const DataPacket& asDataPacket() const;
328
329 //! Get this as an EndPacket
330 //!
331 const EndPacket& asEndPacket() const;
332
333 //! Get this as a CancelPacket
334 //!
335 const CancelPacket& asCancelPacket() const;
336
337 //! Initialize this with a StartPacket
338 //!
339 void fromStartPacket(const StartPacket& startPacket);
340
341 //! Initialize this with a DataPacket
342 //!
343 void fromDataPacket(const DataPacket& dataPacket);
344
345 //! Initialize this with an EndPacket
346 //!
347 void fromEndPacket(const EndPacket& endPacket);
348
349 //! Initialize this with a CancelPacket
350 //!
351 void fromCancelPacket(const CancelPacket& cancelPacket);
352
353 //! Get the buffer size needed to hold this FilePacket
354 //!
355 U32 bufferSize() const;
356
357 //! Convert this FilePacket to a Buffer
358 //!
359 SerializeStatus toBuffer(Buffer& buffer) const;
360
361 private:
362 // ----------------------------------------------------------------------
363 // Private methods
364 // ----------------------------------------------------------------------
365
366 //! Initialize this from a SerialBuffer
367 //!
368 SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
369
370 private:
371 // ----------------------------------------------------------------------
372 // Private data
373 // ----------------------------------------------------------------------
374
375 //! this, seen as a header
376 //!
377 Header m_header;
378
379 //! this, seen as a Start packet
380 //!
381 StartPacket m_startPacket;
382
383 //! this, seen as a Data packet
384 //!
385 DataPacket m_dataPacket;
386
387 //! this, seen as an End packet
388 //!
389 EndPacket m_endPacket;
390
391 //! this, seen as a Cancel packet
392 //!
393 CancelPacket m_cancelPacket;
394 };
395
396 } // namespace Fw
397
398 #endif
399