F´ Flight Software - C/C++ Documentation  devel
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 :
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 m_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->m_checksum;
71  }
72 
73  };
74 
76  class FilesReceived {
77 
78  public:
79 
81  FilesReceived(FileUplink *const fileUplink) :
82  m_received_files_counter(0),
83  m_fileUplink(fileUplink)
84  { }
85 
86  public:
87 
89  void fileReceived() {
90  ++this->m_received_files_counter;
91  this->m_fileUplink->tlmWrite_FilesReceived(m_received_files_counter);
92  }
93 
94  PRIVATE:
95 
97  U32 m_received_files_counter;
98 
100  FileUplink *const m_fileUplink;
101 
102  };
103 
105  class PacketsReceived {
106 
107  public:
108 
110  PacketsReceived(FileUplink *const fileUplink) :
111  m_received_packet_count(0),
112  m_fileUplink(fileUplink)
113  { }
114 
115  public:
116 
118  void packetReceived() {
119  ++this->m_received_packet_count;
120  this->m_fileUplink->tlmWrite_PacketsReceived(m_received_packet_count);
121  }
122 
123  PRIVATE:
124 
126  U32 m_received_packet_count;
127 
129  FileUplink *const m_fileUplink;
130 
131  };
132 
134  class Warnings {
135 
136  public:
137 
139  Warnings(FileUplink *const fileUplink) :
140  m_warning_count(0),
141  m_fileUplink(fileUplink)
142  { }
143 
144  public:
145 
147  void invalidReceiveMode(const Fw::FilePacket::Type packetType);
148 
150  void fileOpen(Fw::LogStringArg& fileName);
151 
153  void packetOutOfBounds(
154  const U32 sequenceIndex,
155  Fw::LogStringArg& fileName
156  );
157 
159  void packetOutOfOrder(
160  const U32 sequenceIndex,
161  const U32 lastSequenceIndex
162  );
163 
165  void fileWrite(Fw::LogStringArg& fileName);
166 
168  void badChecksum(
169  const U32 computed,
170  const U32 read
171  );
172 
173  PRIVATE:
174 
176  void warning() {
177  ++this->m_warning_count;
178  this->m_fileUplink->tlmWrite_Warnings(m_warning_count);
179  }
180 
181  PRIVATE:
182 
184  U32 m_warning_count;
185 
187  FileUplink *const m_fileUplink;
188 
189  };
190 
191  public:
192 
193  // ----------------------------------------------------------------------
194  // Construction, initialization, and destruction
195  // ----------------------------------------------------------------------
196 
199  FileUplink(
200  const char *const name
201  );
202 
205  void init(
206  const NATIVE_INT_TYPE queueDepth,
207  const NATIVE_INT_TYPE instance
208  );
209 
212  ~FileUplink();
213 
214  PRIVATE:
215 
216  // ----------------------------------------------------------------------
217  // Handler implementations for user-defined typed input ports
218  // ----------------------------------------------------------------------
219 
222  void bufferSendIn_handler(
223  const NATIVE_INT_TYPE portNum,
224  Fw::Buffer& buffer
225  );
226 
229  void pingIn_handler(
230  const NATIVE_INT_TYPE portNum,
231  U32 key
232  );
233 
234 
235  PRIVATE:
236 
237  // ----------------------------------------------------------------------
238  // Private helper functions
239  // ----------------------------------------------------------------------
240 
242  void handleStartPacket(const Fw::FilePacket::StartPacket& startPacket);
243 
245  void handleDataPacket(const Fw::FilePacket::DataPacket& dataPacket);
246 
248  void handleEndPacket(const Fw::FilePacket::EndPacket& endPacket);
249 
251  void handleCancelPacket();
252 
254  void checkSequenceIndex(const U32 sequenceIndex);
255 
257  void compareChecksums(const Fw::FilePacket::EndPacket& endPacket);
258 
260  void goToStartMode();
261 
263  void goToDataMode();
264 
265  PRIVATE:
266 
267  // ----------------------------------------------------------------------
268  // Member variables
269  // ----------------------------------------------------------------------
270 
272  ReceiveMode m_receiveMode;
273 
275  U32 m_lastSequenceIndex;
276 
278  File m_file;
279 
281  FilesReceived m_filesReceived;
282 
284  PacketsReceived m_packetsReceived;
285 
287  Warnings m_warnings;
288 
289  };
290 
291 }
292 
293 #endif
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
Class representing a CFDP checksum.
Definition: Checksum.hpp:23
The type of a data packet.
Definition: FilePacket.hpp:197
The type of an end packet.
Definition: FilePacket.hpp:269
void init()
Object initializer.
Definition: ObjBase.cpp:27
The type of a start packet.
Definition: FilePacket.hpp:139
Type
Packet type.
Definition: FilePacket.hpp:36