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
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
16 typedef ActiveLogger_Enabled Enabled;
17 typedef ActiveLogger_FilterSeverity FilterSeverity;
18
20 ActiveLoggerComponentBase(name)
21 {
22 // set filter defaults
23 this->m_filterState[FilterSeverity::WARNING_HI].enabled =
24 FILTER_WARNING_HI_DEFAULT?Enabled::ENABLED:Enabled::DISABLED;
25 this->m_filterState[FilterSeverity::WARNING_LO].enabled =
26 FILTER_WARNING_LO_DEFAULT?Enabled::ENABLED:Enabled::DISABLED;
27 this->m_filterState[FilterSeverity::COMMAND].enabled =
28 FILTER_COMMAND_DEFAULT?Enabled::ENABLED:Enabled::DISABLED;
29 this->m_filterState[FilterSeverity::ACTIVITY_HI].enabled =
30 FILTER_ACTIVITY_HI_DEFAULT?Enabled::ENABLED:Enabled::DISABLED;
31 this->m_filterState[FilterSeverity::ACTIVITY_LO].enabled =
32 FILTER_ACTIVITY_LO_DEFAULT?Enabled::ENABLED:Enabled::DISABLED;
33 this->m_filterState[FilterSeverity::DIAGNOSTIC].enabled =
34 FILTER_DIAGNOSTIC_DEFAULT?Enabled::ENABLED:Enabled::DISABLED;
35
36 memset(m_filteredIDs,0,sizeof(m_filteredIDs));
37
38 }
39
41 }
42
44 NATIVE_INT_TYPE queueDepth,
45 NATIVE_INT_TYPE instance
46 ) {
47 ActiveLoggerComponentBase::init(queueDepth,instance);
48 }
49
50 void ActiveLoggerImpl::LogRecv_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity& severity, Fw::LogBuffer &args) {
51
52 // make sure ID is not zero. Zero is reserved for ID filter.
53 FW_ASSERT(id != 0);
54
55 switch (severity.e) {
56 case Fw::LogSeverity::FATAL: // always pass FATAL
57 break;
58 case Fw::LogSeverity::WARNING_HI:
59 if (this->m_filterState[FilterSeverity::WARNING_HI].enabled == Enabled::DISABLED) {
60 return;
61 }
62 break;
63 case Fw::LogSeverity::WARNING_LO:
64 if (this->m_filterState[FilterSeverity::WARNING_LO].enabled == Enabled::DISABLED) {
65 return;
66 }
67 break;
68 case Fw::LogSeverity::COMMAND:
69 if (this->m_filterState[FilterSeverity::COMMAND].enabled == Enabled::DISABLED) {
70 return;
71 }
72 break;
73 case Fw::LogSeverity::ACTIVITY_HI:
74 if (this->m_filterState[FilterSeverity::ACTIVITY_HI].enabled == Enabled::DISABLED) {
75 return;
76 }
77 break;
78 case Fw::LogSeverity::ACTIVITY_LO:
79 if (this->m_filterState[FilterSeverity::ACTIVITY_LO].enabled == Enabled::DISABLED) {
80 return;
81 }
82 break;
83 case Fw::LogSeverity::DIAGNOSTIC:
84 if (this->m_filterState[FilterSeverity::DIAGNOSTIC].enabled == Enabled::DISABLED) {
85 return;
86 }
87 break;
88 default:
89 FW_ASSERT(0,static_cast<NATIVE_INT_TYPE>(severity.e));
90 return;
91 }
92
93 // check ID filters
94 for (NATIVE_INT_TYPE entry = 0; entry < TELEM_ID_FILTER_SIZE; entry++) {
95 if (
96 (m_filteredIDs[entry] == id) &&
97 (severity != Fw::LogSeverity::FATAL)
98 ) {
99 return;
100 }
101 }
102
103 // send event to the logger thread
104 this->loqQueue_internalInterfaceInvoke(id,timeTag,severity,args);
105
106 // if connected, announce the FATAL
107 if (Fw::LogSeverity::FATAL == severity.e) {
108 if (this->isConnected_FatalAnnounce_OutputPort(0)) {
109 this->FatalAnnounce_out(0,id);
110 }
111 }
112 }
113
114 void ActiveLoggerImpl::loqQueue_internalInterfaceHandler(FwEventIdType id, const Fw::Time &timeTag, const Fw::LogSeverity& severity, const Fw::LogBuffer &args) {
115
116 // Serialize event
117 this->m_logPacket.setId(id);
118 this->m_logPacket.setTimeTag(timeTag);
119 this->m_logPacket.setLogBuffer(args);
120 this->m_comBuffer.resetSer();
121 Fw::SerializeStatus stat = this->m_logPacket.serialize(this->m_comBuffer);
122 FW_ASSERT(Fw::FW_SERIALIZE_OK == stat,static_cast<NATIVE_INT_TYPE>(stat));
123
124 if (this->isConnected_PktSend_OutputPort(0)) {
125 this->PktSend_out(0, this->m_comBuffer,0);
126 }
127 }
128
129 void ActiveLoggerImpl::SET_EVENT_FILTER_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, FilterSeverity filterLevel, Enabled filterEnable) {
130 this->m_filterState[filterLevel.e].enabled = filterEnable;
131 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
132 }
133
134 void ActiveLoggerImpl::SET_ID_FILTER_cmdHandler(
135 FwOpcodeType opCode,
136 U32 cmdSeq,
137 U32 ID,
138 Enabled idEnabled
139 ) {
140
141 if (Enabled::ENABLED == idEnabled.e) { // add ID
142 // search list for existing entry
143 for (NATIVE_INT_TYPE entry = 0; entry < TELEM_ID_FILTER_SIZE; entry++) {
144 if (this->m_filteredIDs[entry] == ID) {
145 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
146 this->log_ACTIVITY_HI_ID_FILTER_ENABLED(ID);
147 return;
148 }
149 }
150 // if not already a match, search for an open slot
151 for (NATIVE_INT_TYPE entry = 0; entry < TELEM_ID_FILTER_SIZE; entry++) {
152 if (this->m_filteredIDs[entry] == 0) {
153 this->m_filteredIDs[entry] = ID;
154 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
155 this->log_ACTIVITY_HI_ID_FILTER_ENABLED(ID);
156 return;
157 }
158 }
159 // if an empty slot was not found, send an error event
160 this->log_WARNING_LO_ID_FILTER_LIST_FULL(ID);
161 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::EXECUTION_ERROR);
162 } else { // remove ID
163 // search list for existing entry
164 for (NATIVE_INT_TYPE entry = 0; entry < TELEM_ID_FILTER_SIZE; entry++) {
165 if (this->m_filteredIDs[entry] == ID) {
166 this->m_filteredIDs[entry] = 0; // zero entry
167 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
168 this->log_ACTIVITY_HI_ID_FILTER_REMOVED(ID);
169 return;
170 }
171 }
172 // if it gets here, wasn't found
173 this->log_WARNING_LO_ID_FILTER_NOT_FOUND(ID);
174 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::EXECUTION_ERROR);
175 }
176
177 }
178
179 void ActiveLoggerImpl::DUMP_FILTER_STATE_cmdHandler(
180 FwOpcodeType opCode,
181 U32 cmdSeq
182 ) {
183
184 // first, iterate through severity filters
185 for (NATIVE_UINT_TYPE filter = 0; filter < FilterSeverity::NUM_CONSTANTS; filter++) {
186 FilterSeverity filterState(static_cast<FilterSeverity::t>(filter));
187 this->log_ACTIVITY_LO_SEVERITY_FILTER_STATE(
188 filterState,
189 Enabled::ENABLED == this->m_filterState[filter].enabled.e
190 );
191 }
192
193 // iterate through ID filter
194 for (NATIVE_INT_TYPE entry = 0; entry < TELEM_ID_FILTER_SIZE; entry++) {
195 if (this->m_filteredIDs[entry] != 0) {
196 this->log_ACTIVITY_HI_ID_FILTER_ENABLED(this->m_filteredIDs[entry]);
197 }
198 }
199
200 this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK);
201 }
202
203 void ActiveLoggerImpl::pingIn_handler(
204 const NATIVE_INT_TYPE portNum,
205 U32 key
206 )
207 {
208 // return key
209 this->pingOut_out(0,key);
210 }
211
212} // 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:7
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
U32 FwEventIdType
Definition FpConfig.h:62
U32 FwOpcodeType
Definition FpConfig.h:56
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
void resetSer()
reset to beginning of buffer to reuse for serialization
ActiveLoggerImpl(const char *compName)
constructor
virtual ~ActiveLoggerImpl()
destructor
void init(NATIVE_INT_TYPE queueDepth, NATIVE_INT_TYPE instance)
initialization function
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
ActiveLogger_Enabled Enabled
ActiveLogger_FilterSeverity FilterSeverity