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 
17 #include <Os/File.hpp>
18 #include <Os/SandboxedFile.hpp>
20 
21 namespace Svc {
22 
23 class FileUplink final : public FileUplinkComponentBase {
24  friend class FileUplinkTester;
25 
26  private:
27  // ----------------------------------------------------------------------
28  // Types
29  // ----------------------------------------------------------------------
30 
32  typedef enum { START, DATA } ReceiveMode;
33 
35  class File {
36  friend class FileUplinkTester;
37 
38  public:
40  U32 size;
41 
43  Fw::LogStringArg name;
44 
46  Os::SandboxedFile osFile;
47 
48  private:
50  ::CFDP::Checksum m_checksum;
51 
52  public:
54  Os::File::Status open(const Fw::FilePacket::StartPacket& startPacket);
55 
58  Os::File::Status write(const U8* const data, const U32 byteOffset, const U32 length);
59 
61  void getChecksum(::CFDP::Checksum& checksum) { checksum = this->m_checksum; }
62  };
63 
65  class FilesReceived {
66  friend class FileUplinkTester;
67 
68  public:
70  FilesReceived(FileUplink* const fileUplink) : m_received_files_counter(0), m_fileUplink(fileUplink) {}
71 
72  public:
74  void fileReceived() {
75  ++this->m_received_files_counter;
76  this->m_fileUplink->tlmWrite_FilesReceived(m_received_files_counter);
77  }
78 
79  private:
81  U32 m_received_files_counter;
82 
84  FileUplink* const m_fileUplink;
85  };
86 
88  class FilesReceivedFailed {
89  friend class FileUplinkTester;
90 
91  public:
93  FilesReceivedFailed(FileUplink* const fileUplink) : m_failed_files_counter(0), m_fileUplink(fileUplink) {}
94 
95  public:
97  void fileReceivedFailed() {
98  ++this->m_failed_files_counter;
99  this->m_fileUplink->tlmWrite_FilesReceivedFailed(m_failed_files_counter);
100  }
101 
102  private:
104  U32 m_failed_files_counter;
105 
107  FileUplink* const m_fileUplink;
108  };
109 
111  class PacketsReceived {
112  friend class FileUplinkTester;
113 
114  public:
116  PacketsReceived(FileUplink* const fileUplink) : m_received_packet_count(0), m_fileUplink(fileUplink) {}
117 
118  public:
120  void packetReceived() {
121  ++this->m_received_packet_count;
122  this->m_fileUplink->tlmWrite_PacketsReceived(m_received_packet_count);
123  }
124 
125  private:
127  U32 m_received_packet_count;
128 
130  FileUplink* const m_fileUplink;
131  };
132 
134  class Warnings {
135  friend class FileUplinkTester;
136 
137  public:
139  Warnings(FileUplink* const fileUplink) : m_warning_count(0), m_fileUplink(fileUplink) {}
140 
141  public:
143  void invalidReceiveMode(const Fw::FilePacket::Type packetType);
144 
146  void fileOpen(Fw::LogStringArg& fileName);
147 
149  void packetOutOfBounds(const U32 sequenceIndex, Fw::LogStringArg& fileName);
150 
152  void packetOutOfOrder(const U32 sequenceIndex, const U32 lastSequenceIndex);
153 
155  void packetDuplicate(const U32 sequenceIndex);
156 
158  void fileWrite(Fw::LogStringArg& fileName);
159 
161  void badChecksum(const U32 computed, const U32 read);
162 
163  private:
165  void warning() {
166  ++this->m_warning_count;
167  this->m_fileUplink->tlmWrite_Warnings(m_warning_count);
168  }
169 
170  private:
172  U32 m_warning_count;
173 
175  FileUplink* const m_fileUplink;
176  };
177 
178  public:
179  // ----------------------------------------------------------------------
180  // Construction, initialization, and destruction
181  // ----------------------------------------------------------------------
182 
185  FileUplink(const char* const name
186  );
187 
190  ~FileUplink();
191 
201  void configure(const char* directory);
202 
203  private:
204  // ----------------------------------------------------------------------
205  // Handler implementations for user-defined typed input ports
206  // ----------------------------------------------------------------------
207 
210  void bufferSendIn_handler(const FwIndexType portNum,
211  Fw::Buffer& buffer
212  );
213 
216  void pingIn_handler(const FwIndexType portNum,
217  U32 key
218  );
219 
220  private:
221  // ----------------------------------------------------------------------
222  // Private helper functions
223  // ----------------------------------------------------------------------
224 
226  void handleStartPacket(const Fw::FilePacket::StartPacket& startPacket);
227 
229  void handleDataPacket(const Fw::FilePacket::DataPacket& dataPacket);
230 
232  void handleEndPacket(const Fw::FilePacket::EndPacket& endPacket);
233 
235  void handleCancelPacket();
236 
238  void checkSequenceIndex(const U32 sequenceIndex);
239 
241  bool checkDuplicatedPacket(const U32 sequenceIndex);
242 
244  bool compareChecksums(const Fw::FilePacket::EndPacket& endPacket);
245 
247  void goToStartMode();
248 
250  void goToDataMode();
251 
252  private:
253  // ----------------------------------------------------------------------
254  // Member variables
255  // ----------------------------------------------------------------------
256 
258  ReceiveMode m_receiveMode;
259 
261  U32 m_lastSequenceIndex;
262 
264  Os::File::Status m_lastPacketWriteStatus;
265 
267  File m_file;
268 
270  FilesReceived m_filesReceived;
271 
273  FilesReceivedFailed m_filesReceivedFailed;
274 
276  PacketsReceived m_packetsReceived;
277 
279  Warnings m_warnings;
280 };
281 
282 } // namespace Svc
283 
284 #endif
The type of a data packet.
Definition: FilePacket.hpp:171
A wrapper around Os::File that restricts file access to an allowed directory.
Type
Packet type.
Definition: FilePacket.hpp:40
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:121
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
PlatformIndexType FwIndexType
RateGroupDivider component implementation.
The type of an end packet.
Definition: FilePacket.hpp:230