F´ Flight Software - C/C++ Documentation  NASA-v1.6.0
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 "Svc/ComLogger/ComLoggerComponentAc.hpp"
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 namespace Svc {
28 
29  class ComLogger :
30  public ComLoggerComponentBase
31  {
32  // ----------------------------------------------------------------------
33  // Construction, initialization, and destruction
34  // ----------------------------------------------------------------------
35 
36  public:
37 
38  // CONSTRUCTOR:
39  // filePrefix: string to prepend the file name with, ie. "thermal_telemetry"
40  // maxFileSize: the maximum size a file should reach before being closed and a new one opened
41  // storeBufferLength: if true, store the length of each com buffer before storing the buffer itself,
42  // otherwise just store the com buffer. false might be advantageous in a system
43  // where you can ensure that all buffers given to the ComLogger are the same size
44  // in which case you do not need the overhead. Or you store an id which you can
45  // match to an expected size on the ground during post processing.
46  ComLogger(const char* compName, const char* filePrefix, U32 maxFileSize, bool storeBufferLength=true);
47 
48  void init(
49  NATIVE_INT_TYPE queueDepth,
50  NATIVE_INT_TYPE instance
51  );
52 
53  ~ComLogger();
54 
55  // ----------------------------------------------------------------------
56  // Handler implementations
57  // ----------------------------------------------------------------------
58 
59  PRIVATE:
60 
61  void comIn_handler(
62  NATIVE_INT_TYPE 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 NATIVE_INT_TYPE portNum,
76  U32 key
77  );
78 
79  // ----------------------------------------------------------------------
80  // Constants:
81  // ----------------------------------------------------------------------
82  // The maximum size of a filename
83  enum {
84  MAX_FILENAME_SIZE = NAME_MAX, // as defined in limits.h
85  MAX_PATH_SIZE = COMLOGGER_PATH_MAX
86  };
87 
88  // The filename data:
89  CHAR filePrefix[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
90  U32 maxFileSize;
91 
92  // ----------------------------------------------------------------------
93  // Internal state:
94  // ----------------------------------------------------------------------
95  enum FileMode {
96  CLOSED = 0,
97  OPEN = 1
98  };
99 
100  FileMode fileMode;
101  Os::File file;
102  CHAR fileName[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
103  CHAR hashFileName[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
104  U32 byteCount;
105  bool writeErrorOccurred;
106  bool openErrorOccurred;
107  bool storeBufferLength;
108 
109  // ----------------------------------------------------------------------
110  // File functions:
111  // ----------------------------------------------------------------------
112  void openFile(
113  );
114 
115  void closeFile(
116  );
117 
118  void writeComBufferToFile(
119  Fw::ComBuffer &data,
120  U16 size
121  );
122 
123  // ----------------------------------------------------------------------
124  // Helper functions:
125  // ----------------------------------------------------------------------
126 
127  bool writeToFile(
128  void* data,
129  U16 length
130  );
131 
132  void writeHashFile(
133  );
134  };
135 };
136 
137 #endif
Svc::ComLogger::ComLogger
ComLogger(const char *compName, const char *filePrefix, U32 maxFileSize, bool storeBufferLength=true)
Definition: ComLogger.cpp:21
Svc::ComLogger::~ComLogger
~ComLogger()
Definition: ComLogger.cpp:53
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:27
COMLOGGER_PATH_MAX
#define COMLOGGER_PATH_MAX
Definition: ComLogger.hpp:24
CHAR
char CHAR
Definition: BasicTypes.hpp:99
Hash.hpp
FwOpcodeType
#define FwOpcodeType
Type representation for a command opcode.
Definition: FpConfig.hpp:62
Svc::ComLogger::init
void init(NATIVE_INT_TYPE queueDepth, NATIVE_INT_TYPE instance)
Definition: ComLogger.cpp:44
File.hpp
Svc
Definition: ActiveRateGroupCfg.hpp:18
Mutex.hpp
Fw::ComBuffer
Definition: ComBuffer.hpp:21
Os::File
Definition: File.hpp:11
Svc::ComLogger
Definition: ComLogger.hpp:29