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  friend class ComLoggerTester;
26 
27  // ----------------------------------------------------------------------
28  // Construction, initialization, and destruction
29  // ----------------------------------------------------------------------
30 
31  public:
32 
33  // CONSTRUCTOR:
34  // filePrefix: string to prepend the file name with, ie. "thermal_telemetry"
35  // maxFileSize: the maximum size a file should reach before being closed and a new one opened
36  // storeBufferLength: if true, store the length of each com buffer before storing the buffer itself,
37  // otherwise just store the com buffer. false might be advantageous in a system
38  // where you can ensure that all buffers given to the ComLogger are the same size
39  // in which case you do not need the overhead. Or you store an id which you can
40  // match to an expected size on the ground during post processing.
41  ComLogger(const char* compName, const char* filePrefix, U32 maxFileSize, bool storeBufferLength=true);
42 
43  // CONSTRUCTOR:
44  ComLogger(const char* compName);
45 
46  // filePrefix: string to prepend the file name with, ie. "thermal_telemetry"
47  // maxFileSize: the maximum size a file should reach before being closed and a new one opened
48  // storeBufferLength: if true, store the length of each com buffer before storing the buffer itself,
49  // otherwise just store the com buffer. false might be advantageous in a system
50  // where you can ensure that all buffers given to the ComLogger are the same size
51  // in which case you do not need the overhead. Or you store an id which you can
52  // match to an expected size on the ground during post processing.
53  void init_log_file(const char* filePrefix, U32 maxFileSize, bool storeBufferLength=true);
54 
55  ~ComLogger();
56 
57  // ----------------------------------------------------------------------
58  // Handler implementations
59  // ----------------------------------------------------------------------
60 
61  private:
62 
63  void comIn_handler(
64  FwIndexType portNum,
65  Fw::ComBuffer &data,
66  U32 context
67  );
68 
69  void CloseFile_cmdHandler(
70  FwOpcodeType opCode,
71  U32 cmdSeq
72  );
73 
76  void pingIn_handler(
77  const FwIndexType portNum,
78  U32 key
79  );
80 
81  // The filename data:
82  Fw::FileNameString m_filePrefix;
83  U32 m_maxFileSize;
84 
85  // ----------------------------------------------------------------------
86  // Internal state:
87  // ----------------------------------------------------------------------
88  enum FileMode {
89  CLOSED = 0,
90  OPEN = 1
91  };
92 
93  FileMode m_fileMode;
94  Os::File m_file;
95 
96  Fw::FileNameString m_fileName;
97  Fw::FileNameString m_hashFileName;
98  U32 m_byteCount;
99  bool m_writeErrorOccurred;
100  bool m_openErrorOccurred;
101  bool m_storeBufferLength;
102  bool m_initialized;
103 
104  // ----------------------------------------------------------------------
105  // File functions:
106  // ----------------------------------------------------------------------
107  void openFile(
108  );
109 
110  void closeFile(
111  );
112 
113  void writeComBufferToFile(
114  Fw::ComBuffer &data,
115  U16 size
116  );
117 
118  // ----------------------------------------------------------------------
119  // Helper functions:
120  // ----------------------------------------------------------------------
121 
122  bool writeToFile(
123  void* data,
124  U16 length
125  );
126 
127  void writeHashFile(
128  );
129  };
130 }
131 
132 #endif
FwIdType FwOpcodeType
The type of a command opcode.
friend class ComLoggerTester
Definition: ComLogger.hpp:25
void init_log_file(const char *filePrefix, U32 maxFileSize, bool storeBufferLength=true)
Definition: ComLogger.cpp:52
PlatformIndexType FwIndexType
RateGroupDivider component implementation.
ComLogger(const char *compName, const char *filePrefix, U32 maxFileSize, bool storeBufferLength=true)
Definition: ComLogger.cpp:22
Auto-generated base for ComLogger component.