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  ~FileUplink();
206 
207  PRIVATE:
208 
209  // ----------------------------------------------------------------------
210  // Handler implementations for user-defined typed input ports
211  // ----------------------------------------------------------------------
212 
215  void bufferSendIn_handler(
216  const NATIVE_INT_TYPE portNum,
217  Fw::Buffer& buffer
218  );
219 
222  void pingIn_handler(
223  const NATIVE_INT_TYPE portNum,
224  U32 key
225  );
226 
227 
228  PRIVATE:
229 
230  // ----------------------------------------------------------------------
231  // Private helper functions
232  // ----------------------------------------------------------------------
233 
235  void handleStartPacket(const Fw::FilePacket::StartPacket& startPacket);
236 
238  void handleDataPacket(const Fw::FilePacket::DataPacket& dataPacket);
239 
241  void handleEndPacket(const Fw::FilePacket::EndPacket& endPacket);
242 
244  void handleCancelPacket();
245 
247  void checkSequenceIndex(const U32 sequenceIndex);
248 
250  void compareChecksums(const Fw::FilePacket::EndPacket& endPacket);
251 
253  void goToStartMode();
254 
256  void goToDataMode();
257 
258  PRIVATE:
259 
260  // ----------------------------------------------------------------------
261  // Member variables
262  // ----------------------------------------------------------------------
263 
265  ReceiveMode m_receiveMode;
266 
268  U32 m_lastSequenceIndex;
269 
271  File m_file;
272 
274  FilesReceived m_filesReceived;
275 
277  PacketsReceived m_packetsReceived;
278 
280  Warnings m_warnings;
281 
282  };
283 
284 }
285 
286 #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