F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
EventManager.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 <Fw/Logger/Logger.hpp>
9 #include <Fw/Types/Assert.hpp>
10 #include <Os/File.hpp>
12 
13 namespace Svc {
14 static_assert(std::numeric_limits<FwSizeType>::max() >= TELEM_ID_FILTER_SIZE,
15  "TELEM_ID_FILTER_SIZE must fit within range of FwSizeType");
18 
19 EventManager::EventManager(const char* name) : EventManagerComponentBase(name), m_severityFilter() {
20  // set filter defaults
27 }
28 
30 
31 void EventManager::LogRecv_handler(FwIndexType portNum,
32  FwEventIdType id,
33  Fw::Time& timeTag,
34  const Fw::LogSeverity& severity,
35  Fw::LogBuffer& args) {
36  // Severity may arrive from external sources (e.g. a hub bridging another
37  // address space), so drop invalid values rather than asserting
38  if (!severity.isValid()) {
39  Fw::Logger::log("[ERROR] EventManager: dropping event 0x%x (invalid severity %d)\n", static_cast<U32>(id),
40  static_cast<I32>(severity.e));
41  return;
42  }
43 
44  // Check severity filter (FATAL always passes through)
45  if (this->m_severityFilter.isFiltered(severity)) {
46  return;
47  }
48 
49  // check ID filters
50  this->m_idFilterLock.lock();
51  Fw::Success findStatus = m_filteredIDs.find(id);
52  this->m_idFilterLock.unLock();
53  if ((findStatus == Fw::Success::SUCCESS) && (severity != Fw::LogSeverity::FATAL)) {
54  return;
55  }
56 
57  // send event to the logger thread
58  this->loqQueue_internalInterfaceInvoke(id, timeTag, severity, args);
59 
60  // if connected, announce the FATAL
61  if (Fw::LogSeverity::FATAL == severity.e) {
63  this->FatalAnnounce_out(0, id);
64  }
65  }
66 }
67 
68 void EventManager::loqQueue_internalInterfaceHandler(FwEventIdType id,
69  const Fw::Time& timeTag,
70  const Fw::LogSeverity& severity,
71  const Fw::LogBuffer& args) {
72  // Serialize event
73  this->m_logPacket.setId(id);
74  this->m_logPacket.setTimeTag(timeTag);
75  this->m_logPacket.setLogBuffer(args);
76  this->m_comBuffer.resetSer();
77  Fw::SerializeStatus stat = this->m_logPacket.serializeTo(this->m_comBuffer);
78  // A maximum-size LogBuffer plus the packet header can exceed the com buffer capacity.
79  // Drop the event rather than asserting, since the arguments may arrive from
80  // external sources (e.g. a hub bridging another address space).
81  if (Fw::FW_SERIALIZE_OK != stat) {
82  Fw::Logger::log("[ERROR] EventManager: dropping event 0x%x (serialize status %d)\n", static_cast<U32>(id),
83  static_cast<I32>(stat));
84  return;
85  }
86 
87  if (this->isConnected_PktSend_OutputPort(0)) {
88  this->PktSend_out(0, this->m_comBuffer, 0);
89  }
90 }
91 
92 void EventManager::SET_EVENT_FILTER_cmdHandler(FwOpcodeType opCode,
93  U32 cmdSeq,
94  const FilterSeverity& filterLevel,
95  const Enabled& filterEnable) {
96  // Verify FilterSeverity enum values match EventSeverityFilter index ordering
97  static_assert(static_cast<FwSizeType>(FilterSeverity::WARNING_HI) == 0, "FilterSeverity ordering mismatch");
98  static_assert(static_cast<FwSizeType>(FilterSeverity::WARNING_LO) == 1, "FilterSeverity ordering mismatch");
99  static_assert(static_cast<FwSizeType>(FilterSeverity::COMMAND) == 2, "FilterSeverity ordering mismatch");
100  static_assert(static_cast<FwSizeType>(FilterSeverity::ACTIVITY_HI) == 3, "FilterSeverity ordering mismatch");
101  static_assert(static_cast<FwSizeType>(FilterSeverity::ACTIVITY_LO) == 4, "FilterSeverity ordering mismatch");
102  static_assert(static_cast<FwSizeType>(FilterSeverity::DIAGNOSTIC) == 5, "FilterSeverity ordering mismatch");
103 
104  Fw::LogSeverity logSeverity;
105  Fw::Success status = EventSeverityFilter::fromIndex(static_cast<FwSizeType>(filterLevel.e), logSeverity);
106  if (status != Fw::Success::SUCCESS) {
107  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::VALIDATION_ERROR);
108  return;
109  }
110  this->m_severityFilter.setFilter(logSeverity, filterEnable.e == Enabled::ENABLED);
111  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
112 }
113 
114 void EventManager::SET_ID_FILTER_cmdHandler(FwOpcodeType opCode,
115  U32 cmdSeq,
116  FwEventIdType ID,
117  const Enabled& idEnabled
118 ) {
119  if (Enabled::ENABLED == idEnabled.e) { // add ID
120  this->m_idFilterLock.lock();
121  const Fw::Success insertStatus = m_filteredIDs.insert(ID);
122  this->m_idFilterLock.unLock();
123  if (insertStatus == Fw::Success::SUCCESS) {
124  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
126  } else {
127  // if an empty slot was not found, send an error event
129  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
130  }
131  } else { // remove ID
132  this->m_idFilterLock.lock();
133  const Fw::Success removeStatus = m_filteredIDs.remove(ID);
134  this->m_idFilterLock.unLock();
135  if (removeStatus == Fw::Success::SUCCESS) {
136  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
138  } else {
139  // Entry wasn't found
141  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
142  }
143  }
144 }
145 
146 void EventManager::DUMP_FILTER_STATE_cmdHandler(FwOpcodeType opCode,
147  U32 cmdSeq
148 ) {
149  // first, iterate through severity filters
150  for (FwEnumStoreType filter = 0; filter < FilterSeverity::NUM_CONSTANTS; filter++) {
151  FilterSeverity filterState(static_cast<FilterSeverity::t>(filter));
152  Fw::LogSeverity logSeverity;
153  Fw::Success status = EventSeverityFilter::fromIndex(static_cast<FwSizeType>(filter), logSeverity);
154  FW_ASSERT(status == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(filter));
155  this->log_ACTIVITY_LO_SEVERITY_FILTER_STATE(filterState, this->m_severityFilter.isEnabled(logSeverity));
156  }
157 
158  // Snapshot the ID filter under the lock; log after release since LogRecv is
159  // a sync input that may re-enter this component and take the same lock
160  FwEventIdType filteredIDs[TELEM_ID_FILTER_SIZE];
161  FwSizeType numFilteredIDs = 0;
162  this->m_idFilterLock.lock();
163  for (FwEventIdType ID : m_filteredIDs) {
164  FW_ASSERT(numFilteredIDs < TELEM_ID_FILTER_SIZE, static_cast<FwAssertArgType>(numFilteredIDs));
165  filteredIDs[numFilteredIDs] = ID;
166  numFilteredIDs++;
167  }
168  this->m_idFilterLock.unLock();
169  for (FwSizeType i = 0; i < numFilteredIDs; i++) {
170  this->log_ACTIVITY_HI_ID_FILTER_ENABLED(filteredIDs[i]);
171  }
172 
173  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
174 }
175 
176 void EventManager::run_handler(FwIndexType portNum, U32 context) {
178 }
179 
180 void EventManager::pingIn_handler(const FwIndexType portNum, U32 key) {
181  // return key
182  this->pingOut_out(0, key);
183 }
184 
185 } // namespace Svc
Serialization/Deserialization operation was successful.
void log_ACTIVITY_LO_SEVERITY_FILTER_STATE(const Svc::EventManager_FilterSeverity &severity, bool enabled) const
void tlmWrite_EventsDropped(FwSizeType arg, Fw::Time _tlmTime=Fw::Time())
Enabled and disabled state.
FwIdType FwOpcodeType
The type of a command opcode.
Representing success.
PlatformSizeType FwSizeType
I32 FwEnumStoreType
void setTimeTag(const Fw::Time &timeTag)
Definition: LogPacket.cpp:77
EventManager(const char *compName)
constructor
void unLock()
unlock the mutex and assert success
Definition: Mutex.cpp:41
static void log(const char *format,...)
log a formated string with supplied arguments
Definition: Logger.cpp:21
bool isConnected_PktSend_OutputPort(FwIndexType portNum) const
bool isConnected_FatalAnnounce_OutputPort(FwIndexType portNum) const
void setId(FwEventIdType id)
Definition: LogPacket.cpp:69
void setFilter(Fw::LogSeverity severity, bool enabled)
Software diagnostic events.
SerializeStatus
forward declaration for string
FwIdType FwEventIdType
The type of an event identifier.
void log_ACTIVITY_HI_ID_FILTER_ENABLED(FwEventIdType ID) const
Success find(const T &element) const override
Definition: ArraySet.hpp:81
FwSizeType getNumMsgsDropped()
return number of messages dropped
EventManager_Enabled Enabled
Less important informational events.
void log_WARNING_LO_ID_FILTER_LIST_FULL(FwEventIdType ID) const
An activity related to commanding.
A less serious but recoverable event.
Size of telemetry ID filter.
Success remove(const T &element) override
Definition: ArraySet.hpp:103
void pingOut_out(FwIndexType portNum, U32 key) const
Invoke output port pingOut.
void FatalAnnounce_out(FwIndexType portNum, FwEventIdType Id) const
Invoke output port FatalAnnounce.
void resetSer() override
Reset serialization pointer to beginning of buffer.
A serious but recoverable event.
Auto-generated base for EventManager component.
Enum representing event severity.
enum T e
The raw enum value.
Command successfully executed.
virtual ~EventManager()
destructor
void setLogBuffer(const LogBuffer &buffer)
Definition: LogPacket.cpp:73
void log_WARNING_LO_ID_FILTER_NOT_FOUND(FwEventIdType ID) const
void loqQueue_internalInterfaceInvoke(FwEventIdType id, const Fw::Time &timeTag, const Fw::LogSeverity &severity, const Fw::LogBuffer &args)
Internal interface base-class function for loqQueue.
bool isEnabled(Fw::LogSeverity severity) const
Command had execution error.
Important informational events.
EventManager_FilterSeverity FilterSeverity
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
PlatformIndexType FwIndexType
A fatal non-recoverable event.
Command failed validation.
RateGroupDivider component implementation.
void PktSend_out(FwIndexType portNum, Fw::ComBuffer &data, U32 context) const
Invoke output port PktSend.
static Fw::Success fromIndex(FwSizeType index, Fw::LogSeverity &severity)
SerializeStatus serializeTo(SerialBufferBase &buffer, Fw::Endianness mode=Fw::Endianness::BIG) const override
serialize contents
Definition: LogPacket.cpp:19
Success insert(const T &element) override
Definition: ArraySet.hpp:96
#define FW_ASSERT(...)
Definition: Assert.hpp:14
bool isValid() const
Check raw enum value for validity.
Success/Failure.
void log_ACTIVITY_HI_ID_FILTER_REMOVED(FwEventIdType ID) const
bool isFiltered(Fw::LogSeverity severity) const
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34