F´ Flight Software - C/C++ Documentation devel
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 init(
275 const NATIVE_INT_TYPE queueDepth,
276 const NATIVE_INT_TYPE instance
277 );
278
281 void configure(
282 U32 timeout,
283 U32 cooldown,
284 U32 cycleTime,
285 U32 fileQueueDepth
286 );
287
291 void preamble();
292
296
297 PRIVATE:
298
299 // ----------------------------------------------------------------------
300 // Handler implementations for user-defined typed input ports
301 // ----------------------------------------------------------------------
302
305 void Run_handler(
306 const NATIVE_INT_TYPE portNum,
307 NATIVE_UINT_TYPE context
308 );
309
310
313 Svc::SendFileResponse SendFile_handler(
314 const NATIVE_INT_TYPE portNum,
315 const sourceFileNameString& sourceFilename,
316 const destFileNameString& destFilename,
317 U32 offset,
318 U32 length
319 );
320
323 void bufferReturn_handler(
324 const NATIVE_INT_TYPE portNum,
325 Fw::Buffer &fwBuffer
326 );
327
330 void pingIn_handler(
331 const NATIVE_INT_TYPE portNum,
332 U32 key
333 );
334
335
336
337 PRIVATE:
338
339 // ----------------------------------------------------------------------
340 // Command handler implementations
341 // ----------------------------------------------------------------------
342
345 void SendFile_cmdHandler(
346 const FwOpcodeType opCode,
347 const U32 cmdSeq,
348 const Fw::CmdStringArg& sourceFilename,
349 const Fw::CmdStringArg& destFilename
350 );
351
354 void Cancel_cmdHandler(
355 const FwOpcodeType opCode,
356 const U32 cmdSeq
357 );
358
361 void SendPartial_cmdHandler(
362 FwOpcodeType opCode,
363 U32 cmdSeq,
364 const Fw::CmdStringArg& sourceFilename,
365 const Fw::CmdStringArg& destFilename,
366 U32 startOffset,
367 U32 length
368 );
369
370
371 PRIVATE:
372
373 // ----------------------------------------------------------------------
374 // Private helper methods
375 // ----------------------------------------------------------------------
376
377
378 void sendFile(
379 const char* sourceFilename,
380 const char* destFilename,
381 U32 startOffset,
382 U32 length
383 );
384
385 //Individual packet transfer functions
386 Os::File::Status sendDataPacket(U32 &byteOffset);
387 void sendCancelPacket();
388 void sendEndPacket();
389 void sendStartPacket();
390 void sendFilePacket(const Fw::FilePacket& filePacket);
391
392 //State-helper functions
393 void exitFileTransfer();
394 void enterCooldown();
395
396 //Function to acquire a buffer internally
397 void getBuffer(Fw::Buffer& buffer, PacketType type);
398 //Downlink the "next" packet
399 void downlinkPacket();
400 //Finish the file transfer
401 void finishHelper(bool is_cancel);
402 // Convert internal status enum to a command response;
403 Fw::CmdResponse statusToCmdResp(SendFileStatus status);
404 //Send response after completing file downlink
405 void sendResponse(SendFileStatus resp);
406
407 PRIVATE:
408
409 // ----------------------------------------------------------------------
410 // Member variables
411 // ----------------------------------------------------------------------
412
414 bool m_configured;
415
417 Os::Queue m_fileQueue;
418
420 U8 m_memoryStore[COUNT_PACKET_TYPE][FILEDOWNLINK_INTERNAL_BUFFER_SIZE];
421
423 Mode m_mode;
424
426 File m_file;
427
429 FilesSent m_filesSent;
430
432 PacketsSent m_packetsSent;
433
435 Warnings m_warnings;
436
438 U32 m_sequenceIndex;
439
441 U32 m_timeout;
442
444 U32 m_cooldown;
445
447 U32 m_curTimer;
448
450 U32 m_cycleTime;
451
453 Fw::Buffer m_buffer;
454
456 U32 m_bufferSize;
457
459 U32 m_byteOffset;
460
462 U32 m_endOffset;
463
465 Fw::FilePacket::Type m_lastCompletedType;
466
468 U32 m_lastBufferId;
469
471 struct FileEntry m_curEntry;
472
474 U32 m_cntxId;
475 };
476
477} // end namespace Svc
478
479#endif
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:26
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
U32 FwOpcodeType
Definition FpConfig.h:56
Class representing a CFDP checksum.
Definition Checksum.hpp:23
Enum representing a command response.
void init()
Object initializer.
Definition ObjBase.cpp:27
void unLock()
unlock the mutex
Definition Mutex.cpp:13
void lock()
lock the mutex
Definition Mutex.cpp:12
SendFileRequestPortStrings::StringSize100 sourceFileNameString
SendFileRequestPortStrings::StringSize100 destFileNameString
static const U32 FILEDOWNLINK_INTERNAL_BUFFER_SIZE
A file packet.
Type
Packet type.