This is Unofficial EPICS BASE Doxygen Site
devAiSoft.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 /*
11  * Original Authors: Bob Dalesio and Marty Kraimer
12  * Date: 3/6/91
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 "epicsMath.h"
23 #include "recGbl.h"
24 #include "devSup.h"
25 #include "aiRecord.h"
26 #include "epicsExport.h"
27 
28 /* Create the dset for devAiSoft */
29 static long init_record(dbCommon *pcommon);
30 static long read_ai(aiRecord *prec);
31 
32 aidset devAiSoft = {
33  {6, NULL, NULL, init_record, NULL},
34  read_ai, NULL
35 };
37 
38 static long init_record(dbCommon *pcommon)
39 {
40  aiRecord *prec = (aiRecord *)pcommon;
41 
42  if (recGblInitConstantLink(&prec->inp, DBF_DOUBLE, &prec->val))
43  prec->udf = FALSE;
44 
45  return 0;
46 }
47 
48 struct aivt {
49  double val;
51 };
52 
53 static long readLocked(struct link *pinp, void *vvt)
54 {
55  struct aivt *pvt = (struct aivt *) vvt;
56  long status = dbGetLink(pinp, DBR_DOUBLE, &pvt->val, 0, 0);
57 
58  if (!status && pvt->ptime)
59  dbGetTimeStamp(pinp, pvt->ptime);
60 
61  return status;
62 }
63 
64 static long read_ai(aiRecord *prec)
65 {
66  long status;
67  struct aivt vt;
68 
69  if (dbLinkIsConstant(&prec->inp))
70  return 2;
71 
72  vt.ptime = (dbLinkIsConstant(&prec->tsel) &&
73  prec->tse == epicsTimeEventDeviceTime) ? &prec->time : NULL;
74 
75  status = dbLinkDoLocked(&prec->inp, readLocked, &vt);
76  if (status == S_db_noLSET)
77  status = readLocked(&prec->inp, &vt);
78 
79  if (!status) {
80  /* Apply smoothing algorithm */
81  if (prec->smoo != 0.0 && prec->dpvt && finite(prec->val))
82  prec->val = vt.val * (1.0 - prec->smoo) + (prec->val * prec->smoo);
83  else
84  prec->val = vt.val;
85 
86  prec->udf = FALSE;
87  prec->dpvt = &devAiSoft; /* Any non-zero value */
88  }
89  else
90  prec->dpvt = NULL;
91 
92  return 2;
93 }
#define FALSE
Definition: dbDefs.h:32
pvd::Status status
#define init_record
#define NULL
Definition: catime.c:38
aidset devAiSoft
Definition: devAiSoft.c:32
Miscellaneous macro definitions.
double val
Definition: devAiSoft.c:49
Device support routines.
Definition: devSup.h:140
#define epicsTimeEventDeviceTime
Definition: epicsTime.h:362
epicsTimeStamp * ptime
Definition: devAiSoft.c:50
#define DBR_DOUBLE
Definition: db_access.h:76
Definition: devAiSoft.c:48
EPICS time stamp, for use from C code.
Definition: epicsTime.h:33
#define finite(x)
Definition: epicsMath.h:16
int prec
Definition: reader.c:29
epicsExportAddress(dset, devAiSoft)
Exporting IOC objects.