This is Unofficial EPICS BASE Doxygen Site
eventRecord.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 
10 /* recEvent.c - Record Support Routines for Event records */
11 /*
12  * Author: Janet Anderson
13  * Date: 12-13-91
14  */
15 
16 #include <stddef.h>
17 #include <stdlib.h>
18 #include <stdarg.h>
19 #include <stdio.h>
20 #include <string.h>
21 
22 #include "dbDefs.h"
23 #include "epicsPrint.h"
24 #include "alarm.h"
25 #include "callback.h"
26 #include "dbAccess.h"
27 #include "dbEvent.h"
28 #include "dbScan.h"
29 #include "dbFldTypes.h"
30 #include "devSup.h"
31 #include "errMdef.h"
32 #include "recSup.h"
33 #include "recGbl.h"
34 #include "special.h"
35 #include "menuYesNo.h"
36 
37 #define GEN_SIZE_OFFSET
38 #include "eventRecord.h"
39 #undef GEN_SIZE_OFFSET
40 #include "epicsExport.h"
41 
42 /* Create RSET - Record Support Entry Table*/
43 #define report NULL
44 #define initialize NULL
45 static long init_record(struct dbCommon *, int);
46 static long process(struct dbCommon *);
47 static long special(DBADDR *, int);
48 #define get_value NULL
49 #define cvt_dbaddr NULL
50 #define get_array_info NULL
51 #define put_array_info NULL
52 #define get_units NULL
53 #define get_precision NULL
54 #define get_enum_str NULL
55 #define get_enum_strs NULL
56 #define put_enum_str NULL
57 #define get_graphic_double NULL
58 #define get_control_double NULL
59 #define get_alarm_double NULL
60 
62  RSETNUMBER,
63  report,
64  initialize,
66  process,
67  special,
68  get_value,
69  cvt_dbaddr,
72  get_units,
80 };
81 epicsExportAddress(rset,eventRSET);
82 
83 static void monitor(eventRecord *);
84 static long readValue(eventRecord *);
85 
86 
87 static long init_record(struct dbCommon *pcommon, int pass)
88 {
89  struct eventRecord *prec = (struct eventRecord *)pcommon;
90  eventdset *pdset;
91  long status=0;
92 
93  if (pass == 0) return 0;
94 
95  recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
96  recGblInitConstantLink(&prec->siol, DBF_STRING, &prec->sval);
97 
98  if( (pdset=(eventdset *)(prec->dset)) && (pdset->common.init_record) )
99  status=(*pdset->common.init_record)(pcommon);
100 
101  prec->epvt = eventNameToHandle(prec->val);
102 
103  return(status);
104 }
105 
106 static long process(struct dbCommon *pcommon)
107 {
108  struct eventRecord *prec = (struct eventRecord *)pcommon;
109  eventdset *pdset = (eventdset *)(prec->dset);
110  long status=0;
111  unsigned char pact=prec->pact;
112 
113  if((pdset!=NULL) && (pdset->common.number >= 5) && pdset->read_event )
114  status=readValue(prec); /* read the new value */
115  /* check if device support set pact */
116  if ( !pact && prec->pact ) return(0);
117  prec->pact = TRUE;
118 
119  postEvent(prec->epvt);
120 
121  recGblGetTimeStampSimm(prec, prec->simm, &prec->siol);
122 
123  /* check event list */
124  monitor(prec);
125 
126  /* process the forward scan link record */
127  recGblFwdLink(prec);
128 
129  prec->pact=FALSE;
130  return(status);
131 }
132 
133 
134 static long special(DBADDR *paddr, int after)
135 {
136  eventRecord *prec = (eventRecord *)paddr->precord;
137 
138  if (dbGetFieldIndex(paddr) == eventRecordSIMM) {
139  if (!after)
140  recGblSaveSimm(prec->sscn, &prec->oldsimm, prec->simm);
141  else
142  recGblCheckSimm((dbCommon *)prec, &prec->sscn, prec->oldsimm, prec->simm);
143  return 0;
144  }
145 
146  if (!after) return 0;
147 
148  if (dbGetFieldIndex(paddr) == eventRecordVAL) {
149  prec->epvt = eventNameToHandle(prec->val);
150  }
151 
152  return 0;
153 }
154 
155 
156 static void monitor(eventRecord *prec)
157 {
158  unsigned short monitor_mask;
159 
160  /* get previous stat and sevr and new stat and sevr*/
161  monitor_mask = recGblResetAlarms(prec);
162  db_post_events(prec,&prec->val,monitor_mask|DBE_VALUE);
163  return;
164 }
165 
166 static long readValue(eventRecord *prec)
167 {
168  eventdset *pdset = (eventdset *) prec->dset;
169  long status = 0;
170 
171  if (!prec->pact) {
172  status = recGblGetSimm((dbCommon *)prec, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
173  if (status) return status;
174  }
175 
176  switch (prec->simm) {
177  case menuYesNoNO:
178  status = pdset->read_event(prec);
179  break;
180 
181  case menuYesNoYES: {
182  recGblSetSevr(prec, SIMM_ALARM, prec->sims);
183  if (prec->pact || (prec->sdly < 0.)) {
184  status = dbGetLink(&prec->siol, DBR_STRING, &prec->sval, 0, 0);
185  if (status == 0) {
186  if (strcmp(prec->sval, prec->val) != 0) {
187  strcpy(prec->val, prec->sval);
188  prec->epvt = eventNameToHandle(prec->val);
189  }
190  prec->udf = FALSE;
191  }
192  prec->pact = FALSE;
193  } else { /* !prec->pact && delay >= 0. */
194  epicsCallback *pvt = prec->simpvt;
195  if (!pvt) {
196  pvt = calloc(1, sizeof(epicsCallback)); /* very lazy allocation of callback structure */
197  prec->simpvt = pvt;
198  }
199  if (pvt) callbackRequestProcessCallbackDelayed(pvt, prec->prio, prec, prec->sdly);
200  prec->pact = TRUE;
201  }
202  break;
203  }
204 
205  default:
206  recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
207  status = -1;
208  }
209 
210  return status;
211 }
#define RSETNUMBER
Definition: recSup.h:92
#define DBR_STRING
Definition: db_access.h:69
epicsExportAddress(rset, eventRSET)
#define FALSE
Definition: dbDefs.h:32
#define get_value
Definition: eventRecord.c:48
pvd::Status status
rset eventRSET
Definition: eventRecord.c:61
#define init_record
#define SOFT_ALARM
Definition: alarm.h:106
#define NULL
Definition: catime.c:38
Miscellaneous macro definitions.
#define get_alarm_double
Definition: eventRecord.c:59
#define put_array_info
Definition: eventRecord.c:51
#define DBE_VALUE
Definition: caeventmask.h:38
Device support routines.
#define SIMM_ALARM
Definition: alarm.h:110
#define get_array_info
Definition: eventRecord.c:50
#define put_enum_str
Definition: eventRecord.c:56
#define report
Definition: eventRecord.c:43
#define get_units
Definition: eventRecord.c:52
#define get_enum_str
Definition: eventRecord.c:54
#define get_control_double
Definition: eventRecord.c:58
#define TRUE
Definition: dbDefs.h:27
#define get_enum_strs
Definition: eventRecord.c:55
if(yy_init)
Definition: scan.c:972
Definition: recSup.h:67
#define initialize
Definition: eventRecord.c:44
int prec
Definition: reader.c:29
#define get_graphic_double
Definition: eventRecord.c:57
#define INVALID_ALARM
Definition: alarm.h:53
#define cvt_dbaddr
Definition: eventRecord.c:49
#define special
Definition: dfanoutRecord.c:50
#define get_precision
Definition: eventRecord.c:53
Exporting IOC objects.