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>
19 
20 namespace Svc {
21 
22 class FileUplink final : public FileUplinkComponentBase {
23  friend class FileUplinkTester;
24 
25  private:
26  // ----------------------------------------------------------------------
27  // Types
28  // ----------------------------------------------------------------------
29 
31  typedef enum { START, DATA } ReceiveMode;
32 
34  class File {
35  friend class FileUplinkTester;
36 
37  public:
39  U32 size;
40 
42  Fw::LogStringArg name;
43 
45  Os::File osFile;
46 
47  private:
49  ::CFDP::Checksum m_checksum;
50 
51  public:
53  Os::File::Status open(const Fw::FilePacket::StartPacket& startPacket);
54 
56  Os::File::Status write(const U8* const data, const U32 byteOffset, const U32 length);
57 
59  void getChecksum(::CFDP::Checksum& checksum) { checksum = this->m_checksum; }
60  };
61 
63  class FilesReceived {
64  friend class FileUplinkTester;
65 
66  public:
68  FilesReceived(FileUplink* const fileUplink) : m_received_files_counter(0), m_fileUplink(fileUplink) {}
69 
70  public:
72  void fileReceived() {
73  ++this->m_received_files_counter;
74  this->m_fileUplink->tlmWrite_FilesReceived(m_received_files_counter);
75  }
76 
77  private:
79  U32 m_received_files_counter;
80 
82  FileUplink* const m_fileUplink;
83  };
84 
86  class PacketsReceived {
87  friend class FileUplinkTester;
88 
89  public:
91  PacketsReceived(FileUplink* const fileUplink) : m_received_packet_count(0), m_fileUplink(fileUplink) {}
92 
93  public:
95  void packetReceived() {
96  ++this->m_received_packet_count;
97  this->m_fileUplink->tlmWrite_PacketsReceived(m_received_packet_count);
98  }
99 
100  private:
102  U32 m_received_packet_count;
103 
105  FileUplink* const m_fileUplink;
106  };
107 
109  class Warnings {
110  friend class FileUplinkTester;
111 
112  public:
114  Warnings(FileUplink* const fileUplink) : m_warning_count(0), m_fileUplink(fileUplink) {}
115 
116  public:
118  void invalidReceiveMode(const Fw::FilePacket::Type packetType);
119 
121  void fileOpen(Fw::LogStringArg& fileName);
122 
124  void packetOutOfBounds(const U32 sequenceIndex, Fw::LogStringArg& fileName);
125 
127  void packetOutOfOrder(const U32 sequenceIndex, const U32 lastSequenceIndex);
128 
130  void packetDuplicate(const U32 sequenceIndex);
131 
133  void fileWrite(Fw::LogStringArg& fileName);
134 
136  void badChecksum(const U32 computed, const U32 read);
137 
138  private:
140  void warning() {
141  ++this->m_warning_count;
142  this->m_fileUplink->tlmWrite_Warnings(m_warning_count);
143  }
144 
145  private:
147  U32 m_warning_count;
148 
150  FileUplink* const m_fileUplink;
151  };
152 
153  public:
154  // ----------------------------------------------------------------------
155  // Construction, initialization, and destruction
156  // ----------------------------------------------------------------------
157 
160  FileUplink(const char* const name
161  );
162 
165  ~FileUplink();
166 
167  private:
168  // ----------------------------------------------------------------------
169  // Handler implementations for user-defined typed input ports
170  // ----------------------------------------------------------------------
171 
174  void bufferSendIn_handler(const FwIndexType portNum,
175  Fw::Buffer& buffer
176  );
177 
180  void pingIn_handler(const FwIndexType portNum,
181  U32 key
182  );
183 
184  private:
185  // ----------------------------------------------------------------------
186  // Private helper functions
187  // ----------------------------------------------------------------------
188 
190  void handleStartPacket(const Fw::FilePacket::StartPacket& startPacket);
191 
193  void handleDataPacket(const Fw::FilePacket::DataPacket& dataPacket);
194 
196  void handleEndPacket(const Fw::FilePacket::EndPacket& endPacket);
197 
199  void handleCancelPacket();
200 
202  void checkSequenceIndex(const U32 sequenceIndex);
203 
205  bool checkDuplicatedPacket(const U32 sequenceIndex);
206 
208  void compareChecksums(const Fw::FilePacket::EndPacket& endPacket);
209 
211  void goToStartMode();
212 
214  void goToDataMode();
215 
216  private:
217  // ----------------------------------------------------------------------
218  // Member variables
219  // ----------------------------------------------------------------------
220 
222  ReceiveMode m_receiveMode;
223 
225  U32 m_lastSequenceIndex;
226 
228  Os::File::Status m_lastPacketWriteStatus;
229 
231  File m_file;
232 
234  FilesReceived m_filesReceived;
235 
237  PacketsReceived m_packetsReceived;
238 
240  Warnings m_warnings;
241 };
242 
243 } // namespace Svc
244 
245 #endif
The type of a data packet.
Definition: FilePacket.hpp:171
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:53
PlatformIndexType FwIndexType
RateGroupDivider component implementation.
The type of an end packet.
Definition: FilePacket.hpp:230