This is Unofficial EPICS BASE Doxygen Site
devEnviron.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2016 UChicago Argonne LLC, as Operator of Argonne
3 * National Laboratory.
4 * EPICS BASE is distributed subject to a Software License Agreement found
5 * in file LICENSE that is included with this distribution.
6 \*************************************************************************/
7 
8 /* devEnviron.c */
9 
10 #include <stdlib.h>
11 #include <string.h>
12 
13 #include "alarm.h"
14 #include "dbCommon.h"
15 #include "devSup.h"
16 #include "errlog.h"
17 #include "recGbl.h"
18 #include "recSup.h"
19 
20 #include "lsiRecord.h"
21 #include "stringinRecord.h"
22 #include "epicsExport.h"
23 
24 /* lsi device support */
25 
26 static long add_lsi(dbCommon *pcommon) {
27  lsiRecord *prec = (lsiRecord *) pcommon;
28 
29  if (prec->inp.type != INST_IO)
30  return S_dev_badInpType;
31 
32  return 0;
33 }
34 
35 static long del_lsi(dbCommon *pcommon) {
36  return 0;
37 }
38 
39 static struct dsxt dsxtLsiEnviron = {
40  add_lsi, del_lsi
41 };
42 
43 static long init_lsi(int pass)
44 {
45  if (pass == 0)
46  devExtend(&dsxtLsiEnviron);
47 
48  return 0;
49 }
50 
51 static long read_lsi(lsiRecord *prec)
52 {
53  const char *val = getenv(prec->inp.value.instio.string);
54 
55  if (val) {
56  strncpy(prec->val, val, prec->sizv);
57  prec->val[prec->sizv - 1] = 0;
58  prec->len = strlen(prec->val);
59  prec->udf = FALSE;
60  }
61  else {
62  prec->val[0] = 0;
63  prec->len = 1;
64  prec->udf = TRUE;
65  recGblSetSevr(prec, UDF_ALARM, prec->udfs);
66  }
67 
68  return 0;
69 }
70 
71 lsidset devLsiEnviron = {
72  {5, NULL, init_lsi, NULL, NULL }, read_lsi
73 };
74 epicsExportAddress(dset, devLsiEnviron);
75 
76 
77 /* stringin device support */
78 
79 static long add_stringin(dbCommon *pcommon) {
80  stringinRecord *prec = (stringinRecord *) pcommon;
81 
82  if (prec->inp.type != INST_IO)
83  return S_dev_badInpType;
84 
85  return 0;
86 }
87 
88 static long del_stringin(dbCommon *pcommon) {
89  return 0;
90 }
91 
92 static struct dsxt dsxtSiEnviron = {
93  add_stringin, del_stringin
94 };
95 
96 static long init_stringin(int pass)
97 {
98  if (pass == 0)
99  devExtend(&dsxtSiEnviron);
100 
101  return 0;
102 }
103 
104 static long read_stringin(stringinRecord *prec)
105 {
106  const char *val = getenv(prec->inp.value.instio.string);
107 
108  if (val) {
109  strncpy(prec->val, val, MAX_STRING_SIZE);
110  prec->val[MAX_STRING_SIZE - 1] = 0;
111  prec->udf = FALSE;
112  }
113  else {
114  prec->val[0] = 0;
115  prec->udf = TRUE;
116  recGblSetSevr(prec, UDF_ALARM, prec->udfs);
117  }
118 
119  return 0;
120 }
121 
122 stringindset devSiEnviron = {
123  {5, NULL, init_stringin, NULL, NULL},
124  read_stringin
125 };
126 epicsExportAddress(dset, devSiEnviron);
Definition: devSup.h:117
#define FALSE
Definition: dbDefs.h:32
void devExtend(dsxt *pdsxt)
Definition: dbStaticRun.c:60
epicsExportAddress(dset, devLsiEnviron)
stringindset devSiEnviron
Definition: devEnviron.c:122
#define NULL
Definition: catime.c:38
Device support routines.
Definition: devSup.h:140
#define S_dev_badInpType
Definition: devSup.h:171
lsidset devLsiEnviron
Definition: devEnviron.c:71
#define MAX_STRING_SIZE
Definition: epicsTypes.h:65
#define TRUE
Definition: dbDefs.h:27
int prec
Definition: reader.c:29
#define UDF_ALARM
Definition: alarm.h:108
Exporting IOC objects.