F´ Flight Software - C/C++ Documentation  NASA-v1.5.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FileDownlink.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title FileDownlink.hpp
3 // \author bocchino
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 
13 #ifndef Svc_FileDownlink_HPP
14 #define Svc_FileDownlink_HPP
15 
18 #include <Os/File.hpp>
19 #include <Os/Mutex.hpp>
20 
21 namespace Svc {
22 
23  class FileDownlink :
25  {
26 
27  PRIVATE:
28 
29  // ----------------------------------------------------------------------
30  // Types
31  // ----------------------------------------------------------------------
32 
34  class Mode {
35 
36  public:
37 
39  typedef enum { IDLE, DOWNLINK, CANCEL } Type;
40 
41  public:
42 
44  Mode(void) : value(IDLE) { }
45 
46  public:
47 
49  void set(const Type value) {
50  this->mutex.lock();
51  this->value = value;
52  this->mutex.unLock();
53  }
54 
56  Type get(void) {
57  this->mutex.lock();
58  const Type value = this->value;
59  this->mutex.unLock();
60  return value;
61  }
62 
63  private:
64 
66  Type value;
67 
69  Os::Mutex mutex;
70 
71  };
72 
74  class File {
75 
76  public:
77 
79  File() : size(0) { }
80 
81  public:
82 
84  Fw::LogStringArg sourceName;
85 
87  Fw::LogStringArg destName;
88 
90  Os::File osFile;
91 
93  U32 size;
94 
95  PRIVATE:
96 
98  ::CFDP::Checksum checksum;
99 
100  public:
101 
103  Os::File::Status open(
104  const char *const sourceFileName,
105  const char *const destFileName
106  );
107 
109  Os::File::Status read(
110  U8 *const data,
111  const U32 byteOffset,
112  const U32 size
113  );
114 
116  void getChecksum(::CFDP::Checksum& checksum) {
117  checksum = this->checksum;
118  }
119 
120  };
121 
123  class FilesSent {
124 
125  public:
126 
128  FilesSent(FileDownlink *const fileDownlink) :
129  n(0), fileDownlink(fileDownlink)
130  { }
131 
132  public:
133 
135  void fileSent(void) {
136  ++this->n;
137  this->fileDownlink->tlmWrite_FileDownlink_FilesSent(n);
138  }
139 
140  PRIVATE:
141 
143  U32 n;
144 
146  FileDownlink *const fileDownlink;
147 
148  };
149 
151  class PacketsSent {
152 
153  public:
154 
156  PacketsSent(FileDownlink *const fileDownlink) :
157  n(0), fileDownlink(fileDownlink)
158  { }
159 
160  public:
161 
163  void packetSent(void) {
164  ++this->n;
165  this->fileDownlink->tlmWrite_FileDownlink_PacketsSent(n);
166  }
167 
168  PRIVATE:
169 
171  U32 n;
172 
174  FileDownlink *const fileDownlink;
175 
176  };
177 
179  class Warnings {
180 
181  public:
182 
184  Warnings(FileDownlink *const fileDownlink) :
185  n(0), fileDownlink(fileDownlink)
186  { }
187 
188  public:
189 
191  void fileOpenError(void);
192 
194  void fileRead(void);
195 
196  PRIVATE:
197 
199  void warning(void) {
200  ++this->n;
201  this->fileDownlink->tlmWrite_FileDownlink_Warnings(n);
202  }
203 
204  PRIVATE:
205 
207  U32 n;
208 
210  FileDownlink *const fileDownlink;
211 
212  };
213 
214  public:
215 
216  // ----------------------------------------------------------------------
217  // Construction, initialization, and destruction
218  // ----------------------------------------------------------------------
219 
222  FileDownlink(
223  const char *const compName,
224  const U16 downlinkPacketSize
225  );
226 
229  void init(
230  const NATIVE_INT_TYPE queueDepth,
231  const NATIVE_INT_TYPE instance
232  );
233 
236  ~FileDownlink(void);
237 
239 
240  // ----------------------------------------------------------------------
241  // Command handler implementations
242  // ----------------------------------------------------------------------
243 
246  void FileDownlink_SendFile_cmdHandler(
247  const FwOpcodeType opCode,
248  const U32 cmdSeq,
251  );
252 
256  const FwOpcodeType opCode,
257  const U32 cmdSeq
258  );
259 
262  void pingIn_handler(
263  const NATIVE_INT_TYPE portNum,
264  U32 key
265  );
266 
267 
269 
270  // ----------------------------------------------------------------------
271  // Private helper methods
272  // ----------------------------------------------------------------------
273 
274  Os::File::Status sendDataPacket(const U32 byteOffset);
275 
277 
278  void sendCancelPacket(void);
279 
280  void sendEndPacket(void);
281 
282  void sendStartPacket(void);
283 
284  void sendFilePacket(const Fw::FilePacket& filePacket);
285 
287 
288  // ----------------------------------------------------------------------
289  // Member variables
290  // ----------------------------------------------------------------------
291 
293  const U32 downlinkPacketSize;
294 
297 
299  File file;
300 
302  FilesSent filesSent;
303 
305  PacketsSent packetsSent;
306 
308  Warnings warnings;
309 
312 
313  };
314 
315 } // end namespace Svc
316 
317 #endif
PRIVATE
#define PRIVATE
overridable private for unit testing
Definition: BasicTypes.hpp:118
Fw::LogStringArg
Definition: LogString.hpp:11
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Fw::CmdStringArg
Definition: CmdString.hpp:11
Fw::FilePacket
A file packet.
Definition: FilePacket.hpp:27
Fw::ObjBase::init
void init(void)
Object initializer.
Definition: ObjBase.cpp:26
Os::Mutex
Definition: Mutex.hpp:8
FwOpcodeType
#define FwOpcodeType
Type representation for a command opcode.
Definition: FpConfig.hpp:62
File.hpp
CFDP::Checksum
Class representing a CFDP checksum.
Definition: Checksum.hpp:23
FilePacket.hpp
Svc
Definition: ActiveLoggerComponentAc.cpp:22
Os::File::Status
Status
Definition: File.hpp:24
Mutex.hpp
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Os::File
Definition: File.hpp:11