F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ComLogger.hpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // ComLogger.hpp
4 //
5 // ----------------------------------------------------------------------
6 
7 #ifndef Svc_ComLogger_HPP
8 #define Svc_ComLogger_HPP
9 
11 #include <Os/File.hpp>
12 #include <Os/Mutex.hpp>
13 #include <Fw/Types/Assert.hpp>
14 #include <Utils/Hash/Hash.hpp>
16 #include <limits.h>
17 #include <cstdio>
18 #include <cstdarg>
19 
20 namespace Svc {
21 
22  class ComLogger final :
24  {
25  // ----------------------------------------------------------------------
26  // Construction, initialization, and destruction
27  // ----------------------------------------------------------------------
28 
29  public:
30 
31  // CONSTRUCTOR:
32  // filePrefix: string to prepend the file name with, ie. "thermal_telemetry"
33  // maxFileSize: the maximum size a file should reach before being closed and a new one opened
34  // storeBufferLength: if true, store the length of each com buffer before storing the buffer itself,
35  // otherwise just store the com buffer. false might be advantageous in a system
36  // where you can ensure that all buffers given to the ComLogger are the same size
37  // in which case you do not need the overhead. Or you store an id which you can
38  // match to an expected size on the ground during post processing.
39  ComLogger(const char* compName, const char* filePrefix, U32 maxFileSize, bool storeBufferLength=true);
40 
41  // CONSTRUCTOR:
42  ComLogger(const char* compName);
43 
44  // filePrefix: string to prepend the file name with, ie. "thermal_telemetry"
45  // maxFileSize: the maximum size a file should reach before being closed and a new one opened
46  // storeBufferLength: if true, store the length of each com buffer before storing the buffer itself,
47  // otherwise just store the com buffer. false might be advantageous in a system
48  // where you can ensure that all buffers given to the ComLogger are the same size
49  // in which case you do not need the overhead. Or you store an id which you can
50  // match to an expected size on the ground during post processing.
51  void init_log_file(const char* filePrefix, U32 maxFileSize, bool storeBufferLength=true);
52 
53  ~ComLogger();
54 
55  // ----------------------------------------------------------------------
56  // Handler implementations
57  // ----------------------------------------------------------------------
58 
59  PRIVATE:
60 
61  void comIn_handler(
62  FwIndexType portNum,
63  Fw::ComBuffer &data,
64  U32 context
65  );
66 
67  void CloseFile_cmdHandler(
68  FwOpcodeType opCode,
69  U32 cmdSeq
70  );
71 
74  void pingIn_handler(
75  const FwIndexType portNum,
76  U32 key
77  );
78 
79  // The filename data:
80  Fw::FileNameString m_filePrefix;
81  U32 m_maxFileSize;
82 
83  // ----------------------------------------------------------------------
84  // Internal state:
85  // ----------------------------------------------------------------------
86  enum FileMode {
87  CLOSED = 0,
88  OPEN = 1
89  };
90 
91  FileMode m_fileMode;
92  Os::File m_file;
93 
94  Fw::FileNameString m_fileName;
95  Fw::FileNameString m_hashFileName;
96  U32 m_byteCount;
97  bool m_writeErrorOccurred;
98  bool m_openErrorOccurred;
99  bool m_storeBufferLength;
100  bool m_initialized;
101 
102  // ----------------------------------------------------------------------
103  // File functions:
104  // ----------------------------------------------------------------------
105  void openFile(
106  );
107 
108  void closeFile(
109  );
110 
111  void writeComBufferToFile(
112  Fw::ComBuffer &data,
113  U16 size
114  );
115 
116  // ----------------------------------------------------------------------
117  // Helper functions:
118  // ----------------------------------------------------------------------
119 
120  bool writeToFile(
121  void* data,
122  U16 length
123  );
124 
125  void writeHashFile(
126  );
127  };
128 }
129 
130 #endif
void init_log_file(const char *filePrefix, U32 maxFileSize, bool storeBufferLength=true)
Definition: ComLogger.cpp:51
PlatformIndexType FwIndexType
Definition: FpConfig.h:25
U32 FwOpcodeType
Definition: FpConfig.h:91
ComLogger(const char *compName, const char *filePrefix, U32 maxFileSize, bool storeBufferLength=true)
Definition: ComLogger.cpp:21
Auto-generated base for ComLogger component.