F´ Flight Software - C/C++ Documentation NASA-v1.6.0
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 <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 :
37 public ComLoggerComponentBase
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 void init(
56 NATIVE_INT_TYPE queueDepth,
57 NATIVE_INT_TYPE instance
58 );
59
60 ~ComLogger();
61
62 // ----------------------------------------------------------------------
63 // Handler implementations
64 // ----------------------------------------------------------------------
65
66 PRIVATE:
67
68 void comIn_handler(
69 NATIVE_INT_TYPE portNum,
70 Fw::ComBuffer &data,
71 U32 context
72 );
73
74 void CloseFile_cmdHandler(
75 FwOpcodeType opCode,
76 U32 cmdSeq
77 );
78
81 void pingIn_handler(
82 const NATIVE_INT_TYPE portNum,
83 U32 key
84 );
85
86 // ----------------------------------------------------------------------
87 // Constants:
88 // ----------------------------------------------------------------------
89 // The maximum size of a filename
90 enum {
91 MAX_FILENAME_SIZE = COMLOGGER_NAME_MAX,
92 MAX_PATH_SIZE = COMLOGGER_PATH_MAX
93 };
94
95 // The filename data:
96 CHAR filePrefix[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
97 U32 maxFileSize;
98
99 // ----------------------------------------------------------------------
100 // Internal state:
101 // ----------------------------------------------------------------------
102 enum FileMode {
103 CLOSED = 0,
104 OPEN = 1
105 };
106
107 FileMode fileMode;
108 Os::File file;
109 CHAR fileName[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
110 CHAR hashFileName[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
111 U32 byteCount;
112 bool writeErrorOccurred;
113 bool openErrorOccurred;
114 bool storeBufferLength;
115
116 // ----------------------------------------------------------------------
117 // File functions:
118 // ----------------------------------------------------------------------
119 void openFile(
120 );
121
122 void closeFile(
123 );
124
125 void writeComBufferToFile(
126 Fw::ComBuffer &data,
127 U16 size
128 );
129
130 // ----------------------------------------------------------------------
131 // Helper functions:
132 // ----------------------------------------------------------------------
133
134 bool writeToFile(
135 void* data,
136 U16 length
137 );
138
139 void writeHashFile(
140 );
141 };
142};
143
144#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(NATIVE_INT_TYPE queueDepth, NATIVE_INT_TYPE instance)
Definition ComLogger.cpp:44