F´ Flight Software - C/C++ Documentation  devel
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 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 packetDuplicate(
166  const U32 sequenceIndex
167  );
168 
170  void fileWrite(Fw::LogStringArg& fileName);
171 
173  void badChecksum(
174  const U32 computed,
175  const U32 read
176  );
177 
178  PRIVATE:
179 
181  void warning() {
182  ++this->m_warning_count;
183  this->m_fileUplink->tlmWrite_Warnings(m_warning_count);
184  }
185 
186  PRIVATE:
187 
189  U32 m_warning_count;
190 
192  FileUplink *const m_fileUplink;
193 
194  };
195 
196  public:
197 
198  // ----------------------------------------------------------------------
199  // Construction, initialization, and destruction
200  // ----------------------------------------------------------------------
201 
204  FileUplink(
205  const char *const name
206  );
207 
210  ~FileUplink();
211 
212  PRIVATE:
213 
214  // ----------------------------------------------------------------------
215  // Handler implementations for user-defined typed input ports
216  // ----------------------------------------------------------------------
217 
220  void bufferSendIn_handler(
221  const NATIVE_INT_TYPE portNum,
222  Fw::Buffer& buffer
223  );
224 
227  void pingIn_handler(
228  const NATIVE_INT_TYPE portNum,
229  U32 key
230  );
231 
232 
233  PRIVATE:
234 
235  // ----------------------------------------------------------------------
236  // Private helper functions
237  // ----------------------------------------------------------------------
238 
240  void handleStartPacket(const Fw::FilePacket::StartPacket& startPacket);
241 
243  void handleDataPacket(const Fw::FilePacket::DataPacket& dataPacket);
244 
246  void handleEndPacket(const Fw::FilePacket::EndPacket& endPacket);
247 
249  void handleCancelPacket();
250 
252  void checkSequenceIndex(const U32 sequenceIndex);
253 
255  bool checkDuplicatedPacket(const U32 sequenceIndex);
256 
258  void compareChecksums(const Fw::FilePacket::EndPacket& endPacket);
259 
261  void goToStartMode();
262 
264  void goToDataMode();
265 
266  PRIVATE:
267 
268  // ----------------------------------------------------------------------
269  // Member variables
270  // ----------------------------------------------------------------------
271 
273  ReceiveMode m_receiveMode;
274 
276  U32 m_lastSequenceIndex;
277 
279  Os::File::Status m_lastPacketWriteStatus;
280 
282  File m_file;
283 
285  FilesReceived m_filesReceived;
286 
288  PacketsReceived m_packetsReceived;
289 
291  Warnings m_warnings;
292 
293  };
294 
295 }
296 
297 #endif
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
Class representing a 32-bit checksum as mandated by the CCSDS File Delivery Protocol.
Definition: Checksum.hpp:53
The type of a data packet.
Definition: FilePacket.hpp:197
The type of an end packet.
Definition: FilePacket.hpp:269
The type of a start packet.
Definition: FilePacket.hpp:139
Type
Packet type.
Definition: FilePacket.hpp:36