CARMA C++
FaultTransport.h
1 /*
2  * Transport for all types of faults generated by the fault system
3  *
4  * This implementation uses an IPQ to transport all faults generated by
5  * the fault system to any other process that wants to listen. The monitor
6  * system is not capable of transporting this data, so we just use our own
7  * custom IPQ to get the job done.
8  *
9  * Copyright (c) 2010 Ira W. Snyder <iws@ovro.caltech.edu>
10  */
11 
12 #ifndef FAULT_TRANSPORT_H
13 #define FAULT_TRANSPORT_H
14 
15 #include <list>
16 #include <memory>
17 #include <string>
18 
19 #include <boost/shared_ptr.hpp>
20 
21 #include <carma/monitor/types.h>
22 using namespace carma::monitor;
23 
24 #include <carma/util/IPQbuffer.h>
25 using namespace carma::util;
26 
27 #include <carma/fault/Constants.h>
28 #include <carma/fault/DagMLNode.h>
29 #include <carma/fault/AlarmFaultAccumulator.h>
30 
31 typedef std::list<std::string> StringList;
32 
33 struct InputFault {
34  uint32_t band;
35  uint32_t input;
36  std::string name;
37 };
38 
39 typedef std::list<struct InputFault> InputFaultList;
40 
41 /* Constants */
42 static const uint32_t kMaxTransportedTagIds = 64;
43 static const int kNumBands = NUM_ASTROBANDS;
44 static const int kNumInputs = NUM_ASTROINPUTS;
45 
46 /*
47  * A per-input fault structure. This will allow us to distinguish
48  * which input the faults came from, if it is needed.
49  */
50 struct LocalElementInput {
51  uint32_t band;
52  uint32_t input;
53  tagIDType id;
54 };
55 
56 /*
57  * This structure holds all blank/flag elements that are to be
58  * transported per band.
59  *
60  * This supports transporting information about per-input blank/flag
61  * information as well as the alarm status.
62  *
63  * This is not as good as it could be, as we have the possibility to
64  * lose information when many inputs have errors. In that case, we
65  * only transport some of the information, and report how much we
66  * dropped. The benefit is that we take up much less IPQ space and
67  * transport the data faster.
68  *
69  * Currently, there is no possible way for RTD to display the amount of
70  * information that the fault system can produce. There is no capability
71  * for a scrolling list. Therefore, truncated information will have
72  * to do for now.
73  *
74  * Only testing will show whether this is a good solution.
75  */
76 
77 struct LocalElementBF
78 {
79  /* Complex Input Blank/Flag Faults */
80  uint32_t numComplexFaults;
81  struct LocalElementInput complexFaultList[kMaxTransportedTagIds];
82 
83  /* Simple Input Blank/Flag Faults */
84  uint32_t numSimpleFaults;
85  tagIDType simpleFaultList[kMaxTransportedTagIds];
86  uint32_t simpleFaultCount[kMaxTransportedTagIds];
87 };
88 
89 struct LocalElementHistory
90 {
91  uint32_t prefix;
92  uint32_t first_frame_bad;
93  uint32_t last_frame_bad;
94  tagIDType id;
95  uint8_t silent;
96 };
97 
98 /* IPQ-derived class to transport data */
99 class CommonIPQ : public IPQbuffer
100 {
101  public:
102  struct LocalElement {
103  uint64_t faultSystemCycle;
104  int32_t inputCmsFrame;
105 
106  /* BF information */
107  struct LocalElementBF blankInfo[kNumBands];
108 
109  /* Alarm information */
110  uint32_t numAlarms;
111  uint32_t alarmPrefix[kMaxTransportedTagIds];
112  tagIDType alarmList[kMaxTransportedTagIds];
113  uint8_t alarmSilent[kMaxTransportedTagIds];
114 
115  /* Disabled Alarm information */
116  uint32_t numDisabled;
117  uint32_t disabledPrefix[kMaxTransportedTagIds];
118  tagIDType disabledList[kMaxTransportedTagIds];
119  uint8_t disabledSilent[kMaxTransportedTagIds];
120 
121  /* Historical Alarm information */
122  uint32_t numHistory;
123  struct LocalElementHistory history[kMaxTransportedTagIds];
124  };
125 
126  explicit CommonIPQ(LocalElement & localElement);
127  void write();
128 
129  private:
130  CommonIPQ(const CommonIPQ & rhs); // No copying
131  CommonIPQ& operator=(const CommonIPQ & rhs); // No copying
132 };
133 
134 /*----------------------------------------------------------------------------*/
135 /* Fault System Transport Writer -- for exclusive use by the fault system */
136 /*----------------------------------------------------------------------------*/
137 
138 class FaultTransportWriter
139 {
140  public:
141  FaultTransportWriter();
142 
143  /* set input CMS frame number */
144  void setCmsFrameNumber(const int frame);
145 
146  /* set fault system cycle number */
147  void setFaultCycleNumber(const uint64_t cycle);
148 
149  /* clear all status */
150  void clear();
151 
152  /* write out the frame */
153  void write();
154 
155  /* add input blank/flag status (incremental) */
156  void addInputFaults(const int band, const int input, const DagMLNodeList &faults);
157 
158  /* set the alarm status */
159  void setAlarmFaults(const DagMLNodeList &faults);
160  void setAlarmDisabled(const DagMLNodeList &disabled);
161  void setAlarmHistory(const AccumulatorList &history);
162 
163  /* hack to allow forcing config error faults */
164  void setConfigFaults(const std::list<carma::monitor::tagIDType> &ids);
165 
166  protected:
167  CommonIPQ::LocalElement localElement_;
168  boost::shared_ptr<CommonIPQ> ipq_;
169 
170  typedef std::map<tagIDType, uint32_t> SimpleFaultMap;
171  std::vector<SimpleFaultMap> maps_;
172 
173  struct LocalElementBF* getBandPtr(int band);
174  void populateSimpleFaultList();
175 };
176 
177 /*----------------------------------------------------------------------------*/
178 /* Fault System Transport Reader -- for use by any readers */
179 /*----------------------------------------------------------------------------*/
180 
181 class FaultTransportReader
182 {
183  public:
184  FaultTransportReader();
185 
186  /* blocking read */
187  void read();
188 
189  /* non-blocking read */
190  void readNewest();
191 
192  /* get input CMS frame number */
193  int getCmsFrameNumber() const;
194 
195  /* get fault system cycle number */
196  uint64_t getFaultCycleNumber() const;
197 
198  /* get fault status */
199  void getSimpleInputFaults(const int band, uint32_t &number, StringList &names);
200  void getComplexInputFaults(const int band, uint32_t &number, InputFaultList &faults);
201  void getComplexInputFaults(const int band, uint32_t &number, StringList &names);
202 
203  void getAlarmFaults(uint32_t &number, StringList &names);
204  void getAlarmDisabled(uint32_t &number, StringList &names);
205  void getAlarmHistory(uint32_t &number, StringList &names);
206 
207  protected:
208  CommonIPQ::LocalElement localElement_;
209  boost::shared_ptr<CommonIPQ> ipq_;
210 
211  struct LocalElementBF* getBandPtr(const int band);
212  void convert_tagid_string(const tagIDType id, std::string &name) const;
213  void convert_prefix_string(const uint32_t id, std::string &prefix) const;
214 };
215 
216 #endif // FAULT_TRANSPORT_H
217 
218 /* vim: set ts=4 sts=4 sw=4 noet: */
IPQ (InterProcessQueue) provides a generic way for information to be shared between processes or thre...
Shared memory storage mechanism for an IPQ buffer.
Definition: IPQbuffer.h:37
type definitions for monitor system