EPICS ARCHIVER V4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
CtrlInfo.h
1 // -*- c++ -*-
2 
3 #ifndef __CTRLINFO_H__
4 #define __CTRLINFO_H__
5 
6 #include <stdio.h>
7 #include <string>
8 
9 #include "tools/MemoryBuffer.h"
10 #include "storage/StorageTypes.h"
11 
14 
20 {
21 public:
22 
23  float disp_high;
24  float disp_low;
25  float low_warn;
26  float low_alarm;
27  float high_warn;
28  float high_alarm;
29 
30  int32_t prec;
31  char units[1];
32 
33 };
34 
37 {
38 public:
39 
40  int16_t num_states;
41  int16_t pad;
42  char state_strings[1];
43 
44 };
45 
53 class CtrlInfoData {
54 public:
55 
56  uint16_t size;
57  uint16_t type;
58 
59  union {
60  NumericInfo analog;
61  EnumeratedInfo index;
62  } value;
63 
64  // class will be as long as necessary
65  // to hold the units or all the state_strings
66 };
67 
75 class CtrlInfo {
76 public:
77 
79  CtrlInfo();
80 
82  CtrlInfo(const CtrlInfo& rhs);
83 
85  CtrlInfo& operator = (const CtrlInfo& rhs);
86 
88  bool operator == (const CtrlInfo& rhs) const;
89 
91  bool operator != (const CtrlInfo& rhs) const
92  { return ! (*this == rhs); }
93 
95  typedef enum {
96  Invalid = 0,
97  Numeric = 1,
99  } Type;
100 
102  Type getType() const;
103 
104  // Read Control Information:
105  // Numeric precision, units,
106  // high/low limits for display etc.:
107 
109  int32_t getPrecision() const;
110 
112  const char* getUnits() const;
113 
115  float getDisplayHigh() const;
116 
118  float getDisplayLow() const;
119 
121  float getHighAlarm() const;
122 
124  float getHighWarning() const;
125 
127  float getLowWarning() const;
128 
130  float getLowAlarm() const;
131 
134  void setNumeric(int32_t prec, const std::string& units,
135  float disp_low, float disp_high,
136  float low_alarm, float low_warn,
137  float high_warn, float high_alarm);
138 
140  void setEnumerated(size_t num_states, char *strings[]);
141 
144  void allocEnumerated(size_t num_states, size_t string_len);
145 
150  void setEnumeratedString(size_t state, const char *string);
151 
155  void calcEnumeratedSize();
156 
158  void formatDouble(double value, std::string& result) const;
159 
161  size_t getNumStates() const;
162 
164  void getState(size_t state, std::string& result) const;
165 
168  bool parseState(const char *text, const char **next, size_t &state) const;
169 
172  // void read(class DataFile *datafile, FileOffset offset);
173 
176  // void write(class DataFile *datafile, FileOffset offset) const;
177 
179  void show(FILE *f) const;
180 
182  size_t getSize() const
183  { return _infobuf.mem()->size; }
184 
187  return _infobuf;
188  }
189 
192  return _infobuf;
193  }
194 
195 protected:
196 
198  const char *getState(size_t state, size_t &len) const;
199 
202 };
203 
205 
206 
207 #endif
float disp_low
low display range
Definition: CtrlInfo.h:24
uint16_t type
type
Definition: CtrlInfo.h:57
float high_warn
high warning
Definition: CtrlInfo.h:27
size_t getSize() const
Returns size.
Definition: CtrlInfo.h:182
A glorified union of NumericInfo and EnumeratedInfo.
Definition: CtrlInfo.h:53
bool parseState(const char *text, const char **next, size_t &state) const
Like strtod, strtol: try to parse, position &#39;next&#39; on character following the recognized state text...
Meta-information for values: Units, limits, etc .
Definition: CtrlInfo.h:75
CtrlInfo for numeric values.
Definition: CtrlInfo.h:19
float getDisplayLow() const
Returns display low.
void calcEnumeratedSize()
After allocEnumerated() and a sequence of setEnumeratedString () calls, this method recalcs the total...
Undefined.
Definition: CtrlInfo.h:96
float getHighWarning() const
Returns high warning.
size_t getNumStates() const
Enumerated: state string.
A numeric CtrlInfo: Limits, units, ...
Definition: CtrlInfo.h:97
float getDisplayHigh() const
Returns display high.
int32_t getPrecision() const
Returns precision.
Type
Type defines the type of value.
Definition: CtrlInfo.h:95
char units[1]
actually as long as needed,
Definition: CtrlInfo.h:31
bool operator!=(const CtrlInfo &rhs) const
&#39;Not equal to&#39; operator
Definition: CtrlInfo.h:91
const MemoryBuffer< CtrlInfoData > & getMemoryBuffer() const
Return a const memory buffer.
Definition: CtrlInfo.h:186
bool operator==(const CtrlInfo &rhs) const
&#39;Equal to&#39; operator
void setEnumerated(size_t num_states, char *strings[])
Initialize an Enumerated CtrlInfo.
CtrlInfo & operator=(const CtrlInfo &rhs)
Copy operator.
int32_t prec
display precision
Definition: CtrlInfo.h:30
float disp_high
high display range
Definition: CtrlInfo.h:23
float getLowAlarm() const
Returns low alarm.
void formatDouble(double value, std::string &result) const
Format a double value according to precision
char state_strings[1]
state strings
Definition: CtrlInfo.h:42
void allocEnumerated(size_t num_states, size_t string_len)
Alternative to setEnumerated: Call with total string length, including all the &#39;\0&#39;s ! ...
Type getType() const
Get the Type for this CtrlInfo.
const T * mem() const
Access as (T *)
Definition: MemoryBuffer.h:56
void setNumeric(int32_t prec, const std::string &units, float disp_low, float disp_high, float low_alarm, float low_warn, float high_warn, float high_alarm)
Initialize a Numeric CtrlInfo (sets Type to Numeric and then sets fields)
MemoryBuffer< CtrlInfoData > & getMemoryBuffer()
Return a const memory buffer.
Definition: CtrlInfo.h:191
CtrlInfo()
Constructor.
float low_alarm
low alarm
Definition: CtrlInfo.h:26
void setEnumeratedString(size_t state, const char *string)
Must be called after allocEnumerated() AND must be called in sequence, i.e.
int16_t pad
one after the other, separated by &#39;\0&#39;
Definition: CtrlInfo.h:41
float low_warn
low warning
Definition: CtrlInfo.h:25
float high_alarm
high alarm
Definition: CtrlInfo.h:28
uint16_t size
size
Definition: CtrlInfo.h:56
CtrlInfo for enumerated channels.
Definition: CtrlInfo.h:36
const char * getUnits() const
Returns units.
void show(FILE *f) const
Read a CtrlInfo from a binary data file.
float getHighAlarm() const
Returns high alarm.
union CtrlInfoData::@0 value
value
float getLowWarning() const
Returns low warning.
An enumerated CtrlInfo: Strings.
Definition: CtrlInfo.h:98
int16_t num_states
state_strings holds num_states strings
Definition: CtrlInfo.h:40
void getState(size_t state, std::string &result) const
Get given state as text (also handles undefined states)