This is Unofficial EPICS BASE Doxygen Site
fanoutRecord.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2012 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 Author: Bob Dalesio
12  * Date: 12-20-88
13  */
14 
15 #include <stddef.h>
16 #include <stdlib.h>
17 #include <stdarg.h>
18 #include <stdio.h>
19 #include <string.h>
20 
21 #include "dbDefs.h"
22 #include "epicsPrint.h"
23 #include "alarm.h"
24 #include "dbAccess.h"
25 #include "dbEvent.h"
26 #include "dbFldTypes.h"
27 #include "errMdef.h"
28 #include "epicsTypes.h"
29 #include "recSup.h"
30 #include "recGbl.h"
31 #include "dbCommon.h"
32 
33 #define GEN_SIZE_OFFSET
34 #include "fanoutRecord.h"
35 #undef GEN_SIZE_OFFSET
36 #include "epicsExport.h"
37 
38 #define NLINKS 16
39 
40 /* Create RSET - Record Support Entry Table*/
41 #define report NULL
42 #define initialize NULL
43 static long init_record(struct dbCommon *, int);
44 static long process(struct dbCommon *);
45 #define special NULL
46 #define get_value NULL
47 #define cvt_dbaddr NULL
48 #define get_array_info NULL
49 #define put_array_info NULL
50 #define get_units NULL
51 #define get_precision NULL
52 #define get_enum_str NULL
53 #define get_enum_strs NULL
54 #define put_enum_str NULL
55 #define get_graphic_double NULL
56 #define get_control_double NULL
57 #define get_alarm_double NULL
58 
60  RSETNUMBER,
61  report,
62  initialize,
64  process,
65  special,
66  get_value,
67  cvt_dbaddr,
70  get_units,
78 };
79 epicsExportAddress(rset,fanoutRSET);
80 
81 static long init_record(struct dbCommon *pcommon, int pass)
82 {
83  struct fanoutRecord *prec = (struct fanoutRecord *)pcommon;
84  if (pass == 0)
85  return 0;
86 
87  recGblInitConstantLink(&prec->sell, DBF_USHORT, &prec->seln);
88  return 0;
89 }
90 
91 static long process(struct dbCommon *pcommon)
92 {
93  struct fanoutRecord *prec = (struct fanoutRecord *)pcommon;
94  struct link *plink;
95  epicsUInt16 seln, events;
96  int i;
97  epicsUInt16 oldn = prec->seln;
98 
99  prec->pact = TRUE;
100 
101  /* fetch link selection */
102  dbGetLink(&prec->sell, DBR_USHORT, &prec->seln, 0, 0);
103  seln = prec->seln;
104 
105  switch (prec->selm) {
106  case fanoutSELM_All:
107  plink = &prec->lnk0;
108  for (i = 0; i < NLINKS; i++, plink++) {
109  dbScanFwdLink(plink);
110  }
111  break;
112 
113  case fanoutSELM_Specified:
114  i = seln + prec->offs;
115  if (i < 0 || i >= NLINKS) {
116  recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
117  break;
118  }
119  plink = &prec->lnk0 + i;
120  dbScanFwdLink(plink);
121  break;
122 
123  case fanoutSELM_Mask:
124  i = prec->shft;
125  if (i < -15 || i > 15) {
126  /* Shifting by more than the number of bits in the
127  * value produces undefined behavior in C */
128  recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
129  break;
130  }
131  seln = (i >= 0) ? seln >> i : seln << -i;
132  if (seln == 0)
133  break;
134  plink = &prec->lnk0;
135  for (i = 0; i < NLINKS; i++, seln >>= 1, plink++) {
136  if (seln & 1)
137  dbScanFwdLink(plink);
138  }
139  break;
140  default:
141  recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
142  }
143  prec->udf = FALSE;
144  recGblGetTimeStamp(prec);
145 
146  /* post monitors */
147  events = recGblResetAlarms(prec);
148  if (events)
149  db_post_events(prec, &prec->val, events);
150  if (prec->seln != oldn)
151  db_post_events(prec, &prec->seln, events | DBE_VALUE | DBE_LOG);
152 
153  /* finish off */
154  recGblFwdLink(prec);
155  prec->pact = FALSE;
156  return 0;
157 }
#define RSETNUMBER
Definition: recSup.h:92
#define FALSE
Definition: dbDefs.h:32
#define special
Definition: fanoutRecord.c:45
int i
Definition: scan.c:967
#define DBR_USHORT
Definition: dbFldTypes.h:80
unsigned short epicsUInt16
Definition: epicsTypes.h:41
#define initialize
Definition: fanoutRecord.c:42
#define init_record
epicsExportAddress(rset, fanoutRSET)
#define SOFT_ALARM
Definition: alarm.h:106
#define NLINKS
Definition: fanoutRecord.c:38
#define put_array_info
Definition: fanoutRecord.c:49
Miscellaneous macro definitions.
rset fanoutRSET
Definition: fanoutRecord.c:59
#define get_control_double
Definition: fanoutRecord.c:56
#define cvt_dbaddr
Definition: fanoutRecord.c:47
#define get_array_info
Definition: fanoutRecord.c:48
#define get_enum_strs
Definition: fanoutRecord.c:53
#define DBE_VALUE
Definition: caeventmask.h:38
#define report
Definition: fanoutRecord.c:41
#define DBE_LOG
Definition: caeventmask.h:40
#define get_graphic_double
Definition: fanoutRecord.c:55
#define get_precision
Definition: fanoutRecord.c:51
#define get_units
Definition: fanoutRecord.c:50
#define TRUE
Definition: dbDefs.h:27
#define get_enum_str
Definition: fanoutRecord.c:52
#define get_value
Definition: fanoutRecord.c:46
Definition: recSup.h:67
int prec
Definition: reader.c:29
#define INVALID_ALARM
Definition: alarm.h:53
#define get_alarm_double
Definition: fanoutRecord.c:57
#define put_enum_str
Definition: fanoutRecord.c:54
Exporting IOC objects.