F´ Flight Software - C/C++ Documentation devel
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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>
15
16#include <limits.h>
17#include <cstdio>
18#include <cstdarg>
19
20// some limits.h don't have PATH_MAX
21#ifdef PATH_MAX
22#define COMLOGGER_PATH_MAX PATH_MAX
23#else
24#define COMLOGGER_PATH_MAX 255
25#endif
26
27// some limits.h don't have NAME_MAX
28#ifdef NAME_MAX
29#define COMLOGGER_NAME_MAX NAME_MAX
30#else
31#define COMLOGGER_NAME_MAX 255
32#endif
33
34namespace Svc {
35
36 class ComLogger :
38 {
39 // ----------------------------------------------------------------------
40 // Construction, initialization, and destruction
41 // ----------------------------------------------------------------------
42
43 public:
44
45 // CONSTRUCTOR:
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 ComLogger(const char* compName, const char* filePrefix, U32 maxFileSize, bool storeBufferLength=true);
54
55 // CONSTRUCTOR:
56 ComLogger(const char* compName);
57
58 void init(
59 NATIVE_INT_TYPE queueDepth,
60 NATIVE_INT_TYPE instance
61 );
62
63 // filePrefix: string to prepend the file name with, ie. "thermal_telemetry"
64 // maxFileSize: the maximum size a file should reach before being closed and a new one opened
65 // storeBufferLength: if true, store the length of each com buffer before storing the buffer itself,
66 // otherwise just store the com buffer. false might be advantageous in a system
67 // where you can ensure that all buffers given to the ComLogger are the same size
68 // in which case you do not need the overhead. Or you store an id which you can
69 // match to an expected size on the ground during post processing.
70 void init_log_file(const char* filePrefix, U32 maxFileSize, bool storeBufferLength=true);
71
72 ~ComLogger();
73
74 // ----------------------------------------------------------------------
75 // Handler implementations
76 // ----------------------------------------------------------------------
77
78 PRIVATE:
79
80 void comIn_handler(
81 NATIVE_INT_TYPE portNum,
82 Fw::ComBuffer &data,
83 U32 context
84 );
85
86 void CloseFile_cmdHandler(
87 FwOpcodeType opCode,
88 U32 cmdSeq
89 );
90
93 void pingIn_handler(
94 const NATIVE_INT_TYPE portNum,
95 U32 key
96 );
97
98 // ----------------------------------------------------------------------
99 // Constants:
100 // ----------------------------------------------------------------------
101 // The maximum size of a filename
102 enum {
103 MAX_FILENAME_SIZE = COMLOGGER_NAME_MAX,
104 MAX_PATH_SIZE = COMLOGGER_PATH_MAX
105 };
106
107 // The filename data:
108 CHAR filePrefix[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
109 U32 maxFileSize;
110
111 // ----------------------------------------------------------------------
112 // Internal state:
113 // ----------------------------------------------------------------------
114 enum FileMode {
115 CLOSED = 0,
116 OPEN = 1
117 };
118
119 FileMode fileMode;
120 Os::File file;
121 CHAR fileName[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
122 CHAR hashFileName[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
123 U32 byteCount;
124 bool writeErrorOccurred;
125 bool openErrorOccurred;
126 bool storeBufferLength;
127 bool initialized;
128
129 // ----------------------------------------------------------------------
130 // File functions:
131 // ----------------------------------------------------------------------
132 void openFile(
133 );
134
135 void closeFile(
136 );
137
138 void writeComBufferToFile(
139 Fw::ComBuffer &data,
140 U16 size
141 );
142
143 // ----------------------------------------------------------------------
144 // Helper functions:
145 // ----------------------------------------------------------------------
146
147 bool writeToFile(
148 void* data,
149 U16 length
150 );
151
152 void writeHashFile(
153 );
154 };
155};
156
157#endif
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
char CHAR
Definition BasicTypes.h:28
#define COMLOGGER_PATH_MAX
Definition ComLogger.hpp:24
#define COMLOGGER_NAME_MAX
Definition ComLogger.hpp:31
U32 FwOpcodeType
Definition FpConfig.h:56
void init()
Object initializer.
Definition ObjBase.cpp:27
Auto-generated base for ComLogger component.
void init_log_file(const char *filePrefix, U32 maxFileSize, bool storeBufferLength=true)
Definition ComLogger.cpp:61
ComLogger(const char *compName, const char *filePrefix, U32 maxFileSize, bool storeBufferLength=true)
Definition ComLogger.cpp:21