AlcapDAQ  1
epics_ca_private.h
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: epics_ca_private.h
4  Created by: RA36 (modified part of epics_ca.c)
5 
6  Contents: Channel Access device driver private function declarations
7 
8  $Id: epics_ca_private.h,v 1.2 2011-06-25 20:56:00 l_data Exp $
9 
10 \********************************************************************/
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include "cadef.h"
16 
17 #ifdef _MSC_VER /* collision between varargs and stdarg */
18 #undef va_arg
19 #undef va_start
20 #undef va_end
21 #endif
22 
23 #include "midas.h"
24 
25 #ifndef _EPICS_CA_PRIVATE_H_
26 #define _EPICS_CA_PRIVATE_H_
27 
28 /*----------------------------------------------------------------------------*/
29 
30 #define CHN_NAME_LENGTH 32 /* length of channel names */
31 #define CHNFLAGS_LENGTH 16 /* chan flags string size */
32 
33 /*----------------------------------------------------------------------------*/
34 
35 #ifdef GFA_SPECIFIC
36 
37 #define DTYPE_LENGTH 40 /* epics DBR_STRING size - fixed */
38 #define DSEC_LENGTH 40 /* epics DBR_STRING size - fixed */
39 
40 #endif
41  // DD settings
42  // DD/Loadfile <loadfile>
43  // <loadfile> will be read and interpreted and DD entries for
44  // EPICS Channel name, Used, Readonly, Chn_flags, Minval, Maxval, Threshold,
45  // Tolerance will be created if it they did not previously exist
46  //
47  // DD/AlarmWhenNOTConnected <alarm>
48  // if not NONE, Alarm <alarm> will initially be reset in epics_ca_init() and
49  // when Sum_NOT_Connected changes to 0.
50  //
51  // DD/Sum_NOT_Connected <number>
52  // <number> > 0 may be used as Alarm level
53  //
54  // DD/AlarmWhenNOTinTolerance <alarm>
55  // if not NONE, Alarm <alarm> will initially be reset in epics_ca_init() and
56  // when Sum_NOT_in_Tolerance changes to 0.
57  // e.g.: Alarm condition for Alarm "BL tolerance"
58  // /Equipment/eblpim3/Settings/Devices/EPICSGFA/DD/Sum_NOT_in_Tolerance > 0
59  //
60  // DD/Sum_NOT_in_Tolerance <number>
61  // <number> > 0 may be used as Alarm level
62  // NOTE: Pending operations set Sum_NOT_in_tolerance > 0 until reliable
63  // checks are possible. To make sure WAIT <device> INRANGE in autorun
64  // waits until all operations are completed.
65  //
66  // DD/EPICS Channel name [] max. 32 characters
67  //
68  // DD/Used [] y/n
69  //
70  // DD/Readonly [] y/n
71  //
72  // DD/Chn_Flags []
73  //
74  // Chn_flags are evaluated when (re)connecting, reading or setting the
75  // respective channel
76  //
77  // - Initial value not changed yet after initial setup
78  // U = NOT USED (Channel will not be handled)
79  //
80  // - Initialized
81  // I = Channel may be used and has no special flags
82  //
83  // - channel subscription may be disabled
84  // S = NO subscription of channel changes
85  // e.g. for strings
86  //
87  // - update demand value of channel when readout of value changes
88  // F = Feedback of demand channel readout to demand value of
89  // channel when demand value was not updated by epics_ca_set()
90  // in the last 60 seconds
91  // NOTE: ODB update only - demand value will not be put to EPICS channel
92  //
93  // See GFA specific flag G for update of Command or Setpoint channel demand
94  // by the interpreted readout of a measured or status channel.
95  //
96  // - Min/Max Info for GUI or Min/Max value when sending new demand value
97  // to EPICS channel
98  // M = Write Min & Max in DD during first init of DD/MinVal and DD/MaxVal
99  // Change new demand value to Min or Max value when out of range
100  //
101  // NOTE: Maybe modify Min/Max of channels manually when channel is not
102  // available during init or Min or Max value should be different
103  // NOTE: any value may be set if MinVal and MaxVal are both equal to 0
104  // NOTE: any value may be set if M is not specified in DD/Chn_Flags
105  //
106  // Delete DD/MinVAl DD/MaxVal after the first setup to regenerate
107  // Min/Max from LOW/HIGH when channels are connected.
108  // NOTE: S and U overrule M
109  //
110  // - information when channel is not connected ....
111  // D = Set measured value to -1 to flag channel not found, disconnected
112  // or no read access
113  //
114  // - information if channel is not connected
115  // C = check if channel is not connected.
116  // NOTE: When NOT connected DD/Sum_NOT_connected is incremented.
117  //
118  // - reset demand value
119  // R = (Re)set Demand value on EPICS channel when channel is reconnected
120  // and readout of demand value and demand value differ.
121  // NOTE: Setpoint must always be valid.
122  // e.g. GFA device type FENTE must therefore always be set to
123  // setpoint and command MOVE_TO_SOL must be set
124  //
125  //*** GFA Specific ***
126  //
127  // - update demand value of channel corresponding to measured or status chan
128  // G = Feedback from "Measured" or "Status" channel readout to correspondng
129  // demand channel and demand value was not updated by epics_ca_set()
130  // in the last 60 seconds.
131  // NOTE: ODB update only - demand value will not be put to EPICS channel
132  // NOTE: Type FENTE :SOL:2 will only be updated with IST1:2 or POSA:2
133  // when not moving anymore (NOT 0x0100 and NOT 0x0200) and in status
134  // "stopped" (0x0004) and previous cmd was SOL=POSA(0x0004)
135  // or cmd was MOVE_TO_CW/CCW (0x0000/0x0001) and status is
136  // "in CW/CCW limit switch" (0x0001/0x0002)
137  // See non GFA specific flag F for update of demand by demand readout
138  //
139  // - additional epics channel e.g. for Power ON/OFF may be set
140  // according to GFA device type
141  //
142  // P = Turn power ON (other channel e.g. :COM:2) when setting this channel
143  // e.g. :SOL:2
144  // N = Turn power ON (other channel e.g. :COM:2) when setting > 0
145  // Turn power OFF (other channel e.g. :COM:2) when setting <= 0
146  // Z = Turn power OFF (other channel e.g. :COM:2) when setting to zero
147  // Turn power ON (other channel e.g. :COM:2) when setting <> zero
148  // NOTE: N overrules Z and P. Z overrules P.
149  //
150  // - set command set_to_demand on other channel
151  // V = Set value for "Move to setpoint" MOVE_TO_SOL=0x0003
152  // (in other channel e.g. :COM:2 for GFA type FENTE)
153  // when setting this channel e.g. :SOL:2
154  //
155  // - check tolerance of this channel
156  // T = check if (this) demand channel e.g. <dev>:SOL:2 and corresponding
157  // measured channel e.g.: <dev>:IST:2 are in tolerance
158  // when <tolerance> of demand is > 0.
159  // Do not check tolerance when demand value is negative and N flag is
160  // set.
161  // NOTE: When NOT in tolerance DD/Sum_NOT_in_Tolerance is incremented.
162  //
163  // Examples of channel flags
164  //
165  // EPICS Channel GFA_type Channel flags Iscmd
166  // ------------- ---------- ------------- ------
167  // FS11-L:COM:2 FENTE I y
168  // FS11-L:STA:1 FENTE IG y
169  // FS11-L:SOL:2 FENTE IVMCTRF y
170  // FS11-L:IST1:2 FENTE IG y
171  // ASM11:COM:2 BEND I y
172  // ASM11:STA:1 BEND IG n
173  // ASM11:SOL:2 BEND IFZMCTR y
174  // ASM11:IST:2 BEND I n
175  // KSD11:COM:2 BX I y
176  // KSD11:STA:1 BX IG n
177  // SEP31HVN:SOLI:2 HVPS IF y
178  // SEP31HVN:SOLV:2 HVPS IFT y
179  //
180  //*** END GFA Specific ***
181  //
182  // DD/Minval [] [0.0]
183  // Minimum value from Loadfile or updated from LOW attribute of Channel
184  // when M flag is set and DD/Minval does not exist
185  //
186  // DD/Maxval [] [0.0]
187  // Maximum value from Loadfile or updated from HIGH attribute of Channel
188  // when M flag is set and DD/Maxval does not exist
189  // NOTE: if Minval[i] and Maxval[i] of EPICS channel [i] is 0.0 there will be
190  // no range checking when a demand value is set on channel [i]
191  //
192  // DD/Tolerance [] [0.0]
193  // Tolerance from Loadfile
194  // NOTE: Tolerance will not be checked when 0.0 is set as tolerance
195  //
196 
197 /*----------------------------------------------------------------------------*/
198 
199 typedef struct {
200  char loadfile[NAME_LENGTH]; // file name of load file
201  char AlarmWhenNOTConnected[NAME_LENGTH];
202  int Sum_NOT_Connected; // sum of DOWN channels with C flag set
203  char AlarmWhenNOTinTolerance[NAME_LENGTH];
204  int Sum_NOT_in_Tolerance; // out of tolerance channels with T flag & tol > 0.0
205  char *channel_names; // channel_names
206 #ifdef GFA_SPECIFIC
207  char *dtype; // description type (also for interpretation by GUI)
208  char *dsec; // description section (also for interpretation by GUI)
209 #endif
210  char *chnflags; // special flags of channel
211  float *minval; // channel minval
212  float *maxval; // channel maxval
213  float *tolerance; // channel tolerance
214  BOOL *used; // used flag
215  BOOL *readonly; // readonly flag
216 } CA_SETTINGS;
217 
218 typedef struct {
219  CA_SETTINGS settings; // DD specific settings in ODB
220  chid *pchid; // channel ID of channels
221  float *array; // channel readout
222  float *array_m; // channel readout mirror
223  float *demand; // channel demand
224  float *threshold; // channel threshold (only used when reading loadfile)
225  DWORD *lastset; // channel timestamp when last set
226  DWORD *lastget; // channel timestamp when last get
227  int *status; // status returned in event handler
228  BOOL *found; // found flag
229  BOOL *iscmd; // iscmd flag
230  BOOL *subscribed; // subscribed flag
231  BOOL *down; // down flag
232  BOOL *firstread; // flag expecting first reading when UP again
233  INT *nerr; // number of errors
234  INT *nmsg; // number of messages
235  INT *tolchan; // index of corresponding tolerance channel
236  INT *gchan; // index of corresponding channel with G-flag
237  BOOL *intol; // channel is/is not in tolerance range
238  INT num_channels; // number of channels
239  DWORD flags; // flags supplied when epics_ca(CMD_INIT, ...) is called
240  INT cmd_disabled; // command execution in epics_ca() is initially disabled
241  INT subscribe_disabled; // subscribe (in connection handler) is initially disabled
242 #ifdef GFA_SPECIFIC
243  BOOL handling_disabled; // GFA specific handling is (currently) disabled
244 #endif // to avoid infinit loop of handling dependencies...
245  char name[NAME_LENGTH]; // equipment <name>
246  HNDLE hkeyDemand; // "/Equipment/<equi>/Variables/Demand" key handle
247  HNDLE hkeyDD; // "DD" key handle
248  HNDLE hkeySNC; // "DD/Sum_NOT_Connected" key handle
249  HNDLE hkeySNT; // "DD/Sum_NOT_in_Tolerance" key handle
250  DWORD lastSNC; // last time Sum_NOT_Connected of C flag channels
251  DWORD lastSNT; // last time Sum_NOT_in_Tolerance of T flag channels
252  INT pending; // pending operation -> increment Sum_NOT_in_Tolerance
253 } CA_INFO;
254 
255 /*---- functions ---------------------------------------------------*/
256 
257 INT epics_ca (INT cmd, ...);
258 
259 INT epics_ca_init (HNDLE , void **, INT);
260 INT epics_ca_exit (CA_INFO *);
261 INT epics_ca_set (CA_INFO *, INT, float, BOOL, BOOL);
262 INT epics_ca_set_all (CA_INFO *, INT, float);
263 INT epics_ca_set_label (CA_INFO *, INT, char *);
264 INT epics_ca_get (CA_INFO *, INT, float *);
265 INT epics_ca_get_demand(CA_INFO *, INT, float *);
266 INT epics_ca_get_all (CA_INFO *, INT, float *);
267 
268 INT epics_ca_set_pending (CA_INFO *, BOOL);
269 
270 INT epics_ca_get_default_name (CA_INFO *, INT, char *);
271 INT epics_ca_get_default_threshold(CA_INFO *, INT, float *);
272 
273 #endif /* _EPICS_CA_PRIVATE_H_ */
274 
275 /*--- EOF epics_ca_private.h -------------------------------------------------*/