F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <stdio.h>
18 #include <cstdarg>
19 
20 namespace Svc {
21 
22  class ComLogger :
23  public ComLoggerComponentBase
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 
52  PRIVATE:
53 
54  void comIn_handler(
55  NATIVE_INT_TYPE portNum,
56  Fw::ComBuffer &data,
57  U32 context
58  );
59 
60  void CloseFile_cmdHandler(
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:
82  U8 filePrefix[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
83  U32 maxFileSize;
84 
85  // ----------------------------------------------------------------------
86  // Internal state:
87  // ----------------------------------------------------------------------
88  enum FileMode {
89  CLOSED = 0,
90  OPEN = 1
91  };
92 
93  FileMode fileMode;
94  Os::File file;
95  U8 fileName[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
96  U8 hashFileName[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
97  U32 byteCount;
98  bool writeErrorOccurred;
99  bool openErrorOccurred;
100  bool storeBufferLength;
101 
102  // ----------------------------------------------------------------------
103  // File functions:
104  // ----------------------------------------------------------------------
105  void openFile(
106  );
107 
108  void closeFile(
109  );
110 
111  void writeComBufferToFile(
112  Fw::ComBuffer &data,
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
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Assert.hpp
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:45
File.hpp
Svc
Definition: ActiveRateGroupImplCfg.hpp:18
Svc::ComLogger::~ComLogger
~ComLogger(void)
Definition: ComLogger.cpp:54
Mutex.hpp
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Fw::ComBuffer
Definition: ComBuffer.hpp:21
Os::File
Definition: File.hpp:11
Svc::ComLogger
Definition: ComLogger.hpp:22