F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
BufferLogger.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title BufferLogger.hpp
3 // \author bocchino, dinkel, mereweth
4 // \brief Svc Buffer Logger interface
5 //
6 // \copyright
7 // Copyright (C) 2015-2017 California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
13 #ifndef Svc_BufferLogger_HPP
14 #define Svc_BufferLogger_HPP
15 
17 #include "Os/File.hpp"
18 #include "Fw/Types/String.hpp"
19 #include "Fw/Types/Assert.hpp"
20 #include "Os/Mutex.hpp"
21 #include "Utils/Hash/Hash.hpp"
22 
23 namespace Svc {
24 
25  class BufferLogger :
27  {
28 
29  PRIVATE:
30 
31  // ----------------------------------------------------------------------
32  // Types
33  // ----------------------------------------------------------------------
34 
36  class File {
37 
38  public:
39 
41  struct Mode {
42  typedef enum {
43  CLOSED = 0,
44  OPEN = 1
45  } t;
46  };
47 
48  public:
49 
51  File(
52  BufferLogger& bufferLogger
53  );
54 
56  ~File();
57 
58  public:
59 
61  void init(
62  const char *const prefix,
63  const char *const suffix,
64  const U32 maxSize,
65  const U8 sizeOfSize
66  );
67 
69  void setBaseName(
70  const Fw::StringBase& baseName
71  );
72 
74  void logBuffer(
75  const U8 *const data,
76  const U32 size
77  );
78 
80  void closeAndEmitEvent();
81 
83  bool flush();
84 
85  PRIVATE:
86 
88  void open();
89 
92  bool writeBuffer(
93  const U8 *const data,
94  const U32 size
95  );
96 
99  bool writeSize(
100  const U32 size
101  );
102 
105  bool writeBytes(
106  const void *const data,
107  const U32 length
108  );
109 
111  void writeHashFile();
112 
114  void close();
115 
116  PRIVATE:
117 
119  BufferLogger& m_bufferLogger;
120 
122  Fw::String m_prefix;
123 
125  Fw::String m_suffix;
126 
128  Fw::String m_baseName;
129 
131  NATIVE_UINT_TYPE m_fileCounter;
132 
134  U32 m_maxSize;
135 
137  U8 m_sizeOfSize;
138 
140  Fw::String m_name;
141 
142  // The current mode
143  Mode::t m_mode;
144 
146  Os::File m_osFile;
147 
149  U32 m_bytesWritten;
150 
151  }; // class File
152 
153  public:
154 
155  // ----------------------------------------------------------------------
156  // Construction, initialization, and destruction
157  // ----------------------------------------------------------------------
158 
160  BufferLogger(
161  const char *const compName
162  );
163 
164 
165  // ----------------------------------------------------------------------
166  // Public methods
167  // ----------------------------------------------------------------------
168 
170  void initLog(
171  const char *const logFilePrefix,
172  const char *const logFileSuffix,
173  const U32 maxFileSize,
174  const U8 sizeOfSize
175  );
176 
177  PRIVATE:
178 
179  // ----------------------------------------------------------------------
180  // Handler implementations for user-defined typed input ports
181  // ----------------------------------------------------------------------
182 
185  void bufferSendIn_handler(
186  const NATIVE_INT_TYPE portNum,
187  Fw::Buffer& fwBuffer
188  );
189 
192  void comIn_handler(
193  const NATIVE_INT_TYPE portNum,
194  Fw::ComBuffer &data,
195  U32 context
196  );
197 
200  void pingIn_handler(
201  const NATIVE_INT_TYPE portNum,
202  U32 key
203  );
204 
207  void schedIn_handler(
208  const NATIVE_INT_TYPE portNum,
209  U32 context
210  );
211 
212  PRIVATE:
213 
214  // ----------------------------------------------------------------------
215  // Command handler implementations
216  // ----------------------------------------------------------------------
217 
220  void BL_OpenFile_cmdHandler(
221  const FwOpcodeType opCode,
222  const U32 cmdSeq,
223  const Fw::CmdStringArg& file
224  );
225 
228  void BL_CloseFile_cmdHandler(
229  const FwOpcodeType opCode,
230  const U32 cmdSeq
231  );
232 
235  void BL_SetLogging_cmdHandler(
236  const FwOpcodeType opCode,
237  const U32 cmdSeq,
239  );
240 
243  void BL_FlushFile_cmdHandler(
244  const FwOpcodeType opCode,
245  const U32 cmdSeq
246  );
247 
248  PRIVATE:
249 
250  // ----------------------------------------------------------------------
251  // Private instance variables
252  // ----------------------------------------------------------------------
253 
255  BufferLogger_LogState m_state;
256 
258  File m_file;
259 
260  };
261 
262 }
263 
264 #endif
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:56
U32 FwOpcodeType
Definition: FpConfig.h:91
void init()
Object initializer.
Definition: ObjBase.cpp:27
Auto-generated base for BufferLogger component.
void initLog(const char *const logFilePrefix, const char *const logFileSuffix, const U32 maxFileSize, const U8 sizeOfSize)
Set up log file parameters.
BufferLogger(const char *const compName)
Create a BufferLogger object.