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
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
23namespace Svc {
24
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
161 const char *const compName
162 );
163
165 void init(
166 const NATIVE_INT_TYPE queueDepth,
167 const NATIVE_INT_TYPE instance
168 );
169
170 // ----------------------------------------------------------------------
171 // Public methods
172 // ----------------------------------------------------------------------
173
175 void initLog(
176 const char *const logFilePrefix,
177 const char *const logFileSuffix,
178 const U32 maxFileSize,
179 const U8 sizeOfSize
180 );
181
182 PRIVATE:
183
184 // ----------------------------------------------------------------------
185 // Handler implementations for user-defined typed input ports
186 // ----------------------------------------------------------------------
187
190 void bufferSendIn_handler(
191 const NATIVE_INT_TYPE portNum,
192 Fw::Buffer& fwBuffer
193 );
194
197 void comIn_handler(
198 const NATIVE_INT_TYPE portNum,
199 Fw::ComBuffer &data,
200 U32 context
201 );
202
205 void pingIn_handler(
206 const NATIVE_INT_TYPE portNum,
207 U32 key
208 );
209
212 void schedIn_handler(
213 const NATIVE_INT_TYPE portNum,
214 NATIVE_UINT_TYPE context
215 );
216
217 PRIVATE:
218
219 // ----------------------------------------------------------------------
220 // Command handler implementations
221 // ----------------------------------------------------------------------
222
225 void BL_OpenFile_cmdHandler(
226 const FwOpcodeType opCode,
227 const U32 cmdSeq,
228 const Fw::CmdStringArg& file
229 );
230
233 void BL_CloseFile_cmdHandler(
234 const FwOpcodeType opCode,
235 const U32 cmdSeq
236 );
237
240 void BL_SetLogging_cmdHandler(
241 const FwOpcodeType opCode,
242 const U32 cmdSeq,
244 );
245
248 void BL_FlushFile_cmdHandler(
249 const FwOpcodeType opCode,
250 const U32 cmdSeq
251 );
252
253 PRIVATE:
254
255 // ----------------------------------------------------------------------
256 // Private instance variables
257 // ----------------------------------------------------------------------
258
260 BufferLogger_LogState m_state;
261
263 File m_file;
264
265 };
266
267}
268
269#endif
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:26
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
U32 FwOpcodeType
Definition FpConfig.h:56
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.