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