This is Unofficial EPICS BASE Doxygen Site
devSASoft.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 Lawrence Berkeley Laboratory,The Control Systems
5 * Group, Systems Engineering Department
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 /*
11  * Author: Carl Lionberger
12  * Date: 9-2-93
13  */
14 
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <string.h>
18 
19 #include "alarm.h"
20 #include "dbDefs.h"
21 #include "dbAccess.h"
22 #include "dbEvent.h"
23 #include "recGbl.h"
24 #include "devSup.h"
25 #include "subArrayRecord.h"
26 #include "epicsExport.h"
27 
28 /* Create the dset for devSASoft */
29 static long init_record(dbCommon *pcommon);
30 static long read_sa(subArrayRecord *prec);
31 
32 sadset devSASoft = {
33  {5, NULL, NULL, init_record, NULL},
34  read_sa
35 };
37 
38 static void subset(subArrayRecord *prec, long nRequest)
39 {
40  long ecount = nRequest - prec->indx;
41 
42  if (ecount > 0) {
43  int esize = dbValueSize(prec->ftvl);
44 
45  if (ecount > prec->nelm)
46  ecount = prec->nelm;
47 
48  memmove(prec->bptr, (char *)prec->bptr + prec->indx * esize,
49  ecount * esize);
50  } else
51  ecount = 0;
52 
53  prec->nord = ecount;
54  prec->udf = FALSE;
55 }
56 
57 static long init_record(dbCommon *pcommon)
58 {
59  subArrayRecord *prec = (subArrayRecord *)pcommon;
60  long nRequest = prec->indx + prec->nelm;
61  long status;
62 
63  if (nRequest > prec->malm)
64  nRequest = prec->malm;
65 
66  status = dbLoadLinkArray(&prec->inp, prec->ftvl, prec->bptr, &nRequest);
67 
68  if (!status && nRequest > 0)
69  subset(prec, nRequest);
70 
71  return status;
72 }
73 
74 struct sart {
75  long nRequest;
77 };
78 
79 static long readLocked(struct link *pinp, void *vrt)
80 {
81  subArrayRecord *prec = (subArrayRecord *) pinp->precord;
82  struct sart *prt = (struct sart *) vrt;
83  long status = dbGetLink(pinp, prec->ftvl, prec->bptr, 0, &prt->nRequest);
84 
85  if (!status && prt->ptime)
86  dbGetTimeStamp(pinp, prt->ptime);
87 
88  return status;
89 }
90 
91 static long read_sa(subArrayRecord *prec)
92 {
93  long status;
94  struct sart rt;
95  epicsUInt32 nord = prec->nord;
96 
97  rt.nRequest = prec->indx + prec->nelm;
98  if (rt.nRequest > prec->malm)
99  rt.nRequest = prec->malm;
100 
101  rt.ptime = (dbLinkIsConstant(&prec->tsel) &&
102  prec->tse == epicsTimeEventDeviceTime) ? &prec->time : NULL;
103 
104  if (dbLinkIsConstant(&prec->inp)) {
105  status = dbLoadLinkArray(&prec->inp, prec->ftvl, prec->bptr, &rt.nRequest);
106  if (status == S_db_badField) { /* INP was empty */
107  rt.nRequest = prec->nord;
108  status = 0;
109  }
110  }
111  else {
112  status = dbLinkDoLocked(&prec->inp, readLocked, &rt);
113 
114  if (status == S_db_noLSET)
115  status = readLocked(&prec->inp, &rt);
116  }
117 
118  if (!status && rt.nRequest > 0) {
119  subset(prec, rt.nRequest);
120 
121  if (nord != prec->nord)
122  db_post_events(prec, &prec->nord, DBE_VALUE | DBE_LOG);
123  }
124 
125  return status;
126 }
Definition: devSASoft.c:74
#define FALSE
Definition: dbDefs.h:32
pvd::Status status
long nRequest
Definition: devSASoft.c:75
#define init_record
epicsTimeStamp * ptime
Definition: devSASoft.c:76
#define NULL
Definition: catime.c:38
unsigned int epicsUInt32
Definition: epicsTypes.h:43
Miscellaneous macro definitions.
sadset devSASoft
Definition: devSASoft.c:32
#define DBE_VALUE
Definition: caeventmask.h:38
Device support routines.
Definition: devSup.h:140
#define epicsTimeEventDeviceTime
Definition: epicsTime.h:362
#define DBE_LOG
Definition: caeventmask.h:40
epicsExportAddress(dset, devSASoft)
EPICS time stamp, for use from C code.
Definition: epicsTime.h:33
if(yy_init)
Definition: scan.c:972
int prec
Definition: reader.c:29
Exporting IOC objects.