F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
BufferLogger.cpp
Go to the documentation of this file.
1// ======================================================================
2// \title BufferLogger.cpp
3// \author bocchino, dinkel, mereweth
4// \brief Svc BufferLogger implementation
5//
6// \copyright
7// Copyright (C) 2015-2017 California Institute of Technology.
8// ALL RIGHTS RESERVED. United States Government Sponsorship
9// acknowledged.
10//
11// ======================================================================
12
14
15namespace Svc {
16
17 typedef BufferLogger_LogState LogState;
18 // ----------------------------------------------------------------------
19 // Construction, initialization, and destruction
20 // ----------------------------------------------------------------------
21
22 BufferLogger ::
23 BufferLogger(const char *const compName) :
24 BufferLoggerComponentBase(compName),
25 m_state(LogState::LOGGING_ON),
26 m_file(*this)
27 {
28
29 }
30
31 void BufferLogger ::
32 init(
33 const NATIVE_INT_TYPE queueDepth,
34 const NATIVE_INT_TYPE instance
35 )
36 {
37 BufferLoggerComponentBase::init(queueDepth, instance);
38 }
39
40 // ----------------------------------------------------------------------
41 // Public methods
42 // ----------------------------------------------------------------------
43
44 //TODO(mereweth) - only allow calling this once?
45 void BufferLogger ::
46 initLog(
47 const char *const logFilePrefix,
48 const char *const logFileSuffix,
49 const U32 maxFileSize,
50 const U8 sizeOfSize
51 )
52 {
53 m_file.init(logFilePrefix, logFileSuffix, maxFileSize, sizeOfSize);
54 }
55
56 // ----------------------------------------------------------------------
57 // Handler implementations for user-defined typed input ports
58 // ----------------------------------------------------------------------
59
60 void BufferLogger ::
61 bufferSendIn_handler(
62 const NATIVE_INT_TYPE portNum,
63 Fw::Buffer& fwBuffer
64 )
65 {
66 if (m_state == LogState::LOGGING_ON) {
67 const U8 *const addr = fwBuffer.getData();
68 const U32 size = fwBuffer.getSize();
69 m_file.logBuffer(addr, size);
70 }
71 this->bufferSendOut_out(0, fwBuffer);
72 }
73
74 void BufferLogger ::
75 comIn_handler(
76 NATIVE_INT_TYPE portNum,
77 Fw::ComBuffer &data,
78 U32 context
79 )
80 {
81 if (m_state == LogState::LOGGING_ON) {
82 const U8 *const addr = data.getBuffAddr();
83 const U32 size = data.getBuffLength();
84 m_file.logBuffer(addr, size);
85 }
86 }
87
88 void BufferLogger ::
89 pingIn_handler(NATIVE_INT_TYPE portNum, U32 key)
90 {
91 this->pingOut_out(0, key);
92 }
93
94 void BufferLogger ::
95 schedIn_handler(
96 const NATIVE_INT_TYPE portNum,
97 NATIVE_UINT_TYPE context
98 )
99 {
100 // TODO
101 }
102
103 // ----------------------------------------------------------------------
104 // Command handler implementations
105 // ----------------------------------------------------------------------
106
107 // TODO(mereweth) - should this command only set the base name?
108 void BufferLogger ::
109 BL_OpenFile_cmdHandler(
110 const FwOpcodeType opCode,
111 const U32 cmdSeq,
112 const Fw::CmdStringArg& file
113 )
114 {
115 m_file.setBaseName(file);
116 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
117 }
118
119 void BufferLogger ::
120 BL_CloseFile_cmdHandler(
121 const FwOpcodeType opCode,
122 const U32 cmdSeq
123 )
124 {
125 m_file.closeAndEmitEvent();
126 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
127 }
128
129 void BufferLogger ::
130 BL_SetLogging_cmdHandler(
131 const FwOpcodeType opCode,
132 const U32 cmdSeq,
133 LogState state
134 )
135 {
136 m_state = state;
137 if (state == LogState::LOGGING_OFF) {
138 m_file.closeAndEmitEvent();
139 }
140 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
141 }
142
143 void BufferLogger ::
144 BL_FlushFile_cmdHandler(
145 const FwOpcodeType opCode,
146 const U32 cmdSeq
147 )
148 {
149 const bool status = m_file.flush();
150 if(status)
151 {
152 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
153 }
154 else
155 {
156 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
157 }
158 }
159
160};
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:26
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
U32 FwOpcodeType
Definition FpConfig.h:56
U8 * getData() const
Definition Buffer.cpp:60
U32 getSize() const
Definition Buffer.cpp:64
U8 * getBuffAddr()
gets buffer address for data filling
Definition ComBuffer.cpp:40
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
BufferLogger_LogState LogState