F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
FileDownlink.hpp
Go to the documentation of this file.
1// ======================================================================
2// \title FileDownlink.hpp
3// \author bocchino, mstarch
4// \brief hpp file for FileDownlink component implementation class
5//
6// \copyright
7// Copyright 2009-2015, by the California Institute of Technology.
8// ALL RIGHTS RESERVED. United States Government Sponsorship
9// acknowledged.
10// ======================================================================
11
12#ifndef Svc_FileDownlink_HPP
13#define Svc_FileDownlink_HPP
14
15#include <FileDownlinkCfg.hpp>
18#include <Os/File.hpp>
19#include <Os/Mutex.hpp>
20#include <Os/Queue.hpp>
21
22
23namespace Svc {
24
27 {
28
29 PRIVATE:
30
31 // ----------------------------------------------------------------------
32 // Types
33 // ----------------------------------------------------------------------
34
36 class Mode {
37
38 public:
39
41 typedef enum { IDLE, DOWNLINK, CANCEL, WAIT, COOLDOWN } Type;
42
43 public:
44
46 Mode() : m_value(IDLE) { }
47
48 public:
49
51 void set(const Type value) {
52 this->m_mutex.lock();
53 this->m_value = value;
54 this->m_mutex.unLock();
55 }
56
58 Type get() {
59 this->m_mutex.lock();
60 const Type value = this->m_value;
61 this->m_mutex.unLock();
62 return value;
63 }
64
65 private:
66
68 Type m_value;
69
71 Os::Mutex m_mutex;
72 };
73
75 class File {
76
77 public:
78
80 File() : m_size(0) { }
81
82 PRIVATE:
83
85 Fw::LogStringArg m_sourceName;
86
88 Fw::LogStringArg m_destName;
89
91 Os::File m_osFile;
92
94 U32 m_size;
95
97 CFDP::Checksum m_checksum;
98
99 public:
100
102 Os::File::Status open(
103 const char *const sourceFileName,
104 const char *const destFileName
105 );
106
108 Os::File::Status read(
109 U8 *const data,
110 const U32 byteOffset,
111 const U32 size
112 );
113
115 void getChecksum(CFDP::Checksum& checksum) {
116 checksum = this->m_checksum;
117 }
118
120 Fw::LogStringArg& getSourceName(void) {
121 return this->m_sourceName;
122 }
123
125 Fw::LogStringArg& getDestName(void) {
126 return this->m_destName;
127 }
128
130 Os::File& getOsFile(void) {
131 return this->m_osFile;
132 }
133
135 U32 getSize(void) {
136 return this->m_size;
137 }
138 };
139
141 class FilesSent {
142
143 public:
144
146 FilesSent(FileDownlink *const fileDownlink) :
147 m_sent_file_count(0),
148 m_fileDownlink(fileDownlink)
149 { }
150
151 public:
152
154 void fileSent() {
155 ++this->m_sent_file_count;
156 this->m_fileDownlink->tlmWrite_FilesSent(m_sent_file_count);
157 }
158
159 PRIVATE:
160
162 U32 m_sent_file_count;
163
165 FileDownlink *const m_fileDownlink;
166
167 };
168
170 class PacketsSent {
171
172 public:
173
175 PacketsSent(FileDownlink *const fileDownlink) :
176 m_sent_packet_count(0),
177 m_fileDownlink(fileDownlink)
178 { }
179
180 public:
181
183 void packetSent() {
184 ++this->m_sent_packet_count;
185 this->m_fileDownlink->tlmWrite_PacketsSent(m_sent_packet_count);
186 }
187
188 PRIVATE:
189
191 U32 m_sent_packet_count;
192
194 FileDownlink *const m_fileDownlink;
195
196 };
197
199 class Warnings {
200
201 public:
202
204 Warnings(FileDownlink *const fileDownlink) :
205 m_warning_count(0),
206 m_fileDownlink(fileDownlink)
207 { }
208
209 public:
210
212 void fileOpenError();
213
215 void fileRead(const Os::File::Status status);
216
217 PRIVATE:
218
220 void warning() {
221 ++this->m_warning_count;
222 this->m_fileDownlink->tlmWrite_Warnings(m_warning_count);
223 }
224
225 PRIVATE:
226
228 U32 m_warning_count;
229
231 FileDownlink *const m_fileDownlink;
232
233 };
234
236 enum CallerSource { COMMAND, PORT };
237
238 #define FILE_ENTRY_FILENAME_LEN 101
239
241 struct FileEntry {
242 char srcFilename[FILE_ENTRY_FILENAME_LEN]; // Name of requested file
243 char destFilename[FILE_ENTRY_FILENAME_LEN]; // Name of requested file
244 U32 offset;
245 U32 length;
246 CallerSource source; // Source of the downlink request
247 FwOpcodeType opCode; // Op code of command, only set for CMD sources.
248 U32 cmdSeq; // CmdSeq number, only set for CMD sources.
249 U32 context; // Context id of request, only set for PORT sources.
250 };
251
254 enum PacketType {
255 FILE_PACKET,
256 CANCEL_PACKET,
257 COUNT_PACKET_TYPE
258 };
259
260 public:
261
262 // ----------------------------------------------------------------------
263 // Construction, initialization, and destruction
264 // ----------------------------------------------------------------------
265
269 const char *const compName
270 );
271
274 void configure(
275 U32 timeout,
276 U32 cooldown,
277 U32 cycleTime,
278 U32 fileQueueDepth
279 );
280
284 void preamble();
285
289
290 PRIVATE:
291
292 // ----------------------------------------------------------------------
293 // Handler implementations for user-defined typed input ports
294 // ----------------------------------------------------------------------
295
298 void Run_handler(
299 const NATIVE_INT_TYPE portNum,
300 U32 context
301 );
302
303
306 Svc::SendFileResponse SendFile_handler(
307 const NATIVE_INT_TYPE portNum,
308 const Fw::StringBase& sourceFilename,
309 const Fw::StringBase& destFilename,
310 U32 offset,
311 U32 length
312 );
313
316 void bufferReturn_handler(
317 const NATIVE_INT_TYPE portNum,
318 Fw::Buffer &fwBuffer
319 );
320
323 void pingIn_handler(
324 const NATIVE_INT_TYPE portNum,
325 U32 key
326 );
327
328
329
330 PRIVATE:
331
332 // ----------------------------------------------------------------------
333 // Command handler implementations
334 // ----------------------------------------------------------------------
335
338 void SendFile_cmdHandler(
339 const FwOpcodeType opCode,
340 const U32 cmdSeq,
341 const Fw::CmdStringArg& sourceFilename,
342 const Fw::CmdStringArg& destFilename
343 );
344
347 void Cancel_cmdHandler(
348 const FwOpcodeType opCode,
349 const U32 cmdSeq
350 );
351
354 void SendPartial_cmdHandler(
355 FwOpcodeType opCode,
356 U32 cmdSeq,
357 const Fw::CmdStringArg& sourceFilename,
358 const Fw::CmdStringArg& destFilename,
359 U32 startOffset,
360 U32 length
361 );
362
363
364 PRIVATE:
365
366 // ----------------------------------------------------------------------
367 // Private helper methods
368 // ----------------------------------------------------------------------
369
370
371 void sendFile(
372 const char* sourceFilename,
373 const char* destFilename,
374 U32 startOffset,
375 U32 length
376 );
377
378 //Individual packet transfer functions
379 Os::File::Status sendDataPacket(U32 &byteOffset);
380 void sendCancelPacket();
381 void sendEndPacket();
382 void sendStartPacket();
383 void sendFilePacket(const Fw::FilePacket& filePacket);
384
385 //State-helper functions
386 void exitFileTransfer();
387 void enterCooldown();
388
389 //Function to acquire a buffer internally
390 void getBuffer(Fw::Buffer& buffer, PacketType type);
391 //Downlink the "next" packet
392 void downlinkPacket();
393 //Finish the file transfer
394 void finishHelper(bool is_cancel);
395 // Convert internal status enum to a command response;
396 Fw::CmdResponse statusToCmdResp(SendFileStatus status);
397 //Send response after completing file downlink
398 void sendResponse(SendFileStatus resp);
399
400 PRIVATE:
401
402 // ----------------------------------------------------------------------
403 // Member variables
404 // ----------------------------------------------------------------------
405
407 bool m_configured;
408
410 Os::Queue m_fileQueue;
411
413 U8 m_memoryStore[COUNT_PACKET_TYPE][FILEDOWNLINK_INTERNAL_BUFFER_SIZE];
414
416 Mode m_mode;
417
419 File m_file;
420
422 FilesSent m_filesSent;
423
425 PacketsSent m_packetsSent;
426
428 Warnings m_warnings;
429
431 U32 m_sequenceIndex;
432
434 U32 m_timeout;
435
437 U32 m_cooldown;
438
440 U32 m_curTimer;
441
443 U32 m_cycleTime;
444
446 Fw::Buffer m_buffer;
447
449 U32 m_bufferSize;
450
452 U32 m_byteOffset;
453
455 U32 m_endOffset;
456
458 Fw::FilePacket::Type m_lastCompletedType;
459
461 U32 m_lastBufferId;
462
464 struct FileEntry m_curEntry;
465
467 U32 m_cntxId;
468 };
469
470} // end namespace Svc
471
472#endif
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:55
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:30
U32 FwOpcodeType
Definition FpConfig.h:91
Class representing a 32-bit checksum as mandated by the CCSDS File Delivery Protocol.
Definition Checksum.hpp:53
Enum representing a command response.
static const U32 FILEDOWNLINK_INTERNAL_BUFFER_SIZE
A file packet.
Type
Packet type.