F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
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 final :
24  {
25 
26  friend class FileUplinkTester;
27 
28  private:
29 
30  // ----------------------------------------------------------------------
31  // Types
32  // ----------------------------------------------------------------------
33 
35  typedef enum { START, DATA } ReceiveMode;
36 
38  class File {
39 
40  friend class FileUplinkTester;
41 
42  public:
43 
45  U32 size;
46 
48  Fw::LogStringArg name;
49 
51  Os::File osFile;
52 
53  private:
54 
56  ::CFDP::Checksum m_checksum;
57 
58  public:
59 
61  Os::File::Status open(
62  const Fw::FilePacket::StartPacket& startPacket
63  );
64 
66  Os::File::Status write(
67  const U8 *const data,
68  const U32 byteOffset,
69  const U32 length
70  );
71 
73  void getChecksum(::CFDP::Checksum& checksum) {
74  checksum = this->m_checksum;
75  }
76 
77  };
78 
80  class FilesReceived {
81 
82  friend class FileUplinkTester;
83 
84  public:
85 
87  FilesReceived(FileUplink *const fileUplink) :
88  m_received_files_counter(0),
89  m_fileUplink(fileUplink)
90  { }
91 
92  public:
93 
95  void fileReceived() {
96  ++this->m_received_files_counter;
97  this->m_fileUplink->tlmWrite_FilesReceived(m_received_files_counter);
98  }
99 
100  private:
101 
103  U32 m_received_files_counter;
104 
106  FileUplink *const m_fileUplink;
107 
108  };
109 
111  class PacketsReceived {
112 
113  friend class FileUplinkTester;
114 
115  public:
116 
118  PacketsReceived(FileUplink *const fileUplink) :
119  m_received_packet_count(0),
120  m_fileUplink(fileUplink)
121  { }
122 
123  public:
124 
126  void packetReceived() {
127  ++this->m_received_packet_count;
128  this->m_fileUplink->tlmWrite_PacketsReceived(m_received_packet_count);
129  }
130 
131  private:
132 
134  U32 m_received_packet_count;
135 
137  FileUplink *const m_fileUplink;
138 
139  };
140 
142  class Warnings {
143 
144  friend class FileUplinkTester;
145 
146  public:
147 
149  Warnings(FileUplink *const fileUplink) :
150  m_warning_count(0),
151  m_fileUplink(fileUplink)
152  { }
153 
154  public:
155 
157  void invalidReceiveMode(const Fw::FilePacket::Type packetType);
158 
160  void fileOpen(Fw::LogStringArg& fileName);
161 
163  void packetOutOfBounds(
164  const U32 sequenceIndex,
165  Fw::LogStringArg& fileName
166  );
167 
169  void packetOutOfOrder(
170  const U32 sequenceIndex,
171  const U32 lastSequenceIndex
172  );
173 
175  void packetDuplicate(
176  const U32 sequenceIndex
177  );
178 
180  void fileWrite(Fw::LogStringArg& fileName);
181 
183  void badChecksum(
184  const U32 computed,
185  const U32 read
186  );
187 
188  private:
189 
191  void warning() {
192  ++this->m_warning_count;
193  this->m_fileUplink->tlmWrite_Warnings(m_warning_count);
194  }
195 
196  private:
197 
199  U32 m_warning_count;
200 
202  FileUplink *const m_fileUplink;
203 
204  };
205 
206  public:
207 
208  // ----------------------------------------------------------------------
209  // Construction, initialization, and destruction
210  // ----------------------------------------------------------------------
211 
214  FileUplink(
215  const char *const name
216  );
217 
220  ~FileUplink();
221 
222  private:
223 
224  // ----------------------------------------------------------------------
225  // Handler implementations for user-defined typed input ports
226  // ----------------------------------------------------------------------
227 
230  void bufferSendIn_handler(
231  const FwIndexType portNum,
232  Fw::Buffer& buffer
233  );
234 
237  void pingIn_handler(
238  const FwIndexType portNum,
239  U32 key
240  );
241 
242 
243  private:
244 
245  // ----------------------------------------------------------------------
246  // Private helper functions
247  // ----------------------------------------------------------------------
248 
250  void handleStartPacket(const Fw::FilePacket::StartPacket& startPacket);
251 
253  void handleDataPacket(const Fw::FilePacket::DataPacket& dataPacket);
254 
256  void handleEndPacket(const Fw::FilePacket::EndPacket& endPacket);
257 
259  void handleCancelPacket();
260 
262  void checkSequenceIndex(const U32 sequenceIndex);
263 
265  bool checkDuplicatedPacket(const U32 sequenceIndex);
266 
268  void compareChecksums(const Fw::FilePacket::EndPacket& endPacket);
269 
271  void goToStartMode();
272 
274  void goToDataMode();
275 
276  private:
277 
278  // ----------------------------------------------------------------------
279  // Member variables
280  // ----------------------------------------------------------------------
281 
283  ReceiveMode m_receiveMode;
284 
286  U32 m_lastSequenceIndex;
287 
289  Os::File::Status m_lastPacketWriteStatus;
290 
292  File m_file;
293 
295  FilesReceived m_filesReceived;
296 
298  PacketsReceived m_packetsReceived;
299 
301  Warnings m_warnings;
302 
303  };
304 
305 }
306 
307 #endif
The type of a data packet.
Definition: FilePacket.hpp:213
Type
Packet type.
Definition: FilePacket.hpp:42
Class representing a 32-bit checksum as mandated by the CCSDS File Delivery Protocol.
Definition: Checksum.hpp:53
The type of a start packet.
Definition: FilePacket.hpp:150
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:56
PlatformIndexType FwIndexType
RateGroupDivider component implementation.
The type of an end packet.
Definition: FilePacket.hpp:287