pva2pva  1.4.1
 All Classes Functions Variables Pages
demo.cpp
1 
2 #include <epicsMath.h>
3 #include <dbAccess.h>
4 #include <dbScan.h>
5 #include <dbLink.h>
6 #include <recGbl.h>
7 #include <alarm.h>
8 
9 #include <longinRecord.h>
10 #include <waveformRecord.h>
11 #include <menuFtype.h>
12 
13 #include <epicsExport.h>
14 
15 namespace {
16 
17 // pi/180
18 static const double pi_180 = 0.017453292519943295;
19 
20 int dummy;
21 
22 long init_spin(waveformRecord *prec)
23 {
24  if(prec->ftvl==menuFtypeDOUBLE)
25  prec->dpvt = &dummy;
26  return 0;
27 }
28 
29 long process_spin(waveformRecord *prec)
30 {
31  if(prec->dpvt != &dummy) {
32  (void)recGblSetSevr(prec, COMM_ALARM, INVALID_ALARM);
33  return 0;
34  }
35 
36  const double freq = 360.0*pi_180/100; // rad/sample
37  double phase = 0;
38  double *val = static_cast<double*>(prec->bptr);
39 
40  long ret = dbGetLink(&prec->inp, DBF_DOUBLE, &phase, 0, 0);
41  if(ret) {
42  (void)recGblSetSevr(prec, LINK_ALARM, INVALID_ALARM);
43  return ret;
44  }
45 
46  phase *= pi_180; // deg -> rad
47 
48  for(size_t i=0, N=prec->nelm; i<N; i++)
49  val[i] = sin(freq*i+phase);
50 
51  prec->nord = prec->nelm;
52 
53 #ifdef DBRutag
54  prec->utag = (prec->utag+1u)&0x7fffffff;
55 #endif
56 
57  return 0;
58 }
59 
60 long process_repeat(waveformRecord *prec)
61 {
62  long ret;
63  if(prec->ftvl!=menuFtypeULONG) {
64  recGblSetSevr(prec, READ_ALARM, INVALID_ALARM);
65  return S_db_badDbrtype;
66  }
67 
68  epicsUInt32 iv=0;
69  if(!!(ret = dbGetLink(&prec->inp, DBF_ULONG, &iv, NULL, NULL))) {
70  recGblSetSevr(prec, READ_ALARM, INVALID_ALARM);
71  return ret;
72  }
73 
74  epicsUInt32 *val = (epicsUInt32*)prec->bptr;
75  for(size_t i=0, N=prec->nelm; i<N; i++) {
76  val[i] = iv;
77  }
78 
79  prec->nord = iv;
80 
81  return 0;
82 }
83 
84 long process_utag(longinRecord *prec)
85 {
86  long status = dbGetLink(&prec->inp, DBR_LONG, &prec->val, 0, 0);
87 #ifdef DBRutag
88  prec->utag = prec->val;
89 #else
90  (void)recGblSetSevr(prec, COMM_ALARM, INVALID_ALARM);
91 #endif
92  return status;
93 }
94 
95 template<typename REC>
96 struct dset5
97 {
98  long count;
99  long (*report)(int);
100  long (*init)(int);
101  long (*init_record)(REC *);
102  long (*get_ioint_info)(int, REC *, IOSCANPVT*);
103  long (*process)(REC *);
104 };
105 
106 dset5<waveformRecord> devWfPDBDemo = {5,0,0,&init_spin,0,&process_spin};
107 dset5<waveformRecord> devWfPDBDemoRepeat = {5,0,0,0,0,&process_repeat};
108 dset5<longinRecord> devLoPDBUTag = {5,0,0,0,0,&process_utag};
109 
110 } // namespace
111 
112 extern "C" {
113 epicsExportAddress(dset, devWfPDBDemo);
114 epicsExportAddress(dset, devWfPDBDemoRepeat);
115 epicsExportAddress(dset, devLoPDBUTag);
116 }