F´ Flight Software - C/C++ Documentation  NASA-v1.5.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 
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 <stdio.h>
18 #include <cstdarg>
19 
20 namespace Svc {
21 
22  class ComLogger :
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  void init(
42  NATIVE_INT_TYPE queueDepth,
43  NATIVE_INT_TYPE instance
44  );
45 
46  ~ComLogger(void);
47 
48  // ----------------------------------------------------------------------
49  // Handler implementations
50  // ----------------------------------------------------------------------
51 
53 
54  void comIn_handler(
57  U32 context
58  );
59 
61  FwOpcodeType opCode,
62  U32 cmdSeq
63  );
64 
67  void pingIn_handler(
68  const NATIVE_INT_TYPE portNum,
69  U32 key
70  );
71 
72  // ----------------------------------------------------------------------
73  // Constants:
74  // ----------------------------------------------------------------------
75  // The maximum size of a filename
76  enum {
77  MAX_FILENAME_SIZE = NAME_MAX, // as defined in limits.h
78  MAX_PATH_SIZE = PATH_MAX
79  };
80 
81  // The filename data:
84 
85  // ----------------------------------------------------------------------
86  // Internal state:
87  // ----------------------------------------------------------------------
88  enum FileMode {
89  CLOSED = 0,
90  OPEN = 1
91  };
92 
97  U32 byteCount;
101 
102  // ----------------------------------------------------------------------
103  // File functions:
104  // ----------------------------------------------------------------------
105  void openFile(
106  );
107 
108  void closeFile(
109  );
110 
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
Svc::ComLogger::ComLogger
ComLogger(const char *compName, const char *filePrefix, U32 maxFileSize, bool storeBufferLength=true)
Definition: ComLogger.cpp:20
Svc::ComLogger::hashFileName
U8 hashFileName[MAX_FILENAME_SIZE+MAX_PATH_SIZE]
Definition: ComLogger.hpp:96
Svc::ComLoggerComponentBase::portNum
PRIVATE NATIVE_INT_TYPE portNum
Definition: ComLoggerComponentAc.hpp:657
PRIVATE
#define PRIVATE
overridable private for unit testing
Definition: BasicTypes.hpp:118
Svc::ComLogger::closeFile
void closeFile()
Definition: ComLogger.cpp:184
Svc::ComLogger::writeComBufferToFile
void writeComBufferToFile(Fw::ComBuffer &data, U16 size)
Definition: ComLogger.cpp:204
Svc::ComLogger::file
Os::File file
Definition: ComLogger.hpp:94
Svc::ComLogger::context
PRIVATE Fw::ComBuffer U32 context
Definition: ComLogger.hpp:58
Svc::ComLogger::openFile
void openFile()
Definition: ComLogger.cpp:141
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Svc::ComLogger::openErrorOccured
bool openErrorOccured
Definition: ComLogger.hpp:99
Assert.hpp
Svc::ComLogger::byteCount
U32 byteCount
Definition: ComLogger.hpp:97
Svc::ComLogger::storeBufferLength
bool storeBufferLength
Definition: ComLogger.hpp:100
Fw::ObjBase::init
void init(void)
Object initializer.
Definition: ObjBase.cpp:26
Svc::ComLogger::CLOSED
@ CLOSED
Definition: ComLogger.hpp:89
Svc::ComLogger::fileName
U8 fileName[MAX_FILENAME_SIZE+MAX_PATH_SIZE]
Definition: ComLogger.hpp:95
ComLoggerComponentAc.hpp
Hash.hpp
Svc::ComLogger::MAX_FILENAME_SIZE
@ MAX_FILENAME_SIZE
Definition: ComLogger.hpp:77
FwOpcodeType
#define FwOpcodeType
Type representation for a command opcode.
Definition: FpConfig.hpp:62
Svc::ComLoggerComponentBase
Auto-generated base for ComLogger component.
Definition: ComLoggerComponentAc.hpp:46
Svc::ComLoggerComponentBase::key
PROTECTED U32 key
Definition: ComLoggerComponentAc.hpp:311
Svc::ComLogger::OPEN
@ OPEN
Definition: ComLogger.hpp:90
Svc::ComLogger::writeHashFile
void writeHashFile()
Definition: ComLogger.cpp:251
Svc::ComLogger::data
PRIVATE Fw::ComBuffer & data
Definition: ComLogger.hpp:56
Svc::ComLogger::MAX_PATH_SIZE
@ MAX_PATH_SIZE
Definition: ComLogger.hpp:78
Svc::ComLogger::fileMode
FileMode fileMode
Definition: ComLogger.hpp:93
Svc::ComLogger::filePrefix
U8 filePrefix[MAX_FILENAME_SIZE+MAX_PATH_SIZE]
Definition: ComLogger.hpp:82
Svc::ComLogger::writeErrorOccured
bool writeErrorOccured
Definition: ComLogger.hpp:98
File.hpp
Svc::ComLogger::CloseFile_cmdHandler
void CloseFile_cmdHandler(FwOpcodeType opCode, U32 cmdSeq)
Definition: ComLogger.cpp:121
Svc::ComLogger::pingIn_handler
void pingIn_handler(const NATIVE_INT_TYPE portNum, U32 key)
Definition: ComLogger.cpp:131
Svc::ComLogger::writeToFile
bool writeToFile(void *data, U16 length)
Definition: ComLogger.cpp:229
Svc
Definition: ActiveLoggerComponentAc.cpp:22
Svc::ComLoggerComponentBase::cmdSeq
PROTECTED U32 cmdSeq
Definition: ComLoggerComponentAc.hpp:479
Svc::ComLogger::~ComLogger
~ComLogger(void)
Definition: ComLogger.cpp:54
Mutex.hpp
Svc::ComLogger::FileMode
FileMode
Definition: ComLogger.hpp:88
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Svc::ComLogger::maxFileSize
U32 maxFileSize
Definition: ComLogger.hpp:83
Fw::ComBuffer
Definition: ComBuffer.hpp:21
Os::File
Definition: File.hpp:11
Svc::ComLogger
Definition: ComLogger.hpp:24