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
FileUplink.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title FileUplink.hpp
3 // \author bocchino
4 // \brief hpp file for FileUplink component implementation class
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 Svc_FileUplink_HPP
14 #define Svc_FileUplink_HPP
15 
18 #include <Os/File.hpp>
19 
20 namespace Svc {
21 
22  class FileUplink :
24  {
25 
26  PRIVATE:
27 
28  // ----------------------------------------------------------------------
29  // Types
30  // ----------------------------------------------------------------------
31 
33  typedef enum { START, DATA } ReceiveMode;
34 
36  class File {
37 
38  public:
39 
41  U32 size;
42 
44  Fw::LogStringArg name;
45 
47  Os::File osFile;
48 
49  PRIVATE:
50 
52  ::CFDP::Checksum checksum;
53 
54  public:
55 
57  Os::File::Status open(
58  const Fw::FilePacket::StartPacket& startPacket
59  );
60 
62  Os::File::Status write(
63  const U8 *const data,
64  const U32 byteOffset,
65  const U32 length
66  );
67 
69  void getChecksum(::CFDP::Checksum& checksum) {
70  checksum = this->checksum;
71  }
72 
73  };
74 
76  class FilesReceived {
77 
78  public:
79 
81  FilesReceived(FileUplink *const fileUplink) :
82  n(0), fileUplink(fileUplink)
83  { }
84 
85  public:
86 
88  void fileReceived(void) {
89  ++this->n;
90  this->fileUplink->tlmWrite_FileUplink_FilesReceived(n);
91  }
92 
93  PRIVATE:
94 
96  U32 n;
97 
99  FileUplink *const fileUplink;
100 
101  };
102 
104  class PacketsReceived {
105 
106  public:
107 
109  PacketsReceived(FileUplink *const fileUplink) :
110  n(0), fileUplink(fileUplink)
111  { }
112 
113  public:
114 
116  void packetReceived(void) {
117  ++this->n;
118  this->fileUplink->tlmWrite_FileUplink_PacketsReceived(n);
119  }
120 
121  PRIVATE:
122 
124  U32 n;
125 
127  FileUplink *const fileUplink;
128 
129  };
130 
132  class Warnings {
133 
134  public:
135 
137  Warnings(FileUplink *const fileUplink) :
138  n(0), fileUplink(fileUplink)
139  { }
140 
141  public:
142 
144  void invalidReceiveMode(const Fw::FilePacket::Type packetType);
145 
147  void fileOpen(Fw::LogStringArg& fileName);
148 
150  void packetOutOfBounds(
151  const U32 sequenceIndex,
152  Fw::LogStringArg& fileName
153  );
154 
156  void packetOutOfOrder(
157  const U32 sequenceIndex,
158  const U32 lastSequenceIndex
159  );
160 
162  void fileWrite(Fw::LogStringArg& fileName);
163 
165  void badChecksum(
166  const U32 computed,
167  const U32 read
168  );
169 
170  PRIVATE:
171 
173  void warning(void) {
174  ++this->n;
175  this->fileUplink->tlmWrite_FileUplink_Warnings(n);
176  }
177 
178  PRIVATE:
179 
181  U32 n;
182 
184  FileUplink *const fileUplink;
185 
186  };
187 
188  public:
189 
190  // ----------------------------------------------------------------------
191  // Construction, initialization, and destruction
192  // ----------------------------------------------------------------------
193 
196  FileUplink(
197  const char *const name
198  );
199 
202  void init(
203  const NATIVE_INT_TYPE queueDepth,
204  const NATIVE_INT_TYPE instance
205  );
206 
209  ~FileUplink(void);
210 
212 
213  // ----------------------------------------------------------------------
214  // Handler implementations for user-defined typed input ports
215  // ----------------------------------------------------------------------
216 
219  void bufferSendIn_handler(
220  const NATIVE_INT_TYPE portNum,
222  );
223 
226  void pingIn_handler(
227  const NATIVE_INT_TYPE portNum,
228  U32 key
229  );
230 
231 
233 
234  // ----------------------------------------------------------------------
235  // Private helper functions
236  // ----------------------------------------------------------------------
237 
239  void handleStartPacket(const Fw::FilePacket::StartPacket& startPacket);
240 
242  void handleDataPacket(const Fw::FilePacket::DataPacket& dataPacket);
243 
245  void handleEndPacket(const Fw::FilePacket::EndPacket& endPacket);
246 
248  void handleCancelPacket(void);
249 
251  void checkSequenceIndex(const U32 sequenceIndex);
252 
254  void compareChecksums(const Fw::FilePacket::EndPacket& endPacket);
255 
257  void goToStartMode(void);
258 
260  void goToDataMode(void);
261 
263 
264  // ----------------------------------------------------------------------
265  // Member variables
266  // ----------------------------------------------------------------------
267 
269  ReceiveMode receiveMode;
270 
273 
275  File file;
276 
278  FilesReceived filesReceived;
279 
281  PacketsReceived packetsReceived;
282 
284  Warnings warnings;
285 
286  };
287 
288 }
289 
290 #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::FilePacket::StartPacket
The type of a start packet.
Definition: FilePacket.hpp:118
Fw::FilePacket::DataPacket
The type of a data packet.
Definition: FilePacket.hpp:162
Fw::Buffer
Definition: BufferSerializableAc.hpp:24
Fw::FilePacket::EndPacket
The type of an end packet.
Definition: FilePacket.hpp:216
Fw::ObjBase::init
void init(void)
Object initializer.
Definition: ObjBase.cpp:26
Fw::FilePacket::Type
Type
Packet type.
Definition: FilePacket.hpp:36
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
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Os::File
Definition: File.hpp:11