CARMA C++
MonitorPointThreshold.h
Go to the documentation of this file.
1 /* MonitorPointThreshold.h - Contains class & types useful for
2  * monitor point thresholding.
3  *
4  * @CarmaCopyright@
5  */
6 
18 #ifndef CARMA_MONITOR_POINT_THRESHOLD_H
19 #define CARMA_MONITOR_POINT_THRESHOLD_H
20 
21 #include <complex>
22 #include <string>
23 
25 #include "carma/monitor/types.h"
27 
28 
29 namespace carma {
30 namespace monitor {
31 
32 
33 class MonitorPoint;
34 
35 
36 struct ThresholdStruct {
37  long flags;
38  tagIDType tagID; // identifies associated monitor point
39  MonitorValueType type; // identifies type of threshold value
40  MonitorValue thresholdRange[THRESHOLD_NUM_VALUES];
41  // warning range -
42  // low end is warningRange[low]
43  // high end is warningRange[high]
44  // error range -
45  // low end is errorRange[THRESHOLD_LOW_VALUE]
46  // high end is errorRange[THRESHOLD_HIGH_VALUE]
47 };
48 // Note that warningRange is contained within errorRange, so
49 // warningRange[THRESHOLD_LOW_VALUE] >= errorRange[THRESHOLD_LOW_VALUE] and
50 // warningRange[THRESHOLD_HIGH_VALUE] <= errorRange[THRESHOLD_HIGH_VALUE]
51 // Also, warningRange[THRESHOLD_LOW_VALUE] <= warningRange[THRESHOLD_HIGH_VALUE], and
52 // errorRange[THRESHOLD_LOW_VALUE] <= errorRange[THRESHOLD_HIGH_VALUE].
53 
54 
55 class MonitorPointThreshold {
56  public:
57 
58  explicit MonitorPointThreshold( ThresholdStruct & thresholdStruct );
59 
60  ~MonitorPointThreshold( );
61 
65  tagIDType getTagID( ) const;
66 
70  MonitorValueType getValueType( ) const;
71 
75  bool isSet( ) const;
76 
78  bool errorLowIsSet( ) const;
79 
81  bool warnLowIsSet( ) const;
82 
84  bool errorHighIsSet( ) const;
85 
87  bool warnHighIsSet( ) const;
88 
89  void setRangeValue( ThresholdValueEnum lowHigh, MonitorValue value );
90  void setRangeValue( ThresholdValueEnum lowHigh, char value );
91  void setRangeValue( ThresholdValueEnum lowHigh, short value );
92  void setRangeValue( ThresholdValueEnum lowHigh, long value );
93  void setRangeValue( ThresholdValueEnum lowHigh, bool value );
94  void setRangeValue( ThresholdValueEnum lowHigh, float value );
95  void setRangeValue( ThresholdValueEnum lowHigh, double value );
96  void setRangeValue( ThresholdValueEnum lowHigh, const ::std::string & value );
97  void setRangeValue( ThresholdValueEnum lowHigh, ::std::complex< float > value );
98  void setRangeValueSerialNo( ThresholdValueEnum lowHigh, long value );
99 
100  const MonitorValue& getThresholdValue( ThresholdValueEnum lowHigh ) const;
101  char getByteThresholdValue( ThresholdValueEnum lowHigh ) const;
102  short getShortThresholdValue( ThresholdValueEnum lowHigh ) const;
103  long getLongThresholdValue( ThresholdValueEnum lowHigh ) const;
104  bool getBoolThresholdValue( ThresholdValueEnum lowHigh ) const;
105  float getFloatThresholdValue( ThresholdValueEnum lowHigh ) const;
106  double getDoubleThresholdValue( ThresholdValueEnum lowHigh ) const;
107  const ::std::string getStringThresholdValue( ThresholdValueEnum lowHigh ) const;
108  const ::std::complex< float > getComplexThresholdValue( ThresholdValueEnum lowHigh ) const;
109  long getSerialNoThresholdValue( ThresholdValueEnum lowHigh ) const;
110 
120  void setThresholdValuesFromDefaults( const MonitorPoint & mp );
121 
122  protected:
123  void unset( ThresholdValueEnum lowhigh );
124 
125  private:
126  ThresholdStruct & thresholds_;
127 };
128 
129 
136 class InvalidThresholdException : public ::carma::util::ErrorException {
137  public:
141  InvalidThresholdException( const ::std::string & message,
142  const char * fileName,
143  int fileNo );
147  ~InvalidThresholdException( ) throw( );
148 };
149 
150 
151 } // namespace carma::monitor
152 } // namespace carma
153 
154 
155 inline
156 carma::monitor::MonitorPointThreshold::MonitorPointThreshold(
157  ThresholdStruct & threshold ) :
158 thresholds_( threshold )
159 {
160 }
161 
162 
163 inline
164 carma::monitor::MonitorPointThreshold::~MonitorPointThreshold( )
165 {
166 }
167 
168 
169 inline long
170 carma::monitor::MonitorPointThreshold::getTagID( ) const
171 {
172  return thresholds_.tagID;
173 }
174 
175 
177 carma::monitor::MonitorPointThreshold::getValueType( ) const
178 {
179  return thresholds_.type;
180 }
181 
182 
183 inline bool
184 carma::monitor::MonitorPointThreshold::isSet( ) const
185 {
186  return (thresholds_.flags != THRESHOLD_NONE_SET);
187 }
188 
189 
190 inline bool
191 carma::monitor::MonitorPointThreshold::errorLowIsSet( ) const
192 {
193  return ((thresholds_.flags & THRESHOLD_ERROR_LOW_SET)
194  == THRESHOLD_ERROR_LOW_SET);
195 }
196 
197 
198 inline bool
199 carma::monitor::MonitorPointThreshold::warnLowIsSet( ) const
200 {
201  return ((thresholds_.flags & THRESHOLD_WARN_LOW_SET)
202  == THRESHOLD_WARN_LOW_SET);
203 }
204 
205 
206 inline bool
207 carma::monitor::MonitorPointThreshold::errorHighIsSet( ) const
208 {
209  return ((thresholds_.flags & THRESHOLD_ERROR_HIGH_SET)
210  == THRESHOLD_ERROR_HIGH_SET);
211 }
212 
213 
214 inline bool
215 carma::monitor::MonitorPointThreshold::warnHighIsSet( ) const
216 {
217  return ((thresholds_.flags & THRESHOLD_WARN_HIGH_SET)
218  == THRESHOLD_WARN_HIGH_SET);
219 }
220 
221 
222 inline const carma::monitor::MonitorValue &
223 carma::monitor::MonitorPointThreshold::getThresholdValue(
224  const ThresholdValueEnum lowHigh ) const
225 {
226  return thresholds_.thresholdRange[ lowHigh ];
227 }
228 
229 
230 inline char
231 carma::monitor::MonitorPointThreshold::getByteThresholdValue(
232  const ThresholdValueEnum lowHigh ) const
233 {
234  return getThresholdValue( lowHigh ).byte;
235 }
236 
237 
238 inline short
239 carma::monitor::MonitorPointThreshold::getShortThresholdValue(
240  const ThresholdValueEnum lowHigh ) const
241 {
242  return getThresholdValue( lowHigh ).sh;
243 }
244 
245 
246 inline long
247 carma::monitor::MonitorPointThreshold::getLongThresholdValue(
248  const ThresholdValueEnum lowHigh ) const
249 {
250  return getThresholdValue( lowHigh ).lo;
251 }
252 
253 
254 inline bool
255 carma::monitor::MonitorPointThreshold::getBoolThresholdValue(
256  const ThresholdValueEnum lowHigh ) const
257 {
258  return getThresholdValue( lowHigh ).bo;
259 }
260 
261 
262 inline float
263 carma::monitor::MonitorPointThreshold::getFloatThresholdValue(
264  const ThresholdValueEnum lowHigh ) const
265 {
266  return getThresholdValue( lowHigh ).fl;
267 }
268 
269 
270 inline double
271 carma::monitor::MonitorPointThreshold::getDoubleThresholdValue(
272  const ThresholdValueEnum lowHigh ) const
273 {
274  return getThresholdValue( lowHigh ).db;
275 }
276 
277 
278 inline const ::std::string
279 carma::monitor::MonitorPointThreshold::getStringThresholdValue(
280  const ThresholdValueEnum lowHigh ) const
281 {
282  return ::std::string( getThresholdValue( lowHigh ).str );
283 }
284 
285 
286 inline const ::std::complex< float >
287 carma::monitor::MonitorPointThreshold::getComplexThresholdValue(
288  const ThresholdValueEnum lowHigh ) const
289 {
290  return ::std::complex< float >( getThresholdValue( lowHigh ).complex[0],
291  getThresholdValue( lowHigh ).complex[1] );
292 }
293 
294 
295 inline long
296 carma::monitor::MonitorPointThreshold::getSerialNoThresholdValue(
297  const ThresholdValueEnum lowHigh ) const
298 {
299  return getThresholdValue( lowHigh ).sn;
300 }
301 
302 
303 inline
304 carma::monitor::InvalidThresholdException::InvalidThresholdException(
305  const ::std::string & message,
306  const char * const fileName,
307  const int fileNo ) :
308 ::carma::util::ErrorException( message, fileName, fileNo )
309 {
310 }
311 
312 
313 inline
314 carma::monitor::InvalidThresholdException::~InvalidThresholdException( )
315 throw( )
316 {
317 }
318 
319 
320 #endif
short MonitorValueType
Enumeration of possible types for monitor point values.
Exception class for errors.
Class wrapper for monitor point samples stored in a subsystem frame.
Exception class for errors The exception comes with a text string that can be printed or logged...
ErrorException(const std::string &msg, const char *filename, int lineNo)
Constructor.
type definitions for monitor system
Union of all possible types of monitor sample values.