This is Unofficial EPICS BASE Doxygen Site
stringoutRecord.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 /* recStringout.c - Record Support Routines for Stringout records */
11 /*
12  * Author: Janet Anderson
13  * Date: 4/23/91
14  */
15 
16 
17 #include <stddef.h>
18 #include <stdlib.h>
19 #include <stdarg.h>
20 #include <stdio.h>
21 #include <string.h>
22 
23 #include "dbDefs.h"
24 #include "epicsPrint.h"
25 #include "alarm.h"
26 #include "callback.h"
27 #include "dbAccess.h"
28 #include "dbEvent.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 "menuOmsl.h"
36 #include "menuIvoa.h"
37 #include "menuYesNo.h"
38 
39 #define GEN_SIZE_OFFSET
40 #include "stringoutRecord.h"
41 #undef GEN_SIZE_OFFSET
42 #include "epicsExport.h"
43 
44 /* Create RSET - Record Support Entry Table*/
45 #define report NULL
46 #define initialize NULL
47 static long init_record(struct dbCommon *, int);
48 static long process(struct dbCommon *);
49 static long special(DBADDR *, int);
50 #define get_value NULL
51 #define cvt_dbaddr NULL
52 #define get_array_info NULL
53 #define put_array_info NULL
54 #define get_units NULL
55 #define get_precision NULL
56 #define get_enum_str NULL
57 #define get_enum_strs NULL
58 #define put_enum_str NULL
59 #define get_graphic_double NULL
60 #define get_control_double NULL
61 #define get_alarm_double NULL
62 
64  RSETNUMBER,
65  report,
66  initialize,
68  process,
69  special,
70  get_value,
71  cvt_dbaddr,
74  get_units,
82 };
83 epicsExportAddress(rset,stringoutRSET);
84 
85 static void monitor(stringoutRecord *);
86 static long writeValue(stringoutRecord *);
87 
88 
89 static long init_record(struct dbCommon *pcommon, int pass)
90 {
91  struct stringoutRecord *prec = (struct stringoutRecord *)pcommon;
92  STATIC_ASSERT(sizeof(prec->oval)==sizeof(prec->val));
93  STATIC_ASSERT(sizeof(prec->ivov)==sizeof(prec->val));
94  stringoutdset *pdset = (stringoutdset *) prec->dset;
95 
96  if (pass == 0) return 0;
97 
98  recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
99 
100  if (!pdset) {
101  recGblRecordError(S_dev_noDSET, prec, "stringout: init_record");
102  return S_dev_noDSET;
103  }
104 
105  /* must have write_stringout functions defined */
106  if ((pdset->common.number < 5) || (pdset->write_stringout == NULL)) {
107  recGblRecordError(S_dev_missingSup, prec, "stringout: init_record");
108  return S_dev_missingSup;
109  }
110 
111  /* get the initial value dol is a constant*/
112  if (recGblInitConstantLink(&prec->dol, DBF_STRING, prec->val))
113  prec->udf = FALSE;
114 
115  if (pdset->common.init_record) {
116  long status = pdset->common.init_record(pcommon);
117 
118  if(status)
119  return status;
120  }
121  strncpy(prec->oval, prec->val, sizeof(prec->oval));
122  return 0;
123 }
124 
125 static long process(struct dbCommon *pcommon)
126 {
127  struct stringoutRecord *prec = (struct stringoutRecord *)pcommon;
128  stringoutdset *pdset = (stringoutdset *)(prec->dset);
129  long status=0;
130  unsigned char pact=prec->pact;
131 
132  if( (pdset==NULL) || (pdset->write_stringout==NULL) ) {
133  prec->pact=TRUE;
134  recGblRecordError(S_dev_missingSup,(void *)prec,"write_stringout");
135  return(S_dev_missingSup);
136  }
137  if (!prec->pact &&
138  !dbLinkIsConstant(&prec->dol) &&
139  prec->omsl == menuOmslclosed_loop) {
140  status = dbGetLink(&prec->dol, DBR_STRING, prec->val, 0, 0);
141  if (!dbLinkIsConstant(&prec->dol) && !status)
142  prec->udf=FALSE;
143  }
144 
145  if(prec->udf == TRUE ){
146  recGblSetSevr(prec,UDF_ALARM,prec->udfs);
147  }
148 
149  if (prec->nsev < INVALID_ALARM )
150  status=writeValue(prec); /* write the new value */
151  else {
152  switch (prec->ivoa) {
153  case (menuIvoaContinue_normally) :
154  status=writeValue(prec); /* write the new value */
155  break;
156  case (menuIvoaDon_t_drive_outputs) :
157  break;
158  case (menuIvoaSet_output_to_IVOV) :
159  if(prec->pact == FALSE){
160  strncpy(prec->val, prec->ivov, sizeof(prec->val));
161  }
162  status=writeValue(prec); /* write the new value */
163  break;
164  default :
165  status=-1;
166  recGblRecordError(S_db_badField,(void *)prec,
167  "stringout:process Illegal IVOA field");
168  }
169  }
170 
171  /* check if device support set pact */
172  if ( !pact && prec->pact ) return(0);
173 
174  prec->pact = TRUE;
175  recGblGetTimeStampSimm(prec, prec->simm, NULL);
176 
177  monitor(prec);
178  recGblFwdLink(prec);
179  prec->pact=FALSE;
180  return(status);
181 }
182 
183 static long special(DBADDR *paddr, int after)
184 {
185  stringoutRecord *prec = (stringoutRecord *)(paddr->precord);
186  int special_type = paddr->special;
187 
188  switch(special_type) {
189  case(SPC_MOD):
190  if (dbGetFieldIndex(paddr) == stringoutRecordSIMM) {
191  if (!after)
192  recGblSaveSimm(prec->sscn, &prec->oldsimm, prec->simm);
193  else
194  recGblCheckSimm((dbCommon *)prec, &prec->sscn, prec->oldsimm, prec->simm);
195  return 0;
196  }
197  default:
198  recGblDbaddrError(S_db_badChoice, paddr, "stringout: special");
199  return(S_db_badChoice);
200  }
201 }
202 
203 static void monitor(stringoutRecord *prec)
204 {
205  int monitor_mask = recGblResetAlarms(prec);
206 
207  if (strncmp(prec->oval, prec->val, sizeof(prec->val))) {
208  monitor_mask |= DBE_VALUE | DBE_LOG;
209  strncpy(prec->oval, prec->val, sizeof(prec->oval));
210  }
211 
212  if (prec->mpst == stringoutPOST_Always)
213  monitor_mask |= DBE_VALUE;
214  if (prec->apst == stringoutPOST_Always)
215  monitor_mask |= DBE_LOG;
216 
217  if (monitor_mask)
218  db_post_events(prec, prec->val, monitor_mask);
219 }
220 
221 static long writeValue(stringoutRecord *prec)
222 {
223  stringoutdset *pdset = (stringoutdset *) prec->dset;
224  long status = 0;
225 
226  if (!prec->pact) {
227  status = recGblGetSimm((dbCommon *)prec, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
228  if (status) return status;
229  }
230 
231  switch (prec->simm) {
232  case menuYesNoNO:
233  status = pdset->write_stringout(prec);
234  break;
235 
236  case menuYesNoYES: {
237  recGblSetSevr(prec, SIMM_ALARM, prec->sims);
238  if (prec->pact || (prec->sdly < 0.)) {
239  status = dbPutLink(&prec->siol, DBR_STRING, &prec->val, 1);
240  prec->pact = FALSE;
241  } else { /* !prec->pact && delay >= 0. */
242  epicsCallback *pvt = prec->simpvt;
243  if (!pvt) {
244  pvt = calloc(1, sizeof(epicsCallback)); /* very lazy allocation of callback structure */
245  prec->simpvt = pvt;
246  }
247  if (pvt) callbackRequestProcessCallbackDelayed(pvt, prec->prio, prec, prec->sdly);
248  prec->pact = TRUE;
249  }
250  break;
251  }
252 
253  default:
254  recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
255  status = -1;
256  }
257 
258  return status;
259 }
#define cvt_dbaddr
#define RSETNUMBER
Definition: recSup.h:92
#define DBR_STRING
Definition: db_access.h:69
#define FALSE
Definition: dbDefs.h:32
pvd::Status status
#define get_enum_str
#define init_record
#define S_dev_missingSup
Definition: devSup.h:170
rset stringoutRSET
#define SOFT_ALARM
Definition: alarm.h:106
#define report
#define NULL
Definition: catime.c:38
Miscellaneous macro definitions.
#define get_array_info
#define get_graphic_double
#define DBE_VALUE
Definition: caeventmask.h:38
Device support routines.
#define get_alarm_double
#define STATIC_ASSERT(expr)
Declare a condition that should be true at compile-time.
Definition: epicsAssert.h:86
#define DBE_LOG
Definition: caeventmask.h:40
#define SIMM_ALARM
Definition: alarm.h:110
#define get_value
#define initialize
#define get_units
#define put_array_info
epicsExportAddress(rset, stringoutRSET)
#define TRUE
Definition: dbDefs.h:27
if(yy_init)
Definition: scan.c:972
Definition: recSup.h:67
#define SPC_MOD
Definition: special.h:33
#define put_enum_str
int prec
Definition: reader.c:29
#define INVALID_ALARM
Definition: alarm.h:53
#define special
Definition: dfanoutRecord.c:50
#define get_control_double
#define S_dev_noDSET
Definition: devSup.h:169
#define UDF_ALARM
Definition: alarm.h:108
#define get_enum_strs
Exporting IOC objects.
#define get_precision