24 #include <epicsTypes.h> 26 #include <dbStaticLib.h> 35 #include <stringinRecord.h> 40 #include <epicsExport.h> 44 std::string strip(
const std::string& inp)
46 size_t S = inp.find_first_not_of(
" \t"),
47 E = inp.find_last_not_of(
" \t");
51 return inp.substr(S,
E-S+1);
56 template<
typename REC>
57 explicit DBENT(REC *prec)
59 dbInitEntry(pdbbase, &entry);
60 if(dbFindRecord(&entry, prec->name))
61 throw std::logic_error(
"Failed to lookup DBENTRY from dbCommon");
64 dbFinishEntry(&entry);
69 typedef std::map<epicsInt32, std::string> lut_t;
75 long init_record_lut(stringinRecord *prec)
78 mrf::auto_ptr<LUTPriv>
priv(
new LUTPriv);
80 priv->unknown =
"<unknown>";
84 for(
long status = dbFirstInfo(&entry.entry); status==0; status = dbNextInfo(&entry.entry))
86 const char *
const name = dbGetInfoName(&entry.entry);
88 std::string line(dbGetInfoString(&entry.entry));
90 if(strcmp(name,
"lutX")==0) {
91 priv->unknown = strip(line);
93 printf(
"%s : LUT <fallback> -> \"%s\"\n", prec->name,
priv->unknown.c_str());
96 }
else if(strncmp(name,
"lut", 3)!=0) {
100 size_t eq = line.find_first_of(
'=');
102 fprintf(stderr,
"%s : info %s value missing '=' : %s\n", prec->name, name, line.c_str());
108 std::string num(line.substr(0, eq));
110 fprintf(stderr,
"%s : info %s index not number \"%s\"\n", prec->name, name, num.c_str());
111 throw std::runtime_error(
"Invalid LUT entry");
115 std::pair<LUTPriv::lut_t::iterator, bool> ret =
116 priv->lut.insert(std::make_pair(raw, strip(line.substr(eq+1))));
119 printf(
"%s : LUT %u -> \"%s\"\n", prec->name, ret.first->first, ret.first->second.c_str());
123 strncpy(prec->val,
priv->unknown.c_str(),
sizeof(prec->val));
124 prec->val[
sizeof(prec->val)-1] =
'\0';
126 prec->dpvt =
priv.release();
133 long read_lut(stringinRecord *prec)
135 const LUTPriv *
const priv =
static_cast<LUTPriv*
>(prec->dpvt);
137 (void)recGblSetSevr(prec, COMM_ALARM, INVALID_ALARM);
141 const std::string *val = &priv->unknown;
144 long status = dbGetLink(&prec->inp, DBR_LONG, &raw, 0, 0);
147 (void)recGblSetSevr(prec, LINK_ALARM, INVALID_ALARM);
150 LUTPriv::lut_t::const_iterator it = priv->lut.find(raw);
151 if(it==priv->lut.end()) {
152 (void)recGblSetSevr(prec, READ_ALARM, INVALID_ALARM);
159 printf(
"%s : LUT status=%ld select=%u VAL=\"%s\"\n",
160 prec->name, status, (
unsigned)raw, val->c_str());
162 strncpy(prec->val, val->c_str(),
sizeof(prec->val));
163 prec->val[
sizeof(prec->val)-1] =
'\0';
173 (DEVSUPFUN)&init_record_lut,
175 (DEVSUPFUN)&read_lut,
int epicsParseUInt32(const char *str, epicsUInt32 *to, int base, char **units)
epicsExportAddress(dset, devLUTSI)