F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
ActiveLoggerImpl.cpp
Go to the documentation of this file.
1/*
2 * TestCommand1Impl.cpp
3 *
4 * Created on: Mar 28, 2014
5 * Author: tcanham
6 */
7
8#include <cstdio>
9
11#include <Fw/Types/Assert.hpp>
12#include <Os/File.hpp>
13
14namespace Svc {
15
18
21 {
22 // set filter defaults
23 this->m_filterState[FilterSeverity::WARNING_HI].enabled =
25 this->m_filterState[FilterSeverity::WARNING_LO].enabled =
27 this->m_filterState[FilterSeverity::COMMAND].enabled =
29 this->m_filterState[FilterSeverity::ACTIVITY_HI].enabled =
31 this->m_filterState[FilterSeverity::ACTIVITY_LO].enabled =
33 this->m_filterState[FilterSeverity::DIAGNOSTIC].enabled =
35
36 memset(m_filteredIDs,0,sizeof(m_filteredIDs));
37
38 }
39
42
43 void ActiveLoggerImpl::LogRecv_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity& severity, Fw::LogBuffer &args) {
44
45 // make sure ID is not zero. Zero is reserved for ID filter.
46 FW_ASSERT(id != 0);
47
48 switch (severity.e) {
49 case Fw::LogSeverity::FATAL: // always pass FATAL
50 break;
52 if (this->m_filterState[FilterSeverity::WARNING_HI].enabled == Enabled::DISABLED) {
53 return;
54 }
55 break;
57 if (this->m_filterState[FilterSeverity::WARNING_LO].enabled == Enabled::DISABLED) {
58 return;
59 }
60 break;
62 if (this->m_filterState[FilterSeverity::COMMAND].enabled == Enabled::DISABLED) {
63 return;
64 }
65 break;
67 if (this->m_filterState[FilterSeverity::ACTIVITY_HI].enabled == Enabled::DISABLED) {
68 return;
69 }
70 break;
72 if (this->m_filterState[FilterSeverity::ACTIVITY_LO].enabled == Enabled::DISABLED) {
73 return;
74 }
75 break;
77 if (this->m_filterState[FilterSeverity::DIAGNOSTIC].enabled == Enabled::DISABLED) {
78 return;
79 }
80 break;
81 default:
82 FW_ASSERT(0,static_cast<NATIVE_INT_TYPE>(severity.e));
83 return;
84 }
85
86 // check ID filters
87 for (NATIVE_INT_TYPE entry = 0; entry < TELEM_ID_FILTER_SIZE; entry++) {
88 if (
89 (m_filteredIDs[entry] == id) &&
90 (severity != Fw::LogSeverity::FATAL)
91 ) {
92 return;
93 }
94 }
95
96 // send event to the logger thread
97 this->loqQueue_internalInterfaceInvoke(id,timeTag,severity,args);
98
99 // if connected, announce the FATAL
100 if (Fw::LogSeverity::FATAL == severity.e) {
102 this->FatalAnnounce_out(0,id);
103 }
104 }
105 }
106
107 void ActiveLoggerImpl::loqQueue_internalInterfaceHandler(FwEventIdType id, const Fw::Time &timeTag, const Fw::LogSeverity& severity, const Fw::LogBuffer &args) {
108
109 // Serialize event
110 this->m_logPacket.setId(id);
111 this->m_logPacket.setTimeTag(timeTag);
112 this->m_logPacket.setLogBuffer(args);
113 this->m_comBuffer.resetSer();
114 Fw::SerializeStatus stat = this->m_logPacket.serialize(this->m_comBuffer);
115 FW_ASSERT(Fw::FW_SERIALIZE_OK == stat,static_cast<NATIVE_INT_TYPE>(stat));
116
117 if (this->isConnected_PktSend_OutputPort(0)) {
118 this->PktSend_out(0, this->m_comBuffer,0);
119 }
120 }
121
122 void ActiveLoggerImpl::SET_EVENT_FILTER_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, FilterSeverity filterLevel, Enabled filterEnable) {
123 this->m_filterState[filterLevel.e].enabled = filterEnable;
124 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
125 }
126
127 void ActiveLoggerImpl::SET_ID_FILTER_cmdHandler(
128 FwOpcodeType opCode,
129 U32 cmdSeq,
130 U32 ID,
131 Enabled idEnabled
132 ) {
133
134 if (Enabled::ENABLED == idEnabled.e) { // add ID
135 // search list for existing entry
136 for (NATIVE_INT_TYPE entry = 0; entry < TELEM_ID_FILTER_SIZE; entry++) {
137 if (this->m_filteredIDs[entry] == ID) {
138 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
140 return;
141 }
142 }
143 // if not already a match, search for an open slot
144 for (NATIVE_INT_TYPE entry = 0; entry < TELEM_ID_FILTER_SIZE; entry++) {
145 if (this->m_filteredIDs[entry] == 0) {
146 this->m_filteredIDs[entry] = ID;
147 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
149 return;
150 }
151 }
152 // if an empty slot was not found, send an error event
155 } else { // remove ID
156 // search list for existing entry
157 for (NATIVE_INT_TYPE entry = 0; entry < TELEM_ID_FILTER_SIZE; entry++) {
158 if (this->m_filteredIDs[entry] == ID) {
159 this->m_filteredIDs[entry] = 0; // zero entry
160 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
162 return;
163 }
164 }
165 // if it gets here, wasn't found
168 }
169
170 }
171
172 void ActiveLoggerImpl::DUMP_FILTER_STATE_cmdHandler(
173 FwOpcodeType opCode,
174 U32 cmdSeq
175 ) {
176
177 // first, iterate through severity filters
178 for (NATIVE_UINT_TYPE filter = 0; filter < FilterSeverity::NUM_CONSTANTS; filter++) {
179 FilterSeverity filterState(static_cast<FilterSeverity::t>(filter));
181 filterState,
182 Enabled::ENABLED == this->m_filterState[filter].enabled.e
183 );
184 }
185
186 // iterate through ID filter
187 for (NATIVE_INT_TYPE entry = 0; entry < TELEM_ID_FILTER_SIZE; entry++) {
188 if (this->m_filteredIDs[entry] != 0) {
189 this->log_ACTIVITY_HI_ID_FILTER_ENABLED(this->m_filteredIDs[entry]);
190 }
191 }
192
193 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
194 }
195
196 void ActiveLoggerImpl::pingIn_handler(
197 const NATIVE_INT_TYPE portNum,
198 U32 key
199 )
200 {
201 // return key
202 this->pingOut_out(0,key);
203 }
204
205} // namespace Svc
@ FILTER_WARNING_HI_DEFAULT
WARNING HI events are filtered at input.
@ FILTER_WARNING_LO_DEFAULT
WARNING LO events are filtered at input.
@ FILTER_ACTIVITY_HI_DEFAULT
ACTIVITY HI events are filtered at input.
@ FILTER_ACTIVITY_LO_DEFAULT
ACTIVITY LO events are filtered at input.
@ FILTER_COMMAND_DEFAULT
COMMAND events are filtered at input.
@ FILTER_DIAGNOSTIC_DEFAULT
DIAGNOSTIC events are filtered at input.
@ TELEM_ID_FILTER_SIZE
Size of telemetry ID filter.
#define FW_ASSERT(...)
Definition Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:55
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:56
U32 FwEventIdType
Definition FpConfig.h:103
U32 FwOpcodeType
Definition FpConfig.h:91
@ EXECUTION_ERROR
Command had execution error.
@ OK
Command successfully executed.
SerializeStatus serialize(SerializeBufferBase &buffer) const
serialize contents
Definition LogPacket.cpp:20
void setId(FwEventIdType id)
Definition LogPacket.cpp:69
void setTimeTag(const Fw::Time &timeTag)
Definition LogPacket.cpp:77
void setLogBuffer(const LogBuffer &buffer)
Definition LogPacket.cpp:73
Enum representing event severity.
T e
The raw enum value.
@ WARNING_HI
A serious but recoverable event.
@ ACTIVITY_HI
Important informational events.
@ FATAL
A fatal non-recoverable event.
@ WARNING_LO
A less serious but recoverable event.
@ DIAGNOSTIC
Software diagnostic events.
@ ACTIVITY_LO
Less important informational events.
@ COMMAND
An activity related to commanding.
void resetSer()
reset to beginning of buffer to reuse for serialization
@ NUM_CONSTANTS
The number of enumerated constants.
Auto-generated base for ActiveLogger component.
void FatalAnnounce_out(FwIndexType portNum, FwEventIdType Id)
Invoke output port FatalAnnounce.
bool isConnected_FatalAnnounce_OutputPort(FwIndexType portNum)
void log_ACTIVITY_LO_SEVERITY_FILTER_STATE(Svc::ActiveLogger_FilterSeverity severity, bool enabled) const
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
void pingOut_out(FwIndexType portNum, U32 key)
Invoke output port pingOut.
void PktSend_out(FwIndexType portNum, Fw::ComBuffer &data, U32 context)
Invoke output port PktSend.
bool isConnected_PktSend_OutputPort(FwIndexType portNum)
void loqQueue_internalInterfaceInvoke(FwEventIdType id, const Fw::Time &timeTag, const Fw::LogSeverity &severity, const Fw::LogBuffer &args)
Internal interface base-class function for loqQueue.
ActiveLoggerImpl(const char *compName)
constructor
virtual ~ActiveLoggerImpl()
destructor
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
ActiveLogger_Enabled Enabled
ActiveLogger_FilterSeverity FilterSeverity