F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
HealthComponentImpl.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Health.hpp
3 // \author Tim
4 // \brief hpp file for Health component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
13 #include <Fw/FPrimeBasicTypes.hpp>
14 #include <Fw/Types/Assert.hpp>
16 
17 namespace Svc {
18 
19 // ----------------------------------------------------------------------
20 // Construction, initialization, and destruction
21 // ----------------------------------------------------------------------
22 
23 HealthImpl::HealthImpl(const char* const compName)
24  : HealthComponentBase(compName),
25  m_numPingEntries(0),
26  m_key(0),
27  m_watchDogCode(0),
28  m_warnings(0),
29  m_enabled(Fw::Enabled::ENABLED),
30  queue_depth(0) {
32  (HealthComponentBase::NUM_PINGSEND_OUTPUT_PORTS <= std::numeric_limits<FwIndexType>::max()),
33  "NUM_PINGSEND_OUTPUT_PORTS must fit in the positive range of FwIndexType");
34  // clear tracker by disabling pings
35  for (FwIndexType entry = 0; entry < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_pingTrackerEntries));
36  entry++) {
37  this->m_pingTrackerEntries[entry].enabled = Fw::Enabled::DISABLED;
38  }
39 }
40 
41 void HealthImpl::init(const FwSizeType queueDepth, const FwEnumStoreType instance) {
42  HealthComponentBase::init(queueDepth, instance);
43  this->queue_depth = queueDepth;
44 }
45 
46 void HealthImpl::setPingEntries(PingEntry* pingEntries, FwIndexType numPingEntries, U32 watchDogCode) {
47  FW_ASSERT(pingEntries);
48  // make sure not asking for more pings than ports
49  FW_ASSERT(numPingEntries <= NUM_PINGSEND_OUTPUT_PORTS);
50 
51  this->m_numPingEntries = numPingEntries;
52  this->m_watchDogCode = watchDogCode;
53 
54  // copy entries to private data
55  for (FwIndexType entry = 0; entry < numPingEntries; entry++) {
56  FW_ASSERT(pingEntries[entry].warnCycles <= pingEntries[entry].fatalCycles,
57  static_cast<FwAssertArgType>(pingEntries[entry].warnCycles),
58  static_cast<FwAssertArgType>(pingEntries[entry].fatalCycles));
59  this->m_pingTrackerEntries[entry].entry = pingEntries[entry];
60  this->m_pingTrackerEntries[entry].cycleCount = 0;
61  this->m_pingTrackerEntries[entry].enabled = Fw::Enabled::ENABLED;
62  this->m_pingTrackerEntries[entry].key = 0;
63  }
64 }
65 
67 
68 // ----------------------------------------------------------------------
69 // Handler implementations for user-defined typed input ports
70 // ----------------------------------------------------------------------
71 
72 void HealthImpl::PingReturn_handler(const FwIndexType portNum, U32 key) {
73  // verify the key value
74  if (key != this->m_pingTrackerEntries[portNum].key) {
75  Fw::LogStringArg _arg = this->m_pingTrackerEntries[portNum].entry.entryName;
76  this->log_FATAL_HLTH_PING_WRONG_KEY(_arg, key);
77  } else {
78  // reset the counter and clear the key
79  this->m_pingTrackerEntries[portNum].cycleCount = 0;
80  this->m_pingTrackerEntries[portNum].key = 0;
81  }
82 }
83 
84 void HealthImpl::Run_handler(const FwIndexType portNum, U32 context) {
85  // dispatch messages
86  for (FwSizeType i = 0; i < this->queue_depth; i++) {
87  MsgDispatchStatus stat = this->doDispatch();
88  if (MSG_DISPATCH_EMPTY == stat) {
89  break;
90  }
91  FW_ASSERT(MSG_DISPATCH_OK == stat);
92  }
93 
94  if (this->m_enabled == Fw::Enabled::ENABLED) {
95  // cycle through ping table, pinging ports that are not awaiting a reply
96  // for ports that are awaiting a reply, decrement their counters
97  // and check for violations
98 
99  for (FwIndexType entry = 0; entry < this->m_numPingEntries; entry++) {
100  if (Fw::Enabled::ENABLED == this->m_pingTrackerEntries[entry].enabled) {
101  // If clear entry
102  if (0 == this->m_pingTrackerEntries[entry].cycleCount) {
103  // start a ping
104  this->m_pingTrackerEntries[entry].key = this->m_key;
105  // send ping
106  this->PingSend_out(static_cast<FwIndexType>(entry), this->m_pingTrackerEntries[entry].key);
107  // increment key
108  this->m_key++;
109  // increment cycles for the entry
110  this->m_pingTrackerEntries[entry].cycleCount++;
111  } else {
112  // check to see if it is at warning threshold
113  if (this->m_pingTrackerEntries[entry].cycleCount ==
114  this->m_pingTrackerEntries[entry].entry.warnCycles) {
115  Fw::LogStringArg _arg = this->m_pingTrackerEntries[entry].entry.entryName;
116  this->log_WARNING_HI_HLTH_PING_WARN(_arg);
117  this->tlmWrite_PingLateWarnings(++this->m_warnings);
118  } else {
119  // check for FATAL timeout value
120  if (this->m_pingTrackerEntries[entry].entry.fatalCycles ==
121  this->m_pingTrackerEntries[entry].cycleCount) {
122  Fw::LogStringArg _arg = this->m_pingTrackerEntries[entry].entry.entryName;
123  this->log_FATAL_HLTH_PING_LATE(_arg);
124  }
125  } // if at warning or fatal threshold
126 
127  this->m_pingTrackerEntries[entry].cycleCount++;
128  } // if clear entry
129  } // if entry has ping enabled
130  } // for each entry
131 
132  // do other specialized platform checks (e.g. VxWorks suspended tasks)
133  this->doOtherChecks();
134 
135  } // If health checking is enabled
136 
137  // stroke watchdog.
138  if (this->isConnected_WdogStroke_OutputPort(0)) {
139  this->WdogStroke_out(0, this->m_watchDogCode);
140  }
141 }
142 
143 // ----------------------------------------------------------------------
144 // Command handler implementations
145 // ----------------------------------------------------------------------
146 
147 void HealthImpl::HLTH_ENABLE_cmdHandler(const FwOpcodeType opCode, U32 cmdSeq, Fw::Enabled enable) {
148  this->m_enabled = enable;
150  if (enable == Fw::Enabled::ENABLED) {
151  isEnabled = Fw::Enabled::ENABLED;
152  }
153  this->log_ACTIVITY_HI_HLTH_CHECK_ENABLE(isEnabled);
154  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
155 }
156 
157 void HealthImpl::HLTH_PING_ENABLE_cmdHandler(const FwOpcodeType opCode,
158  U32 cmdSeq,
159  const Fw::CmdStringArg& entry,
160  Fw::Enabled enable) {
161  // check to see if entry is in range
162  FwIndexType entryIndex = this->findEntry(entry);
163 
164  if (-1 == entryIndex) {
165  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::VALIDATION_ERROR);
166  return;
167  }
168 
169  this->m_pingTrackerEntries[entryIndex].enabled = enable.e;
171  if (enable == Fw::Enabled::ENABLED) {
172  isEnabled = Fw::Enabled::ENABLED;
173  }
174  Fw::LogStringArg arg;
175  arg = entry;
176  this->log_ACTIVITY_HI_HLTH_CHECK_PING(isEnabled, arg);
177  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
178 }
179 
180 void HealthImpl::HLTH_CHNG_PING_cmdHandler(const FwOpcodeType opCode,
181  U32 cmdSeq,
182  const Fw::CmdStringArg& entry,
183  U32 warningValue,
184  U32 fatalValue) {
185  // check to see if entry is in range
186  FwIndexType entryIndex = this->findEntry(entry);
187  if (-1 == entryIndex) {
188  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::VALIDATION_ERROR);
189  return;
190  }
191 
192  // check to see if warningValue less than or equal to fatalValue
193  if (warningValue > fatalValue) {
194  Fw::LogStringArg arg;
195  arg = entry;
196  this->log_WARNING_HI_HLTH_PING_INVALID_VALUES(arg, warningValue, fatalValue);
197  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::VALIDATION_ERROR);
198  return;
199  }
200 
201  this->m_pingTrackerEntries[entryIndex].entry.warnCycles = warningValue;
202  this->m_pingTrackerEntries[entryIndex].entry.fatalCycles = fatalValue;
203  Fw::LogStringArg arg = entry;
204  this->log_ACTIVITY_HI_HLTH_PING_UPDATED(arg, warningValue, fatalValue);
205  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
206 }
207 
208 FwIndexType HealthImpl::findEntry(const Fw::CmdStringArg& entry) {
209  static_assert(std::numeric_limits<FwIndexType>::is_signed, "FwIndexType must be signed to return -1 for error");
210  // walk through entries
211  for (FwIndexType tableEntry = 0; tableEntry < NUM_PINGSEND_OUTPUT_PORTS; tableEntry++) {
212  if (entry == this->m_pingTrackerEntries[tableEntry].entry.entryName) {
213  return static_cast<FwIndexType>(tableEntry);
214  }
215  }
216  Fw::LogStringArg arg = entry;
218 
219  return -1;
220 }
221 
222 } // end namespace Svc
Auto-generated base for Health component.
Enabled and disabled state.
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
FwIdType FwOpcodeType
The type of a command opcode.
void tlmWrite_PingLateWarnings(U32 arg, Fw::Time _tlmTime=Fw::Time()) const
void log_FATAL_HLTH_PING_WRONG_KEY(const Fw::StringBase &entry, U32 badKey) const
PlatformSizeType FwSizeType
I32 FwEnumStoreType
Enabled state.
virtual MsgDispatchStatus doDispatch()
Called in the message loop to dispatch a message from the queue.
void log_WARNING_LO_HLTH_CHECK_LOOKUP_ERROR(const Fw::StringBase &entry) const
void log_WARNING_HI_HLTH_PING_INVALID_VALUES(const Fw::StringBase &entry, U32 warn, U32 fatal) const
struct for ping entry
void init()
Object initializer.
Definition: ObjBase.cpp:24
virtual void doOtherChecks()
additional checks function
T e
The raw enum value.
~HealthImpl()
Component destructor.
void setPingEntries(PingEntry *pingEntries, FwIndexType numPingEntries, U32 watchDogCode)
Set ping entry tables.
void log_ACTIVITY_HI_HLTH_CHECK_PING(Fw::Enabled enabled, const Fw::StringBase &entry) const
void WdogStroke_out(FwIndexType portNum, U32 code)
Invoke output port WdogStroke.
Enabled and disabled states.
Command successfully executed.
bool isConnected_WdogStroke_OutputPort(FwIndexType portNum)
HealthImpl(const char *const compName)
HealthImpl constructor.
void log_FATAL_HLTH_PING_LATE(const Fw::StringBase &entry) const
PlatformIndexType FwIndexType
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:90
Command failed validation.
RateGroupDivider component implementation.
void log_ACTIVITY_HI_HLTH_CHECK_ENABLE(Fw::Enabled enabled) const
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Disabled state.
void log_WARNING_HI_HLTH_PING_WARN(const Fw::StringBase &entry) const
void PingSend_out(FwIndexType portNum, U32 key)
Invoke output port PingSend.
void log_ACTIVITY_HI_HLTH_PING_UPDATED(const Fw::StringBase &entry, U32 warn, U32 fatal) const