CARMA C++
AlarmFaultAccumulator.h
1 /*
2  * Fault System Alarm Accumulator
3  *
4  * This code implements an accumulator which will take input from a
5  * single-frame-only (instantaneous) alarm evaluator, and keep track of
6  * which faults have been present long enough to ring the alarm.
7  *
8  * It also takes care of storing a configurable amount of history information
9  * so that a simple historical log of faults can be presented to the user.
10  *
11  * Copyright (c) 2011 Ira W. Snyder <iws@ovro.caltech.edu>
12  */
13 
14 #ifndef ALARM_FAULT_ACCUMULATOR_H
15 #define ALARM_FAULT_ACCUMULATOR_H
16 
17 #include <string>
18 #include <list>
19 #include <map>
20 
21 #include <stdint.h>
22 
23 #include <boost/circular_buffer.hpp>
24 #include <boost/shared_ptr.hpp>
25 
26 #include <carma/fault/DagMLNode.h>
27 
28 /*----------------------------------------------------------------------------*/
29 /* Accumulator Information Storage */
30 /*----------------------------------------------------------------------------*/
31 
32 struct AccumulatorInfo
33 {
34  DagMLNodePtr node;
35  unsigned int first_frame_bad;
36  unsigned int last_frame_bad;
37  unsigned int frames_bad;
38  bool seen_this_iteration;
39 
40  /* ctor */
41  AccumulatorInfo(DagMLNodePtr node);
42 };
43 
44 typedef boost::shared_ptr<struct AccumulatorInfo> AccumulatorInfoPtr;
45 
46 typedef std::map <uint32_t, AccumulatorInfoPtr> AccumulatorMap;
47 typedef std::list<AccumulatorInfoPtr> AccumulatorList;
48 typedef boost::circular_buffer<AccumulatorInfoPtr> AccumulatorCircBuf;
49 
50 /*----------------------------------------------------------------------------*/
51 /* AlarmFaultAccumulator Class */
52 /*----------------------------------------------------------------------------*/
53 
54 class AlarmFaultAccumulator
55 {
56  public:
57  AlarmFaultAccumulator(const unsigned int history_len);
58 
59  void traversal_setup(const unsigned int frame);
60  void traversal_addFault(DagMLNodePtr &node);
61  void traversal_cleanup();
62 
63  bool isAlarm(const DagMLNodePtr &node);
64 
65  void getAlarms(DagMLNodeList &alarms);
66  void getAlarmHistory(AccumulatorList &list);
67 
68  // for debugging
69  void dump();
70 
71  protected:
72  bool isAlarm(const AccumulatorInfoPtr &info);
73 
74  private:
75  AccumulatorMap map_;
76  AccumulatorCircBuf circ_;
77  unsigned int current_frame_;
78 };
79 
80 #endif /* ALARM_FAULT_ACCUMULATOR_H */
81 
82 /* vim: set ts=4 sts=4 sw=4 noet tw=92: */