Move all under modules/database

This commit is contained in:
Ralph Lange committed 2018-06-19 11:31:13 +02:00
1 parent e613d685fd
commit 568c405165
562 files changed
-101

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
#*************************************************************************
# Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
TOP = ../..
include $(TOP)/configure/CONFIG
STDDIR=$(TOP)/src/std
LIBRARY_IOC += dbRecStd
dbRecStd_LIBS = dbCore ca Com
dbRecStd_RCS += dbRecStd.rc
include $(STDDIR)/rec/Makefile
include $(STDDIR)/dev/Makefile
include $(STDDIR)/filters/Makefile
include $(STDDIR)/link/Makefile
include $(STDDIR)/softIoc/Makefile
include $(TOP)/configure/RULES
include $(STDDIR)/rec/RULES
include $(STDDIR)/softIoc/RULES
+36
View File
@@ -0,0 +1,36 @@
#include <winver.h>
#include "epicsVersion.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION EPICS_VERSION,EPICS_REVISION,EPICS_MODIFICATION,EPICS_PATCH_LEVEL
PRODUCTVERSION EPICS_VERSION,EPICS_REVISION,EPICS_MODIFICATION,EPICS_PATCH_LEVEL
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_UNKNOWN
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments","Record and Soft Device Support Library for EPICS\0"
VALUE "CompanyName", "The EPICS collaboration\0"
VALUE "FileDescription", "Record and Soft Device Support Library\0"
VALUE "FileVersion", EPICS_VERSION_STRING "\0"
VALUE "InternalName", "dbRecStd\0"
VALUE "LegalCopyright", "Copyright (C) Univ. of California, Univ. of Chicago\0"
VALUE "OriginalFilename", "dbRecStd.dll\0"
VALUE "ProductName", "Experimental Physics and Industrial Control System (EPICS)\0"
VALUE "ProductVersion", EPICS_VERSION_STRING "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
+76
View File
@@ -0,0 +1,76 @@
#*************************************************************************
# Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
# This is a Makefile fragment, see src/std/Makefile.
SRC_DIRS += $(STDDIR)/dev
DBD += devSoft.dbd
dbRecStd_SRCS += devAaiSoft.c
dbRecStd_SRCS += devAaoSoft.c
dbRecStd_SRCS += devAiSoft.c
dbRecStd_SRCS += devAiSoftRaw.c
dbRecStd_SRCS += devAoSoft.c
dbRecStd_SRCS += devAoSoftRaw.c
dbRecStd_SRCS += devBiSoft.c
dbRecStd_SRCS += devBiSoftRaw.c
dbRecStd_SRCS += devBiDbState.c
dbRecStd_SRCS += devBoSoft.c
dbRecStd_SRCS += devBoSoftRaw.c
dbRecStd_SRCS += devBoDbState.c
dbRecStd_SRCS += devCalcoutSoft.c
dbRecStd_SRCS += devEventSoft.c
dbRecStd_SRCS += devHistogramSoft.c
dbRecStd_SRCS += devI64inSoft.c
dbRecStd_SRCS += devI64outSoft.c
dbRecStd_SRCS += devLiSoft.c
dbRecStd_SRCS += devLoSoft.c
dbRecStd_SRCS += devLsiSoft.c
dbRecStd_SRCS += devLsoSoft.c
dbRecStd_SRCS += devMbbiDirectSoft.c
dbRecStd_SRCS += devMbbiDirectSoftRaw.c
dbRecStd_SRCS += devMbbiSoft.c
dbRecStd_SRCS += devMbbiSoftRaw.c
dbRecStd_SRCS += devMbboDirectSoft.c
dbRecStd_SRCS += devMbboDirectSoftRaw.c
dbRecStd_SRCS += devMbboSoft.c
dbRecStd_SRCS += devMbboSoftRaw.c
dbRecStd_SRCS += devPrintfSoft.c
dbRecStd_SRCS += devSASoft.c
dbRecStd_SRCS += devSiSoft.c
dbRecStd_SRCS += devSoSoft.c
dbRecStd_SRCS += devWfSoft.c
dbRecStd_SRCS += devGeneralTime.c
dbRecStd_SRCS += devAiSoftCallback.c
dbRecStd_SRCS += devBiSoftCallback.c
dbRecStd_SRCS += devI64inSoftCallback.c
dbRecStd_SRCS += devLiSoftCallback.c
dbRecStd_SRCS += devMbbiDirectSoftCallback.c
dbRecStd_SRCS += devMbbiSoftCallback.c
dbRecStd_SRCS += devSiSoftCallback.c
dbRecStd_SRCS += devAoSoftCallback.c
dbRecStd_SRCS += devBoSoftCallback.c
dbRecStd_SRCS += devCalcoutSoftCallback.c
dbRecStd_SRCS += devI64outSoftCallback.c
dbRecStd_SRCS += devLoSoftCallback.c
dbRecStd_SRCS += devLsoSoftCallback.c
dbRecStd_SRCS += devMbboSoftCallback.c
dbRecStd_SRCS += devMbboDirectSoftCallback.c
dbRecStd_SRCS += devPrintfSoftCallback.c
dbRecStd_SRCS += devSoSoftCallback.c
dbRecStd_SRCS += devTimestamp.c
dbRecStd_SRCS += devStdio.c
dbRecStd_SRCS += devEnviron.c
dbRecStd_SRCS += asSubRecordFunctions.c
@@ -0,0 +1,91 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* asSubRecordFunctions.c */
/* Author: Marty Kraimer Date: 01MAY2000 */
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "dbAccess.h"
#include "cantProceed.h"
#include "callback.h"
#include "alarm.h"
#include "errlog.h"
#include "dbEvent.h"
#include "recSup.h"
#include "recGbl.h"
#include "registryFunction.h"
#include "asLib.h"
#include "asDbLib.h"
#include "subRecord.h"
#include "epicsExport.h"
/* The following is provided for access security*/
/*It allows a CA client to force access security initialization*/
static void myCallback(CALLBACK *pcallback)
{
ASDBCALLBACK *pasdbcallback = (ASDBCALLBACK *)pcallback;
subRecord *precord;
rset *prset;
callbackGetUser(precord,pcallback);
prset=(rset *)(precord->rset);
precord->val = 0.0;
if(pasdbcallback->status) {
recGblSetSevr(precord,READ_ALARM,precord->brsv);
recGblRecordError(pasdbcallback->status,precord,"asInit Failed");
}
dbScanLock((dbCommon *)precord);
(*prset->process)((dbCommon *)precord);
dbScanUnlock((dbCommon *)precord);
}
long asSubInit(subRecord *precord,void *process)
{
ASDBCALLBACK *pcallback;
pcallback = (ASDBCALLBACK *)callocMustSucceed(
1,sizeof(ASDBCALLBACK),"asSubInit");
precord->dpvt = (void *)pcallback;
callbackSetCallback(myCallback,&pcallback->callback);
callbackSetUser(precord,&pcallback->callback);
return(0);
}
long asSubProcess(subRecord *precord)
{
ASDBCALLBACK *pcallback = (ASDBCALLBACK *)precord->dpvt;
if(!precord->pact && precord->val==1.0) {
db_post_events(precord,&precord->val,DBE_VALUE);
callbackSetPriority(precord->prio,&pcallback->callback);
asInitAsyn(pcallback);
precord->pact=TRUE;
return(1);
}
db_post_events(precord,&precord->val,DBE_VALUE);
return(0);
}
static registryFunctionRef asSubRef[] = {
{"asSubInit",(REGISTRYFUNCTION)asSubInit},
{"asSubProcess",(REGISTRYFUNCTION)asSubProcess}
};
static void asSub(void)
{
registryFunctionRefAdd(asSubRef,NELEMENTS(asSubRef));
}
epicsExportRegistrar(asSub);
+106
View File
@@ -0,0 +1,106 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* devAaiSoft.c - Device Support Routines for soft Waveform Records
*
* Original Author: Bob Dalesio
* Current Author: Dirk Zimoch
* Date: 27-MAY-2010
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "dbConstLink.h"
#include "recGbl.h"
#include "devSup.h"
#include "cantProceed.h"
#include "menuYesNo.h"
#include "aaiRecord.h"
#include "epicsExport.h"
/* Create the dset for devAaiSoft */
static long init_record();
static long read_aai();
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_aai;
} devAaiSoft = {
5,
NULL,
NULL,
init_record,
NULL,
read_aai
};
epicsExportAddress(dset,devAaiSoft);
static long init_record(aaiRecord *prec)
{
DBLINK *plink = &prec->inp;
/* This is pass 0, link hasn't been initialized yet */
dbInitLink(plink, DBF_INLINK);
if (dbLinkIsConstant(plink)) {
long nRequest = prec->nelm;
long status;
/* Allocate a buffer, record support hasn't done that yet */
if (!prec->bptr) {
prec->bptr = callocMustSucceed(nRequest, dbValueSize(prec->ftvl),
"devAaiSoft: buffer calloc failed");
}
status = dbLoadLinkArray(plink, prec->ftvl, prec->bptr, &nRequest);
if (!status && nRequest > 0) {
prec->nord = nRequest;
prec->udf = FALSE;
}
}
return 0;
}
static long readLocked(struct link *pinp, void *dummy)
{
aaiRecord *prec = (aaiRecord *) pinp->precord;
long nRequest = prec->nelm;
long status = dbGetLink(pinp, prec->ftvl, prec->bptr, 0, &nRequest);
if (!status && nRequest > 0) {
prec->nord = nRequest;
prec->udf = FALSE;
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(pinp, &prec->time);
}
return status;
}
static long read_aai(aaiRecord *prec)
{
struct link *pinp = prec->simm == menuYesNoYES ? &prec->siol : &prec->inp;
long status = dbLinkDoLocked(pinp, readLocked, NULL);
if (status == S_db_noLSET)
status = readLocked(pinp, NULL);
return status;
}
+68
View File
@@ -0,0 +1,68 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* devAaoSoft.c - Device Support Routines for soft Waveform Records
*
* Original Author: Bob Dalesio
* Current Author: Dirk Zimoch
* Date: 27-MAY-2010
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "cantProceed.h"
#include "menuYesNo.h"
#include "aaoRecord.h"
#include "epicsExport.h"
/* Create the dset for devAaoSoft */
static long init_record();
static long write_aao();
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_aao;
} devAaoSoft = {
5,
NULL,
NULL,
init_record,
NULL,
write_aao
};
epicsExportAddress(dset,devAaoSoft);
static long init_record(aaoRecord *prec)
{
if (dbLinkIsConstant(&prec->out)) {
prec->nord = 0;
}
return 0;
}
static long write_aao(aaoRecord *prec)
{
long nRequest = prec->nord;
dbPutLink(prec->simm == menuYesNoYES ? &prec->siol : &prec->out,
prec->ftvl, prec->bptr, nRequest);
return 0;
}
+104
View File
@@ -0,0 +1,104 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Authors: Bob Dalesio and Marty Kraimer
* Date: 3/6/91
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "epicsMath.h"
#include "recGbl.h"
#include "devSup.h"
#include "aiRecord.h"
#include "epicsExport.h"
/* Create the dset for devAiSoft */
static long init_record(aiRecord *prec);
static long read_ai(aiRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_ai;
DEVSUPFUN special_linconv;
} devAiSoft = {
6,
NULL,
NULL,
init_record,
NULL,
read_ai,
NULL
};
epicsExportAddress(dset, devAiSoft);
static long init_record(aiRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBF_DOUBLE, &prec->val))
prec->udf = FALSE;
return 0;
}
struct aivt {
double val;
epicsTimeStamp *ptime;
};
static long readLocked(struct link *pinp, void *vvt)
{
struct aivt *pvt = (struct aivt *) vvt;
long status = dbGetLink(pinp, DBR_DOUBLE, &pvt->val, 0, 0);
if (!status && pvt->ptime)
dbGetTimeStamp(pinp, pvt->ptime);
return status;
}
static long read_ai(aiRecord *prec)
{
long status;
struct aivt vt;
if (dbLinkIsConstant(&prec->inp))
return 2;
vt.ptime = (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime) ? &prec->time : NULL;
status = dbLinkDoLocked(&prec->inp, readLocked, &vt);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, &vt);
if (!status) {
/* Apply smoothing algorithm */
if (prec->smoo != 0.0 && prec->dpvt && finite(prec->val))
prec->val = vt.val * (1.0 - prec->smoo) + (prec->val * prec->smoo);
else
prec->val = vt.val;
prec->udf = FALSE;
prec->dpvt = &devAiSoft; /* Any non-zero value */
}
else
prec->dpvt = NULL;
return 2;
}
@@ -0,0 +1,226 @@
/*************************************************************************\
* Copyright (c) 2010 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devAiSoftCallback.c */
/*
* Authors: Marty Kraimer & Andrew Johnson
*/
#include <stdlib.h>
#include <stdio.h>
#include "alarm.h"
#include "callback.h"
#include "cantProceed.h"
#include "dbCommon.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "dbChannel.h"
#include "dbNotify.h"
#include "epicsAssert.h"
#include "epicsMath.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "link.h"
#include "aiRecord.h"
#include "epicsExport.h"
#define GET_OPTIONS (DBR_STATUS | DBR_TIME)
typedef struct devPvt {
processNotify pn;
CALLBACK callback;
long options;
int status;
int smooth;
struct {
DBRstatus
DBRtime
epicsFloat64 value;
} buffer;
} devPvt;
static void getCallback(processNotify *ppn, notifyGetType type)
{
aiRecord *prec = (aiRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
long no_elements = 1;
if (ppn->status == notifyCanceled) {
printf("devAiSoftCallback::getCallback notifyCanceled\n");
return;
}
assert(type == getFieldType);
pdevPvt->status = dbChannelGetField(ppn->chan, DBR_DOUBLE,
&pdevPvt->buffer, &pdevPvt->options, &no_elements, 0);
}
static void doneCallback(processNotify *ppn)
{
aiRecord *prec = (aiRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
callbackRequestProcessCallback(&pdevPvt->callback, prec->prio, prec);
}
static long add_record(dbCommon *pcommon)
{
aiRecord *prec = (aiRecord *)pcommon;
DBLINK *plink = &prec->inp;
dbChannel *chan;
devPvt *pdevPvt;
processNotify *ppn;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
if (plink->type != PV_LINK) {
long status = S_db_badField;
recGblRecordError(status, (void *)prec,
"devAiSoftCallback (add_record) Illegal INP field");
return status;
}
chan = dbChannelCreate(plink->value.pv_link.pvname);
if (!chan) {
long status = S_db_notFound;
recGblRecordError(status, (void *)prec,
"devAiSoftCallback (add_record) link target not found");
return status;
}
pdevPvt = calloc(1, sizeof(*pdevPvt));
if (!pdevPvt) {
long status = S_db_noMemory;
recGblRecordError(status, (void *)prec,
"devAiSoftCallback (add_record) out of memory, calloc() failed");
return status;
}
ppn = &pdevPvt->pn;
plink->type = PN_LINK;
plink->value.pv_link.pvlMask &= pvlOptMsMode; /* Severity flags only */
ppn->usrPvt = prec;
ppn->chan = chan;
ppn->getCallback = getCallback;
ppn->doneCallback = doneCallback;
ppn->requestType = processGetRequest;
pdevPvt->options = GET_OPTIONS;
prec->dpvt = pdevPvt;
return 0;
}
static long del_record(dbCommon *pcommon) {
aiRecord *prec = (aiRecord *)pcommon;
DBLINK *plink = &prec->inp;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
assert(plink->type == PN_LINK);
dbNotifyCancel(&pdevPvt->pn);
dbChannelDelete(pdevPvt->pn.chan);
free(pdevPvt);
plink->type = PV_LINK;
return 0;
}
static struct dsxt dsxtSoftCallback = {
add_record, del_record
};
static long init(int pass)
{
if (pass == 0) devExtend(&dsxtSoftCallback);
return 0;
}
static long init_record(aiRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBF_DOUBLE, &prec->val))
prec->udf = FALSE;
return 0;
}
static long read_ai(aiRecord *prec)
{
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (!prec->dpvt)
return 2;
if (!prec->pact) {
dbProcessNotify(&pdevPvt->pn);
prec->pact = TRUE;
return 0;
}
if (pdevPvt->status) {
recGblSetSevr(prec, READ_ALARM, INVALID_ALARM);
pdevPvt->smooth = FALSE;
return 2;
}
/* Apply smoothing algorithm */
if (prec->smoo != 0.0 && pdevPvt->smooth && finite(prec->val))
prec->val = prec->val * prec->smoo +
pdevPvt->buffer.value * (1.0 - prec->smoo);
else
prec->val = pdevPvt->buffer.value;
prec->udf = FALSE;
pdevPvt->smooth = TRUE;
switch (prec->inp.value.pv_link.pvlMask & pvlOptMsMode) {
case pvlOptNMS:
break;
case pvlOptMSI:
if (pdevPvt->buffer.severity < INVALID_ALARM)
break;
/* else fall through */
case pvlOptMS:
recGblSetSevr(prec, LINK_ALARM, pdevPvt->buffer.severity);
break;
case pvlOptMSS:
recGblSetSevr(prec, pdevPvt->buffer.status,
pdevPvt->buffer.severity);
break;
}
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
prec->time = pdevPvt->buffer.time;
return 2;
}
/* Create the dset for devAiSoftCallback */
struct {
dset common;
DEVSUPFUN read_ai;
DEVSUPFUN special_linconv;
} devAiSoftCallback = {
{6, NULL, init, init_record, NULL},
read_ai,
NULL
};
epicsExportAddress(dset, devAiSoftCallback);
@@ -0,0 +1,79 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Authors: Bob Dalesio and Marty Kraimer
* Date: 6-1-90
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "aiRecord.h"
#include "epicsExport.h"
/* Create the dset for devAiSoftRaw */
static long init_record(aiRecord *prec);
static long read_ai(aiRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_ai;
DEVSUPFUN special_linconv;
} devAiSoftRaw = {
6,
NULL,
NULL,
init_record,
NULL,
read_ai,
NULL
};
epicsExportAddress(dset, devAiSoftRaw);
static long init_record(aiRecord *prec)
{
recGblInitConstantLink(&prec->inp, DBF_LONG, &prec->rval);
return 0;
}
static long readLocked(struct link *pinp, void *dummy)
{
aiRecord *prec = (aiRecord *) pinp->precord;
long status = dbGetLink(pinp, DBR_LONG, &prec->rval, 0, 0);
if (status) return status;
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(pinp, &prec->time);
return status;
}
static long read_ai(aiRecord *prec)
{
long status = dbLinkDoLocked(&prec->inp, readLocked, NULL);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, NULL);
return status;
}
+74
View File
@@ -0,0 +1,74 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devAoSoft.c */
/* Device Support Routines for soft Analog Output Records*/
/*
* Original Author: Bob Dalesio
* Current Author: Marty Kraimer
* Date: 6-1-90
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "link.h"
#include "special.h"
#include "aoRecord.h"
#include "epicsExport.h"
/* added for Channel Access Links */
static long init_record(aoRecord *prec);
/* Create the dset for devAoSoft */
static long write_ao(aoRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_ao;
DEVSUPFUN special_linconv;
}devAoSoft={
6,
NULL,
NULL,
init_record,
NULL,
write_ao,
NULL};
epicsExportAddress(dset,devAoSoft);
static long init_record(aoRecord *prec)
{
long status=0;
status = 2;
return status;
} /* end init_record() */
static long write_ao(aoRecord *prec)
{
long status;
status = dbPutLink(&prec->out,DBR_DOUBLE, &prec->oval,1);
return(status);
}
@@ -0,0 +1,68 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devAoSoftCallbackCallback.c */
/*
* Author: Marty Kraimer
* Date: 04NOV2003
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "dbCa.h"
#include "link.h"
#include "special.h"
#include "aoRecord.h"
#include "epicsExport.h"
/* Create the dset for devAoSoftCallback */
static long write_ao(aoRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_ao;
DEVSUPFUN special_linconv;
}devAoSoftCallback={
6,
NULL,
NULL,
NULL,
NULL,
write_ao,
NULL};
epicsExportAddress(dset,devAoSoftCallback);
static long write_ao(aoRecord *prec)
{
struct link *plink = &prec->out;
long status;
if (prec->pact)
return 0;
status = dbPutLinkAsync(plink, DBR_DOUBLE, &prec->oval, 1);
if (!status)
prec->pact = TRUE;
else if (status == S_db_noLSET)
status = dbPutLink(plink, DBR_DOUBLE, &prec->oval, 1);
return status;
}
@@ -0,0 +1,62 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devAoSoftRaw.c */
/* Device Support Routines for soft raw Analog Output Records*/
/*
* Author: Janet Anderson
* Date: 09-25-91
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "link.h"
#include "special.h"
#include "aoRecord.h"
#include "epicsExport.h"
/* Create the dset for devAoSoftRaw */
static long write_ao(aoRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_ao;
DEVSUPFUN special_linconv;
}devAoSoftRaw={
6,
NULL,
NULL,
NULL,
NULL,
write_ao,
NULL
};
epicsExportAddress(dset,devAoSoftRaw);
static long write_ao(aoRecord *prec)
{
long status;
status = dbPutLink(&prec->out,DBR_LONG,&prec->rval,1);
return(status);
}
@@ -0,0 +1,88 @@
/*************************************************************************\
* Copyright (c) 2010 Brookhaven National Laboratory.
* Copyright (c) 2010 Helmholtz-Zentrum Berlin
* fuer Materialien und Energie GmbH.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Ralph Lange <Ralph.Lange@bessy.de>
*/
#include "errlog.h"
#include "dbState.h"
#include "devSup.h"
#include "recGbl.h"
#include "dbLink.h"
#include "dbAccessDefs.h"
#include "biRecord.h"
#include "epicsExport.h"
#define DEVSUPNAME "devBiDbState"
static long add_record (struct dbCommon *pdbc)
{
biRecord *prec = (biRecord *) pdbc;
if (INST_IO != prec->inp.type) {
recGblRecordError(S_db_badField, (void *) prec, DEVSUPNAME ": Illegal INP field");
return(S_db_badField);
}
if (!(prec->dpvt = dbStateFind(prec->inp.value.instio.string)) &&
prec->inp.value.instio.string &&
'\0' != *prec->inp.value.instio.string) {
errlogSevPrintf(errlogInfo, DEVSUPNAME ": Creating new db state '%s'\n",
prec->inp.value.instio.string);
prec->dpvt = dbStateCreate(prec->inp.value.instio.string);
}
return 0;
}
static long del_record (struct dbCommon *pdbc)
{
biRecord *prec = (biRecord *) pdbc;
prec->dpvt = NULL;
return 0;
}
static struct dsxt myDsxt = {
add_record,
del_record
};
static long init(int pass)
{
if (pass == 0)
devExtend(&myDsxt);
return 0;
}
static long read_bi(biRecord *prec)
{
if (prec->dpvt) {
prec->val = dbStateGet(prec->dpvt);
prec->udf = FALSE;
}
return 2;
}
static struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_bi;
} devBiDbState = {
5,
NULL,
init,
NULL,
NULL,
read_bi
};
epicsExportAddress(dset, devBiDbState);
+78
View File
@@ -0,0 +1,78 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Authors: Bob Dalesio and Marty Kraimer
* Date: 6-1-90
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "biRecord.h"
#include "epicsExport.h"
/* Create the dset for devBiSoft */
static long init_record(biRecord *prec);
static long read_bi(biRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_bi;
} devBiSoft = {
5,
NULL,
NULL,
init_record,
NULL,
read_bi
};
epicsExportAddress(dset, devBiSoft);
static long init_record(biRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBF_ENUM, &prec->val))
prec->udf = FALSE;
return 0;
}
static long readLocked(struct link *pinp, void *dummy)
{
biRecord *prec = (biRecord *) pinp->precord;
long status = dbGetLink(pinp, DBR_USHORT, &prec->val, 0, 0);
if (status) return status;
prec->udf = FALSE;
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(pinp, &prec->time);
return 2;
}
static long read_bi(biRecord *prec)
{
long status = dbLinkDoLocked(&prec->inp, readLocked, NULL);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, NULL);
return status;
}
@@ -0,0 +1,214 @@
/*************************************************************************\
* Copyright (c) 2010 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devBiSoftCallback.c */
/*
* Authors: Marty Kraimer & Andrew Johnson
*/
#include <stdlib.h>
#include <stdio.h>
#include "alarm.h"
#include "callback.h"
#include "cantProceed.h"
#include "dbCommon.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "dbChannel.h"
#include "dbNotify.h"
#include "epicsAssert.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "link.h"
#include "biRecord.h"
#include "epicsExport.h"
#define GET_OPTIONS (DBR_STATUS | DBR_TIME)
typedef struct devPvt {
processNotify pn;
CALLBACK callback;
long options;
int status;
struct {
DBRstatus
DBRtime
epicsEnum16 value;
} buffer;
} devPvt;
static void getCallback(processNotify *ppn,notifyGetType type)
{
biRecord *prec = (biRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
long no_elements = 1;
if (ppn->status == notifyCanceled) {
printf("devBiSoftCallback::getCallback notifyCanceled\n");
return;
}
assert(type == getFieldType);
pdevPvt->status = dbChannelGetField(ppn->chan, DBR_ENUM,
&pdevPvt->buffer, &pdevPvt->options, &no_elements, 0);
}
static void doneCallback(processNotify *ppn)
{
biRecord *prec = (biRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
callbackRequestProcessCallback(&pdevPvt->callback, prec->prio, prec);
}
static long add_record(dbCommon *pcommon)
{
biRecord *prec = (biRecord *)pcommon;
DBLINK *plink = &prec->inp;
dbChannel *chan;
devPvt *pdevPvt;
processNotify *ppn;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
if (plink->type != PV_LINK) {
long status = S_db_badField;
recGblRecordError(status, (void *)prec,
"devBiSoftCallback (add_record) Illegal INP field");
return status;
}
chan = dbChannelCreate(plink->value.pv_link.pvname);
if (!chan) {
long status = S_db_notFound;
recGblRecordError(status, (void *)prec,
"devBiSoftCallback (add_record) link target not found");
return status;
}
pdevPvt = calloc(1, sizeof(*pdevPvt));
if (!pdevPvt) {
long status = S_db_noMemory;
recGblRecordError(status, (void *)prec,
"devBiSoftCallback (add_record) out of memory, calloc() failed");
return status;
}
ppn = &pdevPvt->pn;
plink->type = PN_LINK;
plink->value.pv_link.pvlMask &= pvlOptMsMode; /* Severity flags only */
ppn->usrPvt = prec;
ppn->chan = chan;
ppn->getCallback = getCallback;
ppn->doneCallback = doneCallback;
ppn->requestType = processGetRequest;
pdevPvt->options = GET_OPTIONS;
prec->dpvt = pdevPvt;
return 0;
}
static long del_record(dbCommon *pcommon) {
biRecord *prec = (biRecord *)pcommon;
DBLINK *plink = &prec->inp;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
assert(plink->type == PN_LINK);
dbNotifyCancel(&pdevPvt->pn);
dbChannelDelete(pdevPvt->pn.chan);
free(pdevPvt);
plink->type = PV_LINK;
return 0;
}
static struct dsxt dsxtSoftCallback = {
add_record, del_record
};
static long init(int pass)
{
if (pass == 0) devExtend(&dsxtSoftCallback);
return 0;
}
static long init_record(biRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBR_ENUM, &prec->val))
prec->udf = FALSE;
return 0;
}
static long read_bi(biRecord *prec)
{
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (!prec->dpvt)
return 2;
if (!prec->pact) {
dbProcessNotify(&pdevPvt->pn);
prec->pact = TRUE;
return 0;
}
if (pdevPvt->status) {
recGblSetSevr(prec, READ_ALARM, INVALID_ALARM);
return 2;
}
prec->val = pdevPvt->buffer.value;
prec->udf = FALSE;
switch (prec->inp.value.pv_link.pvlMask & pvlOptMsMode) {
case pvlOptNMS:
break;
case pvlOptMSI:
if (pdevPvt->buffer.severity < INVALID_ALARM)
break;
/* else fall through */
case pvlOptMS:
recGblSetSevr(prec, LINK_ALARM, pdevPvt->buffer.severity);
break;
case pvlOptMSS:
recGblSetSevr(prec, pdevPvt->buffer.status,
pdevPvt->buffer.severity);
break;
}
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
prec->time = pdevPvt->buffer.time;
return 2;
}
/* Create the dset for devBiSoftCallback */
struct {
dset common;
DEVSUPFUN read_bi;
} devBiSoftCallback = {
{5, NULL, init, init_record, NULL},
read_bi
};
epicsExportAddress(dset, devBiSoftCallback);
@@ -0,0 +1,77 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Authors: Bob Dalesio and Marty Kraimer
* Date: 6-1-90
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "biRecord.h"
#include "epicsExport.h"
/* Create the dset for devBiSoftRaw */
static long init_record(biRecord *prec);
static long read_bi(biRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_bi;
} devBiSoftRaw = {
5,
NULL,
NULL,
init_record,
NULL,
read_bi
};
epicsExportAddress(dset, devBiSoftRaw);
static long init_record(biRecord *prec)
{
recGblInitConstantLink(&prec->inp, DBF_ULONG, &prec->rval);
return 0;
}
static long readLocked(struct link *pinp, void *dummy)
{
biRecord *prec = (biRecord *) pinp->precord;
long status = dbGetLink(pinp, DBR_ULONG, &prec->rval, 0, 0);
if (status) return status;
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(pinp, &prec->time);
return status;
}
static long read_bi(biRecord *prec)
{
long status = dbLinkDoLocked(&prec->inp, readLocked, NULL);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, NULL);
return status;
}
@@ -0,0 +1,86 @@
/*************************************************************************\
* Copyright (c) 2010 Brookhaven National Laboratory.
* Copyright (c) 2010 Helmholtz-Zentrum Berlin
* fuer Materialien und Energie GmbH.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Ralph Lange <Ralph.Lange@bessy.de>
*/
#include "errlog.h"
#include "dbState.h"
#include "devSup.h"
#include "recGbl.h"
#include "dbAccessDefs.h"
#include "boRecord.h"
#include "epicsExport.h"
#define DEVSUPNAME "devBoDbState"
static long add_record (struct dbCommon *pdbc)
{
boRecord *prec = (boRecord *) pdbc;
if (INST_IO != prec->out.type) {
recGblRecordError(S_db_badField, (void *) prec, DEVSUPNAME ": Illegal OUT field");
return(S_db_badField);
}
if (!(prec->dpvt = dbStateFind(prec->out.value.instio.string)) &&
prec->out.value.instio.string &&
'\0' != *prec->out.value.instio.string) {
errlogSevPrintf(errlogInfo, DEVSUPNAME ": Creating new db state '%s'\n",
prec->out.value.instio.string);
prec->dpvt = dbStateCreate(prec->out.value.instio.string);
}
return 0;
}
static long del_record (struct dbCommon *pdbc)
{
boRecord *prec = (boRecord *) pdbc;
prec->dpvt = NULL;
return 0;
}
static struct dsxt myDsxt = {
add_record,
del_record
};
static long init(int pass)
{
if (pass == 0)
devExtend(&myDsxt);
return 0;
}
static long write_bo(boRecord *prec)
{
if (prec->val)
dbStateSet(prec->dpvt);
else
dbStateClear(prec->dpvt);
return 0;
}
static struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_bo;
} devBoDbState = {
5,
NULL,
init,
NULL,
NULL,
write_bo
};
epicsExportAddress(dset, devBoDbState);
+72
View File
@@ -0,0 +1,72 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devBoSoft.c - Device Support Routines for Soft Binary Output*/
/*
* Original Author: Bob Dalesio
* Current Author: Marty Kraimer
* Date: 6-1-90
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "boRecord.h"
#include "epicsExport.h"
static long init_record(boRecord *prec);
/* Create the dset for devBoSoft */
static long write_bo(boRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_bo;
}devBoSoft={
5,
NULL,
NULL,
init_record,
NULL,
write_bo
};
epicsExportAddress(dset,devBoSoft);
static long init_record(boRecord *prec)
{
long status=0;
/* dont convert */
status=2;
return status;
} /* end init_record() */
static long write_bo(boRecord *prec)
{
long status;
status = dbPutLink(&prec->out,DBR_USHORT,&prec->val,1);
return(status);
}
@@ -0,0 +1,67 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devBoCallbackSoft.c */
/*
* Author: Marty Kraimer
* Date: 04NOV2003
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbLock.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "boRecord.h"
#include "epicsExport.h"
/* Create the dset for devBoCallbackSoft */
static long write_bo(boRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_bo;
}devBoSoftCallback={
5,
NULL,
NULL,
NULL,
NULL,
write_bo
};
epicsExportAddress(dset,devBoSoftCallback);
static long write_bo(boRecord *prec)
{
struct link *plink = &prec->out;
long status;
if (prec->pact)
return 0;
status = dbPutLinkAsync(plink, DBR_USHORT, &prec->val, 1);
if (!status)
prec->pact = TRUE;
else if (status == S_db_noLSET)
status = dbPutLink(plink, DBR_USHORT, &prec->val, 1);
return status;
}
@@ -0,0 +1,71 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devBoSoftRaw.c - Device Support Routines for SoftRaw Binary Output*/
/*
* Author: Janet Anderson
* Date: 3-28-92
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "boRecord.h"
#include "epicsExport.h"
/* added for Channel Access Links */
static long init_record(boRecord *prec);
/* Create the dset for devBoSoftRaw */
static long write_bo(boRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_bo;
}devBoSoftRaw={
5,
NULL,
NULL,
init_record,
NULL,
write_bo
};
epicsExportAddress(dset,devBoSoftRaw);
static long init_record(boRecord *prec)
{
long status;
/*Don't convert*/
status = 2;
return status;
} /* end init_record() */
static long write_bo(boRecord *prec)
{
long status;
status = dbPutLink(&prec->out,DBR_LONG, &prec->rval,1);
return(status);
}
@@ -0,0 +1,49 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devCalcoutSoft.c */
/*
* Author: Marty Kraimer
* Date: 05DEC2003
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "link.h"
#include "special.h"
#include "postfix.h"
#include "calcoutRecord.h"
#include "epicsExport.h"
static long write_calcout(calcoutRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write;
} devCalcoutSoft = {
5, NULL, NULL, NULL, NULL, write_calcout
};
epicsExportAddress(dset, devCalcoutSoft);
static long write_calcout(calcoutRecord *prec)
{
return dbPutLink(&prec->out, DBR_DOUBLE, &prec->oval, 1);
}
@@ -0,0 +1,62 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devCalcoutSoftCallback.c */
/*
* Author: Marty Kraimer
* Date: 05DEC2003
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "link.h"
#include "special.h"
#include "postfix.h"
#include "calcoutRecord.h"
#include "epicsExport.h"
static long write_calcout(calcoutRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write;
} devCalcoutSoftCallback = {
5, NULL, NULL, NULL, NULL, write_calcout
};
epicsExportAddress(dset, devCalcoutSoftCallback);
static long write_calcout(calcoutRecord *prec)
{
struct link *plink = &prec->out;
long status;
if (prec->pact)
return 0;
status = dbPutLinkAsync(plink, DBR_DOUBLE, &prec->oval, 1);
if (!status)
prec->pact = TRUE;
else if (status == S_db_noLSET)
status = dbPutLink(plink, DBR_DOUBLE, &prec->oval, 1);
return 0;
}
+128
View File
@@ -0,0 +1,128 @@
/*************************************************************************\
* Copyright (c) 2016 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devEnviron.c */
#include <stdlib.h>
#include <string.h>
#include "alarm.h"
#include "dbCommon.h"
#include "devSup.h"
#include "errlog.h"
#include "recGbl.h"
#include "recSup.h"
#include "lsiRecord.h"
#include "stringinRecord.h"
#include "epicsExport.h"
/* lsi device support */
static long add_lsi(dbCommon *pcommon) {
lsiRecord *prec = (lsiRecord *) pcommon;
if (prec->inp.type != INST_IO)
return S_dev_badInpType;
return 0;
}
static long del_lsi(dbCommon *pcommon) {
return 0;
}
static struct dsxt dsxtLsiEnviron = {
add_lsi, del_lsi
};
static long init_lsi(int pass)
{
if (pass == 0)
devExtend(&dsxtLsiEnviron);
return 0;
}
static long read_lsi(lsiRecord *prec)
{
const char *val = getenv(prec->inp.value.instio.string);
if (val) {
strncpy(prec->val, val, prec->sizv);
prec->val[prec->sizv - 1] = 0;
prec->len = strlen(prec->val);
prec->udf = FALSE;
}
else {
prec->val[0] = 0;
prec->len = 1;
prec->udf = TRUE;
recGblSetSevr(prec, UDF_ALARM, prec->udfs);
}
return 0;
}
lsidset devLsiEnviron = {
5, NULL, init_lsi, NULL, NULL, read_lsi
};
epicsExportAddress(dset, devLsiEnviron);
/* stringin device support */
static long add_stringin(dbCommon *pcommon) {
stringinRecord *prec = (stringinRecord *) pcommon;
if (prec->inp.type != INST_IO)
return S_dev_badInpType;
return 0;
}
static long del_stringin(dbCommon *pcommon) {
return 0;
}
static struct dsxt dsxtSiEnviron = {
add_stringin, del_stringin
};
static long init_stringin(int pass)
{
if (pass == 0)
devExtend(&dsxtSiEnviron);
return 0;
}
static long read_stringin(stringinRecord *prec)
{
const char *val = getenv(prec->inp.value.instio.string);
if (val) {
strncpy(prec->val, val, MAX_STRING_SIZE);
prec->val[MAX_STRING_SIZE - 1] = 0;
prec->udf = FALSE;
}
else {
prec->val[0] = 0;
prec->udf = TRUE;
recGblSetSevr(prec, UDF_ALARM, prec->udfs);
}
return 0;
}
static struct {
dset common;
DEVSUPFUN read;
} devSiEnviron = {
{5, NULL, init_stringin, NULL, NULL}, read_stringin
};
epicsExportAddress(dset, devSiEnviron);
@@ -0,0 +1,96 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Janet Anderson
* Date: 04-21-91
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "eventRecord.h"
#include "epicsExport.h"
/* Create the dset for devEventSoft */
static long init_record(eventRecord *prec);
static long read_event(eventRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_event;
} devEventSoft = {
5,
NULL,
NULL,
init_record,
NULL,
read_event
};
epicsExportAddress(dset, devEventSoft);
static long init_record(eventRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBF_STRING, prec->val))
prec->udf = FALSE;
return 0;
}
struct eventvt {
char newEvent[MAX_STRING_SIZE];
epicsTimeStamp *ptime;
};
static long readLocked(struct link *pinp, void *vvt)
{
struct eventvt *pvt = (struct eventvt *) vvt;
long status = dbGetLink(pinp, DBR_STRING, pvt->newEvent, 0, 0);
if (!status && pvt->ptime)
dbGetTimeStamp(pinp, pvt->ptime);
return status;
}
static long read_event(eventRecord *prec)
{
long status;
struct eventvt vt;
if (dbLinkIsConstant(&prec->inp))
return 0;
vt.ptime = (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime) ? &prec->time : NULL;
status = dbLinkDoLocked(&prec->inp, readLocked, &vt);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, &vt);
if (!status) {
if (strcmp(vt.newEvent, prec->val) != 0) {
strcpy(prec->val, vt.newEvent);
prec->epvt = eventNameToHandle(prec->val);
}
prec->udf = FALSE;
}
return status;
}
@@ -0,0 +1,297 @@
/*************************************************************************\
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Author: Sheng Peng, ORNL / SNS Project
* Date: 07/2004
*
* EPICS device support for general timestamp support
*
* Integrated into base by Peter Denison, Diamond Light Source
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "epicsString.h"
#include "epicsGeneralTime.h"
#include "aiRecord.h"
#include "boRecord.h"
#include "longinRecord.h"
#include "stringinRecord.h"
#include "epicsExport.h"
/********* ai record **********/
static int getCurrentTime(double * pseconds)
{
epicsTimeStamp ts;
if (epicsTimeOK == epicsTimeGetCurrent(&ts)) {
*pseconds = ts.secPastEpoch + ((double)(ts.nsec)) * 1e-9;
return 0;
}
return -1;
}
static struct ai_channel {
char *name;
int (*get)(double *);
} ai_channels[] = {
{"TIME", getCurrentTime},
};
static long init_ai(aiRecord *prec)
{
int i;
if (prec->inp.type != INST_IO) {
recGblRecordError(S_db_badField, (void *)prec,
"devAiGeneralTime::init_ai: Illegal INP field");
prec->pact = TRUE;
return S_db_badField;
}
for (i = 0; i < NELEMENTS(ai_channels); i++) {
struct ai_channel *pchan = &ai_channels[i];
if (!epicsStrCaseCmp(prec->inp.value.instio.string, pchan->name)) {
prec->dpvt = pchan;
return 0;
}
}
recGblRecordError(S_db_badField, (void *)prec,
"devAiGeneralTime::init_ai: Bad parm");
prec->pact = TRUE;
prec->dpvt = NULL;
return S_db_badField;
}
static long read_ai(aiRecord *prec)
{
struct ai_channel *pchan = (struct ai_channel *)prec->dpvt;
if (!pchan) return -1;
if (pchan->get(&prec->val) == 0) {
prec->udf = FALSE;
return 2;
}
prec->udf = TRUE;
recGblSetSevr(prec, READ_ALARM, INVALID_ALARM);
return -1;
}
struct {
dset common;
DEVSUPFUN read_write;
DEVSUPFUN special_linconv;
} devAiGeneralTime = {
{6, NULL, NULL, init_ai, NULL}, read_ai, NULL
};
epicsExportAddress(dset, devAiGeneralTime);
/********* bo record **********/
static void resetErrors(void)
{
generalTimeResetErrorCounts();
}
static struct bo_channel {
char *name;
void (*put)(void);
} bo_channels[] = {
{"RSTERRCNT", resetErrors},
};
static long init_bo(boRecord *prec)
{
int i;
if (prec->out.type != INST_IO) {
recGblRecordError(S_db_badField, (void *)prec,
"devAiGeneralTime::init_ai: Illegal INP field");
prec->pact = TRUE;
return S_db_badField;
}
for (i = 0; i < NELEMENTS(bo_channels); i++) {
struct bo_channel *pchan = &bo_channels[i];
if (!epicsStrCaseCmp(prec->out.value.instio.string, pchan->name)) {
prec->dpvt = pchan;
prec->mask = 0;
return 2;
}
}
recGblRecordError(S_db_badField, (void *)prec,
"devBoGeneralTime::init_bo: Bad parm");
prec->pact = TRUE;
prec->dpvt = NULL;
return S_db_badField;
}
static long write_bo(boRecord *prec)
{
struct bo_channel *pchan = (struct bo_channel *)prec->dpvt;
if (!pchan) return -1;
pchan->put();
return 0;
}
struct {
dset common;
DEVSUPFUN read_write;
} devBoGeneralTime = {
{5, NULL, NULL, init_bo, NULL}, write_bo
};
epicsExportAddress(dset, devBoGeneralTime);
/******* longin record *************/
static int errorCount(void)
{
return generalTimeGetErrorCounts();
}
static struct li_channel {
char *name;
int (*get)(void);
} li_channels[] = {
{"GETERRCNT", errorCount},
};
static long init_li(longinRecord *prec)
{
int i;
if (prec->inp.type != INST_IO) {
recGblRecordError(S_db_badField, (void *)prec,
"devLiGeneralTime::init_li: Illegal INP field");
prec->pact = TRUE;
return S_db_badField;
}
for (i = 0; i < NELEMENTS(li_channels); i++) {
struct li_channel *pchan = &li_channels[i];
if (!epicsStrCaseCmp(prec->inp.value.instio.string, pchan->name)) {
prec->dpvt = pchan;
return 0;
}
}
recGblRecordError(S_db_badField, (void *)prec,
"devLiGeneralTime::init_li: Bad parm");
prec->pact = TRUE;
prec->dpvt = NULL;
return S_db_badField;
}
static long read_li(longinRecord *prec)
{
struct li_channel *pchan = (struct li_channel *)prec->dpvt;
if (!pchan) return -1;
prec->val = pchan->get();
return 0;
}
struct {
dset common;
DEVSUPFUN read_write;
} devLiGeneralTime = {
{5, NULL, NULL, init_li, NULL}, read_li
};
epicsExportAddress(dset, devLiGeneralTime);
/********** stringin record **********/
static const char * timeProvider(void)
{
return generalTimeCurrentProviderName();
}
static const char * highestProvider(void)
{
return generalTimeHighestCurrentName();
}
static const char * eventProvider(void)
{
return generalTimeEventProviderName();
}
static struct si_channel {
char *name;
const char * (*get)(void);
} si_channels[] = {
{"BESTTCP", timeProvider},
{"TOPTCP", highestProvider},
{"BESTTEP", eventProvider},
};
static long init_si(stringinRecord *prec)
{
int i;
if (prec->inp.type != INST_IO) {
recGblRecordError(S_db_badField, (void *)prec,
"devSiGeneralTime::init_si: Illegal INP field");
prec->pact = TRUE;
return S_db_badField;
}
for (i = 0; i < NELEMENTS(si_channels); i++) {
struct si_channel *pchan = &si_channels[i];
if (!epicsStrCaseCmp(prec->inp.value.instio.string, pchan->name)) {
prec->dpvt = pchan;
return 0;
}
}
recGblRecordError(S_db_badField, (void *)prec,
"devSiGeneralTime::init_si: Bad parm");
prec->pact = TRUE;
prec->dpvt = NULL;
return S_db_badField;
}
static long read_si(stringinRecord *prec)
{
struct si_channel *pchan = (struct si_channel *)prec->dpvt;
const char *name;
if (!pchan) return -1;
name = pchan->get();
if (name) {
strncpy(prec->val, name, sizeof(prec->val));
prec->val[sizeof(prec->val) - 1] = '\0';
} else {
strcpy(prec->val, "No working providers");
recGblSetSevr(prec, READ_ALARM, MAJOR_ALARM);
}
prec->udf = FALSE;
return 0;
}
struct {
dset common;
DEVSUPFUN read_write;
} devSiGeneralTime = {
{5, NULL, NULL, init_si, NULL}, read_si
};
epicsExportAddress(dset, devSiGeneralTime);
@@ -0,0 +1,64 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devHistogramSoft.c */
/*
* Author: Janet Anderson
* Date: 07/02/91
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "cvtTable.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "link.h"
#include "histogramRecord.h"
#include "epicsExport.h"
/* Create the dset for devHistogramSoft */
static long init_record(histogramRecord *prec);
static long read_histogram(histogramRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_histogram;
DEVSUPFUN special_linconv;
}devHistogramSoft={
6,
NULL,
NULL,
init_record,
NULL,
read_histogram,
NULL
};
epicsExportAddress(dset,devHistogramSoft);
static long init_record(histogramRecord *prec)
{
if (recGblInitConstantLink(&prec->svl,DBF_DOUBLE,&prec->sgnl))
prec->udf = FALSE;
return 0;
}
static long read_histogram(histogramRecord *prec)
{
dbGetLink(&prec->svl, DBR_DOUBLE, &prec->sgnl, 0, 0);
return 0; /*add count*/
}
@@ -0,0 +1,78 @@
/*************************************************************************\
* Copyright (c) 2016 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Author: Janet Anderson
* Date: 09-23-91
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "int64inRecord.h"
#include "epicsExport.h"
/* Create the dset for devI64inSoft */
static long init_record(int64inRecord *prec);
static long read_int64in(int64inRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_int64in;
} devI64inSoft = {
5,
NULL,
NULL,
init_record,
NULL,
read_int64in
};
epicsExportAddress(dset, devI64inSoft);
static long init_record(int64inRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBF_INT64, &prec->val))
prec->udf = FALSE;
return 0;
}
static long readLocked(struct link *pinp, void *dummy)
{
int64inRecord *prec = (int64inRecord *) pinp->precord;
long status = dbGetLink(&prec->inp, DBR_INT64, &prec->val, 0, 0);
if (status) return status;
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(pinp, &prec->time);
return status;
}
static long read_int64in(int64inRecord *prec)
{
long status = dbLinkDoLocked(&prec->inp, readLocked, NULL);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, NULL);
return status;
}
@@ -0,0 +1,214 @@
/*************************************************************************\
* Copyright (c) 2016 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devI64inSoftCallback.c */
/*
* Authors: Marty Kraimer & Andrew Johnson
*/
#include <stdlib.h>
#include <stdio.h>
#include "alarm.h"
#include "callback.h"
#include "cantProceed.h"
#include "dbCommon.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "dbChannel.h"
#include "dbNotify.h"
#include "epicsAssert.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "link.h"
#include "int64inRecord.h"
#include "epicsExport.h"
#define GET_OPTIONS (DBR_STATUS | DBR_TIME)
typedef struct devPvt {
processNotify pn;
CALLBACK callback;
long options;
int status;
struct {
DBRstatus
DBRtime
epicsInt64 value;
} buffer;
} devPvt;
static void getCallback(processNotify *ppn, notifyGetType type)
{
int64inRecord *prec = (int64inRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
long no_elements = 1;
if (ppn->status == notifyCanceled) {
printf("devI64inSoftCallback::getCallback notifyCanceled\n");
return;
}
assert(type == getFieldType);
pdevPvt->status = dbChannelGetField(ppn->chan, DBR_INT64,
&pdevPvt->buffer, &pdevPvt->options, &no_elements, 0);
}
static void doneCallback(processNotify *ppn)
{
int64inRecord *prec = (int64inRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
callbackRequestProcessCallback(&pdevPvt->callback, prec->prio, prec);
}
static long add_record(dbCommon *pcommon)
{
int64inRecord *prec = (int64inRecord *)pcommon;
DBLINK *plink = &prec->inp;
dbChannel *chan;
devPvt *pdevPvt;
processNotify *ppn;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
if (plink->type != PV_LINK) {
long status = S_db_badField;
recGblRecordError(status, (void *)prec,
"devI64inSoftCallback (add_record) Illegal INP field");
return status;
}
chan = dbChannelCreate(plink->value.pv_link.pvname);
if (!chan) {
long status = S_db_notFound;
recGblRecordError(status, (void *)prec,
"devI64inSoftCallback (init_record) linked record not found");
return status;
}
pdevPvt = calloc(1, sizeof(*pdevPvt));
if (!pdevPvt) {
long status = S_db_noMemory;
recGblRecordError(status, (void *)prec,
"devI64inSoftCallback (add_record) out of memory, calloc() failed");
return status;
}
ppn = &pdevPvt->pn;
plink->type = PN_LINK;
plink->value.pv_link.pvlMask &= pvlOptMsMode; /* Severity flags only */
ppn->usrPvt = prec;
ppn->chan = chan;
ppn->getCallback = getCallback;
ppn->doneCallback = doneCallback;
ppn->requestType = processGetRequest;
pdevPvt->options = GET_OPTIONS;
prec->dpvt = pdevPvt;
return 0;
}
static long del_record(dbCommon *pcommon) {
int64inRecord *prec = (int64inRecord *)pcommon;
DBLINK *plink = &prec->inp;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
assert(plink->type == PN_LINK);
dbNotifyCancel(&pdevPvt->pn);
dbChannelDelete(pdevPvt->pn.chan);
free(pdevPvt);
plink->type = PV_LINK;
return 0;
}
static struct dsxt dsxtSoftCallback = {
add_record, del_record
};
static long init(int pass)
{
if (pass == 0) devExtend(&dsxtSoftCallback);
return 0;
}
static long init_record(int64inRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBR_INT64, &prec->val))
prec->udf = FALSE;
return 0;
}
static long read_int64in(int64inRecord *prec)
{
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (!prec->dpvt)
return 0;
if (!prec->pact) {
dbProcessNotify(&pdevPvt->pn);
prec->pact = TRUE;
return 0;
}
if (pdevPvt->status) {
recGblSetSevr(prec, READ_ALARM, INVALID_ALARM);
return pdevPvt->status;
}
prec->val = pdevPvt->buffer.value;
prec->udf = FALSE;
switch (prec->inp.value.pv_link.pvlMask & pvlOptMsMode) {
case pvlOptNMS:
break;
case pvlOptMSI:
if (pdevPvt->buffer.severity < INVALID_ALARM)
break;
/* else fall through */
case pvlOptMS:
recGblSetSevr(prec, LINK_ALARM, pdevPvt->buffer.severity);
break;
case pvlOptMSS:
recGblSetSevr(prec, pdevPvt->buffer.status,
pdevPvt->buffer.severity);
break;
}
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
prec->time = pdevPvt->buffer.time;
return 0;
}
/* Create the dset for devI64inSoftCallback */
struct {
dset common;
DEVSUPFUN read_int64in;
} devI64inSoftCallback = {
{5, NULL, init, init_record, NULL},
read_int64in
};
epicsExportAddress(dset, devI64inSoftCallback);
@@ -0,0 +1,57 @@
/*************************************************************************\
* Copyright (c) 2016 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Author: Janet Anderson
* Date: 09-23-91
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "int64outRecord.h"
#include "epicsExport.h"
/* Create the dset for devI64outSoft */
static long init_record(int64outRecord *prec);
static long write_int64out(int64outRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_int64out;
} devI64outSoft = {
5,
NULL,
NULL,
init_record,
NULL,
write_int64out
};
epicsExportAddress(dset, devI64outSoft);
static long init_record(int64outRecord *prec)
{
return 0;
}
static long write_int64out(int64outRecord *prec)
{
dbPutLink(&prec->out, DBR_INT64, &prec->val,1);
return 0;
}
@@ -0,0 +1,62 @@
/*************************************************************************\
* Copyright (c) 2016 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Author: Marty Kraimer
* Date: 04NOV2003
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "int64outRecord.h"
#include "epicsExport.h"
/* Create the dset for devI64outSoftCallback */
static long write_int64out(int64outRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_int64out;
} devI64outSoftCallback = {
5,
NULL,
NULL,
NULL,
NULL,
write_int64out
};
epicsExportAddress(dset, devI64outSoftCallback);
static long write_int64out(int64outRecord *prec)
{
struct link *plink = &prec->out;
long status;
if (prec->pact)
return 0;
status = dbPutLinkAsync(plink, DBR_INT64, &prec->val, 1);
if (!status)
prec->pact = TRUE;
else if (status == S_db_noLSET)
status = dbPutLink(plink, DBR_INT64, &prec->val, 1);
return status;
}
+78
View File
@@ -0,0 +1,78 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Janet Anderson
* Date: 09-23-91
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "longinRecord.h"
#include "epicsExport.h"
/* Create the dset for devLiSoft */
static long init_record(longinRecord *prec);
static long read_longin(longinRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_longin;
} devLiSoft = {
5,
NULL,
NULL,
init_record,
NULL,
read_longin
};
epicsExportAddress(dset, devLiSoft);
static long init_record(longinRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBF_LONG, &prec->val))
prec->udf = FALSE;
return 0;
}
static long readLocked(struct link *pinp, void *dummy)
{
longinRecord *prec = (longinRecord *) pinp->precord;
long status = dbGetLink(pinp, DBR_LONG, &prec->val, 0, 0);
if (status) return status;
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(pinp, &prec->time);
return status;
}
static long read_longin(longinRecord *prec)
{
long status = dbLinkDoLocked(&prec->inp, readLocked, NULL);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, NULL);
return status;
}
@@ -0,0 +1,214 @@
/*************************************************************************\
* Copyright (c) 2010 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devLiSoftCallback.c */
/*
* Authors: Marty Kraimer & Andrew Johnson
*/
#include <stdlib.h>
#include <stdio.h>
#include "alarm.h"
#include "callback.h"
#include "cantProceed.h"
#include "dbCommon.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "dbChannel.h"
#include "dbNotify.h"
#include "epicsAssert.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "link.h"
#include "longinRecord.h"
#include "epicsExport.h"
#define GET_OPTIONS (DBR_STATUS | DBR_TIME)
typedef struct devPvt {
processNotify pn;
CALLBACK callback;
long options;
int status;
struct {
DBRstatus
DBRtime
epicsInt32 value;
} buffer;
} devPvt;
static void getCallback(processNotify *ppn, notifyGetType type)
{
longinRecord *prec = (longinRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
long no_elements = 1;
if (ppn->status == notifyCanceled) {
printf("devLiSoftCallback::getCallback notifyCanceled\n");
return;
}
assert(type == getFieldType);
pdevPvt->status = dbChannelGetField(ppn->chan, DBR_LONG,
&pdevPvt->buffer, &pdevPvt->options, &no_elements, 0);
}
static void doneCallback(processNotify *ppn)
{
longinRecord *prec = (longinRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
callbackRequestProcessCallback(&pdevPvt->callback, prec->prio, prec);
}
static long add_record(dbCommon *pcommon)
{
longinRecord *prec = (longinRecord *)pcommon;
DBLINK *plink = &prec->inp;
dbChannel *chan;
devPvt *pdevPvt;
processNotify *ppn;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
if (plink->type != PV_LINK) {
long status = S_db_badField;
recGblRecordError(status, (void *)prec,
"devLiSoftCallback (add_record) Illegal INP field");
return status;
}
chan = dbChannelCreate(plink->value.pv_link.pvname);
if (!chan) {
long status = S_db_notFound;
recGblRecordError(status, (void *)prec,
"devLiSoftCallback (init_record) linked record not found");
return status;
}
pdevPvt = calloc(1, sizeof(*pdevPvt));
if (!pdevPvt) {
long status = S_db_noMemory;
recGblRecordError(status, (void *)prec,
"devLiSoftCallback (add_record) out of memory, calloc() failed");
return status;
}
ppn = &pdevPvt->pn;
plink->type = PN_LINK;
plink->value.pv_link.pvlMask &= pvlOptMsMode; /* Severity flags only */
ppn->usrPvt = prec;
ppn->chan = chan;
ppn->getCallback = getCallback;
ppn->doneCallback = doneCallback;
ppn->requestType = processGetRequest;
pdevPvt->options = GET_OPTIONS;
prec->dpvt = pdevPvt;
return 0;
}
static long del_record(dbCommon *pcommon) {
longinRecord *prec = (longinRecord *)pcommon;
DBLINK *plink = &prec->inp;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
assert(plink->type == PN_LINK);
dbNotifyCancel(&pdevPvt->pn);
dbChannelDelete(pdevPvt->pn.chan);
free(pdevPvt);
plink->type = PV_LINK;
return 0;
}
static struct dsxt dsxtSoftCallback = {
add_record, del_record
};
static long init(int pass)
{
if (pass == 0) devExtend(&dsxtSoftCallback);
return 0;
}
static long init_record(longinRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBR_LONG, &prec->val))
prec->udf = FALSE;
return 0;
}
static long read_li(longinRecord *prec)
{
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (!prec->dpvt)
return 0;
if (!prec->pact) {
dbProcessNotify(&pdevPvt->pn);
prec->pact = TRUE;
return 0;
}
if (pdevPvt->status) {
recGblSetSevr(prec, READ_ALARM, INVALID_ALARM);
return pdevPvt->status;
}
prec->val = pdevPvt->buffer.value;
prec->udf = FALSE;
switch (prec->inp.value.pv_link.pvlMask & pvlOptMsMode) {
case pvlOptNMS:
break;
case pvlOptMSI:
if (pdevPvt->buffer.severity < INVALID_ALARM)
break;
/* else fall through */
case pvlOptMS:
recGblSetSevr(prec, LINK_ALARM, pdevPvt->buffer.severity);
break;
case pvlOptMSS:
recGblSetSevr(prec, pdevPvt->buffer.status,
pdevPvt->buffer.severity);
break;
}
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
prec->time = pdevPvt->buffer.time;
return 0;
}
/* Create the dset for devLiSoftCallback */
struct {
dset common;
DEVSUPFUN read_li;
} devLiSoftCallback = {
{5, NULL, init, init_record, NULL},
read_li
};
epicsExportAddress(dset, devLiSoftCallback);
+57
View File
@@ -0,0 +1,57 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devLoSoft.c */
/*
* Author: Janet Anderson
* Date: 09-23-91
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "longoutRecord.h"
#include "epicsExport.h"
/* Create the dset for devLoSoft */
static long init_record(longoutRecord *prec);
static long write_longout(longoutRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_longout;
}devLoSoft={
5,
NULL,
NULL,
init_record,
NULL,
write_longout
};
epicsExportAddress(dset,devLoSoft);
static long init_record(longoutRecord *prec)
{
return 0;
} /* end init_record() */
static long write_longout(longoutRecord *prec)
{
dbPutLink(&prec->out,DBR_LONG, &prec->val,1);
return 0;
}
@@ -0,0 +1,65 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devLoSoftCallback.c */
/*
* Author: Marty Kraimer
* Date: 04NOV2003
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "longoutRecord.h"
#include "epicsExport.h"
/* Create the dset for devLoSoftCallback */
static long write_longout(longoutRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_longout;
}devLoSoftCallback={
5,
NULL,
NULL,
NULL,
NULL,
write_longout
};
epicsExportAddress(dset,devLoSoftCallback);
static long write_longout(longoutRecord *prec)
{
struct link *plink = &prec->out;
long status;
if (prec->pact)
return 0;
status = dbPutLinkAsync(plink, DBR_LONG, &prec->val, 1);
if (!status)
prec->pact = TRUE;
else if (status == S_db_noLSET)
status = dbPutLink(plink, DBR_LONG, &prec->val, 1);
return status;
}
+54
View File
@@ -0,0 +1,54 @@
/*************************************************************************\
* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* Long String Input soft device support
*
* Author: Andrew Johnson
* Date: 2012-11-28
*/
#include "dbAccess.h"
#include "epicsTime.h"
#include "link.h"
#include "lsiRecord.h"
#include "epicsExport.h"
static long init_record(lsiRecord *prec)
{
dbLoadLinkLS(&prec->inp, prec->val, prec->sizv, &prec->len);
return 0;
}
static long readLocked(struct link *pinp, void *dummy)
{
lsiRecord *prec = (lsiRecord *) pinp->precord;
long status = dbGetLinkLS(pinp, prec->val, prec->sizv, &prec->len);
if (status) return status;
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(pinp, &prec->time);
return status;
}
static long read_string(lsiRecord *prec)
{
long status = dbLinkDoLocked(&prec->inp, readLocked, NULL);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, NULL);
return status;
}
lsidset devLsiSoft = {
5, NULL, NULL, init_record, NULL, read_string
};
epicsExportAddress(dset, devLsiSoft);
+26
View File
@@ -0,0 +1,26 @@
/*************************************************************************\
* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* Long String Output soft device support
*
* Author: Andrew Johnson
* Date: 2012-11-29
*/
#include "dbAccess.h"
#include "lsoRecord.h"
#include "epicsExport.h"
static long write_string(lsoRecord *prec)
{
return dbPutLinkLS(&prec->out, prec->val, prec->len);
}
lsodset devLsoSoft = {
5, NULL, NULL, NULL, NULL, write_string
};
epicsExportAddress(dset, devLsoSoft);
@@ -0,0 +1,46 @@
/*************************************************************************\
* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Andrew Johnson
* Date: 30 Nov 2012
*/
#include "alarm.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "lsoRecord.h"
#include "epicsExport.h"
static long write_string(lsoRecord *prec)
{
struct link *plink = &prec->out;
int dtyp = dbGetLinkDBFtype(plink);
long len = prec->len;
long status;
if (prec->pact || dtyp < 0)
return 0;
if (dtyp != DBR_CHAR && dtyp != DBF_UCHAR) {
dtyp = DBR_STRING;
len = 1;
}
status = dbPutLinkAsync(plink, dtyp, prec->val, len);
if (!status)
prec->pact = TRUE;
else if (status == S_db_noLSET)
status = dbPutLink(plink, dtyp, prec->val, len);
return status;
}
lsodset devLsoSoftCallback = {
5, NULL, NULL, NULL, NULL, write_string
};
epicsExportAddress(dset, devLsoSoftCallback);
@@ -0,0 +1,79 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Authors: Bob Dalesio and Matthew Needes
* Date: 10-08-93
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "mbbiDirectRecord.h"
#include "epicsExport.h"
/* Create the dset for devMbbiDirectSoft */
static long init_record(mbbiDirectRecord *prec);
static long read_mbbi(mbbiDirectRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_mbbi;
} devMbbiDirectSoft = {
5,
NULL,
NULL,
init_record,
NULL,
read_mbbi
};
epicsExportAddress(dset, devMbbiDirectSoft);
static long init_record(mbbiDirectRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBF_ENUM, &prec->val))
prec->udf = FALSE;
return 0;
}
static long readLocked(struct link *pinp, void *dummy)
{
mbbiDirectRecord *prec = (mbbiDirectRecord *) pinp->precord;
long status = dbGetLink(pinp, DBR_USHORT, &prec->val, 0, 0);
if (status) return status;
prec->udf = FALSE;
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(pinp, &prec->time);
return 2;
}
static long read_mbbi(mbbiDirectRecord *prec)
{
long status = dbLinkDoLocked(&prec->inp, readLocked, NULL);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, NULL);
return status;
}
@@ -0,0 +1,214 @@
/*************************************************************************\
* Copyright (c) 2010 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devMbbiDirectSoftCallback.c */
/*
* Authors: Marty Kraimer & Andrew Johnson
*/
#include <stdlib.h>
#include <stdio.h>
#include "alarm.h"
#include "callback.h"
#include "cantProceed.h"
#include "dbCommon.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "dbChannel.h"
#include "dbNotify.h"
#include "epicsAssert.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "link.h"
#include "mbbiDirectRecord.h"
#include "epicsExport.h"
#define GET_OPTIONS (DBR_STATUS | DBR_TIME)
typedef struct devPvt {
processNotify pn;
CALLBACK callback;
long options;
int status;
struct {
DBRstatus
DBRtime
epicsUInt16 value;
} buffer;
} devPvt;
static void getCallback(processNotify *ppn, notifyGetType type)
{
mbbiDirectRecord *prec = (mbbiDirectRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
long no_elements = 1;
if (ppn->status == notifyCanceled) {
printf("devMbbiDirectSoftCallback::getCallback notifyCanceled\n");
return;
}
assert(type == getFieldType);
pdevPvt->status = dbChannelGetField(ppn->chan, DBR_USHORT,
&pdevPvt->buffer, &pdevPvt->options, &no_elements, 0);
}
static void doneCallback(processNotify *ppn)
{
mbbiDirectRecord *prec = (mbbiDirectRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
callbackRequestProcessCallback(&pdevPvt->callback, prec->prio, prec);
}
static long add_record(dbCommon *pcommon)
{
mbbiDirectRecord *prec = (mbbiDirectRecord *)pcommon;
DBLINK *plink = &prec->inp;
dbChannel *chan;
devPvt *pdevPvt;
processNotify *ppn;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
if (plink->type != PV_LINK) {
long status = S_db_badField;
recGblRecordError(status, (void *)prec,
"devMbbiDirectSoftCallback (add_record) Illegal INP field");
return status;
}
chan = dbChannelCreate(plink->value.pv_link.pvname);
if (!chan) {
long status = S_db_notFound;
recGblRecordError(status,(void *)prec,
"devMbbiDirectSoftCallback (add_record) linked record not found");
return status;
}
pdevPvt = calloc(1, sizeof(*pdevPvt));
if (!pdevPvt) {
long status = S_db_noMemory;
recGblRecordError(status, (void *)prec,
"devMbbiDirectSoftCallback (add_record) out of memory, calloc() failed");
return status;
}
ppn = &pdevPvt->pn;
plink->type = PN_LINK;
plink->value.pv_link.pvlMask &= pvlOptMsMode; /* Severity flags only */
ppn->usrPvt = prec;
ppn->chan = chan;
ppn->getCallback = getCallback;
ppn->doneCallback = doneCallback;
ppn->requestType = processGetRequest;
pdevPvt->options = GET_OPTIONS;
prec->dpvt = pdevPvt;
return 0;
}
static long del_record(dbCommon *pcommon) {
mbbiDirectRecord *prec = (mbbiDirectRecord *)pcommon;
DBLINK *plink = &prec->inp;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
assert(plink->type == PN_LINK);
dbNotifyCancel(&pdevPvt->pn);
dbChannelDelete(pdevPvt->pn.chan);
free(pdevPvt);
plink->type = PV_LINK;
return 0;
}
static struct dsxt dsxtSoftCallback = {
add_record, del_record
};
static long init(int pass)
{
if (pass == 0) devExtend(&dsxtSoftCallback);
return 0;
}
static long init_record(mbbiDirectRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBR_ENUM, &prec->val))
prec->udf = FALSE;
return 0;
}
static long read_mbbiDirect(mbbiDirectRecord *prec)
{
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (!prec->dpvt)
return 2;
if (!prec->pact) {
dbProcessNotify(&pdevPvt->pn);
prec->pact = TRUE;
return 0;
}
if (pdevPvt->status) {
recGblSetSevr(prec, READ_ALARM, INVALID_ALARM);
return 2;
}
prec->val = pdevPvt->buffer.value;
prec->udf = FALSE;
switch (prec->inp.value.pv_link.pvlMask & pvlOptMsMode) {
case pvlOptNMS:
break;
case pvlOptMSI:
if (pdevPvt->buffer.severity < INVALID_ALARM)
break;
/* else fall through */
case pvlOptMS:
recGblSetSevr(prec, LINK_ALARM, pdevPvt->buffer.severity);
break;
case pvlOptMSS:
recGblSetSevr(prec, pdevPvt->buffer.status,
pdevPvt->buffer.severity);
break;
}
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
prec->time = pdevPvt->buffer.time;
return 2;
}
/* Create the dset for devMbbiDirectSoftCallback */
struct {
dset common;
DEVSUPFUN read_mbbiDirect;
} devMbbiDirectSoftCallback = {
{5, NULL, init, init_record, NULL},
read_mbbiDirect
};
epicsExportAddress(dset, devMbbiDirectSoftCallback);
@@ -0,0 +1,69 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Authors: Bob Dalesio and Matthew Needes
* Date: 10-08-93
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "mbbiDirectRecord.h"
#include "epicsExport.h"
/* Create the dset for devMbbiDirectSoftRaw */
static long init_record(mbbiDirectRecord *prec);
static long read_mbbi(mbbiDirectRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_mbbi;
} devMbbiDirectSoftRaw = {
5,
NULL,
NULL,
init_record,
NULL,
read_mbbi
};
epicsExportAddress(dset, devMbbiDirectSoftRaw);
static long init_record(mbbiDirectRecord *prec)
{
recGblInitConstantLink(&prec->inp, DBF_ULONG, &prec->rval);
/* Preserve old functionality */
if (prec->nobt == 0)
prec->mask = 0xffffffff;
prec->mask <<= prec->shft;
return 0;
}
static long read_mbbi(mbbiDirectRecord *prec)
{
if (!dbGetLink(&prec->inp, DBR_LONG, &prec->rval, 0, 0)) {
prec->rval &= prec->mask;
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(&prec->inp, &prec->time);
}
return 0;
}
@@ -0,0 +1,79 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Authors: Bob Dalesio and Marty Kraimer
* Date: 6-1-90
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "mbbiRecord.h"
#include "epicsExport.h"
/* Create the dset for devMbbiSoft */
static long init_record(mbbiRecord *prec);
static long read_mbbi(mbbiRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_mbbi;
} devMbbiSoft = {
5,
NULL,
NULL,
init_record,
NULL,
read_mbbi
};
epicsExportAddress(dset, devMbbiSoft);
static long init_record(mbbiRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBF_ENUM, &prec->val))
prec->udf = FALSE;
return 0;
}
static long readLocked(struct link *pinp, void *dummy)
{
mbbiRecord *prec = (mbbiRecord *) pinp->precord;
long status = dbGetLink(pinp, DBR_USHORT, &prec->val, 0, 0);
if (status) return status;
prec->udf = FALSE;
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(pinp, &prec->time);
return 2;
}
static long read_mbbi(mbbiRecord *prec)
{
long status = dbLinkDoLocked(&prec->inp, readLocked, NULL);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, NULL);
return status;
}
@@ -0,0 +1,214 @@
/*************************************************************************\
* Copyright (c) 2010 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devMbbiSoftCallback.c */
/*
* Authors: Marty Kraimer & Andrew Johnson
*/
#include <stdlib.h>
#include <stdio.h>
#include "alarm.h"
#include "callback.h"
#include "cantProceed.h"
#include "dbCommon.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "dbChannel.h"
#include "dbNotify.h"
#include "epicsAssert.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "link.h"
#include "mbbiRecord.h"
#include "epicsExport.h"
#define GET_OPTIONS (DBR_STATUS | DBR_TIME)
typedef struct devPvt {
processNotify pn;
CALLBACK callback;
long options;
int status;
struct {
DBRstatus
DBRtime
epicsEnum16 value;
} buffer;
} devPvt;
static void getCallback(processNotify *ppn, notifyGetType type)
{
mbbiRecord *prec = (mbbiRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
long no_elements = 1;
if (ppn->status == notifyCanceled) {
printf("devMbbiSoftCallback::getCallback notifyCanceled\n");
return;
}
assert(type == getFieldType);
pdevPvt->status = dbChannelGetField(ppn->chan, DBR_ENUM,
&pdevPvt->buffer, &pdevPvt->options, &no_elements, 0);
}
static void doneCallback(processNotify *ppn)
{
mbbiRecord *prec = (mbbiRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
callbackRequestProcessCallback(&pdevPvt->callback, prec->prio, prec);
}
static long add_record(dbCommon *pcommon)
{
mbbiRecord *prec = (mbbiRecord *)pcommon;
DBLINK *plink = &prec->inp;
dbChannel *chan;
devPvt *pdevPvt;
processNotify *ppn;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
if (plink->type != PV_LINK) {
long status = S_db_badField;
recGblRecordError(status, (void *)prec,
"devMbbiSoftCallback (add_record) Illegal INP field");
return status;
}
chan = dbChannelCreate(plink->value.pv_link.pvname);
if (!chan) {
long status = S_db_notFound;
recGblRecordError(status, (void *)prec,
"devMbbiSoftCallback (add_record) linked record not found");
return status;
}
pdevPvt = calloc(1, sizeof(*pdevPvt));
if (!pdevPvt) {
long status = S_db_noMemory;
recGblRecordError(status, (void *)prec,
"devMbbiSoftCallback (add_record) out of memory, calloc() failed");
return status;
}
ppn = &pdevPvt->pn;
plink->type = PN_LINK;
plink->value.pv_link.pvlMask &= pvlOptMsMode; /* Severity flags only */
ppn->usrPvt = prec;
ppn->chan = chan;
ppn->getCallback = getCallback;
ppn->doneCallback = doneCallback;
ppn->requestType = processGetRequest;
pdevPvt->options = GET_OPTIONS;
prec->dpvt = pdevPvt;
return 0;
}
static long del_record(dbCommon *pcommon) {
mbbiRecord *prec = (mbbiRecord *)pcommon;
DBLINK *plink = &prec->inp;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
assert(plink->type == PN_LINK);
dbNotifyCancel(&pdevPvt->pn);
dbChannelDelete(pdevPvt->pn.chan);
free(pdevPvt);
plink->type = PV_LINK;
return 0;
}
static struct dsxt dsxtSoftCallback = {
add_record, del_record
};
static long init(int pass)
{
if (pass == 0) devExtend(&dsxtSoftCallback);
return 0;
}
static long init_record(mbbiRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBR_ENUM, &prec->val))
prec->udf = FALSE;
return 0;
}
static long read_mbbi(mbbiRecord *prec)
{
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (!prec->dpvt)
return 2;
if (!prec->pact) {
dbProcessNotify(&pdevPvt->pn);
prec->pact = TRUE;
return 0;
}
if (pdevPvt->status) {
recGblSetSevr(prec, READ_ALARM, INVALID_ALARM);
return 2;
}
prec->val = pdevPvt->buffer.value;
prec->udf = FALSE;
switch (prec->inp.value.pv_link.pvlMask & pvlOptMsMode) {
case pvlOptNMS:
break;
case pvlOptMSI:
if (pdevPvt->buffer.severity < INVALID_ALARM)
break;
/* else fall through */
case pvlOptMS:
recGblSetSevr(prec, LINK_ALARM, pdevPvt->buffer.severity);
break;
case pvlOptMSS:
recGblSetSevr(prec, pdevPvt->buffer.status,
pdevPvt->buffer.severity);
break;
}
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
prec->time = pdevPvt->buffer.time;
return 2;
}
/* Create the dset for devMbbiSoftCallback */
struct {
dset common;
DEVSUPFUN read_mbbi;
} devMbbiSoftCallback = {
{5, NULL, init, init_record, NULL},
read_mbbi
};
epicsExportAddress(dset,devMbbiSoftCallback);
@@ -0,0 +1,85 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Authors: Bob Dalesio and Marty Kraimer
* Date: 6-1-90
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "mbbiRecord.h"
#include "epicsExport.h"
/* Create the dset for devMbbiSoftRaw */
static long init_record(mbbiRecord *prec);
static long read_mbbi(mbbiRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_mbbi;
} devMbbiSoftRaw = {
5,
NULL,
NULL,
init_record,
NULL,
read_mbbi
};
epicsExportAddress(dset, devMbbiSoftRaw);
static long init_record(mbbiRecord *prec)
{
recGblInitConstantLink(&prec->inp, DBF_ULONG, &prec->rval);
/* Preserve old functionality*/
if (prec->nobt == 0)
prec->mask = 0xffffffff;
prec->mask <<= prec->shft;
return 0;
}
static long readLocked(struct link *pinp, void *dummy)
{
mbbiRecord *prec = (mbbiRecord *) pinp->precord;
long status = dbGetLink(pinp, DBR_LONG, &prec->rval, 0, 0);
if (status) return status;
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(pinp, &prec->time);
return status;
}
static long read_mbbi(mbbiRecord *prec)
{
long status = dbLinkDoLocked(&prec->inp, readLocked, NULL);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, NULL);
if (!status)
prec->rval &= prec->mask;
return status;
}
@@ -0,0 +1,36 @@
/*************************************************************************\
* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devMbboDirectSoft.c */
/*
* Original Author: Bob Dalesio
* Date: 10-08-93
*/
#include <stdio.h>
#include "dbAccess.h"
#include "devSup.h"
#include "mbboDirectRecord.h"
#include "epicsExport.h"
static long write_mbbo(mbboDirectRecord *prec)
{
dbPutLink(&prec->out, DBR_USHORT, &prec->val, 1);
return 0;
}
/* Create the dset for devMbboDirectSoft */
struct {
dset common;
DEVSUPFUN write;
} devMbboDirectSoft = {
{5, NULL, NULL, NULL, NULL},
write_mbbo
};
epicsExportAddress(dset, devMbboDirectSoft);
@@ -0,0 +1,49 @@
/*************************************************************************\
* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devMbboDirectSoftCallback.c */
/*
* Original Author: Marty Kraimer
* Date: 04NOV2003
*/
#include <stdio.h>
#include "alarm.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "mbboDirectRecord.h"
#include "epicsExport.h"
static long write_mbbo(mbboDirectRecord *prec)
{
struct link *plink = &prec->out;
long status;
if (prec->pact)
return 0;
status = dbPutLinkAsync(plink, DBR_USHORT, &prec->val, 1);
if (!status)
prec->pact = TRUE;
else if (status == S_db_noLSET)
status = dbPutLink(plink, DBR_USHORT, &prec->val, 1);
return status;
}
/* Create the dset for devMbboSoft */
struct {
dset common;
DEVSUPFUN write;
} devMbboDirectSoftCallback = {
{5, NULL, NULL, NULL, NULL},
write_mbbo
};
epicsExportAddress(dset, devMbboDirectSoftCallback);
@@ -0,0 +1,50 @@
/*************************************************************************\
* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devMbboDirectSoftRaw.c */
/*
* Original Author: Janet Anderson
* Date: 10-08-93
*/
#include <stdio.h>
#include "dbAccess.h"
#include "epicsTypes.h"
#include "devSup.h"
#include "mbboDirectRecord.h"
#include "epicsExport.h"
static long init_record(mbboDirectRecord *prec)
{
if (prec->nobt == 0)
prec->mask = 0xffffffff;
prec->mask <<= prec->shft;
return 2; /* Don't convert */
}
static long write_mbbo(mbboDirectRecord *prec)
{
epicsUInt32 data;
data = prec->rval & prec->mask;
dbPutLink(&prec->out, DBR_ULONG, &data, 1);
return 0;
}
/* Create the dset for devMbboDirectSoftRaw */
struct {
dset common;
DEVSUPFUN write;
} devMbboDirectSoftRaw = {
{5, NULL, NULL, init_record, NULL},
write_mbbo
};
epicsExportAddress(dset, devMbboDirectSoftRaw);
@@ -0,0 +1,60 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devMbboSoft.c */
/*
* Original Author: Bob Dalesio
* Current Author: Marty Kraimer
* Date: 6-1-90
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "mbboRecord.h"
#include "epicsExport.h"
/* Create the dset for devMbboSoft */
static long init_record(mbboRecord *prec);
static long write_mbbo(mbboRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_mbbo;
}devMbboSoft={
5,
NULL,
NULL,
init_record,
NULL,
write_mbbo
};
epicsExportAddress(dset,devMbboSoft);
static long init_record(mbboRecord *prec)
{
/*dont convert*/
return 2;
} /* end init_record() */
static long write_mbbo(mbboRecord *prec)
{
dbPutLink(&prec->out,DBR_USHORT, &prec->val,1);
return 0;
}
@@ -0,0 +1,64 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devMbboSoftCallback.c */
/*
* Author: Marty Kraimer
* Date: 04NOV2003
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "mbboRecord.h"
#include "epicsExport.h"
/* Create the dset for devMbboSoftCallback */
static long write_mbbo(mbboRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_mbbo;
}devMbboSoftCallback={
5,
NULL,
NULL,
NULL,
NULL,
write_mbbo
};
epicsExportAddress(dset,devMbboSoftCallback);
static long write_mbbo(mbboRecord *prec)
{
struct link *plink = &prec->out;
long status;
if (prec->pact)
return 0;
status = dbPutLinkAsync(plink, DBR_USHORT, &prec->val, 1);
if (!status)
prec->pact = TRUE;
else if (status == S_db_noLSET)
status = dbPutLink(plink, DBR_USHORT, &prec->val, 1);
return status;
}
@@ -0,0 +1,50 @@
/*************************************************************************\
* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devMbboSoftRaw.c */
/*
* Original Author: Janet Anderson
* Date: 3-28-92
*/
#include <stdio.h>
#include "dbAccess.h"
#include "epicsTypes.h"
#include "devSup.h"
#include "mbboRecord.h"
#include "epicsExport.h"
static long init_record(mbboRecord *prec)
{
if (prec->nobt == 0)
prec->mask = 0xffffffff;
prec->mask <<= prec->shft;
return 2; /* Don't convert */
}
static long write_mbbo(mbboRecord *prec)
{
epicsUInt32 data;
data = prec->rval & prec->mask;
dbPutLink(&prec->out, DBR_ULONG, &data, 1);
return 0;
}
/* Create the dset for devMbboSoftRaw */
struct {
dset common;
DEVSUPFUN write;
} devMbboSoftRaw = {
{5, NULL, NULL, init_record, NULL},
write_mbbo
};
epicsExportAddress(dset, devMbboSoftRaw);
@@ -0,0 +1,25 @@
/*************************************************************************\
* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Andrew Johnson
* Date: 28 Sept 2012
*/
#include "dbAccess.h"
#include "printfRecord.h"
#include "epicsExport.h"
static long write_string(printfRecord *prec)
{
return dbPutLinkLS(&prec->out, prec->val, prec->len);
}
printfdset devPrintfSoft = {
5, NULL, NULL, NULL, NULL, write_string
};
epicsExportAddress(dset, devPrintfSoft);
@@ -0,0 +1,45 @@
/*************************************************************************\
* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Andrew Johnson
* Date: 28 Sept 2012
*/
#include "alarm.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "printfRecord.h"
#include "epicsExport.h"
static long write_string(printfRecord *prec)
{
struct link *plink = &prec->out;
int dtyp = dbGetLinkDBFtype(plink);
long len = prec->len;
long status;
if (prec->pact || dtyp < 0)
return 0;
if (dtyp != DBR_CHAR && dtyp != DBF_UCHAR) {
dtyp = DBR_STRING;
len = 1;
}
status = dbPutLinkAsync(plink, dtyp, prec->val, len);
if (!status)
prec->pact = TRUE;
else if (status == S_db_noLSET)
status = dbPutLink(plink, dtyp, prec->val, len);
return status;
}
printfdset devPrintfSoftCallback = {
5, NULL, NULL, NULL, NULL, write_string
};
epicsExportAddress(dset, devPrintfSoftCallback);
+130
View File
@@ -0,0 +1,130 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 Lawrence Berkeley Laboratory,The Control Systems
* Group, Systems Engineering Department
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Carl Lionberger
* Date: 9-2-93
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "subArrayRecord.h"
#include "epicsExport.h"
/* Create the dset for devSASoft */
static long init_record(subArrayRecord *prec);
static long read_sa(subArrayRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_sa;
} devSASoft = {
5,
NULL,
NULL,
init_record,
NULL,
read_sa
};
epicsExportAddress(dset, devSASoft);
static void subset(subArrayRecord *prec, long nRequest)
{
long ecount = nRequest - prec->indx;
if (ecount > 0) {
int esize = dbValueSize(prec->ftvl);
if (ecount > prec->nelm)
ecount = prec->nelm;
memmove(prec->bptr, (char *)prec->bptr + prec->indx * esize,
ecount * esize);
} else
ecount = 0;
prec->nord = ecount;
prec->udf = FALSE;
}
static long init_record(subArrayRecord *prec)
{
long nRequest = prec->indx + prec->nelm;
long status;
if (nRequest > prec->malm)
nRequest = prec->malm;
status = dbLoadLinkArray(&prec->inp, prec->ftvl, prec->bptr, &nRequest);
if (!status && nRequest > 0)
subset(prec, nRequest);
return status;
}
struct sart {
long nRequest;
epicsTimeStamp *ptime;
};
static long readLocked(struct link *pinp, void *vrt)
{
subArrayRecord *prec = (subArrayRecord *) pinp->precord;
struct sart *prt = (struct sart *) vrt;
long status = dbGetLink(pinp, prec->ftvl, prec->bptr, 0, &prt->nRequest);
if (!status && prt->ptime)
dbGetTimeStamp(pinp, prt->ptime);
return status;
}
static long read_sa(subArrayRecord *prec)
{
long status;
struct sart rt;
rt.nRequest = prec->indx + prec->nelm;
if (rt.nRequest > prec->malm)
rt.nRequest = prec->malm;
rt.ptime = (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime) ? &prec->time : NULL;
if (dbLinkIsConstant(&prec->inp)) {
status = dbLoadLinkArray(&prec->inp, prec->ftvl, prec->bptr, &rt.nRequest);
if (status == S_db_badField) { /* INP was empty */
rt.nRequest = prec->nord;
status = 0;
}
}
else {
status = dbLinkDoLocked(&prec->inp, readLocked, &rt);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, &rt);
}
if (!status && rt.nRequest > 0)
subset(prec, rt.nRequest);
return status;
}
+83
View File
@@ -0,0 +1,83 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Janet Anderson
* Date: 04-21-91
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "epicsTime.h"
#include "recGbl.h"
#include "devSup.h"
#include "link.h"
#include "stringinRecord.h"
#include "epicsExport.h"
/* Create the dset for devSiSoft */
static long init_record(stringinRecord *prec);
static long read_stringin(stringinRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_stringin;
} devSiSoft = {
5,
NULL,
NULL,
init_record,
NULL,
read_stringin
};
epicsExportAddress(dset, devSiSoft);
static long init_record(stringinRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBF_STRING, prec->val))
prec->udf = FALSE;
return 0;
}
static long readLocked(struct link *pinp, void *dummy)
{
stringinRecord *prec = (stringinRecord *) pinp->precord;
long status = dbGetLink(pinp, DBR_STRING, prec->val, 0, 0);
if (status) return status;
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
dbGetTimeStamp(pinp, &prec->time);
return status;
}
static long read_stringin(stringinRecord *prec)
{
long status = dbLinkDoLocked(&prec->inp, readLocked, NULL);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, NULL);
if (!status && !dbLinkIsConstant(&prec->inp))
prec->udf = FALSE;
return status;
}
@@ -0,0 +1,217 @@
/*************************************************************************\
* Copyright (c) 2010 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* devSiSoftCallback.c */
/*
* Authors: Marty Kraimer & Andrew Johnson
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "callback.h"
#include "cantProceed.h"
#include "dbCommon.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "dbChannel.h"
#include "dbNotify.h"
#include "epicsAssert.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "link.h"
#include "stringinRecord.h"
#include "epicsExport.h"
#define GET_OPTIONS (DBR_STATUS | DBR_TIME)
typedef struct devPvt {
DBADDR dbaddr;
processNotify pn;
CALLBACK callback;
long options;
int status;
struct {
DBRstatus
DBRtime
char value[MAX_STRING_SIZE];
} buffer;
} devPvt;
static void getCallback(processNotify *ppn, notifyGetType type)
{
stringinRecord *prec = (stringinRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
long no_elements = 1;
if (ppn->status==notifyCanceled) {
printf("devSiSoftCallback::getCallback notifyCanceled\n");
return;
}
assert(type == getFieldType);
pdevPvt->status = dbChannelGetField(ppn->chan, DBR_STRING,
&pdevPvt->buffer, &pdevPvt->options, &no_elements, 0);
}
static void doneCallback(processNotify *ppn)
{
stringinRecord *prec = (stringinRecord *)ppn->usrPvt;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
callbackRequestProcessCallback(&pdevPvt->callback, prec->prio, prec);
}
static long add_record(dbCommon *pcommon)
{
stringinRecord *prec = (stringinRecord *)pcommon;
DBLINK *plink = &prec->inp;
dbChannel *chan;
devPvt *pdevPvt;
processNotify *ppn;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
if (plink->type != PV_LINK) {
long status = S_db_badField;
recGblRecordError(status, (void *)prec,
"devSiSoftCallback (add_record) Illegal INP field");
return status;
}
pdevPvt = calloc(1, sizeof(*pdevPvt));
if (!pdevPvt) {
long status = S_db_noMemory;
recGblRecordError(status, (void *)prec,
"devSiSoftCallback (add_record) out of memory, calloc() failed");
return status;
}
ppn = &pdevPvt->pn;
chan = dbChannelCreate(plink->value.pv_link.pvname);
if (!chan) {
long status = S_db_notFound;
recGblRecordError(status, (void *)prec,
"devSiSoftCallback (add_record) linked record not found");
return status;
}
plink->type = PN_LINK;
plink->value.pv_link.pvlMask &= pvlOptMsMode; /* Severity flags only */
ppn->usrPvt = prec;
ppn->chan = chan;
ppn->getCallback = getCallback;
ppn->doneCallback = doneCallback;
ppn->requestType = processGetRequest;
pdevPvt->options = GET_OPTIONS;
prec->dpvt = pdevPvt;
return 0;
}
static long del_record(dbCommon *pcommon) {
stringinRecord *prec = (stringinRecord *)pcommon;
DBLINK *plink = &prec->inp;
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (dbLinkIsDefined(plink) && dbLinkIsConstant(plink))
return 0;
assert(plink->type == PN_LINK);
dbNotifyCancel(&pdevPvt->pn);
dbChannelDelete(pdevPvt->pn.chan);
free(pdevPvt);
plink->type = PV_LINK;
return 0;
}
static struct dsxt dsxtSoftCallback = {
add_record, del_record
};
static long init(int pass)
{
if (pass == 0) devExtend(&dsxtSoftCallback);
return 0;
}
static long init_record(stringinRecord *prec)
{
if (recGblInitConstantLink(&prec->inp, DBR_STRING, &prec->val))
prec->udf = FALSE;
return 0;
}
static long read_si(stringinRecord *prec)
{
devPvt *pdevPvt = (devPvt *)prec->dpvt;
if (!prec->dpvt)
return 0;
if (!prec->pact) {
dbProcessNotify(&pdevPvt->pn);
prec->pact = TRUE;
return 0;
}
if (pdevPvt->status) {
recGblSetSevr(prec, READ_ALARM, INVALID_ALARM);
return pdevPvt->status;
}
strncpy(prec->val, pdevPvt->buffer.value, MAX_STRING_SIZE);
prec->val[MAX_STRING_SIZE-1] = 0;
prec->udf = FALSE;
switch (prec->inp.value.pv_link.pvlMask & pvlOptMsMode) {
case pvlOptNMS:
break;
case pvlOptMSI:
if (pdevPvt->buffer.severity < INVALID_ALARM)
break;
/* else fall through */
case pvlOptMS:
recGblSetSevr(prec, LINK_ALARM, pdevPvt->buffer.severity);
break;
case pvlOptMSS:
recGblSetSevr(prec, pdevPvt->buffer.status,
pdevPvt->buffer.severity);
break;
}
if (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime)
prec->time = pdevPvt->buffer.time;
return 0;
}
/* Create the dset for devSiSoftCallback */
struct {
dset common;
DEVSUPFUN read_li;
} devSiSoftCallback = {
{5, NULL, init, init_record, NULL},
read_si
};
epicsExportAddress(dset,devSiSoftCallback);
+53
View File
@@ -0,0 +1,53 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Janet Anderson
* Date: 21APR1991
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "stringoutRecord.h"
#include "epicsExport.h"
/* Create the dset for devSoSoft */
static long write_stringout(stringoutRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_stringout;
} devSoSoft = {
5,
NULL,
NULL,
NULL,
NULL,
write_stringout
};
epicsExportAddress(dset, devSoSoft);
static long write_stringout(stringoutRecord *prec)
{
long status;
status = dbPutLink(&prec->out, DBR_STRING, prec->val, 1);
return status;
}
@@ -0,0 +1,63 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Marty Kraimer
* Date: 04NOV2003
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "recSup.h"
#include "devSup.h"
#include "stringoutRecord.h"
#include "epicsExport.h"
/* Create the dset for devSoSoftCallback */
static long write_stringout(stringoutRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_stringout;
} devSoSoftCallback = {
5,
NULL,
NULL,
NULL,
NULL,
write_stringout
};
epicsExportAddress(dset, devSoSoftCallback);
static long write_stringout(stringoutRecord *prec)
{
struct link *plink = &prec->out;
long status;
if (prec->pact)
return 0;
status = dbPutLinkAsync(plink, DBR_STRING, &prec->val, 1);
if (!status)
prec->pact = TRUE;
else if (status == S_db_noLSET)
status = dbPutLink(plink, DBR_STRING, &prec->val, 1);
return status;
}
+71
View File
@@ -0,0 +1,71 @@
# devSoft.dbd
device(aai,CONSTANT,devAaiSoft,"Soft Channel")
device(aao,CONSTANT,devAaoSoft,"Soft Channel")
device(ai,CONSTANT,devAiSoft,"Soft Channel")
device(ao,CONSTANT,devAoSoft,"Soft Channel")
device(bi,CONSTANT,devBiSoft,"Soft Channel")
device(bo,CONSTANT,devBoSoft,"Soft Channel")
device(calcout,CONSTANT,devCalcoutSoft,"Soft Channel")
device(event,CONSTANT,devEventSoft,"Soft Channel")
device(histogram,CONSTANT,devHistogramSoft,"Soft Channel")
device(int64in,CONSTANT,devI64inSoft,"Soft Channel")
device(int64out,CONSTANT,devI64outSoft,"Soft Channel")
device(longin,CONSTANT,devLiSoft,"Soft Channel")
device(longout,CONSTANT,devLoSoft,"Soft Channel")
device(lsi,CONSTANT,devLsiSoft,"Soft Channel")
device(lso,CONSTANT,devLsoSoft,"Soft Channel")
device(mbbi,CONSTANT,devMbbiSoft,"Soft Channel")
device(mbbiDirect,CONSTANT,devMbbiDirectSoft,"Soft Channel")
device(mbbo,CONSTANT,devMbboSoft,"Soft Channel")
device(mbboDirect,CONSTANT,devMbboDirectSoft,"Soft Channel")
device(printf,CONSTANT,devPrintfSoft,"Soft Channel")
device(stringin,CONSTANT,devSiSoft,"Soft Channel")
device(stringout,CONSTANT,devSoSoft,"Soft Channel")
device(subArray,CONSTANT,devSASoft,"Soft Channel")
device(waveform,CONSTANT,devWfSoft,"Soft Channel")
device(ai,CONSTANT,devAiSoftRaw,"Raw Soft Channel")
device(ao,CONSTANT,devAoSoftRaw,"Raw Soft Channel")
device(bi,CONSTANT,devBiSoftRaw,"Raw Soft Channel")
device(bo,CONSTANT,devBoSoftRaw,"Raw Soft Channel")
device(mbbi,CONSTANT,devMbbiSoftRaw,"Raw Soft Channel")
device(mbbiDirect,CONSTANT,devMbbiDirectSoftRaw,"Raw Soft Channel")
device(mbbo,CONSTANT,devMbboSoftRaw,"Raw Soft Channel")
device(mbboDirect,CONSTANT,devMbboDirectSoftRaw,"Raw Soft Channel")
device(ai,CONSTANT,devAiSoftCallback,"Async Soft Channel")
device(ao,CONSTANT,devAoSoftCallback,"Async Soft Channel")
device(bi,CONSTANT,devBiSoftCallback,"Async Soft Channel")
device(bo,CONSTANT,devBoSoftCallback,"Async Soft Channel")
device(calcout,CONSTANT,devCalcoutSoftCallback,"Async Soft Channel")
device(int64in,CONSTANT,devI64inSoftCallback,"Async Soft Channel")
device(int64out,CONSTANT,devI64outSoftCallback,"Async Soft Channel")
device(longin,CONSTANT,devLiSoftCallback,"Async Soft Channel")
device(longout,CONSTANT,devLoSoftCallback,"Async Soft Channel")
device(lso,CONSTANT,devLsoSoftCallback,"Async Soft Channel")
device(mbbi,CONSTANT,devMbbiSoftCallback,"Async Soft Channel")
device(mbbiDirect,CONSTANT,devMbbiDirectSoftCallback,"Async Soft Channel")
device(mbbo,CONSTANT,devMbboSoftCallback,"Async Soft Channel")
device(mbboDirect,CONSTANT,devMbboDirectSoftCallback,"Async Soft Channel")
device(printf,CONSTANT,devPrintfSoftCallback,"Async Soft Channel")
device(stringin,CONSTANT,devSiSoftCallback,"Async Soft Channel")
device(stringout,CONSTANT,devSoSoftCallback,"Async Soft Channel")
device(ai, INST_IO,devTimestampAI,"Soft Timestamp")
device(stringin,INST_IO,devTimestampSI,"Soft Timestamp")
device(ai, INST_IO,devAiGeneralTime,"General Time")
device(bo, INST_IO,devBoGeneralTime,"General Time")
device(longin, INST_IO,devLiGeneralTime,"General Time")
device(stringin,INST_IO,devSiGeneralTime,"General Time")
device(lso,INST_IO,devLsoStdio,"stdio")
device(printf,INST_IO,devPrintfStdio,"stdio")
device(stringout,INST_IO,devSoStdio,"stdio")
device(lsi,INST_IO,devLsiEnviron,"getenv")
device(stringin,INST_IO,devSiEnviron,"getenv")
device(bi, INST_IO, devBiDbState, "Db State")
device(bo, INST_IO, devBoDbState, "Db State")
+211
View File
@@ -0,0 +1,211 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
#include <stdio.h>
#include <string.h>
#include "dbCommon.h"
#include "devSup.h"
#include "errlog.h"
#include "recGbl.h"
#include "recSup.h"
#include "lsoRecord.h"
#include "printfRecord.h"
#include "stringoutRecord.h"
#include "epicsExport.h"
typedef int (*PRINTFFUNC)(const char *fmt, ...);
static int stderrPrintf(const char *fmt, ...);
static int logPrintf(const char *fmt, ...);
static struct outStream {
const char *name;
PRINTFFUNC print;
} outStreams[] = {
{"stdout", printf},
{"stderr", stderrPrintf},
{"errlog", logPrintf},
{NULL, NULL}
};
static int stderrPrintf(const char *fmt, ...) {
va_list pvar;
int retval;
va_start(pvar, fmt);
retval = vfprintf(stderr, fmt, pvar);
va_end (pvar);
return retval;
}
static int logPrintf(const char *fmt, ...) {
va_list pvar;
int retval;
va_start(pvar, fmt);
retval = errlogVprintf(fmt, pvar);
va_end (pvar);
return retval;
}
/* lso device support */
static long add_lso(dbCommon *pcommon) {
lsoRecord *prec = (lsoRecord *) pcommon;
struct outStream *pstream;
if (prec->out.type != INST_IO)
return S_dev_badOutType;
for (pstream = outStreams; pstream->name; ++pstream) {
if (strcmp(prec->out.value.instio.string, pstream->name) == 0) {
prec->dpvt = pstream;
return 0;
}
}
prec->dpvt = NULL;
return -1;
}
static long del_lso(dbCommon *pcommon) {
lsoRecord *prec = (lsoRecord *) pcommon;
prec->dpvt = NULL;
return 0;
}
static struct dsxt dsxtLsoStdio = {
add_lso, del_lso
};
static long init_lso(int pass)
{
if (pass == 0) devExtend(&dsxtLsoStdio);
return 0;
}
static long write_lso(lsoRecord *prec)
{
struct outStream *pstream = (struct outStream *)prec->dpvt;
if (pstream)
pstream->print("%s\n", prec->val);
return 0;
}
lsodset devLsoStdio = {
5, NULL, init_lso, NULL, NULL, write_lso
};
epicsExportAddress(dset, devLsoStdio);
/* printf device support */
static long add_printf(dbCommon *pcommon) {
printfRecord *prec = (printfRecord *) pcommon;
struct outStream *pstream;
if (prec->out.type != INST_IO)
return S_dev_badOutType;
for (pstream = outStreams; pstream->name; ++pstream) {
if (strcmp(prec->out.value.instio.string, pstream->name) == 0) {
prec->dpvt = pstream;
return 0;
}
}
prec->dpvt = NULL;
return -1;
}
static long del_printf(dbCommon *pcommon) {
printfRecord *prec = (printfRecord *) pcommon;
prec->dpvt = NULL;
return 0;
}
static struct dsxt dsxtPrintfStdio = {
add_printf, del_printf
};
static long init_printf(int pass)
{
if (pass == 0) devExtend(&dsxtPrintfStdio);
return 0;
}
static long write_printf(printfRecord *prec)
{
struct outStream *pstream = (struct outStream *)prec->dpvt;
if (pstream)
pstream->print("%s\n", prec->val);
return 0;
}
printfdset devPrintfStdio = {
5, NULL, init_printf, NULL, NULL, write_printf
};
epicsExportAddress(dset, devPrintfStdio);
/* stringout device support */
static long add_stringout(dbCommon *pcommon) {
stringoutRecord *prec = (stringoutRecord *) pcommon;
struct outStream *pstream;
if (prec->out.type != INST_IO)
return S_dev_badOutType;
for (pstream = outStreams; pstream->name; ++pstream) {
if (strcmp(prec->out.value.instio.string, pstream->name) == 0) {
prec->dpvt = pstream;
return 0;
}
}
prec->dpvt = NULL;
return -1;
}
static long del_stringout(dbCommon *pcommon) {
stringoutRecord *prec = (stringoutRecord *) pcommon;
prec->dpvt = NULL;
return 0;
}
static struct dsxt dsxtSoStdio = {
add_stringout, del_stringout
};
static long init_stringout(int pass)
{
if (pass == 0) devExtend(&dsxtSoStdio);
return 0;
}
static long write_stringout(stringoutRecord *prec)
{
struct outStream *pstream = (struct outStream *)prec->dpvt;
if (pstream)
pstream->print("%s\n", prec->val);
return 0;
}
static struct {
dset common;
DEVSUPFUN write;
} devSoStdio = {
{5, NULL, init_stringout, NULL, NULL}, write_stringout
};
epicsExportAddress(dset, devSoStdio);
@@ -0,0 +1,77 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Device support for EPICS time stamps
*
* Original Author: Eric Norum
*/
#include "dbDefs.h"
#include "epicsTime.h"
#include "alarm.h"
#include "devSup.h"
#include "recGbl.h"
#include "aiRecord.h"
#include "stringinRecord.h"
#include "epicsExport.h"
/* Extended device support to allow INP field changes */
static long initAllow(int pass) {
if (pass == 0) devExtend(&devSoft_DSXT);
return 0;
}
/* ai record */
static long read_ai(aiRecord *prec)
{
recGblGetTimeStamp(prec);
prec->val = prec->time.secPastEpoch + (double)prec->time.nsec * 1e-9;
prec->udf = FALSE;
return 2;
}
struct {
dset common;
DEVSUPFUN read_write;
DEVSUPFUN special_linconv;
} devTimestampAI = {
{6, NULL, initAllow, NULL, NULL}, read_ai, NULL
};
epicsExportAddress(dset, devTimestampAI);
/* stringin record */
static long read_stringin (stringinRecord *prec)
{
int len;
recGblGetTimeStamp(prec);
len = epicsTimeToStrftime(prec->val, sizeof prec->val,
prec->inp.value.instio.string, &prec->time);
if (len >= sizeof prec->val) {
prec->udf = TRUE;
recGblSetSevr(prec, UDF_ALARM, prec->udfs);
return -1;
}
prec->udf = FALSE;
return 0;
}
struct {
dset common;
DEVSUPFUN read_stringin;
} devTimestampSI = {
{5, NULL, initAllow, NULL, NULL}, read_stringin
};
epicsExportAddress(dset, devTimestampSI);
+99
View File
@@ -0,0 +1,99 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Authors: Bob Dalesio and Marty Kraimer
* Date: 6-1-90
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "recGbl.h"
#include "devSup.h"
#include "waveformRecord.h"
#include "epicsExport.h"
/* Create the dset for devWfSoft */
static long init_record(waveformRecord *prec);
static long read_wf(waveformRecord *prec);
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_wf;
} devWfSoft = {
5,
NULL,
NULL,
init_record,
NULL,
read_wf
};
epicsExportAddress(dset, devWfSoft);
static long init_record(waveformRecord *prec)
{
long nelm = prec->nelm;
long status = dbLoadLinkArray(&prec->inp, prec->ftvl, prec->bptr, &nelm);
if (!status && nelm > 0) {
prec->nord = nelm;
prec->udf = FALSE;
}
else
prec->nord = 0;
return status;
}
struct wfrt {
long nRequest;
epicsTimeStamp *ptime;
};
static long readLocked(struct link *pinp, void *vrt)
{
waveformRecord *prec = (waveformRecord *) pinp->precord;
struct wfrt *prt = (struct wfrt *) vrt;
long status = dbGetLink(pinp, prec->ftvl, prec->bptr, 0, &prt->nRequest);
if (!status && prt->ptime)
dbGetTimeStamp(pinp, prt->ptime);
return status;
}
static long read_wf(waveformRecord *prec)
{
long status;
struct wfrt rt;
rt.nRequest = prec->nelm;
rt.ptime = (dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime) ? &prec->time : NULL;
status = dbLinkDoLocked(&prec->inp, readLocked, &rt);
if (status == S_db_noLSET)
status = readLocked(&prec->inp, &rt);
if (!status && rt.nRequest > 0) {
prec->nord = rt.nRequest;
prec->udf = FALSE;
}
return status;
}
@@ -0,0 +1,36 @@
#include <winver.h>
#include "epicsVersion.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION EPICS_VERSION,EPICS_REVISION,EPICS_MODIFICATION,EPICS_PATCH_LEVEL
PRODUCTVERSION EPICS_VERSION,EPICS_REVISION,EPICS_MODIFICATION,EPICS_PATCH_LEVEL
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_UNKNOWN
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments","Soft Device Support Library for EPICS\0"
VALUE "CompanyName", "The EPICS collaboration\0"
VALUE "FileDescription", "Soft Device Support Library\0"
VALUE "FileVersion", EPICS_VERSION_STRING "\0"
VALUE "InternalName", "softDevIoc\0"
VALUE "LegalCopyright", "Copyright (C) Univ. of California, Univ. of Chicago\0"
VALUE "OriginalFilename", "softDevIoc.dll\0"
VALUE "ProductName", "Experimental Physics and Industrial Control System (EPICS)\0"
VALUE "ProductVersion", EPICS_VERSION_STRING "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
+20
View File
@@ -0,0 +1,20 @@
#*************************************************************************
# Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
# National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
# This is a Makefile fragment, see src/std/Makefile.
SRC_DIRS += $(STDDIR)/filters
DBD += filters.dbd
dbRecStd_SRCS += ts.c
dbRecStd_SRCS += dbnd.c
dbRecStd_SRCS += arr.c
dbRecStd_SRCS += sync.c
HTMLS += filters.html
+232
View File
@@ -0,0 +1,232 @@
/*************************************************************************\
* Copyright (c) 2010 Brookhaven National Laboratory.
* Copyright (c) 2010 Helmholtz-Zentrum Berlin
* fuer Materialien und Energie GmbH.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Ralph Lange <Ralph.Lange@bessy.de>
*/
#include <stdio.h>
#include <freeList.h>
#include <dbAccess.h>
#include <dbExtractArray.h>
#include <db_field_log.h>
#include <dbLock.h>
#include <recSup.h>
#include <epicsExit.h>
#include <special.h>
#include <chfPlugin.h>
#include <epicsExport.h>
typedef struct myStruct {
epicsInt32 start;
epicsInt32 incr;
epicsInt32 end;
void *arrayFreeList;
long no_elements;
} myStruct;
static void *myStructFreeList;
static const chfPluginArgDef opts[] = {
chfInt32 (myStruct, start, "s", 0, 1),
chfInt32 (myStruct, incr, "i", 0, 1),
chfInt32 (myStruct, end, "e", 0, 1),
chfPluginArgEnd
};
static void * allocPvt(void)
{
myStruct *my = (myStruct*) freeListCalloc(myStructFreeList);
if (!my) return NULL;
my->incr = 1;
my->end = -1;
return (void *) my;
}
static void freePvt(void *pvt)
{
myStruct *my = (myStruct*) pvt;
if (my->arrayFreeList) freeListCleanup(my->arrayFreeList);
freeListFree(myStructFreeList, pvt);
}
static int parse_ok(void *pvt)
{
myStruct *my = (myStruct*) pvt;
if (my->incr <= 0) my->incr = 1;
return 0;
}
static void freeArray(db_field_log *pfl)
{
if (pfl->type == dbfl_type_ref) {
freeListFree(pfl->u.r.pvt, pfl->u.r.field);
}
}
static long wrapArrayIndices(long *start, const long increment, long *end,
const long no_elements)
{
long len = 0;
if (*start < 0) *start = no_elements + *start;
if (*start < 0) *start = 0;
if (*start > no_elements) *start = no_elements;
if (*end < 0) *end = no_elements + *end;
if (*end < 0) *end = 0;
if (*end >= no_elements) *end = no_elements - 1;
if (*end - *start >= 0) len = 1 + (*end - *start) / increment;
return len;
}
static db_field_log* filter(void* pvt, dbChannel *chan, db_field_log *pfl)
{
myStruct *my = (myStruct*) pvt;
struct dbCommon *prec;
rset *prset;
long start = my->start;
long end = my->end;
long nTarget = 0;
long offset = 0;
long nSource = chan->addr.no_elements;
long capacity = nSource;
void *pdst;
switch (pfl->type) {
case dbfl_type_val:
/* Only filter arrays */
break;
case dbfl_type_rec:
/* Extract from record */
if (chan->addr.special == SPC_DBADDR &&
nSource > 1 &&
(prset = dbGetRset(&chan->addr)) &&
prset->get_array_info)
{
void *pfieldsave = chan->addr.pfield;
prec = dbChannelRecord(chan);
dbScanLock(prec);
prset->get_array_info(&chan->addr, &nSource, &offset);
nTarget = wrapArrayIndices(&start, my->incr, &end, nSource);
pfl->type = dbfl_type_ref;
pfl->stat = prec->stat;
pfl->sevr = prec->sevr;
pfl->time = prec->time;
pfl->field_type = chan->addr.field_type;
pfl->field_size = chan->addr.field_size;
pfl->no_elements = nTarget;
if (nTarget) {
pdst = freeListCalloc(my->arrayFreeList);
if (pdst) {
pfl->u.r.dtor = freeArray;
pfl->u.r.pvt = my->arrayFreeList;
offset = (offset + start) % chan->addr.no_elements;
dbExtractArrayFromRec(&chan->addr, pdst, nTarget, capacity,
offset, my->incr);
pfl->u.r.field = pdst;
}
}
dbScanUnlock(prec);
chan->addr.pfield = pfieldsave;
}
break;
/* Extract from buffer */
case dbfl_type_ref:
pdst = NULL;
nSource = pfl->no_elements;
nTarget = wrapArrayIndices(&start, my->incr, &end, nSource);
pfl->no_elements = nTarget;
if (nTarget) {
/* Copy the data out */
void *psrc = pfl->u.r.field;
pdst = freeListCalloc(my->arrayFreeList);
if (!pdst) break;
offset = start;
dbExtractArrayFromBuf(psrc, pdst, pfl->field_size, pfl->field_type,
nTarget, nSource, offset, my->incr);
}
if (pfl->u.r.dtor) pfl->u.r.dtor(pfl);
if (nTarget) {
pfl->u.r.dtor = freeArray;
pfl->u.r.pvt = my->arrayFreeList;
pfl->u.r.field = pdst;
}
break;
}
return pfl;
}
static void channelRegisterPost(dbChannel *chan, void *pvt,
chPostEventFunc **cb_out, void **arg_out, db_field_log *probe)
{
myStruct *my = (myStruct*) pvt;
long start = my->start;
long end = my->end;
long max = 0;
if (probe->no_elements <= 1) return; /* array data only */
max = wrapArrayIndices(&start, my->incr, &end, probe->no_elements);
if (max) {
if (!my->arrayFreeList)
freeListInitPvt(&my->arrayFreeList, max * probe->field_size, 2);
if (!my->arrayFreeList) return;
}
probe->no_elements = my->no_elements = max;
*cb_out = filter;
*arg_out = pvt;
}
static void channel_report(dbChannel *chan, void *pvt, int level,
const unsigned short indent)
{
myStruct *my = (myStruct*) pvt;
printf("%*sArray (arr): start=%d, incr=%d, end=%d\n", indent, "",
my->start, my->incr, my->end);
}
static chfPluginIf pif = {
allocPvt,
freePvt,
NULL, /* parse_error, */
parse_ok,
NULL, /* channel_open, */
NULL, /* channelRegisterPre, */
channelRegisterPost,
channel_report,
NULL /* channel_close */
};
static void arrShutdown(void* ignore)
{
if(myStructFreeList)
freeListCleanup(myStructFreeList);
myStructFreeList = NULL;
}
static void arrInitialize(void)
{
if (!myStructFreeList)
freeListInitPvt(&myStructFreeList, sizeof(myStruct), 64);
chfPluginRegister("arr", &pif, opts);
epicsAtExit(arrShutdown, NULL);
}
epicsExportRegistrar(arrInitialize);
+141
View File
@@ -0,0 +1,141 @@
/*************************************************************************\
* Copyright (c) 2010 Brookhaven National Laboratory.
* Copyright (c) 2010 Helmholtz-Zentrum Berlin
* für Materialien und Energie GmbH.
* Copyright (c) 2014 ITER Organization.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Ralph Lange <Ralph.Lange@gmx.de>
*/
#include <stdio.h>
#include <epicsMath.h>
#include <freeList.h>
#include <dbConvertFast.h>
#include <chfPlugin.h>
#include <recGbl.h>
#include <epicsExit.h>
#include <db_field_log.h>
#include <epicsExport.h>
typedef struct myStruct {
int mode;
double cval;
double hyst;
double last;
} myStruct;
static void *myStructFreeList;
static const
chfPluginEnumType modeEnum[] = { {"abs", 0}, {"rel", 1}, {NULL,0} };
static const
chfPluginArgDef opts[] = {
chfDouble (myStruct, cval, "d", 0, 1),
chfEnum (myStruct, mode, "m", 0, 1, modeEnum),
chfTagDouble (myStruct, cval, "abs", mode, 0, 0, 1),
chfTagDouble (myStruct, cval, "rel", mode, 1, 0, 1),
chfPluginArgEnd
};
static void * allocPvt(void)
{
return freeListCalloc(myStructFreeList);
}
static void freePvt(void *pvt)
{
freeListFree(myStructFreeList, pvt);
}
static int parse_ok(void *pvt)
{
myStruct *my = (myStruct*) pvt;
my->hyst = my->cval;
my->last = epicsNAN;
return 0;
}
static db_field_log* filter(void* pvt, dbChannel *chan, db_field_log *pfl) {
myStruct *my = (myStruct*) pvt;
long status;
double val;
unsigned send = 1;
/*
* Only scalar values supported - strings, arrays, and conversion errors
* are just passed on
*/
if (pfl->type == dbfl_type_val) {
DBADDR localAddr = chan->addr; /* Structure copy */
localAddr.field_type = pfl->field_type;
localAddr.field_size = pfl->field_size;
localAddr.no_elements = pfl->no_elements;
localAddr.pfield = (char *) &pfl->u.v.field;
status = dbFastGetConvertRoutine[pfl->field_type][DBR_DOUBLE]
(localAddr.pfield, (void*) &val, &localAddr);
if (!status) {
send = 0;
recGblCheckDeadband(&my->last, val, my->hyst, &send, 1);
if (send && my->mode == 1) {
my->hyst = val * my->cval/100.;
}
}
}
if (!send) {
db_delete_field_log(pfl);
return NULL;
} else return pfl;
}
static void channelRegisterPre(dbChannel *chan, void *pvt,
chPostEventFunc **cb_out, void **arg_out, db_field_log *probe)
{
*cb_out = filter;
*arg_out = pvt;
}
static void channel_report(dbChannel *chan, void *pvt, int level, const unsigned short indent)
{
myStruct *my = (myStruct*) pvt;
printf("%*sDeadband (dbnd): mode=%s, delta=%g%s\n", indent, "",
chfPluginEnumString(modeEnum, my->mode, "n/a"), my->cval,
my->mode == 1 ? "%" : "");
}
static chfPluginIf pif = {
allocPvt,
freePvt,
NULL, /* parse_error, */
parse_ok,
NULL, /* channel_open, */
channelRegisterPre,
NULL, /* channelRegisterPost, */
channel_report,
NULL /* channel_close */
};
static void dbndShutdown(void* ignore)
{
if(myStructFreeList)
freeListCleanup(myStructFreeList);
myStructFreeList = NULL;
}
static void dbndInitialize(void)
{
if (!myStructFreeList)
freeListInitPvt(&myStructFreeList, sizeof(myStruct), 64);
chfPluginRegister("dbnd", &pif, opts);
epicsAtExit(dbndShutdown, NULL);
}
epicsExportRegistrar(dbndInitialize);
@@ -0,0 +1,247 @@
=head1 Channel Filters
Channel Filters can be applied to Channel Access channels by a client, using
a JSON Field Modifier to select the filter and any parameters.
The following filters are available in this release:
=over
=item * L<TimeStamp|/"TimeStamp Filter ts">
=item * L<Deadband|/"Deadband Filter dbnd">
=item * L<Array|/"Array Filter arr">
=item * L<Synchronize|/"Synchronize Filter sync">
=back
=head2 Using Filters
Channel filters can be added to any Channel Access channel name.
There can be more than one filter applied to the same channel, in which case the
order that they are specified will control the order in which they are applied
to the resulting data-stream.
The filter specification must appear after the field name, or if the default
(VAL) field is used after a dot C<.> appended to the record name.
With the exception of the array short-hand which is described below, all filters
must appear inside a pair of braces C< {} > after the dot expressed as a JSON
(L<JavaScript Object Notation|http://www.json.org/>) object, which allows filter
parameters to be included as needed.
Each filter is given as a name/value pair. The filter name (given in parentheses
in the titles below) is a string, and must be enclosed inside double-quotes C<">
characters as per the JSON specification.
Parameters to that filter are provided as the value part of the name/value pair,
and will normally appear as a child JSON object consisting of name/value pairs
inside a nested pair of braces C< {} >.
=head4 Example Filter
Given a record called C<test:channel> the following would apply a filter C<f> to
the VAL field of that record, giving the filter two numeric parameters named
C<lo> and C<hi>:
test:channel.{"f":{"lo":0,"hi":10}}
Note that due to the required presence of the double-quote characters in the
JSON strings in the name string, it will usually be necessary to enclose a
filtered name within single-quotes C<< ' ... ' >> when typing it as an
argument to a Unix shell command.
=head2 Filter Reference
=cut
registrar(tsInitialize)
=head3 TimeStamp Filter C<"ts">
This filter is used to set the timestamp of the value fetched through
the channel to the time the value was fetched (or an update was sent),
rather than the time the record last
processed which could have been days or even weeks ago for some records, or set
to the EPICS epoch if the record has never processed.
=head4 Parameters
None, use an empty pair of braces.
=head4 Example
Hal$ caget -a 'test:channel.{"ts":{}}'
test:channel.{"ts":{}} 2012-08-28 22:10:31.192547 0 UDF INVALID
Hal$ caget -a 'test:channel'
test:channel <undefined> 0 UDF INVALID
=cut
registrar(dbndInitialize)
=head3 Deadband Filter C<"dbnd">
This filter implements a channel-specific monitor deadband, which is applied
after any deadbands implemented by the record itself (it can only drop updates
that the unfiltered channel generates, never add additional updates).
The deadband can be specified as an absolute value change, or as a relative
percentage.
=head4 Parameters
=over
=item Mode+Deadband C<"abs">/C<"rel"> (shorthand)
Mode and deadband can be specified in one definition (shorthand).
The desired mode is given as parameter name (C<"abs"> or C<"rel">), with the
numeric size of the deadband (absolute value or numeric percentage) as value.
=item Deadband C<"d">
The size of the deadband to use.
Relative deadband values are given as a numeric percentage, but without any
trailing percent character.
=item Mode C<"m"> (optional)
A string (enclosed in double-quotes C<">), which should contain either
C<abs> or C<rel>.
The default mode is C<abs> if no mode parameter is included.
=back
=head4 Example
Hal$ camonitor 'test:channel'
test:channel 2012-09-01 22:10:19.600595 1 LOLO MAJOR
test:channel 2012-09-01 22:10:20.600661 2 LOLO MAJOR
test:channel 2012-09-01 22:10:21.600819 3 LOW MINOR
test:channel 2012-09-01 22:10:22.600905 4 LOW MINOR
test:channel 2012-09-01 22:10:23.601023 5
test:channel 2012-09-01 22:10:24.601136 6 HIGH MINOR
^C
Hal$ camonitor 'test:channel.{"dbnd":{"abs":1.5}}'
test:channel.{"dbnd":{"d":1.5}} 2012-09-01 22:11:49.613341 1 LOLO MAJOR
test:channel.{"dbnd":{"d":1.5}} 2012-09-01 22:11:51.613615 3 LOW MINOR
test:channel.{"dbnd":{"d":1.5}} 2012-09-01 22:11:53.613804 5
test:channel.{"dbnd":{"d":1.5}} 2012-09-01 22:11:55.614074 7 HIGH MINOR
test:channel.{"dbnd":{"d":1.5}} 2012-09-01 22:11:57.614305 9 HIHI MAJOR
^C
=cut
registrar(arrInitialize)
=head3 Array Filter C<"arr">
This filter is used to retrieve parts of an array (subarrays and strided
subarrays).
=head4 Parameters
Note: Negative index numbers address from the end of the array, with C<-1> being the last element.
=over
=item Square bracket notation C<[start:increment:end]> (shorthand)
The common square bracket notation with can be used in place of JSON.
Any parameter may be omitted (keeping the colons) to use the default value.
If only one colon is included, this means C<[start:end]> with a increment of 1.
If only a single parameter is used C<[index]> the filter returns one element.
=item Start index C<"s">
Index of the first original array element to retrieve.
=item Increment C<"i">
Index increment between retrieved elements of the original array; must be
a positive number.
=item End index C<"e">
Index of the last original array element to retrieve.
=back
Defaults (when parameters are omitted) are:
C<s=0> (first element), C<i=1> (fetch all elements), C<e=-1>
(last element)
=head4 Example
Hal$ caget test:channel 'test:channel.{"arr":{"s":2,"i":2,"e":8}}' test:channel.[3:5] test:channel.[3:2:-3]
test:channel 10 0 1 2 3 4 5 6 7 8 9
test:channel.{"arr":{"s":2,"i":2,"e":8}} 4 2 4 6 8
test:channel.[3:5] 3 3 4 5
test:channel.[3:2:-3] 3 3 5 7
=cut
registrar(syncInitialize)
=head3 Synchronize Filter C<"sync">
This filter is used to dynamically enable or disable monitors according
to a condition and a state variable declared by the IOC.
State variables have a boolean value and can be set by a binary output
record, an iocsh command or by other software running in the IOC calling
C<dbStateSet()>.
=head4 Parameters
=over
=item Mode+State
Mode and state can be specified in one definition (shorthand).
The desired mode is given as parameter name (C<"before"> / C<"first"> /
C<"while"> / C<"last"> / C<"after"> / C<"unless">), with the state name
(enclosed in double quotes C<">) as value.
=item Mode C<"m">
A single word from the list below, enclosed in double quotes C<">.
This controls how the state value should affect the monitor stream.
=over
=item C<"before"> E<mdash> only the last value received before the state
changes from false to true is forwarded to the client.
=item C<"first"> E<mdash> only the first value received after the state
changes from true to false is forwarded to the client.
=item C<"while"> E<mdash> values are forwarded to the client as long as
the state is true.
=item C<"last"> E<mdash> only the last value received before the state
changes from true to false is forwarded to the client.
=item C<"after"> E<mdash> only the first value received after the state
changes from true to false is forwarded to the client.
=item C<"unless"> E<mdash> values are forwarded to the client as long
as the state is false.
=back
=item State C<"s">
The name of a state variable, enclosed in double quotes C<">.
=back
=head4 Example
Assuming there is a system state called "blue", that is being controlled by
some other facility such as a timing system, updates could be restricted to
periods only when "blue" is true by using
Hal$ camonitor 'test:channel' 'test:channel.{"while":"blue"}'
...
=cut
+194
View File
@@ -0,0 +1,194 @@
/*************************************************************************\
* Copyright (c) 2010 Brookhaven National Laboratory.
* Copyright (c) 2010 Helmholtz-Zentrum Berlin
* fuer Materialien und Energie GmbH.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Ralph Lange <Ralph.Lange@bessy.de>
*/
#include <stdio.h>
#include "freeList.h"
#include "db_field_log.h"
#include "chfPlugin.h"
#include "dbState.h"
#include "epicsExit.h"
#include "epicsAssert.h"
#include "epicsExport.h"
#define STATE_NAME_LENGTH 20
typedef enum syncMode {
syncModeBefore=0,
syncModeFirst=1,
syncModeLast=2,
syncModeAfter=3,
syncModeWhile=4,
syncModeUnless=5
} syncMode;
static const
chfPluginEnumType modeEnum[] = {
{"before", syncModeBefore},
{"first", syncModeFirst},
{"last", syncModeLast},
{"after", syncModeAfter},
{"while", syncModeWhile},
{"unless", syncModeUnless},
{NULL, 0}
};
typedef struct myStruct {
syncMode mode;
char state[STATE_NAME_LENGTH];
dbStateId id;
db_field_log *lastfl;
int laststate:1;
} myStruct;
static void *myStructFreeList;
static const
chfPluginArgDef opts[] = {
chfEnum (myStruct, mode, "m", 1, 1, modeEnum),
chfString (myStruct, state, "s", 1, 0),
chfTagString (myStruct, state, "before", mode, 0, 1, 0),
chfTagString (myStruct, state, "first", mode, 1, 1, 0),
chfTagString (myStruct, state, "last", mode, 2, 1, 0),
chfTagString (myStruct, state, "after", mode, 3, 1, 0),
chfTagString (myStruct, state, "while", mode, 4, 1, 0),
chfTagString (myStruct, state, "unless", mode, 5, 1, 0),
chfPluginArgEnd
};
static void * allocPvt(void)
{
myStruct *my = (myStruct*) freeListCalloc(myStructFreeList);
return (void *) my;
}
static void freePvt(void *pvt)
{
myStruct *my = (myStruct*) pvt;
db_delete_field_log(my->lastfl);
freeListFree(myStructFreeList, pvt);
}
static int parse_ok(void *pvt)
{
myStruct *my = (myStruct*) pvt;
if (!(my->id = dbStateFind(my->state)))
return -1;
return 0;
}
static db_field_log* filter(void* pvt, dbChannel *chan, db_field_log *pfl) {
db_field_log *passfl = NULL;
myStruct *my = (myStruct*) pvt;
int actstate;
if (pfl->ctx == dbfl_context_read)
return pfl;
actstate = dbStateGet(my->id);
switch (my->mode) {
case syncModeBefore:
if (actstate && !my->laststate) {
passfl = my->lastfl;
my->lastfl = NULL;
}
break;
case syncModeFirst:
if (actstate && !my->laststate) {
passfl = pfl;
pfl = NULL;
}
break;
case syncModeLast:
if (!actstate && my->laststate) {
passfl = my->lastfl;
my->lastfl = NULL;
}
break;
case syncModeAfter:
if (!actstate && my->laststate) {
passfl = pfl;
pfl = NULL;
}
break;
case syncModeWhile:
if (actstate) {
passfl = pfl;
}
goto no_shift;
case syncModeUnless:
if (!actstate) {
passfl = pfl;
}
goto no_shift;
}
if (my->lastfl)
db_delete_field_log(my->lastfl);
my->lastfl = pfl;
my->laststate = actstate;
/* since no copy is made we can't keep a reference to the returned fl */
assert(my->lastfl != passfl);
no_shift:
return passfl;
}
static void channelRegisterPre(dbChannel *chan, void *pvt,
chPostEventFunc **cb_out, void **arg_out, db_field_log *probe)
{
*cb_out = filter;
*arg_out = pvt;
}
static void channel_report(dbChannel *chan, void *pvt, int level, const unsigned short indent)
{
myStruct *my = (myStruct*) pvt;
printf("%*sSynchronize (sync): mode=%s, state=%s\n", indent, "",
chfPluginEnumString(modeEnum, my->mode, "n/a"), my->state);
}
static chfPluginIf pif = {
allocPvt,
freePvt,
NULL, /* parse_error, */
parse_ok,
NULL, /* channel_open, */
channelRegisterPre,
NULL, /* channelRegisterPost, */
channel_report,
NULL /* channel_close */
};
static void syncShutdown(void* ignore)
{
if(myStructFreeList)
freeListCleanup(myStructFreeList);
myStructFreeList = NULL;
}
static void syncInitialize(void)
{
if (!myStructFreeList)
freeListInitPvt(&myStructFreeList, sizeof(myStruct), 64);
chfPluginRegister("sync", &pif, opts);
epicsAtExit(syncShutdown, NULL);
}
epicsExportRegistrar(syncInitialize);
+65
View File
@@ -0,0 +1,65 @@
/*************************************************************************\
* Copyright (c) 2010 Brookhaven National Laboratory.
* Copyright (c) 2010 Helmholtz-Zentrum Berlin
* fuer Materialien und Energie GmbH.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Ralph Lange <Ralph.Lange@bessy.de>
*/
#include <stdio.h>
#include <chfPlugin.h>
#include <dbLock.h>
#include <db_field_log.h>
#include <epicsExport.h>
static db_field_log* filter(void* pvt, dbChannel *chan, db_field_log *pfl) {
epicsTimeStamp now;
epicsTimeGetCurrent(&now);
/* If string or array, must make a copy (to ensure coherence between time and data) */
if (pfl->type == dbfl_type_rec) {
dbScanLock(dbChannelRecord(chan));
dbChannelMakeArrayCopy(pvt, pfl, chan);
dbScanUnlock(dbChannelRecord(chan));
}
pfl->time = now;
return pfl;
}
static void channelRegisterPre(dbChannel *chan, void *pvt,
chPostEventFunc **cb_out, void **arg_out, db_field_log *probe)
{
*cb_out = filter;
}
static void channel_report(dbChannel *chan, void *pvt, int level, const unsigned short indent)
{
printf("%*sTimestamp (ts)\n", indent, "");
}
static chfPluginIf pif = {
NULL, /* allocPvt, */
NULL, /* freePvt, */
NULL, /* parse_error, */
NULL, /* parse_ok, */
NULL, /* channel_open, */
channelRegisterPre,
NULL, /* channelRegisterPost, */
channel_report,
NULL /* channel_close */
};
static void tsInitialize(void)
{
chfPluginRegister("ts", &pif, NULL);
}
epicsExportRegistrar(tsInitialize);
+18
View File
@@ -0,0 +1,18 @@
#*************************************************************************
# Copyright (c) 2016 UChicago Argonne LLC, as Operator of Argonne
# National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
# This is a Makefile fragment, see src/std/Makefile.
SRC_DIRS += $(STDDIR)/link
DBD += links.dbd
dbRecStd_SRCS += lnkConst.c
dbRecStd_SRCS += lnkCalc.c
HTMLS += links.html
+131
View File
@@ -0,0 +1,131 @@
=head1 Extensible Links
The extensible link mechanism allows new kinds of record links to be created,
using JSON for the link address syntax.
The IOC continues to support the older link types that do not use JSON to
specify their link addresses.
The following additional link types are available in this release:
=over
=item * L<Constant|/"Constant Link const">
=item * L<Calc|/"Calculation Link calc">
=back
=head2 Using JSON Links
When setting a record link field to a JSON link address, the link specification
must appear inside a pair of braces C< {} > expressed as a JSON (L<JavaScript
Object Notation|http://www.json.org/>) object, which allows link parameters to
be defined as needed by the particular link type. When link fields are set from
an IOC database file at initialization time, the field definitions may take
advantage of a "relaxed JSON" syntax that reduces the number of double-quote
characters required and maintains backwards compatibility with the older
database file syntax.
=head2 Link Type Reference
=cut
link(const, lnkConstIf)
=head3 Constant Link C<"const">
Constant links provide one or more values at link initalization time, but do not
return any data when their C<getValue()> routine is called. Most record types
support the use of constant links by calling C<recGblInitConstantLink()> at
record initialization, which results in the constant value being loaded into the
target field at that time.
Note that for most record types (the C<printf> and C<calcout> records are the
main exceptions) it is pointless to set an input link to a constant link at
runtime since the link initialization that loads the field value usually only
happens when a record is initialized. A constant link that is embedded inside
another input link type such as a calculation link should be OK though since the
link initialization will take place when the record's field gets set.
=head4 Parameters
A const link takes a parameter which may be an integer, double or string, or an
array of those types. If an array contains both integers and double values the
integers will be promoted to doubles. Mixing strings and numbers in an array
results in an error.
=head4 Examples
{const: 3.14159265358979}
{const: "Pi"}
{const: [1, 2.718281828459, 3.14159265358979]}
{const: ["One", "e", "Pi"]}
The JSON syntax does not support Infinity or NaN values when parsing numbers,
but (for scalars) it is possible to provide these in a string which will be
converted to the desired double value at initialization, for example:
field(INP, {const:"Inf"})
=cut
link(calc, lnkCalcIf)
=head3 Calculation Link C<"calc">
Calculation links can perform simple mathematical expressions on scalar
(double-precision floating-point) values obtained from other link types and
return a single double-precision floating-point result. The expressions are
evaluated by the EPICS Calc engine, and up to 12 inputs can be provided.
=head4 Parameters
The link address is a JSON map with the following keys:
=over
=item expr
The primary expression to be evaluated, given as a string.
=item major
An optional expression that returns non-zero to raise a major alarm.
=item minor
An optional expression that returns non-zero to raise a minor alarm.
=item args
A JSON list of up to 12 input arguments for the expression, which are assigned
to the inputs C<A>, C<B>, C<C>, ... C<L>. Each input argument may be either a
numeric literal or an embedded JSON link inside C<{}> braces. The same input
values are provided to the two alarm expressions as to the primary expression.
=item units
An optional string specifying the engineering units for the result of the
expression. Equivalent to the C<EGU> field of a record.
=item prec
An optional integer specifying the numeric precision with which the calculation
result should be displayed. Equivalent to the C<PREC> field of a record.
=item time
An optional string containing a single upper or lower-case letter C<A> ... C<L>
which must correspond to an input provided in the c<args> parameter. When the
record containing such a link has C<TSEL> set to -2 (epicsTimeEventDeviceTime)
the record's timestamp field C<TIME> will be read from the indicated input link
atomically with the value of the input argument.
=back
=head4 Example
{calc: {expr:"A*B", args:[{db:"record.VAL"}, 1.5], prec:3}}
=cut
+691
View File
@@ -0,0 +1,691 @@
/*************************************************************************\
* Copyright (c) 2016 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* lnkCalc.c */
/* Current usage
* {calc:{expr:"A", args:[{...}, ...]}}
* First link in 'args' is 'A', second is 'B', and so forth.
*
* TODO:
* Support setting individual input links instead of the args list.
* {calc:{expr:"K", K:{...}}}
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "alarm.h"
#include "dbDefs.h"
#include "errlog.h"
#include "epicsAssert.h"
#include "epicsString.h"
#include "epicsTypes.h"
#include "dbAccessDefs.h"
#include "dbCommon.h"
#include "dbConvertFast.h"
#include "dbLink.h"
#include "dbJLink.h"
#include "dbStaticLib.h"
#include "dbStaticPvt.h"
#include "postfix.h"
#include "recGbl.h"
#include "epicsExport.h"
typedef long (*FASTCONVERT)();
#define IFDEBUG(n) if(clink->jlink.debug)
typedef struct calc_link {
jlink jlink; /* embedded object */
int nArgs;
enum {
ps_init,
ps_expr, ps_major, ps_minor,
ps_args,
ps_prec,
ps_units,
ps_time,
ps_error
} pstate;
epicsEnum16 stat;
epicsEnum16 sevr;
short prec;
char *expr;
char *major;
char *minor;
char *post_expr;
char *post_major;
char *post_minor;
char *units;
short tinp;
struct link inp[CALCPERFORM_NARGS];
double arg[CALCPERFORM_NARGS];
double val;
} calc_link;
static lset lnkCalc_lset;
/*************************** jlif Routines **************************/
static jlink* lnkCalc_alloc(short dbfType)
{
calc_link *clink = calloc(1, sizeof(struct calc_link));
IFDEBUG(10)
printf("lnkCalc_alloc()\n");
clink->nArgs = 0;
clink->pstate = ps_init;
clink->prec = 15; /* standard value for a double */
clink->tinp = -1;
IFDEBUG(10)
printf("lnkCalc_alloc -> calc@%p\n", clink);
return &clink->jlink;
}
static void lnkCalc_free(jlink *pjlink)
{
calc_link *clink = CONTAINER(pjlink, struct calc_link, jlink);
int i;
IFDEBUG(10)
printf("lnkCalc_free(calc@%p)\n", clink);
for (i = 0; i < clink->nArgs; i++)
dbJLinkFree(clink->inp[i].value.json.jlink);
free(clink->expr);
free(clink->major);
free(clink->minor);
free(clink->post_expr);
free(clink->post_major);
free(clink->post_minor);
free(clink->units);
free(clink);
}
static jlif_result lnkCalc_integer(jlink *pjlink, long long num)
{
calc_link *clink = CONTAINER(pjlink, struct calc_link, jlink);
IFDEBUG(10)
printf("lnkCalc_integer(calc@%p, %lld)\n", clink, num);
if (clink->pstate == ps_prec) {
clink->prec = num;
return jlif_continue;
}
if (clink->pstate != ps_args) {
return jlif_stop;
errlogPrintf("lnkCalc: Unexpected integer %lld\n", num);
}
if (clink->nArgs == CALCPERFORM_NARGS) {
errlogPrintf("lnkCalc: Too many input args, limit is %d\n",
CALCPERFORM_NARGS);
return jlif_stop;
}
clink->arg[clink->nArgs++] = num;
return jlif_continue;
}
static jlif_result lnkCalc_double(jlink *pjlink, double num)
{
calc_link *clink = CONTAINER(pjlink, struct calc_link, jlink);
IFDEBUG(10)
printf("lnkCalc_double(calc@%p, %g)\n", clink, num);
if (clink->pstate != ps_args) {
return jlif_stop;
errlogPrintf("lnkCalc: Unexpected double %g\n", num);
}
if (clink->nArgs == CALCPERFORM_NARGS) {
errlogPrintf("lnkCalc: Too many input args, limit is %d\n",
CALCPERFORM_NARGS);
return jlif_stop;
}
clink->arg[clink->nArgs++] = num;
return jlif_continue;
}
static jlif_result lnkCalc_string(jlink *pjlink, const char *val, size_t len)
{
calc_link *clink = CONTAINER(pjlink, struct calc_link, jlink);
char *inbuf, *postbuf;
short err;
IFDEBUG(10)
printf("lnkCalc_string(calc@%p, \"%.*s\")\n", clink, (int) len, val);
if (clink->pstate == ps_units) {
clink->units = epicsStrnDup(val, len);
return jlif_continue;
}
if (clink->pstate == ps_time) {
char tinp;
if (len != 1 || (tinp = toupper(val[0])) < 'A' || tinp > 'L') {
errlogPrintf("lnkCalc: Bad 'time' parameter \"%.*s\"\n", (int) len, val);
return jlif_stop;
}
clink->tinp = tinp - 'A';
return jlif_continue;
}
if (clink->pstate < ps_expr || clink->pstate > ps_minor) {
errlogPrintf("lnkCalc: Unexpected string \"%.*s\"\n", (int) len, val);
return jlif_stop;
}
postbuf = malloc(INFIX_TO_POSTFIX_SIZE(len+1));
if (!postbuf) {
errlogPrintf("lnkCalc: Out of memory\n");
return jlif_stop;
}
inbuf = malloc(len+1);
if(!inbuf) {
errlogPrintf("lnkCalc: Out of memory\n");
return jlif_stop;
}
memcpy(inbuf, val, len);
inbuf[len] = '\0';
if (clink->pstate == ps_major) {
clink->major = inbuf;
clink->post_major = postbuf;
}
else if (clink->pstate == ps_minor) {
clink->minor = inbuf;
clink->post_minor = postbuf;
}
else {
clink->expr = inbuf;
clink->post_expr = postbuf;
}
if (postfix(inbuf, postbuf, &err) < 0) {
errlogPrintf("lnkCalc: Error in calc expression, %s\n",
calcErrorStr(err));
return jlif_stop;
}
return jlif_continue;
}
static jlif_key_result lnkCalc_start_map(jlink *pjlink)
{
calc_link *clink = CONTAINER(pjlink, struct calc_link, jlink);
IFDEBUG(10)
printf("lnkCalc_start_map(calc@%p)\n", clink);
if (clink->pstate == ps_args)
return jlif_key_child_link;
if (clink->pstate != ps_init) {
errlogPrintf("lnkCalc: Unexpected map\n");
return jlif_key_stop;
}
return jlif_key_continue;
}
static jlif_result lnkCalc_map_key(jlink *pjlink, const char *key, size_t len)
{
calc_link *clink = CONTAINER(pjlink, struct calc_link, jlink);
IFDEBUG(10)
printf("lnkCalc_map_key(calc@%p, \"%.*s\")\n", pjlink, (int) len, key);
if (len == 4) {
if (!strncmp(key, "expr", len) && !clink->post_expr)
clink->pstate = ps_expr;
else if (!strncmp(key, "args", len) && !clink->nArgs)
clink->pstate = ps_args;
else if (!strncmp(key, "prec", len))
clink->pstate = ps_prec;
else if (!strncmp(key, "time", len))
clink->pstate = ps_time;
else {
errlogPrintf("lnkCalc: Unknown key \"%.4s\"\n", key);
return jlif_stop;
}
}
else if (len == 5) {
if (!strncmp(key, "major", len) && !clink->post_major)
clink->pstate = ps_major;
else if (!strncmp(key, "minor", len) && !clink->post_minor)
clink->pstate = ps_minor;
else if (!strncmp(key, "units", len) && !clink->units)
clink->pstate = ps_units;
else {
errlogPrintf("lnkCalc: Unknown key \"%.5s\"\n", key);
return jlif_stop;
}
}
else {
errlogPrintf("lnkCalc: Unknown key \"%.*s\"\n", (int) len, key);
return jlif_stop;
}
return jlif_continue;
}
static jlif_result lnkCalc_end_map(jlink *pjlink)
{
calc_link *clink = CONTAINER(pjlink, struct calc_link, jlink);
IFDEBUG(10)
printf("lnkCalc_end_map(calc@%p)\n", clink);
if (clink->pstate == ps_error)
return jlif_stop;
else if (!clink->post_expr) {
errlogPrintf("lnkCalc: no expression ('expr' key)\n");
return jlif_stop;
}
return jlif_continue;
}
static jlif_result lnkCalc_start_array(jlink *pjlink)
{
calc_link *clink = CONTAINER(pjlink, struct calc_link, jlink);
IFDEBUG(10)
printf("lnkCalc_start_array(calc@%p)\n", clink);
if (clink->pstate != ps_args) {
errlogPrintf("lnkCalc: Unexpected array\n");
return jlif_stop;
}
return jlif_continue;
}
static jlif_result lnkCalc_end_array(jlink *pjlink)
{
calc_link *clink = CONTAINER(pjlink, struct calc_link, jlink);
IFDEBUG(10)
printf("lnkCalc_end_array(calc@%p)\n", clink);
if (clink->pstate == ps_error)
return jlif_stop;
return jlif_continue;
}
static void lnkCalc_end_child(jlink *parent, jlink *child)
{
calc_link *clink = CONTAINER(parent, struct calc_link, jlink);
struct link *plink;
if (clink->nArgs == CALCPERFORM_NARGS) {
dbJLinkFree(child);
errlogPrintf("lnkCalc: Too many input args, limit is %d\n",
CALCPERFORM_NARGS);
clink->pstate = ps_error;
return;
}
plink = &clink->inp[clink->nArgs++];
plink->type = JSON_LINK;
plink->value.json.string = NULL;
plink->value.json.jlink = child;
}
static struct lset* lnkCalc_get_lset(const jlink *pjlink)
{
calc_link *clink = CONTAINER(pjlink, struct calc_link, jlink);
IFDEBUG(10)
printf("lnkCalc_get_lset(calc@%p)\n", pjlink);
return &lnkCalc_lset;
}
static void lnkCalc_report(const jlink *pjlink, int level, int indent)
{
calc_link *clink = CONTAINER(pjlink, struct calc_link, jlink);
int i;
IFDEBUG(10)
printf("lnkCalc_report(calc@%p)\n", clink);
printf("%*s'calc': \"%s\" = %.*g %s\n", indent, "",
clink->expr, clink->prec, clink->val,
clink->units ? clink->units : "");
if (level > 0) {
if (clink->sevr)
printf("%*s Alarm: %s, %s\n", indent, "",
epicsAlarmSeverityStrings[clink->sevr],
epicsAlarmConditionStrings[clink->stat]);
if (clink->post_major)
printf("%*s Major expression: \"%s\"\n", indent, "",
clink->major);
if (clink->post_minor)
printf("%*s Minor expression: \"%s\"\n", indent, "",
clink->minor);
if (clink->tinp >= 0 && clink->tinp < clink->nArgs)
printf("%*s Timestamp input \"%c\"\n", indent, "",
clink->tinp + 'A');
for (i = 0; i < clink->nArgs; i++) {
struct link *plink = &clink->inp[i];
jlink *child = plink->type == JSON_LINK ?
plink->value.json.jlink : NULL;
printf("%*s Input %c: %g\n", indent, "",
i + 'A', clink->arg[i]);
if (child)
dbJLinkReport(child, level - 1, indent + 4);
}
}
}
long lnkCalc_map_children(jlink *pjlink, jlink_map_fn rtn, void *ctx)
{
calc_link *clink = CONTAINER(pjlink, struct calc_link, jlink);
int i;
IFDEBUG(10)
printf("lnkCalc_map_children(calc@%p)\n", clink);
for (i = 0; i < clink->nArgs; i++) {
struct link *child = &clink->inp[i];
long status = dbJLinkMapChildren(child, rtn, ctx);
if (status)
return status;
}
return 0;
}
/*************************** lset Routines **************************/
static void lnkCalc_open(struct link *plink)
{
calc_link *clink = CONTAINER(plink->value.json.jlink,
struct calc_link, jlink);
int i;
IFDEBUG(10)
printf("lnkCalc_open(calc@%p)\n", clink);
for (i = 0; i < clink->nArgs; i++) {
struct link *child = &clink->inp[i];
child->precord = plink->precord;
dbJLinkInit(child);
dbLoadLink(child, DBR_DOUBLE, &clink->arg[i]);
}
}
static void lnkCalc_remove(struct dbLocker *locker, struct link *plink)
{
calc_link *clink = CONTAINER(plink->value.json.jlink,
struct calc_link, jlink);
int i;
IFDEBUG(10)
printf("lnkCalc_remove(calc@%p)\n", clink);
for (i = 0; i < clink->nArgs; i++) {
struct link *child = &clink->inp[i];
dbRemoveLink(locker, child);
}
free(clink->expr);
free(clink->major);
free(clink->minor);
free(clink->post_expr);
free(clink->post_major);
free(clink->post_minor);
free(clink->units);
free(clink);
plink->value.json.jlink = NULL;
}
static int lnkCalc_isConn(const struct link *plink)
{
calc_link *clink = CONTAINER(plink->value.json.jlink,
struct calc_link, jlink);
int connected = 1;
int i;
IFDEBUG(10)
printf("lnkCalc_isConn(calc@%p)\n", clink);
for (i = 0; i < clink->nArgs; i++) {
struct link *child = &clink->inp[i];
if (dbLinkIsVolatile(child) &&
!dbIsLinkConnected(child))
connected = 0;
}
return connected;
}
static int lnkCalc_getDBFtype(const struct link *plink)
{
calc_link *clink = CONTAINER(plink->value.json.jlink,
struct calc_link, jlink);
IFDEBUG(10) {
calc_link *clink = CONTAINER(plink->value.json.jlink,
struct calc_link, jlink);
printf("lnkCalc_getDBFtype(calc@%p)\n", clink);
}
return DBF_DOUBLE;
}
static long lnkCalc_getElements(const struct link *plink, long *nelements)
{
calc_link *clink = CONTAINER(plink->value.json.jlink,
struct calc_link, jlink);
IFDEBUG(10) {
calc_link *clink = CONTAINER(plink->value.json.jlink,
struct calc_link, jlink);
printf("lnkCalc_getElements(calc@%p, (%ld))\n",
clink, *nelements);
}
*nelements = 1;
return 0;
}
/* Get value and timestamp atomically for link indicated by time */
struct lcvt {
double *pval;
epicsTimeStamp *ptime;
};
static long readLocked(struct link *pinp, void *vvt)
{
struct lcvt *pvt = (struct lcvt *) vvt;
long nReq = 1;
long status = dbGetLink(pinp, DBR_DOUBLE, pvt->pval, NULL, &nReq);
if (!status && pvt->ptime)
dbGetTimeStamp(pinp, pvt->ptime);
return status;
}
static long lnkCalc_getValue(struct link *plink, short dbrType, void *pbuffer,
long *pnRequest)
{
calc_link *clink = CONTAINER(plink->value.json.jlink,
struct calc_link, jlink);
dbCommon *prec = plink->precord;
int i;
long status;
FASTCONVERT conv = dbFastPutConvertRoutine[DBR_DOUBLE][dbrType];
IFDEBUG(10)
printf("lnkCalc_getValue(calc@%p, %d, ...)\n",
clink, dbrType);
/* Any link errors will trigger a LINK/INVALID alarm in the child link */
for (i = 0; i < clink->nArgs; i++) {
struct link *child = &clink->inp[i];
long nReq = 1;
if (i == clink->tinp &&
dbLinkIsConstant(&prec->tsel) &&
prec->tse == epicsTimeEventDeviceTime) {
struct lcvt vt = {&clink->arg[i], &prec->time};
status = dbLinkDoLocked(child, readLocked, &vt);
if (status == S_db_noLSET)
status = readLocked(child, &vt);
}
else
dbGetLink(child, DBR_DOUBLE, &clink->arg[i], NULL, &nReq);
}
clink->stat = 0;
clink->sevr = 0;
if (clink->post_expr) {
status = calcPerform(clink->arg, &clink->val, clink->post_expr);
if (!status)
status = conv(&clink->val, pbuffer, NULL);
if (!status && pnRequest)
*pnRequest = 1;
}
else {
status = 0;
if (pnRequest)
*pnRequest = 0;
}
if (!status && clink->post_major) {
double alval = clink->val;
status = calcPerform(clink->arg, &alval, clink->post_major);
if (!status && alval) {
clink->stat = LINK_ALARM;
clink->sevr = MAJOR_ALARM;
recGblSetSevr(prec, clink->stat, clink->sevr);
}
}
if (!status && clink->post_minor) {
double alval = clink->val;
status = calcPerform(clink->arg, &alval, clink->post_minor);
if (!status && alval) {
clink->stat = LINK_ALARM;
clink->sevr = MINOR_ALARM;
recGblSetSevr(prec, clink->stat, clink->sevr);
}
}
return status;
}
static long lnkCalc_getPrecision(const struct link *plink, short *precision)
{
calc_link *clink = CONTAINER(plink->value.json.jlink,
struct calc_link, jlink);
IFDEBUG(10)
printf("lnkCalc_getPrecision(calc@%p)\n", clink);
*precision = clink->prec;
return 0;
}
static long lnkCalc_getUnits(const struct link *plink, char *units, int len)
{
calc_link *clink = CONTAINER(plink->value.json.jlink,
struct calc_link, jlink);
IFDEBUG(10)
printf("lnkCalc_getUnits(calc@%p)\n", clink);
if (clink->units) {
strncpy(units, clink->units, --len);
units[len] = '\0';
}
else
units[0] = '\0';
return 0;
}
static long lnkCalc_getAlarm(const struct link *plink, epicsEnum16 *status,
epicsEnum16 *severity)
{
calc_link *clink = CONTAINER(plink->value.json.jlink,
struct calc_link, jlink);
IFDEBUG(10)
printf("lnkCalc_getAlarm(calc@%p)\n", clink);
if (status)
*status = clink->stat;
if (severity)
*severity = clink->sevr;
return 0;
}
static long doLocked(struct link *plink, dbLinkUserCallback rtn, void *priv)
{
return rtn(plink, priv);
}
/************************* Interface Tables *************************/
static lset lnkCalc_lset = {
0, 1, /* not Constant, Volatile */
lnkCalc_open, lnkCalc_remove,
NULL, NULL, NULL,
lnkCalc_isConn, lnkCalc_getDBFtype, lnkCalc_getElements,
lnkCalc_getValue,
NULL, NULL, NULL,
lnkCalc_getPrecision, lnkCalc_getUnits,
lnkCalc_getAlarm, NULL,
NULL, NULL,
NULL, doLocked
};
static jlif lnkCalcIf = {
"calc", lnkCalc_alloc, lnkCalc_free,
NULL, NULL, lnkCalc_integer, lnkCalc_double, lnkCalc_string,
lnkCalc_start_map, lnkCalc_map_key, lnkCalc_end_map,
lnkCalc_start_array, lnkCalc_end_array,
lnkCalc_end_child, lnkCalc_get_lset,
lnkCalc_report, lnkCalc_map_children
};
epicsExportAddress(jlif, lnkCalcIf);
+632
View File
@@ -0,0 +1,632 @@
/*************************************************************************\
* Copyright (c) 2016 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* lnkConst.c */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "dbDefs.h"
#include "errlog.h"
#include "epicsAssert.h"
#include "epicsString.h"
#include "epicsTypes.h"
#include "dbAccessDefs.h"
#include "dbConvertFast.h"
#include "dbLink.h"
#include "dbJLink.h"
#include "epicsExport.h"
#define IFDEBUG(n) if (clink->jlink.debug)
typedef long (*FASTCONVERT)();
typedef struct const_link {
jlink jlink; /* embedded object */
int nElems;
enum {s0, si64, sf64, sc40, a0, ai64, af64, ac40} type;
union {
epicsInt64 scalar_integer; /* si64 */
epicsFloat64 scalar_double; /* sf64 */
char *scalar_string; /* sc40 */
void *pmem;
epicsInt64 *pintegers; /* ai64 */
epicsFloat64 *pdoubles; /* af64 */
char **pstrings; /* ac40 */
} value;
} const_link;
static lset lnkConst_lset;
/*************************** jlif Routines **************************/
static jlink* lnkConst_alloc(short dbfType)
{
const_link *clink = calloc(1, sizeof(*clink));
IFDEBUG(10)
printf("lnkConst_alloc()\n");
clink->type = s0;
clink->nElems = 0;
clink->value.pmem = NULL;
IFDEBUG(10)
printf("lnkConst_alloc -> const@%p\n", clink);
return &clink->jlink;
}
static void lnkConst_free(jlink *pjlink)
{
const_link *clink = CONTAINER(pjlink, const_link, jlink);
IFDEBUG(10)
printf("lnkConst_free(const@%p) type=%d\n", pjlink, clink->type);
switch (clink->type) {
int i;
case ac40:
for (i=0; i<clink->nElems; i++)
free(clink->value.pstrings[i]);
/* fall through */
case sc40:
case ai64:
case af64:
free(clink->value.pmem);
break;
case s0:
case a0:
case si64:
case sf64:
break;
}
free(clink);
}
static jlif_result lnkConst_integer(jlink *pjlink, long long num)
{
const_link *clink = CONTAINER(pjlink, const_link, jlink);
int newElems = clink->nElems + 1;
IFDEBUG(10)
printf("lnkConst_integer(const@%p, %lld)\n", pjlink, num);
switch (clink->type) {
void *buf;
case s0:
clink->type = si64;
clink->value.scalar_integer = num;
IFDEBUG(12)
printf(" si64 := %lld\n", num);
break;
case a0:
clink->type = ai64;
/* fall through */
case ai64:
buf = realloc(clink->value.pmem, newElems * sizeof(epicsInt64));
if (!buf)
return jlif_stop;
clink->value.pmem = buf;
clink->value.pintegers[clink->nElems] = num;
IFDEBUG(12)
printf(" ai64 += %lld\n", num);
break;
case af64:
buf = realloc(clink->value.pmem, newElems * sizeof(epicsFloat64));
if (!buf)
return jlif_stop;
clink->value.pmem = buf;
clink->value.pdoubles[clink->nElems] = num;
IFDEBUG(12)
printf(" af64 += %lld\n", num);
break;
case ac40:
errlogPrintf("lnkConst: Mixed data types in array\n");
/* fall through */
default:
return jlif_stop;
}
clink->nElems = newElems;
return jlif_continue;
}
static jlif_result lnkConst_boolean(jlink *pjlink, int val)
{
const_link *clink = CONTAINER(pjlink, const_link, jlink);
IFDEBUG(10)
printf("lnkConst_boolean(const@%p, %d)\n", pjlink, val);
return lnkConst_integer(pjlink, val);
}
static jlif_result lnkConst_double(jlink *pjlink, double num)
{
const_link *clink = CONTAINER(pjlink, const_link, jlink);
int newElems = clink->nElems + 1;
IFDEBUG(10)
printf("lnkConst_double(const@%p, %g)\n", pjlink, num);
switch (clink->type) {
epicsFloat64 *f64buf;
int i;
case s0:
clink->type = sf64;
clink->value.scalar_double = num;
break;
case a0:
clink->type = af64;
/* fall through */
case af64:
f64buf = realloc(clink->value.pmem, newElems * sizeof(epicsFloat64));
if (!f64buf)
return jlif_stop;
f64buf[clink->nElems] = num;
clink->value.pdoubles = f64buf;
break;
case ai64: /* promote earlier ai64 values to af64 */
f64buf = calloc(newElems, sizeof(epicsFloat64));
if (!f64buf)
return jlif_stop;
for (i = 0; i < clink->nElems; i++) {
f64buf[i] = clink->value.pintegers[i];
}
free(clink->value.pmem);
f64buf[clink->nElems] = num;
clink->type = af64;
clink->value.pdoubles = f64buf;
break;
case ac40:
errlogPrintf("lnkConst: Mixed data types in array\n");
/* fall through */
default:
return jlif_stop;
}
clink->nElems = newElems;
return jlif_continue;
}
static jlif_result lnkConst_string(jlink *pjlink, const char *val, size_t len)
{
const_link *clink = CONTAINER(pjlink, const_link, jlink);
int newElems = clink->nElems + 1;
IFDEBUG(10)
printf("lnkConst_string(const@%p, \"%.*s\")\n", clink, (int) len, val);
switch (clink->type) {
char **vec, *str;
case s0:
str = malloc(len+1);
if (!str)
return jlif_stop;
strncpy(str, val, len);
str[len] = '\0';
clink->type = sc40;
clink->value.scalar_string = str;
break;
case a0:
clink->type = ac40;
/* fall thorough */
case ac40:
vec = realloc(clink->value.pmem, newElems * sizeof(char *));
if (!vec)
return jlif_stop;
str = malloc(len+1);
if (!str)
return jlif_stop;
strncpy(str, val, len);
str[len] = '\0';
vec[clink->nElems] = str;
clink->value.pstrings = vec;
break;
case af64:
case ai64:
errlogPrintf("lnkConst: Mixed data types in array\n");
/* fall thorough */
default:
return jlif_stop;
}
clink->nElems = newElems;
return jlif_continue;
}
static jlif_result lnkConst_start_array(jlink *pjlink)
{
const_link *clink = CONTAINER(pjlink, const_link, jlink);
IFDEBUG(10)
printf("lnkConst_start_array(const@%p)\n", pjlink);
if (clink->type != s0) {
errlogPrintf("lnkConst: Embedded array value\n");
return jlif_stop;
}
clink->type = a0;
return jlif_continue;
}
static jlif_result lnkConst_end_array(jlink *pjlink)
{
const_link *clink = CONTAINER(pjlink, const_link, jlink);
IFDEBUG(10)
printf("lnkConst_end_array(const@%p)\n", pjlink);
return jlif_continue;
}
static struct lset* lnkConst_get_lset(const jlink *pjlink)
{
const_link *clink = CONTAINER(pjlink, const_link, jlink);
IFDEBUG(10)
printf("lnkConst_get_lset(const@%p)\n", pjlink);
return &lnkConst_lset;
}
/* Report outputs:
* 'const': integer 21
* 'const': double 5.23
* 'const': string "something"
* 'const': array of 999 integers
* [1, 2, 3]
* 'const': array of 1 double
* [1.2345]
* 'const': array of 2 strings
* ["hello", "world"]
*
* Array values are only printed at level 2
* because there might be quite a few of them.
*/
static void lnkConst_report(const jlink *pjlink, int level, int indent)
{
const_link *clink = CONTAINER(pjlink, const_link, jlink);
const char * const type_names[4] = {
"bug", "integer", "double", "string"
};
const char * const dtype = type_names[clink->type & 3];
IFDEBUG(10)
printf("lnkConst_report(const@%p)\n", clink);
if (clink->type > a0) {
const char * const plural = clink->nElems > 1 ? "s" : "";
printf("%*s'const': array of %d %s%s", indent, "",
clink->nElems, dtype, plural);
if (level < 2) {
putchar('\n');
}
else {
int i;
switch (clink->type) {
case ai64:
printf("\n%*s[%lld", indent+2, "", clink->value.pintegers[0]);
for (i = 1; i < clink->nElems; i++) {
printf(", %lld", clink->value.pintegers[i]);
}
break;
case af64:
printf("\n%*s[%g", indent+2, "", clink->value.pdoubles[0]);
for (i = 1; i < clink->nElems; i++) {
printf(", %g", clink->value.pdoubles[i]);
}
break;
case ac40:
printf("\n%*s[\"%s\"", indent+2, "", clink->value.pstrings[0]);
for (i = 1; i < clink->nElems; i++) {
printf(", \"%s\"", clink->value.pstrings[i]);
}
break;
default:
break;
}
printf("]\n");
}
return;
}
printf("%*s'const': %s", indent, "", dtype);
switch (clink->type) {
case si64:
printf(" %lld\n", clink->value.scalar_integer);
return;
case sf64:
printf(" %g\n", clink->value.scalar_double);
return;
case sc40:
printf(" \"%s\"\n", clink->value.scalar_string);
return;
default:
printf(" -- type=%d\n", clink->type);
return;
}
}
/*************************** lset Routines **************************/
static void lnkConst_remove(struct dbLocker *locker, struct link *plink)
{
const_link *clink = CONTAINER(plink->value.json.jlink, const_link, jlink);
IFDEBUG(10)
printf("lnkConst_remove(const@%p)\n", clink);
lnkConst_free(plink->value.json.jlink);
}
static long lnkConst_loadScalar(struct link *plink, short dbrType, void *pbuffer)
{
const_link *clink = CONTAINER(plink->value.json.jlink, const_link, jlink);
long status;
IFDEBUG(10)
printf("lnkConst_loadScalar(const@%p, %d, %p)\n",
clink, dbrType, pbuffer);
switch (clink->type) {
case si64:
IFDEBUG(12)
printf(" si64 %lld\n", clink->value.scalar_integer);
status = dbFastPutConvertRoutine[DBF_INT64][dbrType]
(&clink->value.scalar_integer, pbuffer, NULL);
break;
case sf64:
IFDEBUG(12)
printf(" sf64 %g\n", clink->value.scalar_double);
status = dbFastPutConvertRoutine[DBF_DOUBLE][dbrType]
(&clink->value.scalar_double, pbuffer, NULL);
break;
case sc40:
IFDEBUG(12)
printf(" sc40 '%s'\n", clink->value.scalar_string);
status = dbFastPutConvertRoutine[DBF_STRING][dbrType]
(clink->value.scalar_string, pbuffer, NULL);
break;
case ai64:
IFDEBUG(12)
printf(" ai64 [%lld, ...]\n", clink->value.pintegers[0]);
status = dbFastPutConvertRoutine[DBF_INT64][dbrType]
(clink->value.pintegers, pbuffer, NULL);
break;
case af64:
IFDEBUG(12)
printf(" af64 [%g, ...]\n", clink->value.pdoubles[0]);
status = dbFastPutConvertRoutine[DBF_DOUBLE][dbrType]
(clink->value.pdoubles, pbuffer, NULL);
break;
case ac40:
IFDEBUG(12)
printf(" ac40 ['%s', ...]\n", clink->value.pstrings[0]);
status = dbFastPutConvertRoutine[DBF_STRING][dbrType]
(clink->value.pstrings[0], pbuffer, NULL);
break;
default:
IFDEBUG(12)
printf(" Bad type %d\n", clink->type);
status = S_db_badField;
break;
}
return status;
}
static long lnkConst_loadLS(struct link *plink, char *pbuffer, epicsUInt32 size,
epicsUInt32 *plen)
{
const_link *clink = CONTAINER(plink->value.json.jlink, const_link, jlink);
const char *pstr;
IFDEBUG(10)
printf("lnkConst_loadLS(const@%p, %p, %d, %d)\n",
clink, pbuffer, size, *plen);
if(!size) return 0;
switch (clink->type) {
case sc40:
IFDEBUG(12)
printf(" sc40 '%s'\n", clink->value.scalar_string);
pstr = clink->value.scalar_string;
break;
case ac40:
IFDEBUG(12)
printf(" ac40 ['%s', ...]\n", clink->value.pstrings[0]);
pstr = clink->value.pstrings[0];
break;
default:
IFDEBUG(12)
printf(" Bad type %d\n", clink->type);
return S_db_badField;
}
strncpy(pbuffer, pstr, --size);
pbuffer[size] = 0;
*plen = (epicsUInt32) strlen(pbuffer) + 1;
return 0;
}
static long lnkConst_loadArray(struct link *plink, short dbrType, void *pbuffer,
long *pnReq)
{
const_link *clink = CONTAINER(plink->value.json.jlink, const_link, jlink);
short dbrSize = dbValueSize(dbrType);
char *pdest = pbuffer;
int nElems = clink->nElems;
FASTCONVERT conv;
long status;
IFDEBUG(10)
printf("lnkConst_loadArray(const@%p, %d, %p, (%ld))\n",
clink, dbrType, pbuffer, *pnReq);
if (nElems > *pnReq)
nElems = *pnReq;
switch (clink->type) {
int i;
case si64:
IFDEBUG(12)
printf(" si64 %lld\n", clink->value.scalar_integer);
status = dbFastPutConvertRoutine[DBF_INT64][dbrType]
(&clink->value.scalar_integer, pdest, NULL);
break;
case sf64:
IFDEBUG(12)
printf(" sf64 %g\n", clink->value.scalar_double);
status = dbFastPutConvertRoutine[DBF_DOUBLE][dbrType]
(&clink->value.scalar_double, pdest, NULL);
break;
case sc40:
IFDEBUG(12)
printf(" sc40 '%s'\n", clink->value.scalar_string);
status = dbFastPutConvertRoutine[DBF_STRING][dbrType]
(clink->value.scalar_string, pbuffer, NULL);
break;
case ai64:
IFDEBUG(12)
printf(" ai64 [%lld, ...]\n", clink->value.pintegers[0]);
conv = dbFastPutConvertRoutine[DBF_INT64][dbrType];
for (i = 0; i < nElems; i++) {
conv(&clink->value.pintegers[i], pdest, NULL);
pdest += dbrSize;
}
status = 0;
break;
case af64:
IFDEBUG(12)
printf(" af64 [%g, ...]\n", clink->value.pdoubles[0]);
conv = dbFastPutConvertRoutine[DBF_DOUBLE][dbrType];
for (i = 0; i < nElems; i++) {
conv(&clink->value.pdoubles[i], pdest, NULL);
pdest += dbrSize;
}
status = 0;
break;
case ac40:
IFDEBUG(12)
printf(" ac40 ['%s', ...]\n", clink->value.pstrings[0]);
conv = dbFastPutConvertRoutine[DBF_STRING][dbrType];
for (i = 0; i < nElems; i++) {
conv(clink->value.pstrings[i], pdest, NULL);
pdest += dbrSize;
}
status = 0;
break;
default:
IFDEBUG(12)
printf(" Bad type %d\n", clink->type);
status = S_db_badField;
}
*pnReq = nElems;
return status;
}
static long lnkConst_getNelements(const struct link *plink, long *nelements)
{
const_link *clink = CONTAINER(plink->value.json.jlink, const_link, jlink);
IFDEBUG(10)
printf("lnkConst_getNelements(const@%p, (%ld))\n",
plink->value.json.jlink, *nelements);
*nelements = 0;
return 0;
}
static long lnkConst_getValue(struct link *plink, short dbrType, void *pbuffer,
long *pnRequest)
{
const_link *clink = CONTAINER(plink->value.json.jlink, const_link, jlink);
IFDEBUG(10)
printf("lnkConst_getValue(const@%p, %d, %p, ... (%ld))\n",
plink->value.json.jlink, dbrType, pbuffer,
pnRequest ? *pnRequest : 0);
if (pnRequest)
*pnRequest = 0;
return 0;
}
static long lnkConst_putValue(struct link *plink, short dbrType,
const void *pbuffer, long nRequest)
{
return 0;
}
/************************* Interface Tables *************************/
static lset lnkConst_lset = {
1, 0, /* Constant, not Volatile */
NULL, lnkConst_remove,
lnkConst_loadScalar, lnkConst_loadLS, lnkConst_loadArray, NULL,
NULL, lnkConst_getNelements, lnkConst_getValue,
NULL, NULL, NULL,
NULL, NULL,
NULL, NULL,
lnkConst_putValue, NULL,
NULL, NULL
};
static jlif lnkConstIf = {
"const", lnkConst_alloc, lnkConst_free,
NULL, lnkConst_boolean, lnkConst_integer, lnkConst_double, lnkConst_string,
NULL, NULL, NULL,
lnkConst_start_array, lnkConst_end_array,
NULL, lnkConst_get_lset,
lnkConst_report, NULL
};
epicsExportAddress(jlif, lnkConstIf);
+57
View File
@@ -0,0 +1,57 @@
#*************************************************************************
# Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
# This is a Makefile fragment, see src/std/Makefile.
SRC_DIRS += $(STDDIR)/rec
stdRecords += aaiRecord
stdRecords += aaoRecord
stdRecords += aiRecord
stdRecords += aoRecord
stdRecords += aSubRecord
stdRecords += biRecord
stdRecords += boRecord
stdRecords += calcRecord
stdRecords += calcoutRecord
stdRecords += compressRecord
stdRecords += dfanoutRecord
stdRecords += eventRecord
stdRecords += fanoutRecord
stdRecords += histogramRecord
stdRecords += int64inRecord
stdRecords += int64outRecord
stdRecords += longinRecord
stdRecords += longoutRecord
stdRecords += lsiRecord
stdRecords += lsoRecord
stdRecords += mbbiRecord
stdRecords += mbbiDirectRecord
stdRecords += mbboRecord
stdRecords += mbboDirectRecord
stdRecords += permissiveRecord
stdRecords += printfRecord
stdRecords += selRecord
stdRecords += seqRecord
stdRecords += stateRecord
stdRecords += stringinRecord
stdRecords += stringoutRecord
stdRecords += subRecord
stdRecords += subArrayRecord
stdRecords += waveformRecord
DBDINC += $(stdRecords)
# Generate stdRecords.dbd, not really by concatenation, see RULES
DBDCAT += stdRecords.dbd
stdRecords_DBD = $(patsubst %,%.dbd,$(stdRecords))
dbRecStd_SRCS += $(patsubst %,%.c,$(stdRecords))
HTMLS += $(patsubst %.dbd.pod,%.html,$(notdir $(wildcard ../rec/*Record.dbd.pod)))
+18
View File
@@ -0,0 +1,18 @@
##########################################################################
# Copyright (c) 2014 UChicago Argonne LLC, as Operator of Argonne
# National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in the file LICENSE that is included with this distribution.
##########################################################################
# This is a Makefile fragment, see src/ioc/Makefile.
stdRecords.dbd$(DEP): $(STDDIR)/rec/Makefile $(STDDIR)/rec/RULES
@$(RM) $@
@echo "$(COMMON_DIR)/stdRecords.dbd:" > $@
$(COMMON_DIR)/stdRecords.dbd: $(STDDIR)/rec/Makefile $(STDDIR)/rec/RULES
# This is a target-specific variable
$(COMMON_DIR)/stdRecords.dbd: DBDCAT_COMMAND = \
$(PERL) $(INSTALL_HOST_BIN)/makeIncludeDbd.pl $(stdRecords_DBD) $(@F)
+574
View File
@@ -0,0 +1,574 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Record Support Routines for the Array Subroutine Record type,
* derived from Andy Foster's genSub record, with some features
* removed and asynchronous support added.
*
* Original Author: Andy Foster
* Revised by: Andrew Johnson
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alarm.h"
#include "cantProceed.h"
#include "dbDefs.h"
#include "dbEvent.h"
#include "dbAccess.h"
#include "dbFldTypes.h"
#include "dbStaticLib.h"
#include "errMdef.h"
#include "errlog.h"
#include "recSup.h"
#include "devSup.h"
#include "special.h"
#include "registryFunction.h"
#include "recGbl.h"
#define GEN_SIZE_OFFSET
#include "aSubRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
typedef long (*GENFUNCPTR)(struct aSubRecord *);
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
static long special(DBADDR *, int);
#define get_value NULL
static long cvt_dbaddr(DBADDR *);
static long get_array_info(DBADDR *, long *, long *);
static long put_array_info(DBADDR *, long );
static long get_units(DBADDR *, char *);
static long get_precision(const DBADDR *, long *);
#define get_enum_str NULL
#define get_enum_strs NULL
#define put_enum_str NULL
static long get_graphic_double(DBADDR *, struct dbr_grDouble *);
static long get_control_double(DBADDR *, struct dbr_ctrlDouble *);
static long get_alarm_double(DBADDR *, struct dbr_alDouble *);
rset aSubRSET = {
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double
};
epicsExportAddress(rset, aSubRSET);
static long initFields(epicsEnum16 *pft, epicsUInt32 *pno, epicsUInt32 *pne,
epicsUInt32 *pon, const char **fldnames, void **pval, void **povl);
static long fetch_values(aSubRecord *prec);
static void monitor(aSubRecord *);
static long do_sub(aSubRecord *);
#define NUM_ARGS 21
/* These are the names of the Input fields */
static const char *Ifldnames[] = {
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U"
};
/* These are the names of the Output fields */
static const char *Ofldnames[] = {
"VALA", "VALB", "VALC", "VALD", "VALE", "VALF", "VALG",
"VALH", "VALI", "VALJ", "VALK", "VALL", "VALM", "VALN",
"VALO", "VALP", "VALQ", "VALR", "VALS", "VALT", "VALU"
};
static long init_record(struct dbCommon *pcommon, int pass)
{
struct aSubRecord *prec = (struct aSubRecord *)pcommon;
STATIC_ASSERT(sizeof(prec->onam)==sizeof(prec->snam));
GENFUNCPTR pfunc;
int i;
if (pass == 0) {
/* Allocate memory for arrays */
initFields(&prec->fta, &prec->noa, &prec->nea, NULL,
Ifldnames, &prec->a, NULL);
initFields(&prec->ftva, &prec->nova, &prec->neva, &prec->onva,
Ofldnames, &prec->vala, &prec->ovla);
return 0;
}
/* Initialize the Subroutine Name Link */
recGblInitConstantLink(&prec->subl, DBF_STRING, prec->snam);
/* Initialize Input Links */
for (i = 0; i < NUM_ARGS; i++) {
struct link *plink = &(&prec->inpa)[i];
short dbr = (&prec->fta)[i];
long n = (&prec->noa)[i];
dbLoadLinkArray(plink, dbr, (&prec->a)[i], &n);
if (n > 0)
(&prec->nea)[i] = n;
}
/* Call the user initialization routine if there is one */
if (prec->inam[0] != 0) {
pfunc = (GENFUNCPTR)registryFunctionFind(prec->inam);
if (pfunc) {
pfunc(prec);
} else {
recGblRecordError(S_db_BadSub, (void *)prec,
"aSubRecord::init_record - INAM subr not found");
return S_db_BadSub;
}
}
if (prec->lflg == aSubLFLG_IGNORE &&
prec->snam[0] != 0) {
pfunc = (GENFUNCPTR)registryFunctionFind(prec->snam);
if (pfunc)
prec->sadr = pfunc;
else {
recGblRecordError(S_db_BadSub, (void *)prec,
"aSubRecord::init_record - SNAM subr not found");
return S_db_BadSub;
}
}
strcpy(prec->onam, prec->snam);
prec->oval = prec->val;
for (i = 0; i < NUM_ARGS; i++) {
epicsUInt32 nev = (&prec->neva)[i];
(&prec->onva)[i] = nev;
if (nev)
memcpy((&prec->ovla)[i], (&prec->vala)[i],
dbValueSize((&prec->ftva)[i]) * nev);
}
return 0;
}
static long initFields(epicsEnum16 *pft, epicsUInt32 *pno, epicsUInt32 *pne,
epicsUInt32 *pon, const char **fldnames, void **pval, void **povl)
{
int i;
long status = 0;
for (i = 0; i < NUM_ARGS; i++, pft++, pno++, pne++, pval++) {
epicsUInt32 num;
epicsUInt32 flen;
if (*pft > DBF_ENUM)
*pft = DBF_CHAR;
if (*pno == 0)
*pno = 1;
flen = dbValueSize(*pft);
num = *pno * flen;
*pval = callocMustSucceed(*pno, flen, "aSubRecord::init_record");
*pne = *pno;
if (povl) {
if (num)
*povl = callocMustSucceed(*pno, flen,
"aSubRecord::init_record");
povl++;
*pon++ = *pne;
}
}
return status;
}
static long process(struct dbCommon *pcommon)
{
struct aSubRecord *prec = (struct aSubRecord *)pcommon;
int pact = prec->pact;
long status = 0;
if (!pact) {
prec->pact = TRUE;
status = fetch_values(prec);
prec->pact = FALSE;
}
if (!status) {
status = do_sub(prec);
prec->val = status;
}
if (!pact && prec->pact)
return 0;
prec->pact = TRUE;
/* Push the output link values */
if (!status) {
int i;
for (i = 0; i < NUM_ARGS; i++)
dbPutLink(&(&prec->outa)[i], (&prec->ftva)[i], (&prec->vala)[i],
(&prec->neva)[i]);
}
recGblGetTimeStamp(prec);
monitor(prec);
recGblFwdLink(prec);
prec->pact = FALSE;
return 0;
}
static long fetch_values(aSubRecord *prec)
{
long status;
int i;
if (prec->lflg == aSubLFLG_READ) {
/* Get the Subroutine Name and look it up if changed */
status = dbGetLink(&prec->subl, DBR_STRING, prec->snam, 0, 0);
if (status)
return status;
if (prec->snam[0] != 0 &&
strcmp(prec->snam, prec->onam)) {
GENFUNCPTR pfunc = (GENFUNCPTR)registryFunctionFind(prec->snam);
if (!pfunc)
return S_db_BadSub;
if (prec->sadr!=pfunc && prec->cadr) {
prec->cadr(prec);
prec->cadr = NULL;
}
prec->sadr = pfunc;
strcpy(prec->onam, prec->snam);
}
}
/* Get the input link values */
for (i = 0; i < NUM_ARGS; i++) {
long nRequest = (&prec->noa)[i];
status = dbGetLink(&(&prec->inpa)[i], (&prec->fta)[i], (&prec->a)[i], 0,
&nRequest);
if (nRequest > 0)
(&prec->nea)[i] = nRequest;
if (status)
return status;
}
return 0;
}
#define indexof(field) aSubRecord##field
static long get_inlinkNumber(int fieldIndex) {
if (fieldIndex >= indexof(A) && fieldIndex <= indexof(U))
return fieldIndex - indexof(A);
return -1;
}
static long get_outlinkNumber(int fieldIndex) {
if (fieldIndex >= indexof(VALA) && fieldIndex <= indexof(VALU))
return fieldIndex - indexof(VALA);
return -1;
}
static long get_units(DBADDR *paddr, char *units)
{
aSubRecord *prec = (aSubRecord *)paddr->precord;
int linkNumber;
linkNumber = get_inlinkNumber(dbGetFieldIndex(paddr));
if (linkNumber >= 0) {
dbGetUnits(&prec->inpa + linkNumber, units, DB_UNITS_SIZE);
return 0;
}
linkNumber = get_outlinkNumber(dbGetFieldIndex(paddr));
if (linkNumber >= 0) {
dbGetUnits(&prec->outa + linkNumber, units, DB_UNITS_SIZE);
}
return 0;
}
static long get_precision(const DBADDR *paddr, long *pprecision)
{
aSubRecord *prec = (aSubRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
int linkNumber;
*pprecision = prec->prec;
linkNumber = get_inlinkNumber(fieldIndex);
if (linkNumber >= 0) {
short precision;
if (dbGetPrecision(&prec->inpa + linkNumber, &precision) == 0)
*pprecision = precision;
return 0;
}
linkNumber = get_outlinkNumber(fieldIndex);
if (linkNumber >= 0) {
short precision;
if (dbGetPrecision(&prec->outa + linkNumber, &precision) == 0)
*pprecision = precision;
} else
recGblGetPrec(paddr, pprecision);
return 0;
}
static long get_graphic_double(DBADDR *paddr, struct dbr_grDouble *pgd)
{
aSubRecord *prec = (aSubRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
int linkNumber;
linkNumber = get_inlinkNumber(fieldIndex);
if (linkNumber >= 0) {
dbGetGraphicLimits(&prec->inpa + linkNumber,
&pgd->lower_disp_limit,
&pgd->upper_disp_limit);
return 0;
}
linkNumber = get_outlinkNumber(fieldIndex);
if (linkNumber >= 0) {
dbGetGraphicLimits(&prec->outa + linkNumber,
&pgd->lower_disp_limit,
&pgd->upper_disp_limit);
}
return 0;
}
static long get_control_double(DBADDR *paddr, struct dbr_ctrlDouble *pcd)
{
recGblGetControlDouble(paddr,pcd);
return 0;
}
static long get_alarm_double(DBADDR *paddr, struct dbr_alDouble *pad)
{
aSubRecord *prec = (aSubRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
int linkNumber;
linkNumber = get_inlinkNumber(fieldIndex);
if (linkNumber >= 0) {
dbGetAlarmLimits(&prec->inpa + linkNumber,
&pad->lower_alarm_limit,
&pad->lower_warning_limit,
&pad->upper_warning_limit,
&pad->upper_alarm_limit);
return 0;
}
linkNumber = get_outlinkNumber(fieldIndex);
if (linkNumber >= 0) {
dbGetAlarmLimits(&prec->outa + linkNumber,
&pad->lower_alarm_limit,
&pad->lower_warning_limit,
&pad->upper_warning_limit,
&pad->upper_alarm_limit);
return 0;
}
recGblGetAlarmDouble(paddr, pad);
return 0;
}
static void monitor(aSubRecord *prec)
{
int i;
unsigned short monitor_mask;
monitor_mask = recGblResetAlarms(prec) | DBE_VALUE | DBE_LOG;
/* Post events for VAL field */
if (prec->val != prec->oval) {
db_post_events(prec, &prec->val, monitor_mask);
prec->oval = prec->val;
}
/* Event posting on VAL arrays depends on the setting of prec->eflg */
switch (prec->eflg) {
case aSubEFLG_NEVER:
break;
case aSubEFLG_ON_CHANGE:
for (i = 0; i < NUM_ARGS; i++) {
void *povl = (&prec->ovla)[i];
void *pval = (&prec->vala)[i];
epicsUInt32 *ponv = &(&prec->onva)[i];
epicsUInt32 *pnev = &(&prec->neva)[i];
epicsUInt32 onv = *ponv; /* Num Elements in OVLx */
epicsUInt32 nev = *pnev; /* Num Elements in VALx */
epicsUInt32 alen = dbValueSize((&prec->ftva)[i]) * nev;
if (nev != onv || memcmp(povl, pval, alen)) {
memcpy(povl, pval, alen);
db_post_events(prec, pval, monitor_mask);
if (nev != onv) {
*ponv = nev;
db_post_events(prec, pnev, monitor_mask);
}
}
}
break;
case aSubEFLG_ALWAYS:
for (i = 0; i < NUM_ARGS; i++) {
db_post_events(prec, (&prec->vala)[i], monitor_mask);
db_post_events(prec, &(&prec->neva)[i], monitor_mask);
}
break;
}
return;
}
static long do_sub(aSubRecord *prec)
{
GENFUNCPTR pfunc = prec->sadr;
long status;
if (prec->snam[0] == 0)
return 0;
if (pfunc == NULL) {
recGblSetSevr(prec, BAD_SUB_ALARM, INVALID_ALARM);
return S_db_BadSub;
}
status = pfunc(prec);
if (status < 0)
recGblSetSevr(prec, SOFT_ALARM, prec->brsv);
else
prec->udf = FALSE;
return status;
}
static long cvt_dbaddr(DBADDR *paddr)
{
aSubRecord *prec = (aSubRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
if (fieldIndex >= aSubRecordA &&
fieldIndex <= aSubRecordU) {
int offset = fieldIndex - aSubRecordA;
paddr->pfield = (&prec->a )[offset];
paddr->no_elements = (&prec->noa)[offset];
paddr->field_type = (&prec->fta)[offset];
}
else if (fieldIndex >= aSubRecordVALA &&
fieldIndex <= aSubRecordVALU) {
int offset = fieldIndex - aSubRecordVALA;
paddr->pfield = (&prec->vala)[offset];
paddr->no_elements = (&prec->nova)[offset];
paddr->field_type = (&prec->ftva)[offset];
}
else {
errlogPrintf("aSubRecord::cvt_dbaddr called for %s.%s\n",
prec->name, paddr->pfldDes->name);
return 0;
}
paddr->dbr_field_type = paddr->field_type;
paddr->field_size = dbValueSize(paddr->field_type);
return 0;
}
static long get_array_info(DBADDR *paddr, long *no_elements, long *offset)
{
aSubRecord *prec = (aSubRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
if (fieldIndex >= aSubRecordA &&
fieldIndex <= aSubRecordU) {
*no_elements = (&prec->nea)[fieldIndex - aSubRecordA];
}
else if (fieldIndex >= aSubRecordVALA &&
fieldIndex <= aSubRecordVALU) {
*no_elements = (&prec->neva)[fieldIndex - aSubRecordVALA];
}
else {
errlogPrintf("aSubRecord::get_array_info called for %s.%s\n",
prec->name, paddr->pfldDes->name);
}
*offset = 0;
return 0;
}
static long put_array_info(DBADDR *paddr, long nNew)
{
aSubRecord *prec = (aSubRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
if (fieldIndex >= aSubRecordA &&
fieldIndex <= aSubRecordU) {
(&prec->nea)[fieldIndex - aSubRecordA] = nNew;
}
else if (fieldIndex >= aSubRecordVALA &&
fieldIndex <= aSubRecordVALU) {
(&prec->neva)[fieldIndex - aSubRecordVALA] = nNew;
}
else {
errlogPrintf("aSubRecord::put_array_info called for %s.%s\n",
prec->name, paddr->pfldDes->name);
}
return 0;
}
static long special(DBADDR *paddr, int after)
{
aSubRecord *prec = (aSubRecord *)paddr->precord;
long status = 0;
if (after &&
prec->lflg == aSubLFLG_IGNORE) {
GENFUNCPTR pfunc;
if (prec->snam[0] == 0)
pfunc = 0;
else {
pfunc = (GENFUNCPTR)registryFunctionFind(prec->snam);
if (!pfunc) {
status = S_db_BadSub;
recGblRecordError(status, (void *)prec, prec->snam);
}
}
if (prec->sadr != pfunc && prec->cadr) {
prec->cadr(prec);
prec->cadr = NULL;
}
prec->sadr = pfunc;
}
return status;
}
File diff suppressed because it is too large. Load diff
+383
View File
@@ -0,0 +1,383 @@
/*************************************************************************\
* Copyright (c) 2002 Southeastern Universities Research Association, as
* Operator of Thomas Jefferson National Accelerator Facility.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* recAai.c */
/* recAai.c - Record Support Routines for Array Analog In records */
/*
* Original Author: Dave Barker
*
* C E B A F
*
* Continuous Electron Beam Accelerator Facility
* Newport News, Virginia, USA.
*
* Copyright SURA CEBAF 1993.
*
* Current Author: Dirk Zimoch <dirk.zimoch@psi.ch>
* Date: 27-MAY-2010
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "dbDefs.h"
#include "epicsPrint.h"
#include "epicsString.h"
#include "alarm.h"
#include "callback.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "dbFldTypes.h"
#include "dbScan.h"
#include "devSup.h"
#include "errMdef.h"
#include "recSup.h"
#include "recGbl.h"
#include "cantProceed.h"
#include "special.h"
#include "menuYesNo.h"
#define GEN_SIZE_OFFSET
#include "aaiRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
static long special(DBADDR *, int);
#define get_value NULL
static long cvt_dbaddr(DBADDR *);
static long get_array_info(DBADDR *, long *, long *);
static long put_array_info(DBADDR *, long);
static long get_units(DBADDR *, char *);
static long get_precision(const DBADDR *, long *);
#define get_enum_str NULL
#define get_enum_strs NULL
#define put_enum_str NULL
static long get_graphic_double(DBADDR *, struct dbr_grDouble *);
static long get_control_double(DBADDR *, struct dbr_ctrlDouble *);
#define get_alarm_double NULL
rset aaiRSET={
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double
};
epicsExportAddress(rset,aaiRSET);
struct aaidset { /* aai dset */
long number;
DEVSUPFUN dev_report;
DEVSUPFUN init;
DEVSUPFUN init_record; /*returns: (-1,0)=>(failure,success)*/
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_aai; /*returns: (-1,0)=>(failure,success)*/
};
static void monitor(aaiRecord *);
static long readValue(aaiRecord *);
static long init_record(struct dbCommon *pcommon, int pass)
{
struct aaiRecord *prec = (struct aaiRecord *)pcommon;
struct aaidset *pdset = (struct aaidset *)(prec->dset);
long status;
/* must have dset defined */
if (!pdset) {
recGblRecordError(S_dev_noDSET, prec, "aai: init_record");
return S_dev_noDSET;
}
if (pass == 0) {
if (prec->nelm <= 0)
prec->nelm = 1;
if (prec->ftvl > DBF_ENUM)
prec->ftvl = DBF_UCHAR;
if (prec->nelm == 1) {
prec->nord = 1;
} else {
prec->nord = 0;
}
/* we must call pdset->init_record in pass 0
because it may set prec->bptr which must
not change after links are established before pass 1
*/
if (pdset->init_record) {
/* init_record may set the bptr to point to the data */
if ((status = pdset->init_record(prec)))
return status;
}
if (!prec->bptr) {
/* device support did not allocate memory so we must do it */
prec->bptr = callocMustSucceed(prec->nelm, dbValueSize(prec->ftvl),
"aai: buffer calloc failed");
}
return 0;
}
recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
/* must have read_aai function defined */
if (pdset->number < 5 || pdset->read_aai == NULL) {
recGblRecordError(S_dev_missingSup, prec, "aai: init_record");
return S_dev_missingSup;
}
return 0;
}
static long process(struct dbCommon *pcommon)
{
struct aaiRecord *prec = (struct aaiRecord *)pcommon;
struct aaidset *pdset = (struct aaidset *)(prec->dset);
long status;
unsigned char pact = prec->pact;
if (pdset == NULL || pdset->read_aai == NULL) {
prec->pact = TRUE;
recGblRecordError(S_dev_missingSup, prec, "read_aai");
return S_dev_missingSup;
}
status = readValue(prec); /* read the new value */
if (!pact && prec->pact) return 0;
prec->pact = TRUE;
prec->udf = FALSE;
recGblGetTimeStampSimm(prec, prec->simm, &prec->siol);
monitor(prec);
/* process the forward scan link record */
recGblFwdLink(prec);
prec->pact = FALSE;
return status;
}
static long special(DBADDR *paddr, int after)
{
aaiRecord *prec = (aaiRecord *)(paddr->precord);
int special_type = paddr->special;
switch(special_type) {
case(SPC_MOD):
if (dbGetFieldIndex(paddr) == aaiRecordSIMM) {
if (!after)
recGblSaveSimm(prec->sscn, &prec->oldsimm, prec->simm);
else
recGblCheckSimm((dbCommon *)prec, &prec->sscn, prec->oldsimm, prec->simm);
return(0);
}
default:
recGblDbaddrError(S_db_badChoice, paddr, "aai: special");
return(S_db_badChoice);
}
}
static long cvt_dbaddr(DBADDR *paddr)
{
aaiRecord *prec = (aaiRecord *)paddr->precord;
paddr->no_elements = prec->nelm;
paddr->field_type = prec->ftvl;
paddr->field_size = dbValueSize(prec->ftvl);
paddr->dbr_field_type = prec->ftvl;
return 0;
}
static long get_array_info(DBADDR *paddr, long *no_elements, long *offset)
{
aaiRecord *prec = (aaiRecord *)paddr->precord;
paddr->pfield = prec->bptr;
*no_elements = prec->nord;
*offset = 0;
return 0;
}
static long put_array_info(DBADDR *paddr, long nNew)
{
aaiRecord *prec = (aaiRecord *)paddr->precord;
prec->nord = nNew;
if (prec->nord > prec->nelm)
prec->nord = prec->nelm;
return 0;
}
#define indexof(field) aaiRecord##field
static long get_units(DBADDR *paddr, char *units)
{
aaiRecord *prec = (aaiRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
if (prec->ftvl == DBF_STRING || prec->ftvl == DBF_ENUM)
break;
case indexof(HOPR):
case indexof(LOPR):
strncpy(units,prec->egu,DB_UNITS_SIZE);
}
return 0;
}
static long get_precision(const DBADDR *paddr, long *precision)
{
aaiRecord *prec = (aaiRecord *)paddr->precord;
*precision = prec->prec;
if (dbGetFieldIndex(paddr) != indexof(VAL))
recGblGetPrec(paddr, precision);
return 0;
}
static long get_graphic_double(DBADDR *paddr, struct dbr_grDouble *pgd)
{
aaiRecord *prec = (aaiRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
pgd->upper_disp_limit = prec->hopr;
pgd->lower_disp_limit = prec->lopr;
break;
case indexof(NORD):
pgd->upper_disp_limit = prec->nelm;
pgd->lower_disp_limit = 0;
break;
default:
recGblGetGraphicDouble(paddr, pgd);
}
return 0;
}
static long get_control_double(DBADDR *paddr, struct dbr_ctrlDouble *pcd)
{
aaiRecord *prec = (aaiRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
pcd->upper_ctrl_limit = prec->hopr;
pcd->lower_ctrl_limit = prec->lopr;
break;
case indexof(NORD):
pcd->upper_ctrl_limit = prec->nelm;
pcd->lower_ctrl_limit = 0;
break;
default:
recGblGetControlDouble(paddr, pcd);
}
return 0;
}
static void monitor(aaiRecord *prec)
{
unsigned short monitor_mask;
unsigned int hash = 0;
monitor_mask = recGblResetAlarms(prec);
if (prec->mpst == aaiPOST_Always)
monitor_mask |= DBE_VALUE;
if (prec->apst == aaiPOST_Always)
monitor_mask |= DBE_LOG;
/* Calculate hash if we are interested in OnChange events. */
if ((prec->mpst == aaiPOST_OnChange) ||
(prec->apst == aaiPOST_OnChange)) {
hash = epicsMemHash(prec->bptr,
prec->nord * dbValueSize(prec->ftvl), 0);
/* Only post OnChange values if the hash is different. */
if (hash != prec->hash) {
if (prec->mpst == aaiPOST_OnChange)
monitor_mask |= DBE_VALUE;
if (prec->apst == aaiPOST_OnChange)
monitor_mask |= DBE_LOG;
/* Store hash for next process. */
prec->hash = hash;
/* Post HASH. */
db_post_events(prec, &prec->hash, DBE_VALUE);
}
}
if (monitor_mask)
db_post_events(prec, &prec->val, monitor_mask);
}
static long readValue(aaiRecord *prec)
{
struct aaidset *pdset = (struct aaidset *) prec->dset;
long status = 0;
if (!prec->pact) {
status = recGblGetSimm((dbCommon *)prec, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
if (status) return status;
}
switch (prec->simm) {
case menuYesNoNO:
status = pdset->read_aai(prec);
break;
case menuYesNoYES: {
recGblSetSevr(prec, SIMM_ALARM, prec->sims);
if (prec->pact || (prec->sdly < 0.)) {
/* Device suport is responsible for buffer
which might be read-only so we may not be
allowed to call dbGetLink on it.
Maybe also device support has an advanced
simulation mode.
Thus call device now.
Reading through SIOL is handled in Soft Channel Device Support
*/
status = pdset->read_aai(prec);
prec->pact = FALSE;
} else { /* !prec->pact && delay >= 0. */
CALLBACK *pvt = prec->simpvt;
if (!pvt) {
pvt = calloc(1, sizeof(CALLBACK)); /* very lazy allocation of callback structure */
prec->simpvt = pvt;
}
if (pvt) callbackRequestProcessCallbackDelayed(pvt, prec->prio, prec, prec->sdly);
prec->pact = TRUE;
}
break;
}
default:
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
status = -1;
}
return status;
}
+143
View File
@@ -0,0 +1,143 @@
#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
menu(aaiPOST) {
choice(aaiPOST_Always,"Always")
choice(aaiPOST_OnChange,"On Change")
}
recordtype(aai) {
include "dbCommon.dbd"
field(VAL,DBF_NOACCESS) {
prompt("Value")
asl(ASL0)
special(SPC_DBADDR)
pp(TRUE)
extra("void * val")
#=type DOUBLE[]
#=read Yes
#=write Yes
}
field(PREC,DBF_SHORT) {
prompt("Display Precision")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(INP,DBF_INLINK) {
prompt("Input Specification")
promptgroup("40 - Input")
interest(1)
}
field(EGU,DBF_STRING) {
prompt("Engineering Units")
promptgroup("80 - Display")
interest(1)
size(16)
prop(YES)
}
field(HOPR,DBF_DOUBLE) {
prompt("High Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(LOPR,DBF_DOUBLE) {
prompt("Low Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(NELM,DBF_ULONG) {
prompt("Number of Elements")
promptgroup("30 - Action")
special(SPC_NOMOD)
interest(1)
initial("1")
}
field(FTVL,DBF_MENU) {
prompt("Field Type of Value")
promptgroup("30 - Action")
special(SPC_NOMOD)
interest(1)
menu(menuFtype)
}
field(NORD,DBF_ULONG) {
prompt("Number elements read")
special(SPC_NOMOD)
}
field(BPTR,DBF_NOACCESS) {
prompt("Buffer Pointer")
special(SPC_NOMOD)
interest(4)
extra("void * bptr")
}
field(SIML,DBF_INLINK) {
prompt("Simulation Mode Link")
promptgroup("90 - Simulate")
interest(1)
}
field(SIMM,DBF_MENU) {
prompt("Simulation Mode")
special(SPC_MOD)
interest(1)
menu(menuYesNo)
}
field(SIMS,DBF_MENU) {
prompt("Simulation Mode Severity")
promptgroup("90 - Simulate")
interest(2)
menu(menuAlarmSevr)
}
field(SIOL,DBF_INLINK) {
prompt("Simulation Input Link")
promptgroup("90 - Simulate")
interest(1)
}
field(OLDSIMM,DBF_MENU) {
prompt("Prev. Simulation Mode")
special(SPC_NOMOD)
interest(4)
menu(menuSimm)
}
field(SSCN,DBF_MENU) {
prompt("Sim. Mode Scan")
promptgroup("90 - Simulate")
interest(1)
menu(menuScan)
initial("65535")
}
field(SDLY,DBF_DOUBLE) {
prompt("Sim. Mode Async Delay")
promptgroup("90 - Simulate")
interest(2)
initial("-1.0")
}
%#include "callback.h"
field(SIMPVT,DBF_NOACCESS) {
prompt("Sim. Mode Private")
special(SPC_NOMOD)
interest(4)
extra("CALLBACK *simpvt")
}
field(MPST,DBF_MENU) {
prompt("Post Value Monitors")
promptgroup("80 - Display")
interest(1)
menu(aaiPOST)
}
field(APST,DBF_MENU) {
prompt("Post Archive Monitors")
promptgroup("80 - Display")
interest(1)
menu(aaiPOST)
}
field(HASH,DBF_ULONG) {
prompt("Hash of OnChange data.")
interest(3)
}
}
+383
View File
@@ -0,0 +1,383 @@
/*************************************************************************\
* Copyright (c) 2002 Southeastern Universities Research Association, as
* Operator of Thomas Jefferson National Accelerator Facility.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* recAao.c */
/* recAao.c - Record Support Routines for Array Analog Out records */
/*
* Original Author: Dave Barker
*
* C E B A F
*
* Continuous Electron Beam Accelerator Facility
* Newport News, Virginia, USA.
*
* Copyright SURA CEBAF 1993.
*
* Current Author: Dirk Zimoch <dirk.zimoch@psi.ch>
* Date: 27-MAY-2010
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "dbDefs.h"
#include "epicsPrint.h"
#include "epicsString.h"
#include "alarm.h"
#include "callback.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "dbFldTypes.h"
#include "dbScan.h"
#include "devSup.h"
#include "errMdef.h"
#include "recSup.h"
#include "recGbl.h"
#include "special.h"
#include "cantProceed.h"
#include "menuYesNo.h"
#define GEN_SIZE_OFFSET
#include "aaoRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
static long special(DBADDR *, int);
#define get_value NULL
static long cvt_dbaddr(DBADDR *);
static long get_array_info(DBADDR *, long *, long *);
static long put_array_info(DBADDR *, long);
static long get_units(DBADDR *, char *);
static long get_precision(const DBADDR *, long *);
#define get_enum_str NULL
#define get_enum_strs NULL
#define put_enum_str NULL
static long get_graphic_double(DBADDR *, struct dbr_grDouble *);
static long get_control_double(DBADDR *, struct dbr_ctrlDouble *);
#define get_alarm_double NULL
rset aaoRSET={
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double
};
epicsExportAddress(rset,aaoRSET);
struct aaodset { /* aao dset */
long number;
DEVSUPFUN dev_report;
DEVSUPFUN init;
DEVSUPFUN init_record; /*returns: (-1,0)=>(failure,success)*/
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_aao; /*returns: (-1,0)=>(failure,success)*/
};
static void monitor(aaoRecord *);
static long writeValue(aaoRecord *);
static long init_record(struct dbCommon *pcommon, int pass)
{
struct aaoRecord *prec = (struct aaoRecord *)pcommon;
struct aaodset *pdset = (struct aaodset *)(prec->dset);
long status;
/* must have dset defined */
if (!pdset) {
recGblRecordError(S_dev_noDSET, prec, "aao: init_record");
return S_dev_noDSET;
}
if (pass == 0) {
if (prec->nelm <= 0)
prec->nelm = 1;
if (prec->ftvl > DBF_ENUM)
prec->ftvl = DBF_UCHAR;
if (prec->nelm == 1) {
prec->nord = 1;
} else {
prec->nord = 0;
}
/* we must call pdset->init_record in pass 0
because it may set prec->bptr which must
not change after links are established before pass 1
*/
if (pdset->init_record) {
/* init_record may set the bptr to point to the data */
if ((status = pdset->init_record(prec)))
return status;
}
if (!prec->bptr) {
/* device support did not allocate memory so we must do it */
prec->bptr = callocMustSucceed(prec->nelm, dbValueSize(prec->ftvl),
"aao: buffer calloc failed");
}
return 0;
}
recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
/* must have write_aao function defined */
if (pdset->number < 5 || pdset->write_aao == NULL) {
recGblRecordError(S_dev_missingSup, prec, "aao: init_record");
return S_dev_missingSup;
}
return 0;
}
static long process(struct dbCommon *pcommon)
{
struct aaoRecord *prec = (struct aaoRecord *)pcommon;
struct aaodset *pdset = (struct aaodset *)(prec->dset);
long status;
unsigned char pact = prec->pact;
if (pdset == NULL || pdset->write_aao == NULL) {
prec->pact = TRUE;
recGblRecordError(S_dev_missingSup, prec, "write_aao");
return S_dev_missingSup;
}
status = writeValue(prec); /* write the data */
if (!pact && prec->pact) return 0;
prec->pact = TRUE;
prec->udf = FALSE;
recGblGetTimeStampSimm(prec, prec->simm, NULL);
monitor(prec);
/* process the forward scan link record */
recGblFwdLink(prec);
prec->pact = FALSE;
return status;
}
static long special(DBADDR *paddr, int after)
{
aaoRecord *prec = (aaoRecord *)(paddr->precord);
int special_type = paddr->special;
switch(special_type) {
case(SPC_MOD):
if (dbGetFieldIndex(paddr) == aaoRecordSIMM) {
if (!after)
recGblSaveSimm(prec->sscn, &prec->oldsimm, prec->simm);
else
recGblCheckSimm((dbCommon *)prec, &prec->sscn, prec->oldsimm, prec->simm);
return(0);
}
default:
recGblDbaddrError(S_db_badChoice, paddr, "aao: special");
return(S_db_badChoice);
}
}
static long cvt_dbaddr(DBADDR *paddr)
{
aaoRecord *prec = (aaoRecord *)paddr->precord;
paddr->no_elements = prec->nelm;
paddr->field_type = prec->ftvl;
paddr->field_size = dbValueSize(prec->ftvl);
paddr->dbr_field_type = prec->ftvl;
return 0;
}
static long get_array_info(DBADDR *paddr, long *no_elements, long *offset)
{
aaoRecord *prec = (aaoRecord *)paddr->precord;
paddr->pfield = prec->bptr;
*no_elements = prec->nord;
*offset = 0;
return 0;
}
static long put_array_info(DBADDR *paddr, long nNew)
{
aaoRecord *prec = (aaoRecord *)paddr->precord;
prec->nord = nNew;
if (prec->nord > prec->nelm)
prec->nord = prec->nelm;
return 0;
}
#define indexof(field) aaoRecord##field
static long get_units(DBADDR *paddr, char *units)
{
aaoRecord *prec = (aaoRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
if (prec->ftvl == DBF_STRING || prec->ftvl == DBF_ENUM)
break;
case indexof(HOPR):
case indexof(LOPR):
strncpy(units,prec->egu,DB_UNITS_SIZE);
}
return 0;
}
static long get_precision(const DBADDR *paddr, long *precision)
{
aaoRecord *prec = (aaoRecord *)paddr->precord;
*precision = prec->prec;
if (dbGetFieldIndex(paddr) != indexof(VAL))
recGblGetPrec(paddr, precision);
return 0;
}
static long get_graphic_double(DBADDR *paddr, struct dbr_grDouble *pgd)
{
aaoRecord *prec = (aaoRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
pgd->upper_disp_limit = prec->hopr;
pgd->lower_disp_limit = prec->lopr;
break;
case indexof(NORD):
pgd->upper_disp_limit = prec->nelm;
pgd->lower_disp_limit = 0;
break;
default:
recGblGetGraphicDouble(paddr, pgd);
}
return 0;
}
static long get_control_double(DBADDR *paddr, struct dbr_ctrlDouble *pcd)
{
aaoRecord *prec = (aaoRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
pcd->upper_ctrl_limit = prec->hopr;
pcd->lower_ctrl_limit = prec->lopr;
break;
case indexof(NORD):
pcd->upper_ctrl_limit = prec->nelm;
pcd->lower_ctrl_limit = 0;
break;
default:
recGblGetControlDouble(paddr, pcd);
}
return 0;
}
static void monitor(aaoRecord *prec)
{
unsigned short monitor_mask;
unsigned int hash = 0;
monitor_mask = recGblResetAlarms(prec);
if (prec->mpst == aaoPOST_Always)
monitor_mask |= DBE_VALUE;
if (prec->apst == aaoPOST_Always)
monitor_mask |= DBE_LOG;
/* Calculate hash if we are interested in OnChange events. */
if ((prec->mpst == aaoPOST_OnChange) ||
(prec->apst == aaoPOST_OnChange)) {
hash = epicsMemHash(prec->bptr,
prec->nord * dbValueSize(prec->ftvl), 0);
/* Only post OnChange values if the hash is different. */
if (hash != prec->hash) {
if (prec->mpst == aaoPOST_OnChange)
monitor_mask |= DBE_VALUE;
if (prec->apst == aaoPOST_OnChange)
monitor_mask |= DBE_LOG;
/* Store hash for next process. */
prec->hash = hash;
/* Post HASH. */
db_post_events(prec, &prec->hash, DBE_VALUE);
}
}
if (monitor_mask)
db_post_events(prec, &prec->val, monitor_mask);
}
static long writeValue(aaoRecord *prec)
{
struct aaodset *pdset = (struct aaodset *) prec->dset;
long status = 0;
if (!prec->pact) {
status = recGblGetSimm((dbCommon *)prec, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
if (status) return status;
}
switch (prec->simm) {
case menuYesNoNO:
status = pdset->write_aao(prec);
break;
case menuYesNoYES: {
recGblSetSevr(prec, SIMM_ALARM, prec->sims);
if (prec->pact || (prec->sdly < 0.)) {
/* Device suport is responsible for buffer
which might be write-only so we may not be
allowed to call dbPutLink on it.
Maybe also device support has an advanced
simulation mode.
Thus call device now.
Writing through SIOL is handled in Soft Channel Device Support
*/
status = pdset->write_aao(prec);
prec->pact = FALSE;
} else { /* !prec->pact && delay >= 0. */
CALLBACK *pvt = prec->simpvt;
if (!pvt) {
pvt = calloc(1, sizeof(CALLBACK)); /* very lazy allocation of callback structure */
prec->simpvt = pvt;
}
if (pvt) callbackRequestProcessCallbackDelayed(pvt, prec->prio, prec, prec->sdly);
prec->pact = TRUE;
}
break;
}
default:
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
status = -1;
}
return status;
}
+143
View File
@@ -0,0 +1,143 @@
#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
menu(aaoPOST) {
choice(aaoPOST_Always,"Always")
choice(aaoPOST_OnChange,"On Change")
}
recordtype(aao) {
include "dbCommon.dbd"
field(VAL,DBF_NOACCESS) {
prompt("Value")
asl(ASL0)
special(SPC_DBADDR)
pp(TRUE)
extra("void * val")
#=type DOUBLE[]
#=read Yes
#=write Yes
}
field(PREC,DBF_SHORT) {
prompt("Display Precision")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(OUT,DBF_OUTLINK) {
prompt("Output Specification")
promptgroup("50 - Output")
interest(1)
}
field(EGU,DBF_STRING) {
prompt("Engineering Units")
promptgroup("80 - Display")
interest(1)
size(16)
prop(YES)
}
field(HOPR,DBF_DOUBLE) {
prompt("High Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(LOPR,DBF_DOUBLE) {
prompt("Low Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(NELM,DBF_ULONG) {
prompt("Number of Elements")
promptgroup("30 - Action")
special(SPC_NOMOD)
interest(1)
initial("1")
}
field(FTVL,DBF_MENU) {
prompt("Field Type of Value")
promptgroup("30 - Action")
special(SPC_NOMOD)
interest(1)
menu(menuFtype)
}
field(NORD,DBF_ULONG) {
prompt("Number elements read")
special(SPC_NOMOD)
}
field(BPTR,DBF_NOACCESS) {
prompt("Buffer Pointer")
special(SPC_NOMOD)
interest(4)
extra("void * bptr")
}
field(SIML,DBF_INLINK) {
prompt("Simulation Mode Link")
promptgroup("90 - Simulate")
interest(1)
}
field(SIMM,DBF_MENU) {
prompt("Simulation Mode")
special(SPC_MOD)
interest(1)
menu(menuYesNo)
}
field(SIMS,DBF_MENU) {
prompt("Simulation Mode Severity")
promptgroup("90 - Simulate")
interest(2)
menu(menuAlarmSevr)
}
field(SIOL,DBF_OUTLINK) {
prompt("Simulation Output Link")
promptgroup("90 - Simulate")
interest(1)
}
field(OLDSIMM,DBF_MENU) {
prompt("Prev. Simulation Mode")
special(SPC_NOMOD)
interest(4)
menu(menuSimm)
}
field(SSCN,DBF_MENU) {
prompt("Sim. Mode Scan")
promptgroup("90 - Simulate")
interest(1)
menu(menuScan)
initial("65535")
}
field(SDLY,DBF_DOUBLE) {
prompt("Sim. Mode Async Delay")
promptgroup("90 - Simulate")
interest(2)
initial("-1.0")
}
%#include "callback.h"
field(SIMPVT,DBF_NOACCESS) {
prompt("Sim. Mode Private")
special(SPC_NOMOD)
interest(4)
extra("CALLBACK *simpvt")
}
field(MPST,DBF_MENU) {
prompt("Post Value Monitors")
promptgroup("80 - Display")
interest(1)
menu(aaoPOST)
}
field(APST,DBF_MENU) {
prompt("Post Archive Monitors")
promptgroup("80 - Display")
interest(1)
menu(aaoPOST)
}
field(HASH,DBF_ULONG) {
prompt("Hash of OnChange data.")
interest(3)
}
}
+528
View File
@@ -0,0 +1,528 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* aiRecord.c - Record Support Routines for Analog Input records */
/*
* Original Author: Bob Dalesio
* Date: 7-14-89
*
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "dbDefs.h"
#include "errlog.h"
#include "epicsMath.h"
#include "alarm.h"
#include "callback.h"
#include "cvtTable.h"
#include "dbAccess.h"
#include "dbScan.h"
#include "dbEvent.h"
#include "dbFldTypes.h"
#include "devSup.h"
#include "menuSimm.h"
#include "recSup.h"
#include "recGbl.h"
#include "special.h"
#include "menuConvert.h"
#define GEN_SIZE_OFFSET
#include "aiRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
/* Hysterisis for alarm filtering: 1-1/e */
#define THRESHOLD 0.6321
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
static long special(DBADDR *, int);
#define get_value NULL
#define cvt_dbaddr NULL
#define get_array_info NULL
#define put_array_info NULL
static long get_units(DBADDR *, char *);
static long get_precision(const DBADDR *, long *);
#define get_enum_str NULL
#define get_enum_strs NULL
#define put_enum_str NULL
static long get_graphic_double(DBADDR *, struct dbr_grDouble *);
static long get_control_double(DBADDR *, struct dbr_ctrlDouble *);
static long get_alarm_double(DBADDR *, struct dbr_alDouble *);
rset aiRSET={
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double
};
epicsExportAddress(rset,aiRSET);
typedef struct aidset { /* analog input dset */
long number;
DEVSUPFUN dev_report;
DEVSUPFUN init;
DEVSUPFUN init_record; /*returns: (-1,0)=>(failure,success)*/
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_ai;/*(0,2)=> success and convert,don't convert)*/
/* if convert then raw value stored in rval */
DEVSUPFUN special_linconv;
}aidset;
static void checkAlarms(aiRecord *prec, epicsTimeStamp *lastTime);
static void convert(aiRecord *prec);
static void monitor(aiRecord *prec);
static long readValue(aiRecord *prec);
static long init_record(struct dbCommon *pcommon, int pass)
{
struct aiRecord *prec = (struct aiRecord *)pcommon;
aidset *pdset;
double eoff = prec->eoff, eslo = prec->eslo;
if (pass == 0) return 0;
recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
recGblInitConstantLink(&prec->siol, DBF_DOUBLE, &prec->sval);
if(!(pdset = (aidset *)(prec->dset))) {
recGblRecordError(S_dev_noDSET,(void *)prec,"ai: init_record");
return(S_dev_noDSET);
}
/* must have read_ai function defined */
if( (pdset->number < 6) || (pdset->read_ai == NULL) ) {
recGblRecordError(S_dev_missingSup,(void *)prec,"ai: init_record");
return(S_dev_missingSup);
}
prec->init = TRUE;
/*The following is for old device support that doesnt know about eoff*/
if ((prec->eslo==1.0) && (prec->eoff==0.0)) {
prec->eoff = prec->egul;
}
if( pdset->init_record ) {
long status=(*pdset->init_record)(prec);
if (prec->linr == menuConvertSLOPE) {
prec->eoff = eoff;
prec->eslo = eslo;
}
return (status);
}
prec->mlst = prec->val;
prec->alst = prec->val;
prec->lalm = prec->val;
prec->oraw = prec->rval;
return(0);
}
static long process(struct dbCommon *pcommon)
{
struct aiRecord *prec = (struct aiRecord *)pcommon;
aidset *pdset = (aidset *)(prec->dset);
long status;
unsigned char pact=prec->pact;
epicsTimeStamp timeLast;
if( (pdset==NULL) || (pdset->read_ai==NULL) ) {
prec->pact=TRUE;
recGblRecordError(S_dev_missingSup,(void *)prec,"read_ai");
return(S_dev_missingSup);
}
timeLast = prec->time;
status=readValue(prec); /* read the new value */
/* check if device support set pact */
if ( !pact && prec->pact ) return(0);
prec->pact = TRUE;
recGblGetTimeStampSimm(prec, prec->simm, &prec->siol);
if (status==0) convert(prec);
else if (status==2) status=0;
if (status == 0) prec->udf = isnan(prec->val);
/* check for alarms */
checkAlarms(prec,&timeLast);
/* check event list */
monitor(prec);
/* process the forward scan link record */
recGblFwdLink(prec);
prec->init=FALSE;
prec->pact=FALSE;
return(status);
}
static long special(DBADDR *paddr,int after)
{
aiRecord *prec = (aiRecord *)(paddr->precord);
aidset *pdset = (aidset *) (prec->dset);
int special_type = paddr->special;
switch(special_type) {
case(SPC_LINCONV):
if(pdset->number<6) {
recGblDbaddrError(S_db_noMod,paddr,"ai: special");
return(S_db_noMod);
}
prec->init=TRUE;
if ((prec->linr == menuConvertLINEAR) && pdset->special_linconv) {
double eoff = prec->eoff;
double eslo = prec->eslo;
long status;
prec->eoff = prec->egul;
status = (*pdset->special_linconv)(prec,after);
if (eoff != prec->eoff)
db_post_events(prec, &prec->eoff, DBE_VALUE|DBE_LOG);
if (eslo != prec->eslo)
db_post_events(prec, &prec->eslo, DBE_VALUE|DBE_LOG);
return(status);
}
return(0);
case(SPC_MOD):
if (dbGetFieldIndex(paddr) == aiRecordSIMM) {
if (!after)
recGblSaveSimm(prec->sscn, &prec->oldsimm, prec->simm);
else
recGblCheckSimm((dbCommon *)prec, &prec->sscn, prec->oldsimm, prec->simm);
return(0);
}
default:
recGblDbaddrError(S_db_badChoice,paddr,"ai: special");
return(S_db_badChoice);
}
}
#define indexof(field) aiRecord##field
static long get_units(DBADDR *paddr, char *units)
{
aiRecord *prec=(aiRecord *)paddr->precord;
if(paddr->pfldDes->field_type == DBF_DOUBLE) {
switch (dbGetFieldIndex(paddr)) {
case indexof(ASLO):
case indexof(AOFF):
case indexof(SMOO):
break;
default:
strncpy(units,prec->egu,DB_UNITS_SIZE);
}
}
return(0);
}
static long get_precision(const DBADDR *paddr, long *precision)
{
aiRecord *prec=(aiRecord *)paddr->precord;
*precision = prec->prec;
if (dbGetFieldIndex(paddr) == indexof(VAL)) return(0);
recGblGetPrec(paddr,precision);
return(0);
}
static long get_graphic_double(DBADDR *paddr,struct dbr_grDouble *pgd)
{
aiRecord *prec=(aiRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
case indexof(HIHI):
case indexof(HIGH):
case indexof(LOW):
case indexof(LOLO):
case indexof(LALM):
case indexof(ALST):
case indexof(MLST):
case indexof(SVAL):
pgd->upper_disp_limit = prec->hopr;
pgd->lower_disp_limit = prec->lopr;
break;
default:
recGblGetGraphicDouble(paddr,pgd);
}
return(0);
}
static long get_control_double(DBADDR *paddr,struct dbr_ctrlDouble *pcd)
{
aiRecord *prec=(aiRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
case indexof(HIHI):
case indexof(HIGH):
case indexof(LOW):
case indexof(LOLO):
case indexof(LALM):
case indexof(ALST):
case indexof(MLST):
case indexof(SVAL):
pcd->upper_ctrl_limit = prec->hopr;
pcd->lower_ctrl_limit = prec->lopr;
break;
default:
recGblGetControlDouble(paddr,pcd);
}
return(0);
}
static long get_alarm_double(DBADDR *paddr,struct dbr_alDouble *pad)
{
aiRecord *prec=(aiRecord *)paddr->precord;
if (dbGetFieldIndex(paddr) == indexof(VAL)) {
pad->upper_alarm_limit = prec->hhsv ? prec->hihi : epicsNAN;
pad->upper_warning_limit = prec->hsv ? prec->high : epicsNAN;
pad->lower_warning_limit = prec->lsv ? prec->low : epicsNAN;
pad->lower_alarm_limit = prec->llsv ? prec->lolo : epicsNAN;
} else recGblGetAlarmDouble(paddr,pad);
return(0);
}
static void checkAlarms(aiRecord *prec, epicsTimeStamp *lastTime)
{
enum {
range_Lolo = 1,
range_Low,
range_Normal,
range_High,
range_Hihi
} alarmRange;
static const epicsEnum16 range_stat[] = {
SOFT_ALARM, LOLO_ALARM, LOW_ALARM,
NO_ALARM, HIGH_ALARM, HIHI_ALARM
};
double val, hyst, lalm, alev, aftc, afvl;
epicsEnum16 asev;
if (prec->udf) {
recGblSetSevr(prec, UDF_ALARM, prec->udfs);
prec->afvl = 0;
return;
}
val = prec->val;
hyst = prec->hyst;
lalm = prec->lalm;
/* check VAL against alarm limits */
if ((asev = prec->hhsv) &&
(val >= (alev = prec->hihi) ||
((lalm == alev) && (val >= alev - hyst))))
alarmRange = range_Hihi;
else
if ((asev = prec->llsv) &&
(val <= (alev = prec->lolo) ||
((lalm == alev) && (val <= alev + hyst))))
alarmRange = range_Lolo;
else
if ((asev = prec->hsv) &&
(val >= (alev = prec->high) ||
((lalm == alev) && (val >= alev - hyst))))
alarmRange = range_High;
else
if ((asev = prec->lsv) &&
(val <= (alev = prec->low) ||
((lalm == alev) && (val <= alev + hyst))))
alarmRange = range_Low;
else {
alev = val;
asev = NO_ALARM;
alarmRange = range_Normal;
}
aftc = prec->aftc;
afvl = 0;
if (aftc > 0) {
/* Apply level filtering */
afvl = prec->afvl;
if (afvl == 0) {
afvl = (double)alarmRange;
} else {
double t = epicsTimeDiffInSeconds(&prec->time, lastTime);
double alpha = aftc / (t + aftc);
/* The sign of afvl indicates whether the result should be
* rounded up or down. This gives the filter hysteresis.
* If afvl > 0 the floor() function rounds to a lower alarm
* level, otherwise to a higher.
*/
afvl = alpha * afvl +
((afvl > 0) ? (1 - alpha) : (alpha - 1)) * alarmRange;
if (afvl - floor(afvl) > THRESHOLD)
afvl = -afvl; /* reverse rounding */
alarmRange = abs((int)floor(afvl));
switch (alarmRange) {
case range_Hihi:
asev = prec->hhsv;
alev = prec->hihi;
break;
case range_High:
asev = prec->hsv;
alev = prec->high;
break;
case range_Normal:
asev = NO_ALARM;
break;
case range_Low:
asev = prec->lsv;
alev = prec->low;
break;
case range_Lolo:
asev = prec->llsv;
alev = prec->lolo;
break;
}
}
}
prec->afvl = afvl;
if (asev) {
/* Report alarm condition, store LALM for future HYST calculations */
if (recGblSetSevr(prec, range_stat[alarmRange], asev))
prec->lalm = alev;
} else {
/* No alarm condition, reset LALM */
prec->lalm = val;
}
}
static void convert(aiRecord *prec)
{
double val;
val = (double)prec->rval + (double)prec->roff;
/* adjust slope and offset */
if(prec->aslo!=0.0) val*=prec->aslo;
val+=prec->aoff;
/* convert raw to engineering units and signal units */
switch (prec->linr) {
case menuConvertNO_CONVERSION:
break; /* do nothing*/
case menuConvertLINEAR:
case menuConvertSLOPE:
val = (val * prec->eslo) + prec->eoff;
break;
default: /* must use breakpoint table */
if (cvtRawToEngBpt(&val,prec->linr,prec->init,(void *)&prec->pbrk,&prec->lbrk)!=0) {
recGblSetSevr(prec,SOFT_ALARM,MAJOR_ALARM);
}
}
/* apply smoothing algorithm */
if (prec->smoo != 0.0 && finite(prec->val)){
if (prec->init) prec->val = val; /* initial condition */
prec->val = val * (1.00 - prec->smoo) + (prec->val * prec->smoo);
}else{
prec->val = val;
}
return;
}
static void monitor(aiRecord *prec)
{
unsigned monitor_mask = recGblResetAlarms(prec);
/* check for value change */
recGblCheckDeadband(&prec->mlst, prec->val, prec->mdel, &monitor_mask, DBE_VALUE);
/* check for archive change */
recGblCheckDeadband(&prec->alst, prec->val, prec->adel, &monitor_mask, DBE_ARCHIVE);
/* send out monitors connected to the value field */
if (monitor_mask){
db_post_events(prec,&prec->val,monitor_mask);
if(prec->oraw != prec->rval) {
db_post_events(prec,&prec->rval,monitor_mask);
prec->oraw = prec->rval;
}
}
return;
}
static long readValue(aiRecord *prec)
{
aidset *pdset = (aidset *)prec->dset;
long status = 0;
if (!prec->pact) {
status = recGblGetSimm((dbCommon *)prec, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
if (status) return status;
}
switch (prec->simm) {
case menuSimmNO:
status = pdset->read_ai(prec);
break;
case menuSimmYES:
case menuSimmRAW: {
recGblSetSevr(prec, SIMM_ALARM, prec->sims);
if (prec->pact || (prec->sdly < 0.)) {
status = dbGetLink(&prec->siol, DBR_DOUBLE, &prec->sval, 0, 0);
if (status == 0) {
if (prec->simm == menuSimmYES) {
prec->val = prec->sval;
status = 2; /* don't convert */
} else {
prec->rval = (long)floor(prec->sval);
status = 0; /* convert RVAL */
}
}
prec->pact = FALSE;
} else { /* !prec->pact && delay >= 0. */
CALLBACK *pvt = prec->simpvt;
if (!pvt) {
pvt = calloc(1, sizeof(CALLBACK)); /* very lazy allocation of callback structure */
prec->simpvt = pvt;
}
if (pvt) callbackRequestProcessCallbackDelayed(pvt, prec->prio, prec, prec->sdly);
prec->pact = TRUE;
}
break;
}
default:
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
status = -1;
}
return status;
}
@@ -0,0 +1,658 @@
#*************************************************************************
# Copyright (c) 2013 UChicago Argonne LLC, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
=title Analog Input Record (ai)
This record type is normally used to obtain an analog value from a hardware
input and convert it to engineering units.
The record supports linear and break-point conversion to engineering units,
smoothing, alarm limits, alarm filtering, and graphics and control limits.
=head2 Parameter Fields
The record-specific fields are described below, grouped by functionality.
=recordtype ai
=cut
recordtype(ai) {
=head3 Input Specification
These fields control where the record will read data from when it is processed:
=fields DTYP, INP
The DTYP field selects which device support layer should be responsible for
providing input data to the record.
The ai device support layers provided by EPICS Base are documented in the
L<Device Support|devSoft> section.
External support modules may provide additional device support for this record
type.
If not set explicitly, the DTYP value defaults to the first device support that
is loaded for the record type, which will usually be the C<Soft Channel> support
that comes with Base.
The INP link field contains a database or channel access link or provides
hardware address information that the device support uses to determine where the
input data should come from.
The format for the INP field value depends on the device support layer that is
selected by the DTYP field.
See L<Address Specification|...> for a description of the various hardware
address formats supported.
=head3 Units Conversion
These fields control if and how the raw input value gets converted into
engineering units:
=fields RVAL, ROFF, ASLO, AOFF, LINR, ESLO, EOFF, EGUL, EGUF
These fields are not used if the device support layer reads its value in
engineering units and puts it directly into the VAL field.
This applies to Soft Channel and Async Soft Channel device support, and is also
fairly common for GPIB and similar high-level device interfaces.
If the device support sets the RVAL field, the LINR field controls how this gets
converted into engineering units and placed in the VAL field as follows:
=over
=item 1.
RVAL is converted to a double and ROFF is added to it.
=item 2.
If ASLO is non-zero the value is multiplied by ASLO.
=item 3.
AOFF is added.
=item 4.
If LINR is C<NO CONVERSION> the units conversion is finished after the above
steps.
=item 5.
If LINR is C<LINEAR> or C<SLOPE>, the value from step 3 above is multiplied by
ESLO and EOFF is added to complete the units conversion process.
=item 6.
Any other value for LINR selects a particular breakpoint table to be used on the
value from step 3 above.
=back
The distinction between the C<LINEAR> and C<SLOPE> settings for the LINR field
are in how the conversion parameters are calculated:
=over
=item *
With C<LINEAR> conversion the user must set EGUL and EGUF to the lowest and
highest possible engineering units values respectively that can be converted by
the hardware.
The device support knows the range of the raw data and calculates ESLO and EOFF
from them.
=item *
C<SLOPE> conversion requires the user to calculate the appropriate scaling and
offset factors and put them directly in ESLO and EOFF.
=back
=head3 Smoothing Filter
This filter is usually only used if the device support sets the RVAL field and
the Units Conversion process is used.
Device support that directly sets the VAL field may implement the filter if
desired.
The filter is controlled with a single parameter field:
=fields SMOO
The SMOO field should be set to a number between 0 and 1.
If set to zero the filter is not used (no smoothing), while if set to one the
result is infinite smoothing (the VAL field will never change).
The calculation performed is:
=over
VAL = VAL * SMOO + (1 - SMOO) * New Data
=back
where C<New Data> was the result from the Units Conversion above.
This implements a first-order infinite impulse response (IIR) digital filter
with z-plane pole at SMOO.
The equivalent continuous-time filter time constant E<tau> is given by
=over
E<tau> = E<minus>T / ln(SMOO)
=back
where T is the time between record processing.
=head3 Undefined Check
If after applying the smoothing filter the VAL field contains a NaN
(Not-a-Number) value, the UDF field is set to a non-zero value, indicating that
the record value is undefined, which will trigger a C<UDF_ALARM> with severity
C<INVALID_ALARM>.
=fields UDF
=head3 Operator Display Parameters
These parameters are used to present meaningful data to the operator.
They do not affect the functioning of the record at all.
=over
=item *
DESC is a string that is usually used to briefly describe the record.
=item *
EGU is a string of up to 16 characters naming the engineering units that the VAL
field represents.
=item *
The HOPR and LOPR fields set the upper and lower display limits for the VAL,
HIHI, HIGH, LOW, and LOLO fields.
=item *
The PREC field determines the floating point precision (i.e. the number of
digits to show after the decimal point) with which to display VAL and the other
DOUBLE fields.
=back
=fields DESC, EGU, HOPR, LOPR, PREC
=head3 Alarm Limits
The user configures limit alarms by putting numerical values into the HIHI,
HIGH, LOW and LOLO fields, and by setting the associated alarm severity in the
corresponding HHSV, HSV, LSV and LLSV menu fields.
The HYST field controls hysteresis to prevent alarm chattering from an input
signal that is close to one of the limits and suffers from significant readout
noise.
The AFTC field sets the time constant on a low-pass filter that delays the
reporting of limit alarms until the signal has been within the alarm range for
that number of seconds (the default AFTC value of zero retains the previous
behavior).
=fields HIHI, HIGH, LOW, LOLO, HHSV, HSV, LSV, LLSV, HYST, AFTC, LALM
=head3 Monitor Parameters
These parameters are used to determine when to send monitors placed on the VAL
field.
The monitors are sent when the current value exceeds the last transmitted value
by the appropriate deadband.
If these fields are set to zero, a monitor will be triggered every time the
value changes; if set to -1, a monitor will be sent every time the record is
processed.
The ADEL field sets the deadband for archive monitors (C<DBE_LOG> events), while
the MDEL field controls value monitors (C<DBE_VALUE> events).
The remaining fields are used by the record at run-time to implement the record
monitoring functionality.
=fields ADEL, MDEL, ALST, MLST, ORAW
=cut
include "dbCommon.dbd"
field(VAL,DBF_DOUBLE) {
prompt("Current EGU Value")
promptgroup("40 - Input")
asl(ASL0)
pp(TRUE)
}
field(INP,DBF_INLINK) {
prompt("Input Specification")
promptgroup("40 - Input")
interest(1)
}
field(PREC,DBF_SHORT) {
prompt("Display Precision")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(LINR,DBF_MENU) {
prompt("Linearization")
promptgroup("60 - Convert")
special(SPC_LINCONV)
pp(TRUE)
interest(1)
menu(menuConvert)
}
field(EGUF,DBF_DOUBLE) {
prompt("Engineer Units Full")
promptgroup("60 - Convert")
special(SPC_LINCONV)
pp(TRUE)
interest(1)
}
field(EGUL,DBF_DOUBLE) {
prompt("Engineer Units Low")
promptgroup("60 - Convert")
special(SPC_LINCONV)
pp(TRUE)
interest(1)
}
field(EGU,DBF_STRING) {
prompt("Engineering Units")
promptgroup("80 - Display")
interest(1)
size(16)
prop(YES)
}
field(HOPR,DBF_DOUBLE) {
prompt("High Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(LOPR,DBF_DOUBLE) {
prompt("Low Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(AOFF,DBF_DOUBLE) {
prompt("Adjustment Offset")
promptgroup("60 - Convert")
pp(TRUE)
interest(1)
}
field(ASLO,DBF_DOUBLE) {
prompt("Adjustment Slope")
promptgroup("60 - Convert")
pp(TRUE)
interest(1)
initial("1")
}
field(SMOO,DBF_DOUBLE) {
prompt("Smoothing")
promptgroup("60 - Convert")
interest(1)
}
field(HIHI,DBF_DOUBLE) {
prompt("Hihi Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(LOLO,DBF_DOUBLE) {
prompt("Lolo Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(HIGH,DBF_DOUBLE) {
prompt("High Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(LOW,DBF_DOUBLE) {
prompt("Low Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(HHSV,DBF_MENU) {
prompt("Hihi Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(LLSV,DBF_MENU) {
prompt("Lolo Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(HSV,DBF_MENU) {
prompt("High Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(LSV,DBF_MENU) {
prompt("Low Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(HYST,DBF_DOUBLE) {
prompt("Alarm Deadband")
promptgroup("70 - Alarm")
interest(1)
}
field(AFTC,DBF_DOUBLE) {
prompt("Alarm Filter Time Constant")
promptgroup("70 - Alarm")
interest(1)
}
field(ADEL,DBF_DOUBLE) {
prompt("Archive Deadband")
promptgroup("80 - Display")
interest(1)
}
field(MDEL,DBF_DOUBLE) {
prompt("Monitor Deadband")
promptgroup("80 - Display")
interest(1)
}
field(LALM,DBF_DOUBLE) {
prompt("Last Value Alarmed")
special(SPC_NOMOD)
interest(3)
}
field(AFVL,DBF_DOUBLE) {
prompt("Alarm Filter Value")
special(SPC_NOMOD)
interest(3)
}
field(ALST,DBF_DOUBLE) {
prompt("Last Value Archived")
special(SPC_NOMOD)
interest(3)
}
field(MLST,DBF_DOUBLE) {
prompt("Last Val Monitored")
special(SPC_NOMOD)
interest(3)
}
field(ESLO,DBF_DOUBLE) {
prompt("Raw to EGU Slope")
promptgroup("60 - Convert")
pp(TRUE)
interest(2)
initial("1")
}
field(EOFF,DBF_DOUBLE) {
prompt("Raw to EGU Offset")
promptgroup("60 - Convert")
pp(TRUE)
interest(2)
}
field(ROFF,DBF_ULONG) {
prompt("Raw Offset")
pp(TRUE)
interest(2)
}
field(PBRK,DBF_NOACCESS) {
prompt("Ptrto brkTable")
special(SPC_NOMOD)
interest(4)
extra("void * pbrk")
}
field(INIT,DBF_SHORT) {
prompt("Initialized?")
special(SPC_NOMOD)
interest(3)
}
field(LBRK,DBF_SHORT) {
prompt("LastBreak Point")
special(SPC_NOMOD)
interest(3)
}
field(RVAL,DBF_LONG) {
prompt("Current Raw Value")
pp(TRUE)
}
field(ORAW,DBF_LONG) {
prompt("Previous Raw Value")
special(SPC_NOMOD)
interest(3)
}
=head3 Simulation Mode
The record provides several fields to support simulation of absent hardware.
If the SIML field is set it is used to read a value into the SIMM field, which
controls whether simulation is used or not:
=over
=item *
SIMM must be zero (C<NO>) for the record to request a value from the device
support.
=item *
If SIMM is C<YES> and the SIOL link field is set, a simlated value in
engineering units is read using the link into the SVAL field, from where it will
subsequently be copied into the VAL field.
=item *
If SIMM is C<RAW> the SIOL link is still read into SVAL, but is then truncated
and copied into the RVAL field.
The L</Units Conversion> process described above is then followed to transform
the simulated raw value into engineering units.
=back
The SIMS field can be set to give the record an alarm severity while it is in
simulation mode.
=fields SIML, SIMM, SIOL, SVAL, SIMS
=cut
field(SIOL,DBF_INLINK) {
prompt("Simulation Input Link")
promptgroup("90 - Simulate")
interest(1)
}
field(SVAL,DBF_DOUBLE) {
prompt("Simulation Value")
}
field(SIML,DBF_INLINK) {
prompt("Simulation Mode Link")
promptgroup("90 - Simulate")
interest(1)
}
field(SIMM,DBF_MENU) {
prompt("Simulation Mode")
special(SPC_MOD)
interest(1)
menu(menuSimm)
}
field(SIMS,DBF_MENU) {
prompt("Simulation Mode Severity")
promptgroup("90 - Simulate")
interest(2)
menu(menuAlarmSevr)
}
field(OLDSIMM,DBF_MENU) {
prompt("Prev. Simulation Mode")
special(SPC_NOMOD)
interest(4)
menu(menuSimm)
}
field(SSCN,DBF_MENU) {
prompt("Sim. Mode Scan")
promptgroup("90 - Simulate")
interest(1)
menu(menuScan)
initial("65535")
}
field(SDLY,DBF_DOUBLE) {
prompt("Sim. Mode Async Delay")
promptgroup("90 - Simulate")
interest(2)
initial("-1.0")
}
%#include "callback.h"
field(SIMPVT,DBF_NOACCESS) {
prompt("Sim. Mode Private")
special(SPC_NOMOD)
interest(4)
extra("CALLBACK *simpvt")
}
}
=head2 Device Support Interface
The record requires device support to provide an entry table (dset) which
defines the following members:
typedef struct {
long number;
long (*report)(int level);
long (*init)(int after);
long (*init_record)(aiRecord *prec);
long (*get_ioint_info)(int cmd, aiRecord *prec, IOSCANPVT *piosl);
long (*read_ai)(aiRecord *prec);
long (*special_linconv)(aiRecord *prec, int after);
} aidset;
The module must set C<number> to at least 6, and provide a pointer to its
C<read_ai()> routine; the other function pointers may be C<NULL> if their
associated functionality is not required for this support layer.
Most device supports also provide an C<init_record()> routine to configure the
record instance and connect it to the hardware or driver support layer, and if
using the record's L</Units Conversion> features they set C<special_linconv()>
as well.
The individual routines are described below.
=head3 Device Support Routines
=head4 long report(int level)
This optional routine is called by the IOC command C<dbior> and is passed the
report level that was requested by the user.
It should print a report on the state of the device support to stdout.
The C<level> parameter may be used to output increasingly more detailed
information at higher levels, or to select different types of information with
different levels.
Level zero should print no more than a small summary.
=head4 long init(int after)
This optional routine is called twice at IOC initialization time.
The first call happens before any of the C<init_record()> calls are made, with
the integer parameter C<after> set to 0.
The second call happens after all of the C<init_record()> calls have been made,
with C<after> set to 1.
=head4 long init_record(aiRecord *prec)
This optional routine is called by the record initialization code for each ai
record instance that has its DTYP field set to use this device support.
It is normally used to check that the INP address is the expected type and that
it points to a valid device; to allocate any record-specific buffer space and
other memory; and to connect any communication channels needed for the
C<read_ai()> routine to work properly.
If the record type's unit conversion features are used, the C<init_record()>
routine should calculate appropriate values for the ESLO and EOFF fields from
the EGUL and EGUF field values.
This calculation only has to be performed if the record's LINR field is set to
C<LINEAR>, but it is not necessary to check that condition first.
This same calculation takes place in the C<special_linconv()> routine, so the
implementation can usually just call that routine to perform the task.
=head4 long get_ioint_info(int cmd, aiRecord *prec, IOSCANPVT *piosl)
This optional routine is called whenever the record's SCAN field is being
changed to or from the value C<I/O Intr> to find out which I/O Interrupt Scan
list the record should be added to or deleted from.
If this routine is not provided, it will not be possible to set the SCAN field
to the value C<I/O Intr> at all.
The C<cmd> parameter is zero when the record is being added to the scan list,
and one when it is being removed from the list.
The routine must determine which interrupt source the record should be connected
to, which it indicates by the scan list that it points the location at C<*piosl>
to before returning.
It can prevent the SCAN field from being changed at all by returning a non-zero
value to its caller.
In most cases the device support will create the I/O Interrupt Scan lists that
it returns for itself, by calling C<void scanIoInit(IOSCANPVT *piosl)> once for
each separate interrupt source.
That routine allocates memory and inializes the list, then passes back a pointer
to the new list in the location at C<*piosl>.
When the device support receives notification that the interrupt has occurred,
it announces that to the IOC by calling C<void scanIoRequest(IOSCANPVT iosl)>
which will arrange for the appropriate records to be processed in a suitable
thread.
The C<scanIoRequest()> routine is safe to call from an interrupt service routine
on embedded architectures (vxWorks and RTEMS).
=head4 long read_ai(aiRecord *prec)
This essential routine is called when the record wants a new value from the
addressed device.
It is responsible for performing (or at least initiating) a read operation, and
(eventually) returning its value to the record.
... PACT and asynchronous processing ...
... return value ...
=head4 long special_linconv(aiRecord *prec, int after)
This optional routine should be provided if the record type's unit conversion
features are used by the device support's C<read_ai()> routine returning a
status value of zero.
It is called by the record code whenever any of the the fields LINR, EGUL or
EGUF are modified and LINR has the value C<LINEAR>.
The routine must calculate and set the fields EOFF and ESLO appropriately based
on the new values of EGUL and EGUF.
These calculations can be expressed in terms of the minimum and maximum raw
values that the C<read_ai()> routine can put in the RVAL field.
When RVAL is set to I<RVAL_max> the VAL field will be set to EGUF, and when RVAL
is set to I<RVAL_min> the VAL field will become EGUL.
The formulae to use are:
=over
EOFF = (I<RVAL_max> * EGUL E<minus> I<RVAL_min> * EGUF) /
(I<RVAL_max> E<minus> I<RVAL_min>)
ESLO = (EGUF E<minus> EGUL) / (I<RVAL_max> E<minus> I<RVAL_min>)
=back
Note that the record support sets EOFF to EGUL before calling this routine,
which is a very common case (when I<RVAL_min> is zero).
=head3 Extended Device Support
...
=cut
+594
View File
@@ -0,0 +1,594 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* aoRecord.c - Record Support Routines for Analog Output records */
/*
* Original Author: Bob Dalesio
* Date: 7-14-89
*
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "dbDefs.h"
#include "epicsPrint.h"
#include "epicsMath.h"
#include "alarm.h"
#include "callback.h"
#include "cvtTable.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "dbFldTypes.h"
#include "devSup.h"
#include "errMdef.h"
#include "special.h"
#include "recSup.h"
#include "recGbl.h"
#include "menuConvert.h"
#include "menuOmsl.h"
#include "menuYesNo.h"
#include "menuIvoa.h"
#define GEN_SIZE_OFFSET
#include "aoRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
static long special(DBADDR *, int);
#define get_value NULL
#define cvt_dbaddr NULL
#define get_array_info NULL
#define put_array_info NULL
static long get_units(DBADDR *, char *);
static long get_precision(const DBADDR *, long *);
#define get_enum_str NULL
#define get_enum_strs NULL
#define put_enum_str NULL
static long get_graphic_double(DBADDR *, struct dbr_grDouble *);
static long get_control_double(DBADDR *, struct dbr_ctrlDouble *);
static long get_alarm_double(DBADDR *, struct dbr_alDouble *);
rset aoRSET={
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double };
struct aodset { /* analog input dset */
long number;
DEVSUPFUN dev_report;
DEVSUPFUN init;
DEVSUPFUN init_record; /*returns: (0,2)=>(success,success no convert)*/
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_ao;/*(0)=>(success ) */
DEVSUPFUN special_linconv;
};
epicsExportAddress(rset,aoRSET);
static void checkAlarms(aoRecord *);
static long fetch_value(aoRecord *, double *);
static void convert(aoRecord *, double);
static void monitor(aoRecord *);
static long writeValue(aoRecord *);
static long init_record(struct dbCommon *pcommon, int pass)
{
struct aoRecord *prec = (struct aoRecord *)pcommon;
struct aodset *pdset;
double eoff = prec->eoff, eslo = prec->eslo;
double value;
long status = 0;
if (pass == 0) return 0;
recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
if(!(pdset = (struct aodset *)(prec->dset))) {
recGblRecordError(S_dev_noDSET,(void *)prec,"ao: init_record");
return(S_dev_noDSET);
}
/* get the initial value if dol is a constant*/
if (recGblInitConstantLink(&prec->dol,DBF_DOUBLE,&prec->val))
prec->udf = isnan(prec->val);
/* must have write_ao function defined */
if ((pdset->number < 6) || (pdset->write_ao ==NULL)) {
recGblRecordError(S_dev_missingSup,(void *)prec,"ao: init_record");
return(S_dev_missingSup);
}
prec->init = TRUE;
/*The following is for old device support that doesnt know about eoff*/
if ((prec->eslo==1.0) && (prec->eoff==0.0)) {
prec->eoff = prec->egul;
}
if (pdset->init_record) {
status = (*pdset->init_record)(prec);
if (prec->linr == menuConvertSLOPE) {
prec->eoff = eoff;
prec->eslo = eslo;
}
switch(status){
case(0): /* convert */
value = (double)prec->rval + (double)prec->roff;
if(prec->aslo!=0.0) value *= prec->aslo;
value += prec->aoff;
if (prec->linr == menuConvertNO_CONVERSION){
; /*do nothing*/
} else if ((prec->linr == menuConvertLINEAR) ||
(prec->linr == menuConvertSLOPE)) {
value = value*prec->eslo + prec->eoff;
}else{
if(cvtRawToEngBpt(&value,prec->linr,prec->init,
(void *)&prec->pbrk,&prec->lbrk)!=0) break;
}
prec->val = value;
prec->udf = isnan(value);
break;
case(2): /* no convert */
break;
default:
recGblRecordError(S_dev_badInitRet,(void *)prec,"ao: init_record");
return(S_dev_badInitRet);
}
}
prec->oval = prec->pval = prec->val;
prec->mlst = prec->val;
prec->alst = prec->val;
prec->lalm = prec->val;
prec->oraw = prec->rval;
prec->orbv = prec->rbv;
return(0);
}
static long process(struct dbCommon *pcommon)
{
struct aoRecord *prec = (struct aoRecord *)pcommon;
struct aodset *pdset = (struct aodset *)(prec->dset);
long status=0;
unsigned char pact=prec->pact;
double value;
if ((pdset==NULL) || (pdset->write_ao==NULL)) {
prec->pact=TRUE;
recGblRecordError(S_dev_missingSup,(void *)prec,"write_ao");
return(S_dev_missingSup);
}
/* fetch value and convert*/
if (prec->pact == FALSE) {
if (!dbLinkIsConstant(&prec->dol) &&
prec->omsl == menuOmslclosed_loop) {
status = fetch_value(prec, &value);
}
else {
value = prec->val;
}
if(!status) convert(prec, value);
prec->udf = isnan(prec->val);
}
/* check for alarms */
checkAlarms(prec);
if (prec->nsev < INVALID_ALARM )
status=writeValue(prec); /* write the new value */
else {
switch (prec->ivoa) {
case (menuIvoaContinue_normally) :
status=writeValue(prec); /* write the new value */
break;
case (menuIvoaDon_t_drive_outputs) :
break;
case (menuIvoaSet_output_to_IVOV) :
if(prec->pact == FALSE){
prec->val=prec->ivov;
value=prec->ivov;
convert(prec,value);
}
status=writeValue(prec); /* write the new value */
break;
default :
status=-1;
recGblRecordError(S_db_badField,(void *)prec,
"ao:process Illegal IVOA field");
}
}
/* check if device support set pact */
if ( !pact && prec->pact ) return(0);
prec->pact = TRUE;
recGblGetTimeStampSimm(prec, prec->simm, NULL);
/* check event list */
monitor(prec);
/* process the forward scan link record */
recGblFwdLink(prec);
prec->init=FALSE;
prec->pact=FALSE;
return(status);
}
static long special(DBADDR *paddr, int after)
{
aoRecord *prec = (aoRecord *)(paddr->precord);
struct aodset *pdset = (struct aodset *) (prec->dset);
int special_type = paddr->special;
switch(special_type) {
case(SPC_LINCONV):
if(pdset->number<6 ) {
recGblDbaddrError(S_db_noMod,paddr,"ao: special");
return(S_db_noMod);
}
prec->init=TRUE;
if ((prec->linr == menuConvertLINEAR) && pdset->special_linconv) {
double eoff = prec->eoff;
double eslo = prec->eslo;
long status;
prec->eoff = prec->egul;
status = (*pdset->special_linconv)(prec,after);
if (eoff != prec->eoff)
db_post_events(prec, &prec->eoff, DBE_VALUE|DBE_LOG);
if (eslo != prec->eslo)
db_post_events(prec, &prec->eslo, DBE_VALUE|DBE_LOG);
return (status);
}
return (0);
case(SPC_MOD):
if (dbGetFieldIndex(paddr) == aoRecordSIMM) {
if (!after)
recGblSaveSimm(prec->sscn, &prec->oldsimm, prec->simm);
else
recGblCheckSimm((dbCommon *)prec, &prec->sscn, prec->oldsimm, prec->simm);
return(0);
}
default:
recGblDbaddrError(S_db_badChoice,paddr,"ao: special");
return(S_db_badChoice);
}
}
#define indexof(field) aoRecord##field
static long get_units(DBADDR * paddr,char *units)
{
aoRecord *prec=(aoRecord *)paddr->precord;
if(paddr->pfldDes->field_type == DBF_DOUBLE) {
switch (dbGetFieldIndex(paddr)) {
case indexof(ASLO):
case indexof(AOFF):
break;
default:
strncpy(units,prec->egu,DB_UNITS_SIZE);
}
}
return(0);
}
static long get_precision(const DBADDR *paddr,long *precision)
{
aoRecord *prec=(aoRecord *)paddr->precord;
*precision = prec->prec;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
case indexof(OVAL):
case indexof(PVAL):
break;
default:
recGblGetPrec(paddr,precision);
}
return(0);
}
static long get_graphic_double(DBADDR *paddr,struct dbr_grDouble *pgd)
{
aoRecord *prec=(aoRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
case indexof(OVAL):
case indexof(PVAL):
case indexof(HIHI):
case indexof(HIGH):
case indexof(LOW):
case indexof(LOLO):
case indexof(LALM):
case indexof(ALST):
case indexof(MLST):
case indexof(IVOV):
pgd->upper_disp_limit = prec->hopr;
pgd->lower_disp_limit = prec->lopr;
break;
default:
recGblGetGraphicDouble(paddr,pgd);
}
return(0);
}
static long get_control_double(DBADDR *paddr, struct dbr_ctrlDouble *pcd)
{
aoRecord *prec=(aoRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
case indexof(OVAL):
case indexof(PVAL):
case indexof(HIHI):
case indexof(HIGH):
case indexof(LOW):
case indexof(LOLO):
case indexof(LALM):
case indexof(ALST):
case indexof(MLST):
pcd->upper_ctrl_limit = prec->drvh;
pcd->lower_ctrl_limit = prec->drvl;
break;
default:
recGblGetControlDouble(paddr,pcd);
}
return(0);
}
static long get_alarm_double(DBADDR *paddr, struct dbr_alDouble *pad)
{
aoRecord *prec=(aoRecord *)paddr->precord;
if(dbGetFieldIndex(paddr) == indexof(VAL)){
pad->upper_alarm_limit = prec->hhsv ? prec->hihi : epicsNAN;
pad->upper_warning_limit = prec->hsv ? prec->high : epicsNAN;
pad->lower_warning_limit = prec->lsv ? prec->low : epicsNAN;
pad->lower_alarm_limit = prec->llsv ? prec->lolo : epicsNAN;
} else recGblGetAlarmDouble(paddr,pad);
return(0);
}
static void checkAlarms(aoRecord *prec)
{
double val, hyst, lalm;
double alev;
epicsEnum16 asev;
if (prec->udf) {
recGblSetSevr(prec, UDF_ALARM, prec->udfs);
return;
}
val = prec->val;
hyst = prec->hyst;
lalm = prec->lalm;
/* alarm condition hihi */
asev = prec->hhsv;
alev = prec->hihi;
if (asev && (val >= alev || ((lalm == alev) && (val >= alev - hyst)))) {
if (recGblSetSevr(prec, HIHI_ALARM, asev))
prec->lalm = alev;
return;
}
/* alarm condition lolo */
asev = prec->llsv;
alev = prec->lolo;
if (asev && (val <= alev || ((lalm == alev) && (val <= alev + hyst)))) {
if (recGblSetSevr(prec, LOLO_ALARM, asev))
prec->lalm = alev;
return;
}
/* alarm condition high */
asev = prec->hsv;
alev = prec->high;
if (asev && (val >= alev || ((lalm == alev) && (val >= alev - hyst)))) {
if (recGblSetSevr(prec, HIGH_ALARM, asev))
prec->lalm = alev;
return;
}
/* alarm condition low */
asev = prec->lsv;
alev = prec->low;
if (asev && (val <= alev || ((lalm == alev) && (val <= alev + hyst)))) {
if (recGblSetSevr(prec, LOW_ALARM, asev))
prec->lalm = alev;
return;
}
/* we get here only if val is out of alarm by at least hyst */
prec->lalm = val;
return;
}
static long fetch_value(aoRecord *prec,double *pvalue)
{
short save_pact;
long status;
save_pact = prec->pact;
prec->pact = TRUE;
/* don't allow dbputs to val field */
prec->val=prec->pval;
status = dbGetLink(&prec->dol,DBR_DOUBLE,pvalue,0,0);
prec->pact = save_pact;
if (status) {
recGblSetSevr(prec,LINK_ALARM,INVALID_ALARM);
return(status);
}
if (prec->oif == aoOIF_Incremental)
*pvalue += prec->val;
return(0);
}
static void convert(aoRecord *prec, double value)
{
/* check drive limits */
if (prec->drvh > prec->drvl) {
if (value > prec->drvh)
value = prec->drvh;
else if (value < prec->drvl)
value = prec->drvl;
}
prec->val = value;
prec->pval = value;
/* now set value equal to desired output value */
/* apply the output rate of change */
if (prec->oroc != 0){/*must be defined and >0*/
double diff;
diff = value - prec->oval;
if (diff < 0) {
if (prec->oroc < -diff)
value = prec->oval - prec->oroc;
} else if (prec->oroc < diff)
value = prec->oval + prec->oroc;
}
prec->omod = (prec->oval!=value);
prec->oval = value;
/* convert */
switch (prec->linr) {
case menuConvertNO_CONVERSION:
break; /* do nothing*/
case menuConvertLINEAR:
case menuConvertSLOPE:
if (prec->eslo == 0.0) value = 0;
else value = (value - prec->eoff) / prec->eslo;
break;
default:
if (cvtEngToRawBpt(&value, prec->linr, prec->init,
(void *)&prec->pbrk, &prec->lbrk) != 0) {
recGblSetSevr(prec, SOFT_ALARM, MAJOR_ALARM);
return;
}
}
value -= prec->aoff;
if (prec->aslo != 0) value /= prec->aslo;
/* Apply raw offset and limits, round to 32-bit integer */
value -= prec->roff;
if (value >= 0.0) {
if (value >= (0x7fffffff - 0.5))
prec->rval = 0x7fffffff;
else
prec->rval = (epicsInt32)(value + 0.5);
} else {
if (value > (0.5 - 0x80000000))
prec->rval = (epicsInt32)(value - 0.5);
else
prec->rval = 0x80000000;
}
}
static void monitor(aoRecord *prec)
{
unsigned monitor_mask = recGblResetAlarms(prec);
/* check for value change */
recGblCheckDeadband(&prec->mlst, prec->val, prec->mdel, &monitor_mask, DBE_VALUE);
/* check for archive change */
recGblCheckDeadband(&prec->alst, prec->val, prec->adel, &monitor_mask, DBE_ARCHIVE);
/* send out monitors connected to the value field */
if (monitor_mask){
db_post_events(prec,&prec->val,monitor_mask);
}
if(prec->omod) monitor_mask |= (DBE_VALUE|DBE_LOG);
if(monitor_mask) {
prec->omod = FALSE;
db_post_events(prec,&prec->oval,monitor_mask);
if(prec->oraw != prec->rval) {
db_post_events(prec,&prec->rval,
monitor_mask|DBE_VALUE|DBE_LOG);
prec->oraw = prec->rval;
}
if(prec->orbv != prec->rbv) {
db_post_events(prec,&prec->rbv,
monitor_mask|DBE_VALUE|DBE_LOG);
prec->orbv = prec->rbv;
}
}
return;
}
static long writeValue(aoRecord *prec)
{
struct aodset *pdset = (struct aodset *) prec->dset;
long status = 0;
if (!prec->pact) {
status = recGblGetSimm((dbCommon *)prec, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
if (status) return status;
}
switch (prec->simm) {
case menuYesNoNO:
status = pdset->write_ao(prec);
break;
case menuYesNoYES: {
recGblSetSevr(prec, SIMM_ALARM, prec->sims);
if (prec->pact || (prec->sdly < 0.)) {
status = dbPutLink(&prec->siol, DBR_DOUBLE, &prec->oval, 1);
prec->pact = FALSE;
} else { /* !prec->pact && delay >= 0. */
CALLBACK *pvt = prec->simpvt;
if (!pvt) {
pvt = calloc(1, sizeof(CALLBACK)); /* very lazy allocation of callback structure */
prec->simpvt = pvt;
}
if (pvt) callbackRequestProcessCallbackDelayed(pvt, prec->prio, prec, prec->sdly);
prec->pact = TRUE;
}
break;
}
default:
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
status = -1;
}
return status;
}
@@ -0,0 +1,944 @@
#*************************************************************************
# Copyright (c) 2013 UChicago Argonne LLC, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
=title Analog Output Record (ao)
This record type is normally used to send an analog value to an output device,
converting it from engineering units into an integer value if necessary.
The record supports alarm and drive limits, rate-of-change limiting, output
value integration, linear and break-point conversion from engineering units, and
graphics and control limits.
=head2 Record-specific Menus
=head3 Menu aoOIF
The OIF field which uses this menu controls whether the record acts as an
integrator (C<Incremental>) or not (C<Full>).
=menu aoOIF
=head2 Parameter Fields
The record-specific fields are described below.
=recordtype ao
=cut
menu(aoOIF) {
choice(aoOIF_Full,"Full")
choice(aoOIF_Incremental,"Incremental")
}
recordtype(ao) {
=head3 Output Value Determination
These fields control how the record determines the value to be output when it
gets processed:
=fields OMSL, DOL, OIF, PVAL, DRVH, DRVL, VAL, OROC, OVAL
The following steps are performed in order during record processing.
=head4 Fetch Value, Integrate
The OMSL menu field is used to determine whether the DOL link and OIF menu
fields should be used during processing or not:
=over
=item *
If OMSL is C<supervisory> the DOL and OIF fields are not used.
The new output value is taken from the VAL field, which may have been set from
elsewhere.
=item *
If OMSL is C<closed_loop> the DOL link field is read to obtain a value; if OIF
is C<Incremental> and the DOL link was read successfully, the record's previous
output value PVAL is added to it.
=back
=head4 Drive Limits
The output value is now clipped to the range DRVL to DRVH inclusive, provided
that DRVH > DRVL.
The result is copied into both the VAL and PVAL fields.
=head4 Limit Rate of Change
If the OROC field is not zero, the VAL field is now adjusted so it is no more
than OROC different to the previous output value given in OVAL.
OROC thus determines the maximum change in the output value that can occur each
time the record gets processed.
The result is copied into the OVAL field, which is used as the input to the
following Units Conversion processing stage.
=head3 Units Conversion
...
For analog output records that do not use the Soft Channel device support
routine, the specified conversions (if any) are performed on the OVAL field and
the resulting value in the RVAL field is sent to the address contained in the
output link after it is adjusted by the values in the AOFF and ASLO fields.
=fields LINR, RVAL, ROFF, EGUF, EGUL, AOFF, ASLO, ESLO, EOFF
=head4 Conversion Related Fields and the Conversion Process
Except for analog outputs that use Soft Channel device support, the LINR field
determines if a conversion is performed and which conversion algorithm is used
to convert OVAL to RVAL.
The LINR field can specify C<LINEAR> or C<SLOPE> for linear conversions,
C<NO CONVERSION> for no conversions at all, or the name of a breakpoint table
such as C<typeKdegC> for breakpoint conversions.
Note that the ESLO, EOFF, EGUF, and EGUL fields are only used for linear
conversions.
Also note that none of these fields have any significance for records that use
the Soft Channel device support module.
=over
=item EGUF, EGUF
The user must calculate these fields when configuring the database for records
that use C<LINEAR> conversions.
They are used to calculate the values for ESLO and EOFF.
See Conversion Specification for more information on how to calculate these
fields.
=item AOFF, ASLO
These fields are adjustment parameters for the raw output values.
They are applied to the raw output value after conversion from engineering
units.
=item ESLO, EOFF
Computed by device support using EGUF and EGUL when LINR specifies C<LINEAR>.
These values must be supplied by the user when LINR specifies C<SLOPE>.
Used only when LINR is C<LINEAR> or C<SLOPE>.
=item ROFF
This field can be used to offset the raw value generated by the conversion
process, which is needed for some kinds of hardware.
=back
Conversion proceeds as follows:
=over
=item 1. If LINR==LINEAR or LINR==SLOPE, then X = (VAL - EOFF) / ESLO,
else if LINR==NO_CONVERSION, then X = VAL,
else X is obtained via breakpoint table.
=item 2. X = (X - AOFF) / ASLO
=item 3. RVAL = round(X) - ROFF
=back
To see how the Raw Soft Channel device support routine uses these
fields, see L</Device Support For Soft Records> below for more
information.
=head3 Output Specification
The analog output record sends its desired output to the address in the
OUT field. For analog outputs that write their values to devices, the
OUT field must specify the address of the I/O card. In addition, the
DTYP field must contain the name of the device support module. Be aware
that the address format differs according to the I/O bus used. See
Address Specification for information on the format of hardware
addresses. The user can see a list of the device support modules
currently supported at the user's local site by using the dbst utility
in R3.13.
For soft records the output link can be a database link, a channel
access link, or a constant value. If the link is a constant, no output
is sent. See Address Specification for information on the format of
database and channel access addresses.
=fields DTYP, OUT
=head3 Operator Display Parameters
These parameters are used to present meaningful data to the operator.
They display the value and other parameters of the analog output either
textually or graphically.
EGU is a string of up to 16 characters describing the units that the
analog output measures. It is retrieved by the get_units record support
routine.
The HOPR and LOPR fields set the upper and lower display limits for the
VAL, OVAL, PVAL, HIHI, HIGH, LOW, and LOLO fields. Both the
get_graphic_double and get_control_double record support routines
retrieve these fields. If these values are defined, they must be in the
range: DRVL E<lt>= LOPR E<lt>= HOPR E<lt>= DRVH.
The PREC field determines the floating point precision with which to
display VAL, OVAL and PVAL. It is used whenever the get_precision
record support routine is called.
See Fields Common to All Record Types for more on the record name
(NAME) and description (DESC) fields.
=fields EGU, HOPR, LOPR, PREC, NAME, DESC
=head3 Alarm Parameters
The possible alarm conditions for analog outputs are the SCAN, READ,
INVALID and limit alarms. The SCAN, READ, and INVALID alarms are called
by the record or device support routines.
The limit alarms are configured by the user in the HIHI, LOLO, HIGH,
and LOW fields, which must be floating-point values. For each of these
fields, there is a corresponding severity field which can be either
NO_ALARM, MINOR, or MAJOR.
See Alarm Specification for a complete explanation of alarms and these
fields. See Invalid Alarm Output Action for more information on the
IVOA and IVOV fields. Alarm Fields lists other fields related to a
alarms that are common to all record types.
=fields HIHI, HIGH, LOW, LOLO, HHSV, HSV, LSV, LLSV, HYST, IVOA, IVOV
=head3 Monitor Parameters
These parameters are used to specify deadbands for monitors on the VAL
field. The monitors are sent when the value field exceeds the last
monitored field by the specified deadband. If these fields have a value
of zero, everytime the value changes, a monitor will be triggered; if
they have a value of -1, everytime the record is processed, monitors
are triggered. ADEL is the deadband for archive monitors, and MDEL the
deadband for all other types of monitors. See Monitor Specification for
a complete explanation of monitors.
=fields ADEL, MDEL
=head3 Run-time and Simulation Mode Parameters
These parameters are used by the run-time code for processing the
analog output. They are not configurable. They represent the current
state of the record. The record support routines use some of them for
more efficient processing.
The ORAW field is used to decide if monitors should be triggered for
RVAL when monitors are triggered for VAL. The RBV field is the actual
read back value obtained from the hardware itself or from the
associated device driver. It is the responsibility of the device
support routine to give this field a value.
ORBV is used to decide if monitors should be triggered for RBV at the
same time monitors are triggered for changes in VAL.
The LALM, MLST, and ALST fields are used to implement the hysteresis
factors for monitor callbacks.
The INIT field is used to initialize the LBRK field and for smoothing.
The PBRK field contains a pointer to the current breakpoint table (if
any), and LBRK contains a pointer to the last breakpoint table used.
The OMOD field indicates whether OVAL differs from VAL. It will be
different if VAL or OVAL have changed since the last time the record
was processed, or if VAL has been adjusted by OROC during the current
processing.
=fields ORAW, RBV, ORBV, LALM, ALST, MLST, INIT, PBRK, LBRK, PVAL, OMOD
The following fields are used to operate the analog output in the
simulation mode. See Fields Common to Many Record Types for more
information on these fields.
=fields SIOL, SIML, SIMM, SIMS
=cut
include "dbCommon.dbd"
field(VAL,DBF_DOUBLE) {
prompt("Desired Output")
promptgroup("50 - Output")
asl(ASL0)
pp(TRUE)
}
field(OVAL,DBF_DOUBLE) {
prompt("Output Value")
}
field(OUT,DBF_OUTLINK) {
prompt("Output Specification")
promptgroup("50 - Output")
interest(1)
}
field(OROC,DBF_DOUBLE) {
prompt("Output Rate of Change")
promptgroup("50 - Output")
interest(1)
}
field(DOL,DBF_INLINK) {
prompt("Desired Output Loc")
promptgroup("40 - Input")
interest(1)
}
field(OMSL,DBF_MENU) {
prompt("Output Mode Select")
promptgroup("50 - Output")
interest(1)
menu(menuOmsl)
}
field(OIF,DBF_MENU) {
prompt("Out Full/Incremental")
promptgroup("50 - Output")
interest(1)
menu(aoOIF)
}
field(PREC,DBF_SHORT) {
prompt("Display Precision")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(LINR,DBF_MENU) {
prompt("Linearization")
promptgroup("60 - Convert")
special(SPC_LINCONV)
pp(TRUE)
interest(1)
menu(menuConvert)
}
field(EGUF,DBF_DOUBLE) {
prompt("Eng Units Full")
promptgroup("60 - Convert")
special(SPC_LINCONV)
pp(TRUE)
interest(1)
}
field(EGUL,DBF_DOUBLE) {
prompt("Eng Units Low")
promptgroup("60 - Convert")
special(SPC_LINCONV)
pp(TRUE)
interest(1)
}
field(EGU,DBF_STRING) {
prompt("Engineering Units")
promptgroup("80 - Display")
interest(1)
size(16)
prop(YES)
}
field(ROFF,DBF_ULONG) {
prompt("Raw Offset")
pp(TRUE)
interest(2)
}
field(EOFF,DBF_DOUBLE) {
prompt("EGU to Raw Offset")
promptgroup("60 - Convert")
pp(TRUE)
interest(2)
}
field(ESLO,DBF_DOUBLE) {
prompt("EGU to Raw Slope")
promptgroup("60 - Convert")
pp(TRUE)
interest(2)
initial("1")
}
field(DRVH,DBF_DOUBLE) {
prompt("Drive High Limit")
promptgroup("30 - Action")
pp(TRUE)
interest(1)
prop(YES)
}
field(DRVL,DBF_DOUBLE) {
prompt("Drive Low Limit")
promptgroup("30 - Action")
pp(TRUE)
interest(1)
prop(YES)
}
field(HOPR,DBF_DOUBLE) {
prompt("High Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(LOPR,DBF_DOUBLE) {
prompt("Low Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(AOFF,DBF_DOUBLE) {
prompt("Adjustment Offset")
promptgroup("60 - Convert")
pp(TRUE)
interest(1)
}
field(ASLO,DBF_DOUBLE) {
prompt("Adjustment Slope")
promptgroup("60 - Convert")
pp(TRUE)
interest(1)
}
field(HIHI,DBF_DOUBLE) {
prompt("Hihi Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(LOLO,DBF_DOUBLE) {
prompt("Lolo Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(HIGH,DBF_DOUBLE) {
prompt("High Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(LOW,DBF_DOUBLE) {
prompt("Low Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(HHSV,DBF_MENU) {
prompt("Hihi Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(LLSV,DBF_MENU) {
prompt("Lolo Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(HSV,DBF_MENU) {
prompt("High Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(LSV,DBF_MENU) {
prompt("Low Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(HYST,DBF_DOUBLE) {
prompt("Alarm Deadband")
promptgroup("70 - Alarm")
interest(1)
}
field(ADEL,DBF_DOUBLE) {
prompt("Archive Deadband")
promptgroup("80 - Display")
interest(1)
}
field(MDEL,DBF_DOUBLE) {
prompt("Monitor Deadband")
promptgroup("80 - Display")
interest(1)
}
field(RVAL,DBF_LONG) {
prompt("Current Raw Value")
pp(TRUE)
}
field(ORAW,DBF_LONG) {
prompt("Previous Raw Value")
special(SPC_NOMOD)
interest(3)
}
field(RBV,DBF_LONG) {
prompt("Readback Value")
special(SPC_NOMOD)
}
field(ORBV,DBF_LONG) {
prompt("Prev Readback Value")
special(SPC_NOMOD)
interest(3)
}
field(PVAL,DBF_DOUBLE) {
prompt("Previous value")
special(SPC_NOMOD)
interest(3)
}
field(LALM,DBF_DOUBLE) {
prompt("Last Value Alarmed")
special(SPC_NOMOD)
interest(3)
}
field(ALST,DBF_DOUBLE) {
prompt("Last Value Archived")
special(SPC_NOMOD)
interest(3)
}
field(MLST,DBF_DOUBLE) {
prompt("Last Val Monitored")
special(SPC_NOMOD)
interest(3)
}
field(PBRK,DBF_NOACCESS) {
prompt("Ptrto brkTable")
special(SPC_NOMOD)
interest(4)
extra("void * pbrk")
}
field(INIT,DBF_SHORT) {
prompt("Initialized?")
special(SPC_NOMOD)
interest(3)
}
field(LBRK,DBF_SHORT) {
prompt("LastBreak Point")
special(SPC_NOMOD)
interest(3)
}
field(SIOL,DBF_OUTLINK) {
prompt("Simulation Output Link")
promptgroup("90 - Simulate")
interest(1)
}
field(SIML,DBF_INLINK) {
prompt("Simulation Mode Link")
promptgroup("90 - Simulate")
interest(1)
}
field(SIMM,DBF_MENU) {
prompt("Simulation Mode")
special(SPC_MOD)
interest(1)
menu(menuYesNo)
}
field(SIMS,DBF_MENU) {
prompt("Simulation Mode Severity")
promptgroup("90 - Simulate")
interest(2)
menu(menuAlarmSevr)
}
field(OLDSIMM,DBF_MENU) {
prompt("Prev. Simulation Mode")
special(SPC_NOMOD)
interest(4)
menu(menuSimm)
}
field(SSCN,DBF_MENU) {
prompt("Sim. Mode Scan")
promptgroup("90 - Simulate")
interest(1)
menu(menuScan)
initial("65535")
}
field(SDLY,DBF_DOUBLE) {
prompt("Sim. Mode Async Delay")
promptgroup("90 - Simulate")
interest(2)
initial("-1.0")
}
%#include "callback.h"
field(SIMPVT,DBF_NOACCESS) {
prompt("Sim. Mode Private")
special(SPC_NOMOD)
interest(4)
extra("CALLBACK *simpvt")
}
field(IVOA,DBF_MENU) {
prompt("INVALID output action")
promptgroup("50 - Output")
interest(2)
menu(menuIvoa)
}
field(IVOV,DBF_DOUBLE) {
prompt("INVALID output value")
promptgroup("50 - Output")
interest(2)
}
field(OMOD,DBF_UCHAR) {
prompt("Was OVAL modified?")
special(SPC_NOMOD)
}
}
=head2 Record Support
=head3 Record Support Routines
The following are the record support routines that would be of interest
to an application developer. Other routines are the get_units,
get_precision, get_graphic_double, and get_control_double routines.
=over
=item init_record
This routine initializes SIMM if SIML is a constant or creates a
channel access link if SIML is PV_LINK. If SIOL is PV_LINK a channel
access link is created.
This routine next checks to see that device support is available. If
DOL is a constant, then VAL is initialized with its value and UDF is
set to FALSE.
The routine next checks to see if the device support write routine is
defined. If either device support or the device support write routine
does not exist, an error message is issued and processing is
terminated.
For compatibility with old device supports that don't know EOFF, if
both EOFF and ESLO have their default value, EOFF is set to EGUL.
If device support includes init_record, it is called.
INIT is set TRUE. This causes PBRK, LBRK, and smoothing to be
re-initialized. If "backwards" linear conversion is requested, then VAL
is computed from RVAL using the algorithm:
VAL = ((RVAL+ROFF) * ASLO + AOFF) * ESLO + EOFF
and UDF is set to FALSE.
For breakpoint conversion, a call is made to cvtEngToRawBpt and UDF is
then set to FALSE. PVAL is set to VAL.
=item process
See next section.
=item special
The only special processing for analog output records is SPC_LINCONV
which is invoked whenever either of the fields LINR, EGUF, EGUL or ROFF
is changed If the device support routine special_linconv exists it is
called.
INIT is set TRUE. This causes PBRK, LBRK, and smoothing to be
re-initialized.
=item get_value
Fills in the values of struct valueDes so that they refer to VAL.
=item get_alarm_double
Sets the following values:
upper_alarm_limit = HIHI
upper_warning_limit = HIGH
lower_warning_limit = LOW
lower_alarm_limit = LOLO
=back
=head3 Record Processing
Routine process implements the following algorithm:
=over
=item 1. Check to see that the appropriate device support module
exists. If it doesn't, an error message is issued and processing is
terminated with the PACT field set to TRUE. This ensures that processes
will no longer be called for this record. Thus error storms will not
occur.
=item 2. Check PACT: If PACT is FALSE call fetch_values and convert
which perform the following steps:
=over
=item * fetch_values:
=over
=item * if DOL is DB_LINK and OMSL is CLOSED_LOOP then get value from
DOL
=item * if OIF is INCREMENTAL then set value = value + VAL else value =
VAL
=back
=item * convert:
=over
=item * If Drive limits are defined force value to be within limits
=item * Set VAL equal to value
=item * Set UDF to FALSE.
=item * If OVAL is undefined set it equal to value
=item * If OROC is defined and not 0 make |value-OVAL| E<lt>=OROC
=item * Set OVAL equal to value
=item * Compute RVAL from OVAL. using linear or break point table
conversion. For linear conversions the algorithm is RVAL =
(OVAL-EOFF)/ESLO.
=item * For break point table conversion a call is made to
cvtEngToRawBpt.
=item * After that, for all conversion types AOFF, ASLO, and ROFF are
calculated in, using the formula RVAL = (RVAL -AOFF) / ASLO - ROFF.
=back
=back
=item 3. Check alarms: This routine checks to see if the new VAL causes
the alarm status and severity to change. If so, NSEV, NSTA and y are
set. It also honors the alarm hysteresis factor (HYST). Thus the value
must change by at least HYST before the alarm status and severity is
reduced.
=item 4. Check severity and write the new value. See Invalid Alarm
Output Action for details on how invalid alarms affect output records.
=item 5. If PACT has been changed to TRUE, the device support write
output routine has started but has not completed writing the new value.
In this case, the processing routine merely returns, leaving PACT TRUE.
=item 6. Check to see if monitors should be invoked:
=over
=item * Alarm monitors are invoked if the alarm status or severity has
changed.
=item * Archive and value change monitors are invoked if ADEL and MDEL
conditions are met.
=item * Monitors for RVAL and for RBV are checked whenever other
monitors are invoked.
=item * NSEV and NSTA are reset to 0.
=back
=item 7. Scan forward link if necessary, set PACT and INIT FALSE, and
return.
=back
=head2 Device Support
=head3 Fields Of Interest To Device Support
Each analog output record must have an associated set of device support
routines. The primary responsibility of the device support routines is
to output a new value whenever write_ao is called. The device support
routines are primarily interested in the following fields:
=over
=item *
PACT E<mdash> Process Active, used to indicate asynchronous completion
=item *
DPVT E<mdash> Device Private, reserved for device support to use
=item *
OUT E<mdash> Output Link, provides addressing information
=item *
EGUF E<mdash> Engineering Units Full
=item *
EGUL E<mdash> Engineering Units Low
=item *
ESLO E<mdash> Engineering Unit Slope
=item *
EOFF E<mdash> Engineering Unit Offset
=item *
OVAL E<mdash> Output Value, in Engineering units
=item *
RVAL E<mdash> Raw Output Value, after conversion
=back
=head3 Device Support routines
Device support consists of the following routines:
=over
=item C<long report(int level)>
This optional routine is called by the IOC command C<dbior> and is passed the
report level that was requested by the user.
It should print a report on the state of the device support to stdout.
The C<level> parameter may be used to output increasingly more detailed
information at higher levels, or to select different types of information with
different levels.
Level zero should print no more than a small summary.
=item C<long init(int after)>
This optional routine is called twice at IOC initialization time.
The first call happens before any of the C<init_record()> calls are made, with
the integer parameter C<after> set to 0.
The second call happens after all of the C<init_record()> calls have been made,
with C<after> set to 1.
=item C<long init_record(aoRecord *prec)>
This optional routine is called by the record initialization code for each ao
record instance that has its DTYP field set to use this device support.
It is normally used to check that the OUT address has the expected type and
points to a valid device; to allocate any record-specific buffer space and
other memory; and to connect any communication channels needed for the
C<write_ao()> routine to work properly.
If the record type's unit conversion features are used, the C<init_record()>
routine should calculate appropriate values for the ESLO and EOFF fields from
the EGUL and EGUF field values.
This calculation only has to be performed if the record's LINR field is set to
C<LINEAR>, but it is not necessary to check that condition first.
This same calculation takes place in the C<special_linconv()> routine, so the
implementation can usually just call that routine to perform the task.
If the the last output value can be read back from the hardware, this routine
should also fetch that value and put it into the record's RVAL or VAL field. The
return value should be zero if the RVAL field has been set, or 2 if either the
VAL field has been set or if the last output value cannot be retrieved.
=item C<long get_ioint_info(int cmd, aoRecord *prec, IOSCANPVT *piosl)>
This optional routine is called whenever the record's SCAN field is being
changed to or from the value C<I/O Intr> to find out which I/O Interrupt Scan
list the record should be added to or deleted from.
If this routine is not provided, it will not be possible to set the SCAN field
to the value C<I/O Intr> at all.
The C<cmd> parameter is zero when the record is being added to the scan list,
and one when it is being removed from the list.
The routine must determine which interrupt source the record should be connected
to, which it indicates by the scan list that it points the location at C<*piosl>
to before returning.
It can prevent the SCAN field from being changed at all by returning a non-zero
value to its caller.
In most cases the device support will create the I/O Interrupt Scan lists that
it returns for itself, by calling C<void scanIoInit(IOSCANPVT *piosl)> once for
each separate interrupt source.
That API allocates memory and inializes the list, then passes back a pointer to
the new list in the location at C<*piosl>.
When the device support receives notification that the interrupt has occurred,
it announces that to the IOC by calling C<void scanIoRequest(IOSCANPVT iosl)>
which will arrange for the appropriate records to be processed in a suitable
thread.
The C<scanIoRequest()> routine is safe to call from an interrupt service routine
on embedded architectures (vxWorks and RTEMS).
=item C<long write_ao(aoRecord *prec)>
This essential routine is called whenever the record has a new output value to
send to the device. It is responsible for performing the write operation, using
either the engineering units value found in the record's OVAL field, or the raw
value from the record's RVAL field if the record type's unit conversion
facilities are used. A return value of zero indicates success, any other value
indicates that an error occurred.
This routine must not block (busy-wait) if the device takes more than a few
microseconds to accept the new value. In that case the routine must use
asynchronous completion to tell the record when the write operation eventually
completes. It signals that this is an asynchronous operation by setting the
record's PACT field to TRUE before it returns, having arranged for the record's
C<process()> routine to be called later once the write operation is over. When
that happens the C<write_ao()> routine will be called again with PACT still set
to TRUE; it should then set it to FALSE to indicate the write has completed, and
return.
=item C<long special_linconv(aoRecord *prec, int after)>
This optional routine should be provided if the record type's unit conversion
features are used by the device support's C<write_ao()> routine utilizing the
RVAL field rather than OVAL or VAL.
It is called by the record code whenever any of the the fields LINR, EGUL or
EGUF are modified and LINR has the value C<LINEAR>.
The routine must calculate and set the fields EOFF and ESLO appropriately based
on the new values of EGUL and EGUF.
These calculations can be expressed in terms of the minimum and maximum raw
values that the C<write_ao()> routine can accept in the RVAL field.
When VAL is EGUF the RVAL field will be set to I<RVAL_max>, and when VAL is
EGUL the RVAL field will become I<RVAL_min>.
The fomulae to use are:
=over
EOFF = (I<RVAL_max> * EGUL E<minus> I<RVAL_min> * EGUF) /
(I<RVAL_max> E<minus> I<RVAL_min>)
ESLO = (EGUF E<minus> EGUL) / (I<RVAL_max> E<minus> I<RVAL_min>)
=back
Note that the record support sets EOFF to EGUL before calling this routine,
which is a very common case (I<RVAL_min> is zero).
=back
=head2 Device Support For Soft Records
Two soft device support modules Soft Channel and Raw Soft Channel are
provided for output records not related to actual hardware devices. The
OUT link type must be either a CONSTANT, DB_LINK, or CA_LINK.
=head3 Soft Channel
This module writes the current value of OVAL.
If the OUT link type is PV_LINK, then dbCaAddInlink is called by
init_record. init_record always returns a value of 2, which means that
no conversion will ever be attempted.
write_ao calls recGblPutLinkValue to write the current value of VAL.
See Soft Output for details.
=head3 Raw Soft Channel
This module is like the previous except that it writes the current
value of RVAL.
=cut
+324
View File
@@ -0,0 +1,324 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* recBi.c - Record Support Routines for Binary Input records */
/*
* Original Author: Bob Dalesio
* Date: 7-14-89
*
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "dbDefs.h"
#include "epicsPrint.h"
#include "alarm.h"
#include "callback.h"
#include "dbAccess.h"
#include "dbFldTypes.h"
#include "dbEvent.h"
#include "devSup.h"
#include "errMdef.h"
#include "menuSimm.h"
#include "recSup.h"
#include "recGbl.h"
#include "special.h"
#define GEN_SIZE_OFFSET
#include "biRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
static long special(DBADDR *, int);
#define get_value NULL
#define cvt_dbaddr NULL
#define get_array_info NULL
#define put_array_info NULL
#define get_units NULL
#define get_precision NULL
static long get_enum_str(const DBADDR *, char *);
static long get_enum_strs(const DBADDR *, struct dbr_enumStrs *);
static long put_enum_str(const DBADDR *, const char *);
#define get_graphic_double NULL
#define get_control_double NULL
#define get_alarm_double NULL
rset biRSET={
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double };
struct bidset { /* binary input dset */
long number;
DEVSUPFUN dev_report;
DEVSUPFUN init;
DEVSUPFUN init_record; /*returns: (-1,0)=>(failure,success)*/
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_bi;/*(0,2)=> success and convert, don't convert)*/
/* if convert then raw value stored in rval */
};
epicsExportAddress(rset,biRSET);
static void checkAlarms(biRecord *);
static void monitor(biRecord *);
static long readValue(biRecord *);
static long init_record(struct dbCommon *pcommon, int pass)
{
struct biRecord *prec = (struct biRecord *)pcommon;
struct bidset *pdset;
long status;
if (pass == 0) return 0;
recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
recGblInitConstantLink(&prec->siol, DBF_USHORT, &prec->sval);
if(!(pdset = (struct bidset *)(prec->dset))) {
recGblRecordError(S_dev_noDSET,(void *)prec,"bi: init_record");
return(S_dev_noDSET);
}
/* must have read_bi function defined */
if( (pdset->number < 5) || (pdset->read_bi == NULL) ) {
recGblRecordError(S_dev_missingSup,(void *)prec,"bi: init_record");
return(S_dev_missingSup);
}
if( pdset->init_record ) {
if((status=(*pdset->init_record)(prec))) return(status);
}
prec->mlst = prec->val;
prec->lalm = prec->val;
prec->oraw = prec->rval;
return(0);
}
static long process(struct dbCommon *pcommon)
{
struct biRecord *prec = (struct biRecord *)pcommon;
struct bidset *pdset = (struct bidset *)(prec->dset);
long status;
unsigned char pact=prec->pact;
if( (pdset==NULL) || (pdset->read_bi==NULL) ) {
prec->pact=TRUE;
recGblRecordError(S_dev_missingSup,(void *)prec,"read_bi");
return(S_dev_missingSup);
}
status=readValue(prec); /* read the new value */
/* check if device support set pact */
if ( !pact && prec->pact ) return(0);
prec->pact = TRUE;
recGblGetTimeStampSimm(prec, prec->simm, &prec->siol);
if(status==0) { /* convert rval to val */
if(prec->rval==0) prec->val =0;
else prec->val = 1;
prec->udf = FALSE;
}
else if(status==2) status=0;
/* check for alarms */
checkAlarms(prec);
/* check event list */
monitor(prec);
/* process the forward scan link record */
recGblFwdLink(prec);
prec->pact=FALSE;
return(status);
}
static long special(DBADDR *paddr, int after)
{
biRecord *prec = (biRecord *)(paddr->precord);
int special_type = paddr->special;
switch(special_type) {
case(SPC_MOD):
if (dbGetFieldIndex(paddr) == biRecordSIMM) {
if (!after)
recGblSaveSimm(prec->sscn, &prec->oldsimm, prec->simm);
else
recGblCheckSimm((dbCommon *)prec, &prec->sscn, prec->oldsimm, prec->simm);
return(0);
}
default:
recGblDbaddrError(S_db_badChoice, paddr, "bi: special");
return(S_db_badChoice);
}
}
static long get_enum_str(const DBADDR *paddr, char *pstring)
{
biRecord *prec=(biRecord *)paddr->precord;
int index;
unsigned short *pfield = (unsigned short *)paddr->pfield;
index = dbGetFieldIndex(paddr);
if(index!=biRecordVAL) {
strcpy(pstring,"Illegal_Value");
} else if(*pfield==0) {
strncpy(pstring,prec->znam,sizeof(prec->znam));
pstring[sizeof(prec->znam)] = 0;
} else if(*pfield==1) {
strncpy(pstring,prec->onam,sizeof(prec->onam));
pstring[sizeof(prec->onam)] = 0;
} else {
strcpy(pstring,"Illegal_Value");
}
return(0);
}
static long get_enum_strs(const DBADDR *paddr,struct dbr_enumStrs *pes)
{
biRecord *prec=(biRecord *)paddr->precord;
pes->no_str = 2;
memset(pes->strs,'\0',sizeof(pes->strs));
strncpy(pes->strs[0],prec->znam,sizeof(prec->znam));
if(*prec->znam!=0) pes->no_str=1;
strncpy(pes->strs[1],prec->onam,sizeof(prec->onam));
if(*prec->onam!=0) pes->no_str=2;
return(0);
}
static long put_enum_str(const DBADDR *paddr, const char *pstring)
{
biRecord *prec=(biRecord *)paddr->precord;
if(strncmp(pstring,prec->znam,sizeof(prec->znam))==0) prec->val = 0;
else if(strncmp(pstring,prec->onam,sizeof(prec->onam))==0) prec->val = 1;
else return(S_db_badChoice);
prec->udf=FALSE;
return(0);
}
static void checkAlarms(biRecord *prec)
{
unsigned short val = prec->val;
if(prec->udf == TRUE){
recGblSetSevr(prec,UDF_ALARM,prec->udfs);
return;
}
if(val>1)return;
/* check for state alarm */
if (val == 0){
recGblSetSevr(prec,STATE_ALARM,prec->zsv);
}else{
recGblSetSevr(prec,STATE_ALARM,prec->osv);
}
/* check for cos alarm */
if(val == prec->lalm) return;
recGblSetSevr(prec,COS_ALARM,prec->cosv);
prec->lalm = val;
return;
}
static void monitor(biRecord *prec)
{
unsigned short monitor_mask;
monitor_mask = recGblResetAlarms(prec);
/* check for value change */
if (prec->mlst != prec->val){
/* post events for value change and archive change */
monitor_mask |= (DBE_VALUE | DBE_LOG);
/* update last value monitored */
prec->mlst = prec->val;
}
/* send out monitors connected to the value field */
if (monitor_mask){
db_post_events(prec,&prec->val,monitor_mask);
}
if(prec->oraw!=prec->rval) {
db_post_events(prec,&prec->rval,
monitor_mask|DBE_VALUE|DBE_LOG);
prec->oraw = prec->rval;
}
return;
}
static long readValue(biRecord *prec)
{
struct bidset *pdset = (struct bidset *)prec->dset;
long status = 0;
if (!prec->pact) {
status = recGblGetSimm((dbCommon *)prec, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
if (status) return status;
}
switch (prec->simm) {
case menuSimmNO:
status = pdset->read_bi(prec);
break;
case menuSimmYES:
case menuSimmRAW: {
recGblSetSevr(prec, SIMM_ALARM, prec->sims);
if (prec->pact || (prec->sdly < 0.)) {
status = dbGetLink(&prec->siol, DBR_ULONG, &prec->sval, 0, 0);
if (status == 0) {
if (prec->simm == menuSimmYES) {
prec->val = prec->sval;
status = 2; /* Don't convert */
} else {
prec->rval = (unsigned short) prec->sval;
}
prec->udf = FALSE;
}
prec->pact = FALSE;
} else { /* !prec->pact && delay >= 0. */
CALLBACK *pvt = prec->simpvt;
if (!pvt) {
pvt = calloc(1, sizeof(CALLBACK)); /* very lazy allocation of callback structure */
prec->simpvt = pvt;
}
if (pvt) callbackRequestProcessCallbackDelayed(pvt, prec->prio, prec, prec->sdly);
prec->pact = TRUE;
}
break;
}
default:
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
status = -1;
}
return status;
}
+134
View File
@@ -0,0 +1,134 @@
#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
recordtype(bi) {
include "dbCommon.dbd"
field(INP,DBF_INLINK) {
prompt("Input Specification")
promptgroup("40 - Input")
interest(1)
}
field(VAL,DBF_ENUM) {
prompt("Current Value")
promptgroup("40 - Input")
asl(ASL0)
pp(TRUE)
}
field(ZSV,DBF_MENU) {
prompt("Zero Error Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
menu(menuAlarmSevr)
}
field(OSV,DBF_MENU) {
prompt("One Error Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
menu(menuAlarmSevr)
}
field(COSV,DBF_MENU) {
prompt("Change of State Svr")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
menu(menuAlarmSevr)
}
field(ZNAM,DBF_STRING) {
prompt("Zero Name")
promptgroup("80 - Display")
pp(TRUE)
interest(1)
size(26)
prop(YES)
}
field(ONAM,DBF_STRING) {
prompt("One Name")
promptgroup("80 - Display")
pp(TRUE)
interest(1)
size(26)
prop(YES)
}
field(RVAL,DBF_ULONG) {
prompt("Raw Value")
pp(TRUE)
}
field(ORAW,DBF_ULONG) {
prompt("prev Raw Value")
special(SPC_NOMOD)
interest(3)
}
field(MASK,DBF_ULONG) {
prompt("Hardware Mask")
special(SPC_NOMOD)
interest(1)
}
field(LALM,DBF_USHORT) {
prompt("Last Value Alarmed")
special(SPC_NOMOD)
interest(3)
}
field(MLST,DBF_USHORT) {
prompt("Last Value Monitored")
special(SPC_NOMOD)
interest(3)
}
field(SIOL,DBF_INLINK) {
prompt("Simulation Input Link")
promptgroup("90 - Simulate")
interest(1)
}
field(SVAL,DBF_ULONG) {
prompt("Simulation Value")
}
field(SIML,DBF_INLINK) {
prompt("Simulation Mode Link")
promptgroup("90 - Simulate")
interest(1)
}
field(SIMM,DBF_MENU) {
prompt("Simulation Mode")
special(SPC_MOD)
interest(1)
menu(menuSimm)
}
field(SIMS,DBF_MENU) {
prompt("Simulation Mode Severity")
promptgroup("90 - Simulate")
interest(2)
menu(menuAlarmSevr)
}
field(OLDSIMM,DBF_MENU) {
prompt("Prev. Simulation Mode")
special(SPC_NOMOD)
interest(4)
menu(menuSimm)
}
field(SSCN,DBF_MENU) {
prompt("Sim. Mode Scan")
promptgroup("90 - Simulate")
interest(1)
menu(menuScan)
initial("65535")
}
field(SDLY,DBF_DOUBLE) {
prompt("Sim. Mode Async Delay")
promptgroup("90 - Simulate")
interest(2)
initial("-1.0")
}
%#include "callback.h"
field(SIMPVT,DBF_NOACCESS) {
prompt("Sim. Mode Private")
special(SPC_NOMOD)
interest(4)
extra("CALLBACK *simpvt")
}
}
+459
View File
@@ -0,0 +1,459 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* recBo.c - Record Support Routines for Binary Output records */
/*
* Original Author: Bob Dalesio
* Date: 7-14-89
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "dbDefs.h"
#include "epicsPrint.h"
#include "alarm.h"
#include "callback.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "dbFldTypes.h"
#include "devSup.h"
#include "errMdef.h"
#include "recSup.h"
#include "recGbl.h"
#include "special.h"
#include "menuIvoa.h"
#include "menuOmsl.h"
#include "menuYesNo.h"
#define GEN_SIZE_OFFSET
#include "boRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
static long special(DBADDR *, int);
#define get_value NULL
#define cvt_dbaddr NULL
#define get_array_info NULL
#define put_array_info NULL
static long get_units(DBADDR *, char *);
static long get_precision(const DBADDR *, long *);
static long get_enum_str(const DBADDR *, char *);
static long get_enum_strs(const DBADDR *, struct dbr_enumStrs *);
static long put_enum_str(const DBADDR *, const char *);
#define get_graphic_double NULL
static long get_control_double(DBADDR *, struct dbr_ctrlDouble *);
#define get_alarm_double NULL
rset boRSET={
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double
};
epicsExportAddress(rset,boRSET);
int boHIGHprecision = 2;
epicsExportAddress(int, boHIGHprecision);
double boHIGHlimit = 100000;
epicsExportAddress(double, boHIGHlimit);
struct bodset { /* binary output dset */
long number;
DEVSUPFUN dev_report;
DEVSUPFUN init;
DEVSUPFUN init_record; /*returns:(0,2)=>(success,success no convert*/
DEVSUPFUN get_ioint_info;
DEVSUPFUN write_bo;/*returns: (-1,0)=>(failure,success)*/
};
/* control block for callback*/
typedef struct myCallback {
CALLBACK callback;
struct dbCommon *precord;
}myCallback;
static void checkAlarms(boRecord *);
static void monitor(boRecord *);
static long writeValue(boRecord *);
static void myCallbackFunc(CALLBACK *arg)
{
myCallback *pcallback;
boRecord *prec;
callbackGetUser(pcallback,arg);
prec=(boRecord *)pcallback->precord;
dbScanLock((struct dbCommon *)prec);
if(prec->pact) {
if((prec->val==1) && (prec->high>0)){
myCallback *pcallback;
pcallback = (myCallback *)(prec->rpvt);
callbackSetPriority(prec->prio, &pcallback->callback);
callbackRequestDelayed(&pcallback->callback,(double)prec->high);
}
} else {
prec->val = 0;
dbProcess((struct dbCommon *)prec);
}
dbScanUnlock((struct dbCommon *)prec);
}
static long init_record(struct dbCommon *pcommon,int pass)
{
struct boRecord *prec = (struct boRecord *)pcommon;
struct bodset *pdset = (struct bodset *) prec->dset;
unsigned short ival = 0;
long status = 0;
myCallback *pcallback;
if (pass == 0) return 0;
recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
if (!pdset) {
recGblRecordError(S_dev_noDSET, prec, "bo: init_record");
return S_dev_noDSET;
}
/* must have write_bo functions defined */
if ((pdset->number < 5) || (pdset->write_bo == NULL)) {
recGblRecordError(S_dev_missingSup, prec, "bo: init_record");
return S_dev_missingSup;
}
/* get the initial value */
if (recGblInitConstantLink(&prec->dol, DBF_USHORT, &ival)) {
prec->val = !!ival;
prec->udf = FALSE;
}
pcallback = (myCallback *) calloc(1, sizeof(myCallback));
prec->rpvt = pcallback;
callbackSetCallback(myCallbackFunc, &pcallback->callback);
callbackSetUser(pcallback, &pcallback->callback);
pcallback->precord = (struct dbCommon *) prec;
if (pdset->init_record) {
status=(*pdset->init_record)(prec);
if(status==0) {
if(prec->rval==0) prec->val = 0;
else prec->val = 1;
prec->udf = FALSE;
} else if (status==2) status=0;
}
prec->mlst = prec->val;
/* convert val to rval */
if ( prec->mask != 0 ) {
if(prec->val==0) prec->rval = 0;
else prec->rval = prec->mask;
} else prec->rval = (epicsUInt32)prec->val;
prec->mlst = prec->val;
prec->lalm = prec->val;
prec->oraw = prec->rval;
prec->orbv = prec->rbv;
return(status);
}
static long process(struct dbCommon *pcommon)
{
struct boRecord *prec = (struct boRecord *)pcommon;
struct bodset *pdset = (struct bodset *)(prec->dset);
long status=0;
unsigned char pact=prec->pact;
if( (pdset==NULL) || (pdset->write_bo==NULL) ) {
prec->pact=TRUE;
recGblRecordError(S_dev_missingSup,(void *)prec,"write_bo");
return(S_dev_missingSup);
}
if (!prec->pact) {
if (!dbLinkIsConstant(&prec->dol) &&
prec->omsl == menuOmslclosed_loop) {
unsigned short val;
prec->pact = TRUE;
status=dbGetLink(&prec->dol,DBR_USHORT, &val,0,0);
prec->pact = FALSE;
if(status==0){
prec->val = val;
prec->udf = FALSE;
}else {
recGblSetSevr(prec,LINK_ALARM,INVALID_ALARM);
}
}
/* convert val to rval */
if ( prec->mask != 0 ) {
if(prec->val==0) prec->rval = 0;
else prec->rval = prec->mask;
} else prec->rval = (epicsUInt32)prec->val;
}
/* check for alarms */
checkAlarms(prec);
if (prec->nsev < INVALID_ALARM )
status=writeValue(prec); /* write the new value */
else {
switch (prec->ivoa) {
case (menuIvoaContinue_normally) :
status=writeValue(prec); /* write the new value */
break;
case (menuIvoaDon_t_drive_outputs) :
break;
case (menuIvoaSet_output_to_IVOV) :
if(prec->pact == FALSE){
/* convert val to rval */
prec->val=prec->ivov;
if ( prec->mask != 0 ) {
if(prec->val==0) prec->rval = 0;
else prec->rval = prec->mask;
} else prec->rval = (epicsUInt32)prec->val;
}
status=writeValue(prec); /* write the new value */
break;
default :
status=-1;
recGblRecordError(S_db_badField,(void *)prec,
"bo:process Illegal IVOA field");
}
}
/* check if device support set pact */
if ( !pact && prec->pact ) return(0);
prec->pact = TRUE;
recGblGetTimeStampSimm(prec, prec->simm, NULL);
if((prec->val==1) && (prec->high>0)){
myCallback *pcallback;
pcallback = (myCallback *)(prec->rpvt);
callbackSetPriority(prec->prio, &pcallback->callback);
callbackRequestDelayed(&pcallback->callback,(double)prec->high);
}
/* check event list */
monitor(prec);
/* process the forward scan link record */
recGblFwdLink(prec);
prec->pact=FALSE;
return(status);
}
static long special(DBADDR *paddr, int after)
{
boRecord *prec = (boRecord *)(paddr->precord);
int special_type = paddr->special;
switch(special_type) {
case(SPC_MOD):
if (dbGetFieldIndex(paddr) == boRecordSIMM) {
if (!after)
recGblSaveSimm(prec->sscn, &prec->oldsimm, prec->simm);
else
recGblCheckSimm((dbCommon *)prec, &prec->sscn, prec->oldsimm, prec->simm);
return(0);
}
default:
recGblDbaddrError(S_db_badChoice, paddr, "bo: special");
return(S_db_badChoice);
}
}
#define indexof(field) boRecord##field
static long get_units(DBADDR *paddr, char *units)
{
if(dbGetFieldIndex(paddr) == indexof(HIGH))
strcpy(units, "s");
return(0);
}
static long get_precision(const DBADDR *paddr, long *precision)
{
if(dbGetFieldIndex(paddr) == indexof(HIGH))
*precision = boHIGHprecision;
else
recGblGetPrec(paddr,precision);
return(0);
}
static long get_control_double(DBADDR *paddr,struct dbr_ctrlDouble *pcd)
{
if(dbGetFieldIndex(paddr) == indexof(HIGH)) {
pcd->lower_ctrl_limit = 0.0;
pcd->upper_ctrl_limit = boHIGHlimit;
} else
recGblGetControlDouble(paddr,pcd);
return(0);
}
static long get_enum_str(const DBADDR *paddr, char *pstring)
{
boRecord *prec=(boRecord *)paddr->precord;
int index;
unsigned short *pfield = (unsigned short *)paddr->pfield;
index = dbGetFieldIndex(paddr);
if(index!=indexof(VAL)) {
strcpy(pstring,"Illegal_Value");
} else if(*pfield==0) {
strncpy(pstring,prec->znam,sizeof(prec->znam));
pstring[sizeof(prec->znam)] = 0;
} else if(*pfield==1) {
strncpy(pstring,prec->onam,sizeof(prec->onam));
pstring[sizeof(prec->onam)] = 0;
} else {
strcpy(pstring,"Illegal_Value");
}
return(0);
}
static long get_enum_strs(const DBADDR *paddr,struct dbr_enumStrs *pes)
{
boRecord *prec=(boRecord *)paddr->precord;
/*SETTING no_str=0 breaks channel access clients*/
pes->no_str = 2;
memset(pes->strs,'\0',sizeof(pes->strs));
strncpy(pes->strs[0],prec->znam,sizeof(prec->znam));
if(*prec->znam!=0) pes->no_str=1;
strncpy(pes->strs[1],prec->onam,sizeof(prec->onam));
if(*prec->onam!=0) pes->no_str=2;
return(0);
}
static long put_enum_str(const DBADDR *paddr, const char *pstring)
{
boRecord *prec=(boRecord *)paddr->precord;
if(strncmp(pstring,prec->znam,sizeof(prec->znam))==0) prec->val = 0;
else if(strncmp(pstring,prec->onam,sizeof(prec->onam))==0) prec->val = 1;
else return(S_db_badChoice);
return(0);
}
static void checkAlarms(boRecord *prec)
{
unsigned short val = prec->val;
/* check for udf alarm */
if(prec->udf == TRUE ){
recGblSetSevr(prec,UDF_ALARM,prec->udfs);
}
/* check for state alarm */
if (val == 0){
recGblSetSevr(prec,STATE_ALARM,prec->zsv);
}else{
recGblSetSevr(prec,STATE_ALARM,prec->osv);
}
/* check for cos alarm */
if(val == prec->lalm) return;
recGblSetSevr(prec,COS_ALARM,prec->cosv);
prec->lalm = val;
return;
}
static void monitor(boRecord *prec)
{
unsigned short monitor_mask;
monitor_mask = recGblResetAlarms(prec);
/* check for value change */
if (prec->mlst != prec->val){
/* post events for value change and archive change */
monitor_mask |= (DBE_VALUE | DBE_LOG);
/* update last value monitored */
prec->mlst = prec->val;
}
/* send out monitors connected to the value field */
if (monitor_mask){
db_post_events(prec,&prec->val,monitor_mask);
}
if(prec->oraw!=prec->rval) {
db_post_events(prec,&prec->rval,
monitor_mask|DBE_VALUE|DBE_LOG);
prec->oraw = prec->rval;
}
if(prec->orbv!=prec->rbv) {
db_post_events(prec,&prec->rbv,
monitor_mask|DBE_VALUE|DBE_LOG);
prec->orbv = prec->rbv;
}
return;
}
static long writeValue(boRecord *prec)
{
struct bodset *pdset = (struct bodset *) prec->dset;
long status = 0;
if (!prec->pact) {
status = recGblGetSimm((dbCommon *)prec, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
if (status) return status;
}
switch (prec->simm) {
case menuYesNoNO:
status = pdset->write_bo(prec);
break;
case menuYesNoYES: {
recGblSetSevr(prec, SIMM_ALARM, prec->sims);
if (prec->pact || (prec->sdly < 0.)) {
status = dbPutLink(&prec->siol, DBR_USHORT, &prec->val, 1);
prec->pact = FALSE;
} else { /* !prec->pact && delay >= 0. */
CALLBACK *pvt = prec->simpvt;
if (!pvt) {
pvt = calloc(1, sizeof(CALLBACK)); /* very lazy allocation of callback structure */
prec->simpvt = pvt;
}
if (pvt) callbackRequestProcessCallbackDelayed(pvt, prec->prio, prec, prec->sdly);
prec->pact = TRUE;
}
break;
}
default:
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
status = -1;
}
return status;
}
+182
View File
@@ -0,0 +1,182 @@
#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
recordtype(bo) {
include "dbCommon.dbd"
field(VAL,DBF_ENUM) {
prompt("Current Value")
promptgroup("50 - Output")
asl(ASL0)
pp(TRUE)
}
field(OMSL,DBF_MENU) {
prompt("Output Mode Select")
promptgroup("50 - Output")
interest(1)
menu(menuOmsl)
}
field(DOL,DBF_INLINK) {
prompt("Desired Output Loc")
promptgroup("40 - Input")
interest(1)
}
field(OUT,DBF_OUTLINK) {
prompt("Output Specification")
promptgroup("50 - Output")
interest(1)
}
field(HIGH,DBF_DOUBLE) {
prompt("Seconds to Hold High")
promptgroup("30 - Action")
interest(1)
}
field(ZNAM,DBF_STRING) {
prompt("Zero Name")
promptgroup("80 - Display")
pp(TRUE)
interest(1)
size(26)
prop(YES)
}
field(ONAM,DBF_STRING) {
prompt("One Name")
promptgroup("80 - Display")
pp(TRUE)
interest(1)
size(26)
prop(YES)
}
field(RVAL,DBF_ULONG) {
prompt("Raw Value")
pp(TRUE)
}
field(ORAW,DBF_ULONG) {
prompt("prev Raw Value")
special(SPC_NOMOD)
interest(3)
}
field(MASK,DBF_ULONG) {
prompt("Hardware Mask")
special(SPC_NOMOD)
interest(1)
}
field(RPVT,DBF_NOACCESS) {
prompt("Record Private")
special(SPC_NOMOD)
interest(4)
extra("void * rpvt")
}
field(WDPT,DBF_NOACCESS) {
prompt("Watch Dog Timer ID")
special(SPC_NOMOD)
interest(4)
extra("void * wdpt")
}
field(ZSV,DBF_MENU) {
prompt("Zero Error Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
menu(menuAlarmSevr)
}
field(OSV,DBF_MENU) {
prompt("One Error Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
menu(menuAlarmSevr)
}
field(COSV,DBF_MENU) {
prompt("Change of State Sevr")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
menu(menuAlarmSevr)
}
field(RBV,DBF_ULONG) {
prompt("Readback Value")
special(SPC_NOMOD)
}
field(ORBV,DBF_ULONG) {
prompt("Prev Readback Value")
special(SPC_NOMOD)
interest(3)
}
field(MLST,DBF_USHORT) {
prompt("Last Value Monitored")
special(SPC_NOMOD)
interest(3)
}
field(LALM,DBF_USHORT) {
prompt("Last Value Alarmed")
special(SPC_NOMOD)
interest(3)
}
field(SIOL,DBF_OUTLINK) {
prompt("Simulation Output Link")
promptgroup("90 - Simulate")
interest(1)
}
field(SIML,DBF_INLINK) {
prompt("Simulation Mode Link")
promptgroup("90 - Simulate")
interest(1)
}
field(SIMM,DBF_MENU) {
prompt("Simulation Mode")
special(SPC_MOD)
interest(1)
menu(menuYesNo)
}
field(SIMS,DBF_MENU) {
prompt("Simulation Mode Severity")
promptgroup("90 - Simulate")
interest(2)
menu(menuAlarmSevr)
}
field(OLDSIMM,DBF_MENU) {
prompt("Prev. Simulation Mode")
special(SPC_NOMOD)
interest(4)
menu(menuSimm)
}
field(SSCN,DBF_MENU) {
prompt("Sim. Mode Scan")
promptgroup("90 - Simulate")
interest(1)
menu(menuScan)
initial("65535")
}
field(SDLY,DBF_DOUBLE) {
prompt("Sim. Mode Async Delay")
promptgroup("90 - Simulate")
interest(2)
initial("-1.0")
}
%#include "callback.h"
field(SIMPVT,DBF_NOACCESS) {
prompt("Sim. Mode Private")
special(SPC_NOMOD)
interest(4)
extra("CALLBACK *simpvt")
}
field(IVOA,DBF_MENU) {
prompt("INVALID outpt action")
promptgroup("50 - Output")
interest(2)
menu(menuIvoa)
}
field(IVOV,DBF_USHORT) {
prompt("INVALID output value")
promptgroup("50 - Output")
interest(2)
}
}
variable(boHIGHprecision, int)
variable(boHIGHlimit, double)
+442
View File
@@ -0,0 +1,442 @@
/*************************************************************************\
* Copyright (c) 2007 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* Record Support Routines for Calculation records */
/*
* Original Author: Julie Sander and Bob Dalesio
* Date: 7-27-87
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "dbDefs.h"
#include "errlog.h"
#include "alarm.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "dbFldTypes.h"
#include "epicsMath.h"
#include "errMdef.h"
#include "recSup.h"
#include "recGbl.h"
#include "special.h"
#define GEN_SIZE_OFFSET
#include "calcRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
/* Hysterisis for alarm filtering: 1-1/e */
#define THRESHOLD 0.6321
/* Create RSET - Record Support Entry Table */
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *prec, int pass);
static long process(struct dbCommon *prec);
static long special(DBADDR *paddr, int after);
#define get_value NULL
#define cvt_dbaddr NULL
#define get_array_info NULL
#define put_array_info NULL
static long get_units(DBADDR *paddr, char *units);
static long get_precision(const DBADDR *paddr, long *precision);
#define get_enum_str NULL
#define get_enum_strs NULL
#define put_enum_str NULL
static long get_graphic_double(DBADDR *paddr, struct dbr_grDouble *pgd);
static long get_control_double(DBADDR *paddr, struct dbr_ctrlDouble *pcd);
static long get_alarm_double(DBADDR *paddr, struct dbr_alDouble *pad);
rset calcRSET={
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double
};
epicsExportAddress(rset, calcRSET);
static void checkAlarms(calcRecord *prec, epicsTimeStamp *timeLast);
static void monitor(calcRecord *prec);
static int fetch_values(calcRecord *prec);
static long init_record(struct dbCommon *pcommon, int pass)
{
struct calcRecord *prec = (struct calcRecord *)pcommon;
struct link *plink;
double *pvalue;
int i;
short error_number;
if (pass==0) return(0);
plink = &prec->inpa;
pvalue = &prec->a;
for (i = 0; i < CALCPERFORM_NARGS; i++, plink++, pvalue++) {
recGblInitConstantLink(plink, DBF_DOUBLE, pvalue);
}
if (postfix(prec->calc, prec->rpcl, &error_number)) {
recGblRecordError(S_db_badField, (void *)prec,
"calc: init_record: Illegal CALC field");
errlogPrintf("%s.CALC: %s in expression \"%s\"\n",
prec->name, calcErrorStr(error_number), prec->calc);
}
return 0;
}
static long process(struct dbCommon *pcommon)
{
struct calcRecord *prec = (struct calcRecord *)pcommon;
epicsTimeStamp timeLast;
prec->pact = TRUE;
if (fetch_values(prec) == 0) {
if (calcPerform(&prec->a, &prec->val, prec->rpcl)) {
recGblSetSevr(prec, CALC_ALARM, INVALID_ALARM);
} else
prec->udf = isnan(prec->val);
}
timeLast = prec->time;
recGblGetTimeStamp(prec);
/* check for alarms */
checkAlarms(prec, &timeLast);
/* check event list */
monitor(prec);
/* process the forward scan link record */
recGblFwdLink(prec);
prec->pact = FALSE;
return 0;
}
static long special(DBADDR *paddr, int after)
{
calcRecord *prec = (calcRecord *)paddr->precord;
short error_number;
if (!after) return 0;
if (paddr->special == SPC_CALC) {
if (postfix(prec->calc, prec->rpcl, &error_number)) {
recGblRecordError(S_db_badField, (void *)prec,
"calc: Illegal CALC field");
errlogPrintf("%s.CALC: %s in expression \"%s\"\n",
prec->name, calcErrorStr(error_number), prec->calc);
return S_db_badField;
}
return 0;
}
recGblDbaddrError(S_db_badChoice, paddr, "calc::special - bad special value!");
return S_db_badChoice;
}
#define indexof(field) calcRecord##field
static long get_linkNumber(int fieldIndex) {
if (fieldIndex >= indexof(A) && fieldIndex <= indexof(L))
return fieldIndex - indexof(A);
if (fieldIndex >= indexof(LA) && fieldIndex <= indexof(LL))
return fieldIndex - indexof(LA);
return -1;
}
static long get_units(DBADDR *paddr, char *units)
{
calcRecord *prec = (calcRecord *)paddr->precord;
int linkNumber;
if(paddr->pfldDes->field_type == DBF_DOUBLE) {
linkNumber = get_linkNumber(dbGetFieldIndex(paddr));
if (linkNumber >= 0)
dbGetUnits(&prec->inpa + linkNumber, units, DB_UNITS_SIZE);
else
strncpy(units,prec->egu,DB_UNITS_SIZE);
}
return 0;
}
static long get_precision(const DBADDR *paddr, long *pprecision)
{
calcRecord *prec = (calcRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
int linkNumber;
*pprecision = prec->prec;
if (fieldIndex == indexof(VAL))
return 0;
linkNumber = get_linkNumber(fieldIndex);
if (linkNumber >= 0) {
short precision;
if (dbGetPrecision(&prec->inpa + linkNumber, &precision) == 0)
*pprecision = precision;
} else
recGblGetPrec(paddr, pprecision);
return 0;
}
static long get_graphic_double(DBADDR *paddr, struct dbr_grDouble *pgd)
{
calcRecord *prec = (calcRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
int linkNumber;
switch (fieldIndex) {
case indexof(VAL):
case indexof(HIHI):
case indexof(HIGH):
case indexof(LOW):
case indexof(LOLO):
case indexof(LALM):
case indexof(ALST):
case indexof(MLST):
pgd->lower_disp_limit = prec->lopr;
pgd->upper_disp_limit = prec->hopr;
break;
default:
linkNumber = get_linkNumber(fieldIndex);
if (linkNumber >= 0) {
dbGetGraphicLimits(&prec->inpa + linkNumber,
&pgd->lower_disp_limit,
&pgd->upper_disp_limit);
} else
recGblGetGraphicDouble(paddr,pgd);
}
return 0;
}
static long get_control_double(DBADDR *paddr, struct dbr_ctrlDouble *pcd)
{
calcRecord *prec = (calcRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
case indexof(HIHI):
case indexof(HIGH):
case indexof(LOW):
case indexof(LOLO):
case indexof(LALM):
case indexof(ALST):
case indexof(MLST):
pcd->lower_ctrl_limit = prec->lopr;
pcd->upper_ctrl_limit = prec->hopr;
break;
default:
recGblGetControlDouble(paddr,pcd);
}
return 0;
}
static long get_alarm_double(DBADDR *paddr, struct dbr_alDouble *pad)
{
calcRecord *prec = (calcRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
int linkNumber;
if (fieldIndex == indexof(VAL)) {
pad->lower_alarm_limit = prec->llsv ? prec->lolo : epicsNAN;
pad->lower_warning_limit = prec->lsv ? prec->low : epicsNAN;
pad->upper_warning_limit = prec->hsv ? prec->high : epicsNAN;
pad->upper_alarm_limit = prec->hhsv ? prec->hihi : epicsNAN;
} else {
linkNumber = get_linkNumber(fieldIndex);
if (linkNumber >= 0) {
dbGetAlarmLimits(&prec->inpa + linkNumber,
&pad->lower_alarm_limit,
&pad->lower_warning_limit,
&pad->upper_warning_limit,
&pad->upper_alarm_limit);
} else
recGblGetAlarmDouble(paddr, pad);
}
return 0;
}
static void checkAlarms(calcRecord *prec, epicsTimeStamp *timeLast)
{
enum {
range_Lolo = 1,
range_Low,
range_Normal,
range_High,
range_Hihi
} alarmRange;
static const epicsEnum16 range_stat[] = {
SOFT_ALARM, LOLO_ALARM, LOW_ALARM,
NO_ALARM, HIGH_ALARM, HIHI_ALARM
};
double val, hyst, lalm, alev, aftc, afvl;
epicsEnum16 asev;
if (prec->udf) {
recGblSetSevr(prec, UDF_ALARM, prec->udfs);
prec->afvl = 0;
return;
}
val = prec->val;
hyst = prec->hyst;
lalm = prec->lalm;
/* check VAL against alarm limits */
if ((asev = prec->hhsv) &&
(val >= (alev = prec->hihi) ||
((lalm == alev) && (val >= alev - hyst))))
alarmRange = range_Hihi;
else
if ((asev = prec->llsv) &&
(val <= (alev = prec->lolo) ||
((lalm == alev) && (val <= alev + hyst))))
alarmRange = range_Lolo;
else
if ((asev = prec->hsv) &&
(val >= (alev = prec->high) ||
((lalm == alev) && (val >= alev - hyst))))
alarmRange = range_High;
else
if ((asev = prec->lsv) &&
(val <= (alev = prec->low) ||
((lalm == alev) && (val <= alev + hyst))))
alarmRange = range_Low;
else {
alev = val;
asev = NO_ALARM;
alarmRange = range_Normal;
}
aftc = prec->aftc;
afvl = 0;
if (aftc > 0) {
/* Apply level filtering */
afvl = prec->afvl;
if (afvl == 0) {
afvl = (double)alarmRange;
} else {
double t = epicsTimeDiffInSeconds(&prec->time, timeLast);
double alpha = aftc / (t + aftc);
/* The sign of afvl indicates whether the result should be
* rounded up or down. This gives the filter hysteresis.
* If afvl > 0 the floor() function rounds to a lower alarm
* level, otherwise to a higher.
*/
afvl = alpha * afvl +
((afvl > 0) ? (1 - alpha) : (alpha - 1)) * alarmRange;
if (afvl - floor(afvl) > THRESHOLD)
afvl = -afvl; /* reverse rounding */
alarmRange = abs((int)floor(afvl));
switch (alarmRange) {
case range_Hihi:
asev = prec->hhsv;
alev = prec->hihi;
break;
case range_High:
asev = prec->hsv;
alev = prec->high;
break;
case range_Normal:
asev = NO_ALARM;
break;
case range_Low:
asev = prec->lsv;
alev = prec->low;
break;
case range_Lolo:
asev = prec->llsv;
alev = prec->lolo;
break;
}
}
}
prec->afvl = afvl;
if (asev) {
/* Report alarm condition, store LALM for future HYST calculations */
if (recGblSetSevr(prec, range_stat[alarmRange], asev))
prec->lalm = alev;
} else {
/* No alarm condition, reset LALM */
prec->lalm = val;
}
}
static void monitor(calcRecord *prec)
{
unsigned monitor_mask;
double *pnew, *pprev;
int i;
monitor_mask = recGblResetAlarms(prec);
/* check for value change */
recGblCheckDeadband(&prec->mlst, prec->val, prec->mdel, &monitor_mask, DBE_VALUE);
/* check for archive change */
recGblCheckDeadband(&prec->alst, prec->val, prec->adel, &monitor_mask, DBE_ARCHIVE);
/* send out monitors connected to the value field */
if (monitor_mask){
db_post_events(prec, &prec->val, monitor_mask);
}
/* check all input fields for changes*/
pnew = &prec->a;
pprev = &prec->la;
for (i = 0; i < CALCPERFORM_NARGS; i++, pnew++, pprev++) {
if (*pnew != *pprev ||
monitor_mask & DBE_ALARM) {
db_post_events(prec, pnew, monitor_mask | DBE_VALUE | DBE_LOG);
*pprev = *pnew;
}
}
return;
}
static int fetch_values(calcRecord *prec)
{
struct link *plink;
double *pvalue;
long status = 0;
int i;
plink = &prec->inpa;
pvalue = &prec->a;
for(i = 0; i < CALCPERFORM_NARGS; i++, plink++, pvalue++) {
int newStatus;
newStatus = dbGetLink(plink, DBR_DOUBLE, pvalue, 0, 0);
if (status == 0) status = newStatus;
}
return status;
}
+324
View File
@@ -0,0 +1,324 @@
#*************************************************************************
# Copyright (c) 2007 UChicago Argonne LLC, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
recordtype(calc) {
include "dbCommon.dbd"
field(VAL,DBF_DOUBLE) {
prompt("Result")
promptgroup("50 - Output")
asl(ASL0)
}
field(CALC,DBF_STRING) {
prompt("Calculation")
promptgroup("30 - Action")
special(SPC_CALC)
pp(TRUE)
size(80)
initial("0")
}
field(INPA,DBF_INLINK) {
prompt("Input A")
promptgroup("41 - Input A-F")
interest(1)
}
field(INPB,DBF_INLINK) {
prompt("Input B")
promptgroup("41 - Input A-F")
interest(1)
}
field(INPC,DBF_INLINK) {
prompt("Input C")
promptgroup("41 - Input A-F")
interest(1)
}
field(INPD,DBF_INLINK) {
prompt("Input D")
promptgroup("41 - Input A-F")
interest(1)
}
field(INPE,DBF_INLINK) {
prompt("Input E")
promptgroup("41 - Input A-F")
interest(1)
}
field(INPF,DBF_INLINK) {
prompt("Input F")
promptgroup("41 - Input A-F")
interest(1)
}
field(INPG,DBF_INLINK) {
prompt("Input G")
promptgroup("42 - Input G-L")
interest(1)
}
field(INPH,DBF_INLINK) {
prompt("Input H")
promptgroup("42 - Input G-L")
interest(1)
}
field(INPI,DBF_INLINK) {
prompt("Input I")
promptgroup("42 - Input G-L")
interest(1)
}
field(INPJ,DBF_INLINK) {
prompt("Input J")
promptgroup("42 - Input G-L")
interest(1)
}
field(INPK,DBF_INLINK) {
prompt("Input K")
promptgroup("42 - Input G-L")
interest(1)
}
field(INPL,DBF_INLINK) {
prompt("Input L")
promptgroup("42 - Input G-L")
interest(1)
}
field(EGU,DBF_STRING) {
prompt("Engineering Units")
promptgroup("80 - Display")
interest(1)
size(16)
prop(YES)
}
field(PREC,DBF_SHORT) {
prompt("Display Precision")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(HOPR,DBF_DOUBLE) {
prompt("High Operating Rng")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(LOPR,DBF_DOUBLE) {
prompt("Low Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(HIHI,DBF_DOUBLE) {
prompt("Hihi Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(LOLO,DBF_DOUBLE) {
prompt("Lolo Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(HIGH,DBF_DOUBLE) {
prompt("High Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(LOW,DBF_DOUBLE) {
prompt("Low Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(HHSV,DBF_MENU) {
prompt("Hihi Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(LLSV,DBF_MENU) {
prompt("Lolo Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(HSV,DBF_MENU) {
prompt("High Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(LSV,DBF_MENU) {
prompt("Low Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(AFTC, DBF_DOUBLE) {
prompt("Alarm Filter Time Constant")
promptgroup("70 - Alarm")
interest(1)
}
field(AFVL, DBF_DOUBLE) {
prompt("Alarm Filter Value")
special(SPC_NOMOD)
interest(3)
}
field(HYST,DBF_DOUBLE) {
prompt("Alarm Deadband")
promptgroup("70 - Alarm")
interest(1)
}
field(ADEL,DBF_DOUBLE) {
prompt("Archive Deadband")
promptgroup("80 - Display")
interest(1)
}
field(MDEL,DBF_DOUBLE) {
prompt("Monitor Deadband")
promptgroup("80 - Display")
interest(1)
}
field(A,DBF_DOUBLE) {
prompt("Value of Input A")
pp(TRUE)
}
field(B,DBF_DOUBLE) {
prompt("Value of Input B")
pp(TRUE)
}
field(C,DBF_DOUBLE) {
prompt("Value of Input C")
pp(TRUE)
}
field(D,DBF_DOUBLE) {
prompt("Value of Input D")
pp(TRUE)
}
field(E,DBF_DOUBLE) {
prompt("Value of Input E")
pp(TRUE)
}
field(F,DBF_DOUBLE) {
prompt("Value of Input F")
pp(TRUE)
}
field(G,DBF_DOUBLE) {
prompt("Value of Input G")
pp(TRUE)
}
field(H,DBF_DOUBLE) {
prompt("Value of Input H")
pp(TRUE)
}
field(I,DBF_DOUBLE) {
prompt("Value of Input I")
pp(TRUE)
}
field(J,DBF_DOUBLE) {
prompt("Value of Input J")
pp(TRUE)
}
field(K,DBF_DOUBLE) {
prompt("Value of Input K")
pp(TRUE)
}
field(L,DBF_DOUBLE) {
prompt("Value of Input L")
pp(TRUE)
}
field(LA,DBF_DOUBLE) {
prompt("Prev Value of A")
special(SPC_NOMOD)
interest(3)
}
field(LB,DBF_DOUBLE) {
prompt("Prev Value of B")
special(SPC_NOMOD)
interest(3)
}
field(LC,DBF_DOUBLE) {
prompt("Prev Value of C")
special(SPC_NOMOD)
interest(3)
}
field(LD,DBF_DOUBLE) {
prompt("Prev Value of D")
special(SPC_NOMOD)
interest(3)
}
field(LE,DBF_DOUBLE) {
prompt("Prev Value of E")
special(SPC_NOMOD)
interest(3)
}
field(LF,DBF_DOUBLE) {
prompt("Prev Value of F")
special(SPC_NOMOD)
interest(3)
}
field(LG,DBF_DOUBLE) {
prompt("Prev Value of G")
special(SPC_NOMOD)
interest(3)
}
field(LH,DBF_DOUBLE) {
prompt("Prev Value of H")
special(SPC_NOMOD)
interest(3)
}
field(LI,DBF_DOUBLE) {
prompt("Prev Value of I")
special(SPC_NOMOD)
interest(3)
}
field(LJ,DBF_DOUBLE) {
prompt("Prev Value of J")
special(SPC_NOMOD)
interest(3)
}
field(LK,DBF_DOUBLE) {
prompt("Prev Value of K")
special(SPC_NOMOD)
interest(3)
}
field(LL,DBF_DOUBLE) {
prompt("Prev Value of L")
special(SPC_NOMOD)
interest(3)
}
field(LALM,DBF_DOUBLE) {
prompt("Last Value Alarmed")
special(SPC_NOMOD)
interest(3)
}
field(ALST,DBF_DOUBLE) {
prompt("Last Value Archived")
special(SPC_NOMOD)
interest(3)
}
field(MLST,DBF_DOUBLE) {
prompt("Last Val Monitored")
special(SPC_NOMOD)
interest(3)
}
%#include "postfix.h"
field(RPCL,DBF_NOACCESS) {
prompt("Reverse Polish Calc")
special(SPC_NOMOD)
interest(4)
extra("char rpcl[INFIX_TO_POSTFIX_SIZE(80)]")
}
}
@@ -0,0 +1,781 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* calcout.c - Record Support Routines for calc with output records */
/*
* Author : Ned Arnold
* Based on recCalc.c by Julie Sander and Bob Dalesio
* Date: 7-27-87
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "dbLink.h"
#include "dbScan.h"
#include "cantProceed.h"
#include "epicsMath.h"
#include "errMdef.h"
#include "errlog.h"
#include "recSup.h"
#include "devSup.h"
#include "recGbl.h"
#include "special.h"
#include "callback.h"
#include "taskwd.h"
#include "menuIvoa.h"
#define GEN_SIZE_OFFSET
#include "calcoutRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
static long special(DBADDR *, int);
#define get_value NULL
#define cvt_dbaddr NULL
#define get_array_info NULL
#define put_array_info NULL
static long get_units(DBADDR *, char *);
static long get_precision(const DBADDR *, long *);
#define get_enum_str NULL
#define get_enum_strs NULL
#define put_enum_str NULL
static long get_graphic_double(DBADDR *, struct dbr_grDouble *);
static long get_control_double(DBADDR *, struct dbr_ctrlDouble *);
static long get_alarm_double(DBADDR *, struct dbr_alDouble *);
rset calcoutRSET = {
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double
};
epicsExportAddress(rset, calcoutRSET);
int calcoutODLYprecision = 2;
epicsExportAddress(int, calcoutODLYprecision);
double calcoutODLYlimit = 100000;
epicsExportAddress(double, calcoutODLYlimit);
typedef struct calcoutDSET {
long number;
DEVSUPFUN dev_report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write;
}calcoutDSET;
/* To provide feedback to the user as to the connection status of the
* links (.INxV and .OUTV), the following algorithm has been implemented ...
*
* A new PV_LINK is checked [in both init() and special()] to see if the
* target is local -- if so it is marked as such. If not, a checkLinkCb
* callback is scheduled to check the connection status later by calling
* dbIsLinkConnected(). Anytime there are unconnected CA_LINKs, another
* callback is scheduled. Once all connections are established, the CA_LINKs
* are checked whenever the record processes.
*
*/
#define NO_CA_LINKS 0
#define CA_LINKS_ALL_OK 1
#define CA_LINKS_NOT_OK 2
typedef struct rpvtStruct {
CALLBACK doOutCb;
CALLBACK checkLinkCb;
short cbScheduled;
short caLinkStat; /* NO_CA_LINKS, CA_LINKS_ALL_OK, CA_LINKS_NOT_OK */
} rpvtStruct;
static void checkAlarms(calcoutRecord *prec);
static void monitor(calcoutRecord *prec);
static int fetch_values(calcoutRecord *prec);
static void execOutput(calcoutRecord *prec);
static void checkLinks(calcoutRecord *prec);
static void checkLinksCallback(CALLBACK *arg);
static long writeValue(calcoutRecord *prec);
int calcoutRecDebug;
static long init_record(struct dbCommon *pcommon, int pass)
{
struct calcoutRecord *prec = (struct calcoutRecord *)pcommon;
DBLINK *plink;
int i;
double *pvalue;
epicsEnum16 *plinkValid;
short error_number;
calcoutDSET *pcalcoutDSET;
rpvtStruct *prpvt;
if (pass == 0) {
prec->rpvt = (rpvtStruct *) callocMustSucceed(1, sizeof(rpvtStruct), "calcoutRecord");
return 0;
}
if (!(pcalcoutDSET = (calcoutDSET *)prec->dset)) {
recGblRecordError(S_dev_noDSET, (void *)prec, "calcout:init_record");
return S_dev_noDSET;
}
/* must have write defined */
if ((pcalcoutDSET->number < 5) || (pcalcoutDSET->write ==NULL)) {
recGblRecordError(S_dev_missingSup, (void *)prec, "calcout:init_record");
return S_dev_missingSup;
}
prpvt = prec->rpvt;
plink = &prec->inpa;
pvalue = &prec->a;
plinkValid = &prec->inav;
for (i = 0; i <= CALCPERFORM_NARGS; i++, plink++, pvalue++, plinkValid++) {
/* Don't InitConstantLink the .OUT link */
if (i < CALCPERFORM_NARGS) {
recGblInitConstantLink(plink, DBF_DOUBLE, pvalue);
}
if (dbLinkIsConstant(plink)) {
*plinkValid = calcoutINAV_CON;
}
else if (dbLinkIsVolatile(plink)) {
int conn = dbIsLinkConnected(plink);
if (conn)
*plinkValid = calcoutINAV_EXT;
else {
/* Monitor for connection */
*plinkValid = calcoutINAV_EXT_NC;
prpvt->caLinkStat = CA_LINKS_NOT_OK;
}
}
else {
/* PV must reside on this ioc */
*plinkValid = calcoutINAV_LOC;
if (!dbIsLinkConnected(plink)) {
errlogPrintf("calcout: %s.INP%c in no-vo disco state\n",
prec->name, i+'A');
}
}
}
prec->clcv = postfix(prec->calc, prec->rpcl, &error_number);
if (prec->clcv){
recGblRecordError(S_db_badField, (void *)prec,
"calcout: init_record: Illegal CALC field");
errlogPrintf("%s.CALC: %s in expression \"%s\"\n",
prec->name, calcErrorStr(error_number), prec->calc);
}
prec->oclv = postfix(prec->ocal, prec->orpc, &error_number);
if (prec->dopt == calcoutDOPT_Use_OVAL && prec->oclv){
recGblRecordError(S_db_badField, (void *)prec,
"calcout: init_record: Illegal OCAL field");
errlogPrintf("%s.OCAL: %s in expression \"%s\"\n",
prec->name, calcErrorStr(error_number), prec->ocal);
}
prpvt = prec->rpvt;
callbackSetCallback(checkLinksCallback, &prpvt->checkLinkCb);
callbackSetPriority(0, &prpvt->checkLinkCb);
callbackSetUser(prec, &prpvt->checkLinkCb);
prpvt->cbScheduled = 0;
prec->epvt = eventNameToHandle(prec->oevt);
if (pcalcoutDSET->init_record) pcalcoutDSET->init_record(prec);
prec->pval = prec->val;
prec->mlst = prec->val;
prec->alst = prec->val;
prec->lalm = prec->val;
prec->povl = prec->oval;
return 0;
}
static long process(struct dbCommon *pcommon)
{
struct calcoutRecord *prec = (struct calcoutRecord *)pcommon;
rpvtStruct *prpvt = prec->rpvt;
int doOutput;
if (!prec->pact) {
prec->pact = TRUE;
/* if some links are CA, check connections */
if (prpvt->caLinkStat != NO_CA_LINKS) {
checkLinks(prec);
}
if (fetch_values(prec) == 0) {
if (calcPerform(&prec->a, &prec->val, prec->rpcl)) {
recGblSetSevr(prec, CALC_ALARM, INVALID_ALARM);
} else {
prec->udf = isnan(prec->val);
}
}
checkAlarms(prec);
/* check for output link execution */
switch (prec->oopt) {
case calcoutOOPT_Every_Time:
doOutput = 1;
break;
case calcoutOOPT_On_Change:
doOutput = ! (fabs(prec->pval - prec->val) <= prec->mdel);
break;
case calcoutOOPT_Transition_To_Zero:
doOutput = ((prec->pval != 0.0) && (prec->val == 0.0));
break;
case calcoutOOPT_Transition_To_Non_zero:
doOutput = ((prec->pval == 0.0) && (prec->val != 0.0));
break;
case calcoutOOPT_When_Zero:
doOutput = (prec->val == 0.0);
break;
case calcoutOOPT_When_Non_zero:
doOutput = (prec->val != 0.0);
break;
default:
doOutput = 0;
break;
}
prec->pval = prec->val;
if (doOutput) {
if (prec->odly > 0.0) {
prec->dlya = 1;
recGblGetTimeStamp(prec);
db_post_events(prec, &prec->dlya, DBE_VALUE);
callbackRequestProcessCallbackDelayed(&prpvt->doOutCb,
prec->prio, prec, (double)prec->odly);
return 0;
} else {
prec->pact = FALSE;
execOutput(prec);
if (prec->pact) return 0;
prec->pact = TRUE;
}
}
recGblGetTimeStamp(prec);
} else { /* pact == TRUE */
if (prec->dlya) {
prec->dlya = 0;
recGblGetTimeStamp(prec);
db_post_events(prec, &prec->dlya, DBE_VALUE);
/* Make pact FALSE for asynchronous device support*/
prec->pact = FALSE;
execOutput(prec);
if (prec->pact) return 0;
prec->pact = TRUE;
} else {/*Device Support is asynchronous*/
writeValue(prec);
recGblGetTimeStamp(prec);
}
}
monitor(prec);
recGblFwdLink(prec);
prec->pact = FALSE;
return 0;
}
static long special(DBADDR *paddr, int after)
{
calcoutRecord *prec = (calcoutRecord *)paddr->precord;
rpvtStruct *prpvt = prec->rpvt;
short error_number;
int fieldIndex = dbGetFieldIndex(paddr);
int lnkIndex;
DBLINK *plink;
double *pvalue;
epicsEnum16 *plinkValid;
if (!after) return 0;
switch(fieldIndex) {
case(calcoutRecordCALC):
prec->clcv = postfix(prec->calc, prec->rpcl, &error_number);
if (prec->clcv){
recGblRecordError(S_db_badField, (void *)prec,
"calcout: special(): Illegal CALC field");
errlogPrintf("%s.CALC: %s in expression \"%s\"\n",
prec->name, calcErrorStr(error_number), prec->calc);
}
db_post_events(prec, &prec->clcv, DBE_VALUE);
return 0;
case(calcoutRecordOCAL):
prec->oclv = postfix(prec->ocal, prec->orpc, &error_number);
if (prec->dopt == calcoutDOPT_Use_OVAL && prec->oclv){
recGblRecordError(S_db_badField, (void *)prec,
"calcout: special(): Illegal OCAL field");
errlogPrintf("%s.OCAL: %s in expression \"%s\"\n",
prec->name, calcErrorStr(error_number), prec->ocal);
}
db_post_events(prec, &prec->oclv, DBE_VALUE);
return 0;
case(calcoutRecordINPA):
case(calcoutRecordINPB):
case(calcoutRecordINPC):
case(calcoutRecordINPD):
case(calcoutRecordINPE):
case(calcoutRecordINPF):
case(calcoutRecordINPG):
case(calcoutRecordINPH):
case(calcoutRecordINPI):
case(calcoutRecordINPJ):
case(calcoutRecordINPK):
case(calcoutRecordINPL):
case(calcoutRecordOUT):
lnkIndex = fieldIndex - calcoutRecordINPA;
plink = &prec->inpa + lnkIndex;
pvalue = &prec->a + lnkIndex;
plinkValid = &prec->inav + lnkIndex;
if (fieldIndex != calcoutRecordOUT)
recGblInitConstantLink(plink, DBF_DOUBLE, pvalue);
if (dbLinkIsConstant(plink)) {
db_post_events(prec, pvalue, DBE_VALUE);
*plinkValid = calcoutINAV_CON;
} else if (dbLinkIsVolatile(plink)) {
int conn = dbIsLinkConnected(plink);
if (conn)
*plinkValid = calcoutINAV_EXT;
else {
/* Monitor for connection */
*plinkValid = calcoutINAV_EXT_NC;
/* DO_CALLBACK, if not already scheduled */
if (!prpvt->cbScheduled) {
callbackRequestDelayed(&prpvt->checkLinkCb, .5);
prpvt->cbScheduled = 1;
prpvt->caLinkStat = CA_LINKS_NOT_OK;
}
}
}
else {
/* PV must reside on this ioc */
*plinkValid = calcoutINAV_LOC;
if (!dbIsLinkConnected(plink)) {
errlogPrintf("calcout: %s.INP%c in no-vo diso state\n",
prec->name, lnkIndex);
}
}
db_post_events(prec, plinkValid, DBE_VALUE);
return 0;
case(calcoutRecordOEVT):
prec->epvt = eventNameToHandle(prec->oevt);
return 0;
default:
recGblDbaddrError(S_db_badChoice, paddr, "calc: special");
return(S_db_badChoice);
}
}
#define indexof(field) calcoutRecord##field
static long get_linkNumber(int fieldIndex) {
if (fieldIndex >= indexof(A) && fieldIndex <= indexof(L))
return fieldIndex - indexof(A);
if (fieldIndex >= indexof(LA) && fieldIndex <= indexof(LL))
return fieldIndex - indexof(LA);
return -1;
}
static long get_units(DBADDR *paddr, char *units)
{
calcoutRecord *prec = (calcoutRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
int linkNumber;
if(fieldIndex == indexof(ODLY)) {
strcpy(units, "s");
return 0;
}
if(paddr->pfldDes->field_type == DBF_DOUBLE) {
linkNumber = get_linkNumber(dbGetFieldIndex(paddr));
if (linkNumber >= 0)
dbGetUnits(&prec->inpa + linkNumber, units, DB_UNITS_SIZE);
else
strncpy(units,prec->egu,DB_UNITS_SIZE);
}
return 0;
}
static long get_precision(const DBADDR *paddr, long *pprecision)
{
calcoutRecord *prec = (calcoutRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
int linkNumber;
if (fieldIndex == indexof(ODLY)) {
*pprecision = calcoutODLYprecision;
return 0;
}
*pprecision = prec->prec;
if (fieldIndex == indexof(VAL))
return 0;
linkNumber = get_linkNumber(fieldIndex);
if (linkNumber >= 0) {
short precision;
if (dbGetPrecision(&prec->inpa + linkNumber, &precision) == 0)
*pprecision = precision;
} else
recGblGetPrec(paddr, pprecision);
return 0;
}
static long get_graphic_double(DBADDR *paddr, struct dbr_grDouble *pgd)
{
calcoutRecord *prec = (calcoutRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
int linkNumber;
switch (fieldIndex) {
case indexof(VAL):
case indexof(HIHI):
case indexof(HIGH):
case indexof(LOW):
case indexof(LOLO):
case indexof(LALM):
case indexof(ALST):
case indexof(MLST):
pgd->lower_disp_limit = prec->lopr;
pgd->upper_disp_limit = prec->hopr;
break;
case indexof(ODLY):
recGblGetGraphicDouble(paddr,pgd);
pgd->lower_disp_limit = 0.0;
break;
default:
linkNumber = get_linkNumber(fieldIndex);
if (linkNumber >= 0) {
dbGetGraphicLimits(&prec->inpa + linkNumber,
&pgd->lower_disp_limit,
&pgd->upper_disp_limit);
} else
recGblGetGraphicDouble(paddr,pgd);
}
return 0;
}
static long get_control_double(DBADDR *paddr, struct dbr_ctrlDouble *pcd)
{
calcoutRecord *prec = (calcoutRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
case indexof(HIHI):
case indexof(HIGH):
case indexof(LOW):
case indexof(LOLO):
case indexof(LALM):
case indexof(ALST):
case indexof(MLST):
pcd->lower_ctrl_limit = prec->lopr;
pcd->upper_ctrl_limit = prec->hopr;
break;
case indexof(ODLY):
pcd->lower_ctrl_limit = 0.0;
pcd->upper_ctrl_limit = calcoutODLYlimit;
break;
default:
recGblGetControlDouble(paddr,pcd);
}
return 0;
}
static long get_alarm_double(DBADDR *paddr, struct dbr_alDouble *pad)
{
calcoutRecord *prec = (calcoutRecord *)paddr->precord;
int fieldIndex = dbGetFieldIndex(paddr);
int linkNumber;
if (fieldIndex == indexof(VAL)) {
pad->upper_alarm_limit = prec->hhsv ? prec->hihi : epicsNAN;
pad->upper_warning_limit = prec->hsv ? prec->high : epicsNAN;
pad->lower_warning_limit = prec->lsv ? prec->low : epicsNAN;
pad->lower_alarm_limit = prec->llsv ? prec->lolo : epicsNAN;
} else {
linkNumber = get_linkNumber(fieldIndex);
if (linkNumber >= 0) {
dbGetAlarmLimits(&prec->inpa + linkNumber,
&pad->lower_alarm_limit,
&pad->lower_warning_limit,
&pad->upper_warning_limit,
&pad->upper_alarm_limit);
} else
recGblGetAlarmDouble(paddr, pad);
}
return 0;
}
static void checkAlarms(calcoutRecord *prec)
{
double val, hyst, lalm;
double alev;
epicsEnum16 asev;
if (prec->udf) {
recGblSetSevr(prec, UDF_ALARM, prec->udfs);
return;
}
val = prec->val;
hyst = prec->hyst;
lalm = prec->lalm;
/* alarm condition hihi */
asev = prec->hhsv;
alev = prec->hihi;
if (asev && (val >= alev || ((lalm == alev) && (val >= alev - hyst)))) {
if (recGblSetSevr(prec, HIHI_ALARM, asev))
prec->lalm = alev;
return;
}
/* alarm condition lolo */
asev = prec->llsv;
alev = prec->lolo;
if (asev && (val <= alev || ((lalm == alev) && (val <= alev + hyst)))) {
if (recGblSetSevr(prec, LOLO_ALARM, asev))
prec->lalm = alev;
return;
}
/* alarm condition high */
asev = prec->hsv;
alev = prec->high;
if (asev && (val >= alev || ((lalm == alev) && (val >= alev - hyst)))) {
if (recGblSetSevr(prec, HIGH_ALARM, asev))
prec->lalm = alev;
return;
}
/* alarm condition low */
asev = prec->lsv;
alev = prec->low;
if (asev && (val <= alev || ((lalm == alev) && (val <= alev + hyst)))) {
if (recGblSetSevr(prec, LOW_ALARM, asev))
prec->lalm = alev;
return;
}
/* we get here only if val is out of alarm by at least hyst */
prec->lalm = val;
return;
}
static void execOutput(calcoutRecord *prec)
{
/* Determine output data */
switch(prec->dopt) {
case calcoutDOPT_Use_VAL:
prec->oval = prec->val;
break;
case calcoutDOPT_Use_OVAL:
if (calcPerform(&prec->a, &prec->oval, prec->orpc)) {
recGblSetSevr(prec, CALC_ALARM, INVALID_ALARM);
} else {
prec->udf = isnan(prec->oval);
}
break;
}
if (prec->udf){
recGblSetSevr(prec, UDF_ALARM, prec->udfs);
}
/* Check to see what to do if INVALID */
if (prec->nsev < INVALID_ALARM ) {
/* Output the value */
writeValue(prec);
/* post output event if set */
if (prec->epvt) postEvent(prec->epvt);
} else switch (prec->ivoa) {
case menuIvoaContinue_normally:
writeValue(prec);
/* post output event if set */
if (prec->epvt) postEvent(prec->epvt);
break;
case menuIvoaDon_t_drive_outputs:
break;
case menuIvoaSet_output_to_IVOV:
prec->oval = prec->ivov;
writeValue(prec);
/* post output event if set */
if (prec->epvt) postEvent(prec->epvt);
break;
default:
recGblRecordError(S_db_badField, (void *)prec,
"calcout:process Illegal IVOA field");
}
}
static void monitor(calcoutRecord *prec)
{
unsigned monitor_mask;
double *pnew;
double *pprev;
int i;
monitor_mask = recGblResetAlarms(prec);
/* check for value change */
recGblCheckDeadband(&prec->mlst, prec->val, prec->mdel, &monitor_mask, DBE_VALUE);
/* check for archive change */
recGblCheckDeadband(&prec->alst, prec->val, prec->adel, &monitor_mask, DBE_ARCHIVE);
/* send out monitors connected to the value field */
if (monitor_mask){
db_post_events(prec, &prec->val, monitor_mask);
}
/* check all input fields for changes*/
for (i = 0, pnew = &prec->a, pprev = &prec->la; i<CALCPERFORM_NARGS;
i++, pnew++, pprev++) {
if ((*pnew != *pprev) || (monitor_mask&DBE_ALARM)) {
db_post_events(prec, pnew, monitor_mask|DBE_VALUE|DBE_LOG);
*pprev = *pnew;
}
}
/* Check OVAL field */
if (prec->povl != prec->oval) {
db_post_events(prec, &prec->oval, monitor_mask|DBE_VALUE|DBE_LOG);
prec->povl = prec->oval;
}
return;
}
static int fetch_values(calcoutRecord *prec)
{
DBLINK *plink; /* structure of the link field */
double *pvalue;
long status = 0;
int i;
for (i = 0, plink = &prec->inpa, pvalue = &prec->a; i<CALCPERFORM_NARGS;
i++, plink++, pvalue++) {
int newStatus;
newStatus = dbGetLink(plink, DBR_DOUBLE, pvalue, 0, 0);
if (!status) status = newStatus;
}
return(status);
}
static void checkLinksCallback(CALLBACK *arg)
{
calcoutRecord *prec;
rpvtStruct *prpvt;
callbackGetUser(prec, arg);
prpvt = prec->rpvt;
dbScanLock((dbCommon *)prec);
prpvt->cbScheduled = 0;
checkLinks(prec);
dbScanUnlock((dbCommon *)prec);
}
static void checkLinks(calcoutRecord *prec)
{
DBLINK *plink;
rpvtStruct *prpvt = prec->rpvt;
int i;
int stat;
int caLink = 0;
int caLinkNc = 0;
epicsEnum16 *plinkValid;
if (calcoutRecDebug) printf("checkLinks() for %p\n", prec);
plink = &prec->inpa;
plinkValid = &prec->inav;
for (i = 0; i<CALCPERFORM_NARGS+1; i++, plink++, plinkValid++) {
if (dbLinkIsVolatile(plink)) {
caLink = 1;
stat = dbIsLinkConnected(plink);
if (!stat && (*plinkValid == calcoutINAV_EXT_NC)) {
caLinkNc = 1;
}
else if (!stat && (*plinkValid == calcoutINAV_EXT)) {
*plinkValid = calcoutINAV_EXT_NC;
db_post_events(prec, plinkValid, DBE_VALUE);
caLinkNc = 1;
}
else if (stat && (*plinkValid == calcoutINAV_EXT_NC)) {
*plinkValid = calcoutINAV_EXT;
db_post_events(prec, plinkValid, DBE_VALUE);
}
}
}
if (caLinkNc)
prpvt->caLinkStat = CA_LINKS_NOT_OK;
else if (caLink)
prpvt->caLinkStat = CA_LINKS_ALL_OK;
else
prpvt->caLinkStat = NO_CA_LINKS;
if (!prpvt->cbScheduled && caLinkNc) {
/* Schedule another CALLBACK */
prpvt->cbScheduled = 1;
callbackRequestDelayed(&prpvt->checkLinkCb, .5);
}
}
static long writeValue(calcoutRecord *prec)
{
calcoutDSET *pcalcoutDSET = (calcoutDSET *)prec->dset;
if (!pcalcoutDSET || !pcalcoutDSET->write) {
errlogPrintf("%s DSET write does not exist\n", prec->name);
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
prec->pact = TRUE;
return(-1);
}
return pcalcoutDSET->write(prec);
}
@@ -0,0 +1,530 @@
#*************************************************************************
# Copyright (c) 2007 UChicago Argonne LLC, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
menu(calcoutOOPT) {
choice(calcoutOOPT_Every_Time,"Every Time")
choice(calcoutOOPT_On_Change,"On Change")
choice(calcoutOOPT_When_Zero,"When Zero")
choice(calcoutOOPT_When_Non_zero,"When Non-zero")
choice(calcoutOOPT_Transition_To_Zero,"Transition To Zero")
choice(calcoutOOPT_Transition_To_Non_zero,"Transition To Non-zero")
}
menu(calcoutDOPT) {
choice(calcoutDOPT_Use_VAL,"Use CALC")
choice(calcoutDOPT_Use_OVAL,"Use OCAL")
}
menu(calcoutINAV) {
choice(calcoutINAV_EXT_NC,"Ext PV NC")
choice(calcoutINAV_EXT,"Ext PV OK")
choice(calcoutINAV_LOC,"Local PV")
choice(calcoutINAV_CON,"Constant")
}
recordtype(calcout) {
include "dbCommon.dbd"
field(RPVT,DBF_NOACCESS) {
prompt("Record Private")
special(SPC_NOMOD)
interest(4)
extra("struct rpvtStruct *rpvt")
}
field(VAL,DBF_DOUBLE) {
prompt("Result")
promptgroup("50 - Output")
asl(ASL0)
}
field(PVAL,DBF_DOUBLE) {
prompt("Previous Value")
}
field(CALC,DBF_STRING) {
prompt("Calculation")
promptgroup("30 - Action")
special(SPC_CALC)
pp(TRUE)
size(80)
initial("0")
}
field(CLCV,DBF_LONG) {
prompt("CALC Valid")
interest(1)
}
field(INPA,DBF_INLINK) {
prompt("Input A")
special(SPC_MOD)
promptgroup("41 - Input A-F")
interest(1)
}
field(INPB,DBF_INLINK) {
prompt("Input B")
special(SPC_MOD)
promptgroup("41 - Input A-F")
interest(1)
}
field(INPC,DBF_INLINK) {
prompt("Input C")
special(SPC_MOD)
promptgroup("41 - Input A-F")
interest(1)
}
field(INPD,DBF_INLINK) {
prompt("Input D")
special(SPC_MOD)
promptgroup("41 - Input A-F")
interest(1)
}
field(INPE,DBF_INLINK) {
prompt("Input E")
special(SPC_MOD)
promptgroup("41 - Input A-F")
interest(1)
}
field(INPF,DBF_INLINK) {
prompt("Input F")
special(SPC_MOD)
promptgroup("41 - Input A-F")
interest(1)
}
field(INPG,DBF_INLINK) {
prompt("Input G")
special(SPC_MOD)
promptgroup("42 - Input G-L")
interest(1)
}
field(INPH,DBF_INLINK) {
prompt("Input H")
special(SPC_MOD)
promptgroup("42 - Input G-L")
interest(1)
}
field(INPI,DBF_INLINK) {
prompt("Input I")
special(SPC_MOD)
promptgroup("42 - Input G-L")
interest(1)
}
field(INPJ,DBF_INLINK) {
prompt("Input J")
special(SPC_MOD)
promptgroup("42 - Input G-L")
interest(1)
}
field(INPK,DBF_INLINK) {
prompt("Input K")
special(SPC_MOD)
promptgroup("42 - Input G-L")
interest(1)
}
field(INPL,DBF_INLINK) {
prompt("Input L")
special(SPC_MOD)
promptgroup("42 - Input G-L")
interest(1)
}
field(OUT,DBF_OUTLINK) {
prompt("Output Specification")
special(SPC_MOD)
promptgroup("50 - Output")
interest(1)
}
field(INAV,DBF_MENU) {
prompt("INPA PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
initial("1")
}
field(INBV,DBF_MENU) {
prompt("INPB PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
initial("1")
}
field(INCV,DBF_MENU) {
prompt("INPC PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
initial("1")
}
field(INDV,DBF_MENU) {
prompt("INPD PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
initial("1")
}
field(INEV,DBF_MENU) {
prompt("INPE PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
initial("1")
}
field(INFV,DBF_MENU) {
prompt("INPF PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
initial("1")
}
field(INGV,DBF_MENU) {
prompt("INPG PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
initial("1")
}
field(INHV,DBF_MENU) {
prompt("INPH PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
initial("1")
}
field(INIV,DBF_MENU) {
prompt("INPI PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
initial("1")
}
field(INJV,DBF_MENU) {
prompt("INPJ PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
initial("1")
}
field(INKV,DBF_MENU) {
prompt("INPK PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
initial("1")
}
field(INLV,DBF_MENU) {
prompt("INPL PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
initial("1")
}
field(OUTV,DBF_MENU) {
prompt("OUT PV Status")
special(SPC_NOMOD)
interest(1)
menu(calcoutINAV)
}
field(OOPT,DBF_MENU) {
prompt("Output Execute Opt")
promptgroup("50 - Output")
interest(1)
menu(calcoutOOPT)
}
field(ODLY,DBF_DOUBLE) {
prompt("Output Execute Delay")
promptgroup("50 - Output")
asl(ASL0)
interest(1)
}
field(DLYA,DBF_USHORT) {
prompt("Output Delay Active")
special(SPC_NOMOD)
asl(ASL0)
}
field(DOPT,DBF_MENU) {
prompt("Output Data Opt")
promptgroup("30 - Action")
interest(1)
menu(calcoutDOPT)
}
field(OCAL,DBF_STRING) {
prompt("Output Calculation")
promptgroup("30 - Action")
special(SPC_CALC)
pp(TRUE)
size(80)
initial("0")
}
field(OCLV,DBF_LONG) {
prompt("OCAL Valid")
interest(1)
}
field(OEVT,DBF_STRING) {
prompt("Event To Issue")
promptgroup("30 - Action")
special(SPC_MOD)
asl(ASL0)
size(40)
}
%#include "dbScan.h"
field(EPVT, DBF_NOACCESS) {
prompt("Event private")
special(SPC_NOMOD)
interest(4)
extra("EVENTPVT epvt")
}
field(IVOA,DBF_MENU) {
prompt("INVALID output action")
promptgroup("50 - Output")
interest(2)
menu(menuIvoa)
}
field(IVOV,DBF_DOUBLE) {
prompt("INVALID output value")
promptgroup("50 - Output")
interest(2)
}
field(EGU,DBF_STRING) {
prompt("Engineering Units")
promptgroup("80 - Display")
interest(1)
size(16)
prop(YES)
}
field(PREC,DBF_SHORT) {
prompt("Display Precision")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(HOPR,DBF_DOUBLE) {
prompt("High Operating Rng")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(LOPR,DBF_DOUBLE) {
prompt("Low Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(HIHI,DBF_DOUBLE) {
prompt("Hihi Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(LOLO,DBF_DOUBLE) {
prompt("Lolo Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(HIGH,DBF_DOUBLE) {
prompt("High Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(LOW,DBF_DOUBLE) {
prompt("Low Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(HHSV,DBF_MENU) {
prompt("Hihi Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(LLSV,DBF_MENU) {
prompt("Lolo Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(HSV,DBF_MENU) {
prompt("High Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(LSV,DBF_MENU) {
prompt("Low Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(HYST,DBF_DOUBLE) {
prompt("Alarm Deadband")
promptgroup("70 - Alarm")
interest(1)
}
field(ADEL,DBF_DOUBLE) {
prompt("Archive Deadband")
promptgroup("80 - Display")
interest(1)
}
field(MDEL,DBF_DOUBLE) {
prompt("Monitor Deadband")
promptgroup("80 - Display")
interest(1)
}
field(A,DBF_DOUBLE) {
prompt("Value of Input A")
pp(TRUE)
}
field(B,DBF_DOUBLE) {
prompt("Value of Input B")
pp(TRUE)
}
field(C,DBF_DOUBLE) {
prompt("Value of Input C")
pp(TRUE)
}
field(D,DBF_DOUBLE) {
prompt("Value of Input D")
pp(TRUE)
}
field(E,DBF_DOUBLE) {
prompt("Value of Input E")
pp(TRUE)
}
field(F,DBF_DOUBLE) {
prompt("Value of Input F")
pp(TRUE)
}
field(G,DBF_DOUBLE) {
prompt("Value of Input G")
pp(TRUE)
}
field(H,DBF_DOUBLE) {
prompt("Value of Input H")
pp(TRUE)
}
field(I,DBF_DOUBLE) {
prompt("Value of Input I")
pp(TRUE)
}
field(J,DBF_DOUBLE) {
prompt("Value of Input J")
pp(TRUE)
}
field(K,DBF_DOUBLE) {
prompt("Value of Input K")
pp(TRUE)
}
field(L,DBF_DOUBLE) {
prompt("Value of Input L")
pp(TRUE)
}
field(OVAL,DBF_DOUBLE) {
prompt("Output Value")
asl(ASL0)
}
field(LA,DBF_DOUBLE) {
prompt("Prev Value of A")
special(SPC_NOMOD)
interest(3)
}
field(LB,DBF_DOUBLE) {
prompt("Prev Value of B")
special(SPC_NOMOD)
interest(3)
}
field(LC,DBF_DOUBLE) {
prompt("Prev Value of C")
special(SPC_NOMOD)
interest(3)
}
field(LD,DBF_DOUBLE) {
prompt("Prev Value of D")
special(SPC_NOMOD)
interest(3)
}
field(LE,DBF_DOUBLE) {
prompt("Prev Value of E")
special(SPC_NOMOD)
interest(3)
}
field(LF,DBF_DOUBLE) {
prompt("Prev Value of F")
special(SPC_NOMOD)
interest(3)
}
field(LG,DBF_DOUBLE) {
prompt("Prev Value of G")
special(SPC_NOMOD)
interest(3)
}
field(LH,DBF_DOUBLE) {
prompt("Prev Value of H")
special(SPC_NOMOD)
interest(3)
}
field(LI,DBF_DOUBLE) {
prompt("Prev Value of I")
special(SPC_NOMOD)
interest(3)
}
field(LJ,DBF_DOUBLE) {
prompt("Prev Value of J")
special(SPC_NOMOD)
interest(3)
}
field(LK,DBF_DOUBLE) {
prompt("Prev Value of K")
special(SPC_NOMOD)
interest(3)
}
field(LL,DBF_DOUBLE) {
prompt("Prev Value of L")
special(SPC_NOMOD)
interest(3)
}
field(POVL,DBF_DOUBLE) {
prompt("Prev Value of OVAL")
asl(ASL0)
}
field(LALM,DBF_DOUBLE) {
prompt("Last Value Alarmed")
special(SPC_NOMOD)
interest(3)
}
field(ALST,DBF_DOUBLE) {
prompt("Last Value Archived")
special(SPC_NOMOD)
interest(3)
}
field(MLST,DBF_DOUBLE) {
prompt("Last Val Monitored")
special(SPC_NOMOD)
interest(3)
}
%#include "postfix.h"
field(RPCL,DBF_NOACCESS) {
prompt("Reverse Polish Calc")
special(SPC_NOMOD)
interest(4)
extra("char rpcl[INFIX_TO_POSTFIX_SIZE(80)]")
}
field(ORPC,DBF_NOACCESS) {
prompt("Reverse Polish OCalc")
special(SPC_NOMOD)
interest(4)
extra("char orpc[INFIX_TO_POSTFIX_SIZE(80)]")
}
}
variable(calcoutODLYprecision, int)
variable(calcoutODLYlimit, double)
@@ -0,0 +1,504 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Author: Bob Dalesio
* Date: 7-14-89
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "dbDefs.h"
#include "epicsPrint.h"
#include "alarm.h"
#include "dbStaticLib.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "dbFldTypes.h"
#include "errMdef.h"
#include "special.h"
#include "recSup.h"
#include "recGbl.h"
#define GEN_SIZE_OFFSET
#include "compressRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
#define indexof(field) compressRecord##field
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
static long special(DBADDR *, int);
#define get_value NULL
static long cvt_dbaddr(DBADDR *);
static long get_array_info(DBADDR *, long *, long *);
static long put_array_info(DBADDR *, long);
static long get_units(DBADDR *, char *);
static long get_precision(const DBADDR *, long *);
#define get_enum_str NULL
#define get_enum_strs NULL
#define put_enum_str NULL
static long get_graphic_double(DBADDR *, struct dbr_grDouble *);
static long get_control_double(DBADDR *, struct dbr_ctrlDouble *);
#define get_alarm_double NULL
rset compressRSET = {
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double
};
epicsExportAddress(rset,compressRSET);
static void reset(compressRecord *prec)
{
prec->nuse = 0;
prec->off = 0;
prec->inx = 0;
prec->cvb = 0.0;
prec->res = 0;
/* allocate memory for the summing buffer for conversions requiring it */
if (prec->alg == compressALG_Average && prec->sptr == NULL) {
prec->sptr = calloc(prec->nsam, sizeof(double));
}
if (prec->bptr && prec->nsam)
memset(prec->bptr, 0, prec->nsam * sizeof(double));
}
static void monitor(compressRecord *prec)
{
unsigned short alarm_mask = recGblResetAlarms(prec);
unsigned short monitor_mask = alarm_mask | DBE_LOG | DBE_VALUE;
if (alarm_mask || prec->nuse != prec->ouse) {
db_post_events(prec, &prec->nuse, monitor_mask);
prec->ouse = prec->nuse;
}
db_post_events(prec, prec->bptr, monitor_mask);
}
static void put_value(compressRecord *prec, double *psource, int n)
{
int fifo = (prec->balg == bufferingALG_FIFO);
epicsUInt32 offset = prec->off;
epicsUInt32 nuse = prec->nuse;
epicsUInt32 nsam = prec->nsam;
nuse += n;
if (nuse > nsam)
nuse = nsam;
while (n--) {
/* for LIFO, decrement before */
if (!fifo)
offset = (offset - 1) % nsam;
prec->bptr[offset] = *psource++;
/* for FIFO, increment after */
if (fifo)
offset = (offset + 1) % nsam;
}
prec->off = offset;
prec->nuse = nuse;
}
/* qsort comparison function (for median calculation) */
static int compare(const void *arg1, const void *arg2)
{
double a = *(double *)arg1;
double b = *(double *)arg2;
if ( a < b ) return -1;
else if ( a == b ) return 0;
else return 1;
}
static int compress_array(compressRecord *prec,
double *psource, int no_elements)
{
epicsInt32 i,j;
epicsInt32 n, nnew;
epicsInt32 nsam = prec->nsam;
double value;
/* skip out of limit data */
if (prec->ilil < prec->ihil) {
while (((*psource < prec->ilil) || (*psource > prec->ihil))
&& (no_elements > 0)) {
no_elements--;
psource++;
}
}
if (prec->n <= 0)
prec->n = 1;
n = prec->n;
if (no_elements < n)
return 1; /*dont do anything*/
/* determine number of samples to take */
if (no_elements < nsam * n)
nnew = (no_elements / n);
else nnew = nsam;
/* compress according to specified algorithm */
switch (prec->alg){
case compressALG_N_to_1_Low_Value:
/* compress N to 1 keeping the lowest value */
for (i = 0; i < nnew; i++) {
value = *psource++;
for (j = 1; j < n; j++, psource++) {
if (value > *psource)
value = *psource;
}
put_value(prec, &value, 1);
}
break;
case compressALG_N_to_1_High_Value:
/* compress N to 1 keeping the highest value */
for (i = 0; i < nnew; i++){
value = *psource++;
for (j = 1; j < n; j++, psource++) {
if (value < *psource)
value = *psource;
}
put_value(prec, &value, 1);
}
break;
case compressALG_N_to_1_Average:
/* compress N to 1 keeping the average value */
for (i = 0; i < nnew; i++) {
value = 0;
for (j = 0; j < n; j++, psource++)
value += *psource;
value /= n;
put_value(prec, &value, 1);
}
break;
case compressALG_N_to_1_Median:
/* compress N to 1 keeping the median value */
/* note: sorts source array (OK; it's a work pointer) */
for (i = 0; i < nnew; i++, psource += nnew) {
qsort(psource, n, sizeof(double), compare);
value = psource[n / 2];
put_value(prec, &value, 1);
}
break;
}
return 0;
}
static int array_average(compressRecord *prec,
double *psource, epicsInt32 no_elements)
{
epicsInt32 i;
epicsInt32 nnow;
epicsInt32 nsam=prec->nsam;
double *psum;
double multiplier;
epicsInt32 inx = prec->inx;
epicsInt32 nuse, n;
nuse = nsam;
if (nuse > no_elements)
nuse = no_elements;
nnow = nuse;
if (nnow > no_elements)
nnow=no_elements;
psum = (double *)prec->sptr;
/* add in the new waveform */
if (inx == 0) {
for (i = 0; i < nnow; i++)
*psum++ = *psource++;
for (i = nnow; i < nuse; i++)
*psum++ = 0;
} else {
for (i = 0; i < nnow; i++)
*psum++ += *psource++;
}
/* do we need to calculate the result */
inx++;
if (prec->n <= 0)
prec->n = 1;
n = prec->n;
if (inx < n) {
prec->inx = inx;
return 1;
}
if (n > 1) {
psum = (double *)prec->sptr;
multiplier = 1.0 / n;
for (i = 0; i < nuse; i++, psum++)
*psum = *psum * multiplier;
}
put_value(prec, prec->sptr, nuse);
prec->inx = 0;
return 0;
}
static int compress_scalar(struct compressRecord *prec,double *psource)
{
double value = *psource;
double *pdest=&prec->cvb;
epicsInt32 inx = prec->inx;
/* compress according to specified algorithm */
switch (prec->alg) {
case (compressALG_N_to_1_Low_Value):
if ((value < *pdest) || (inx == 0))
*pdest = value;
break;
case (compressALG_N_to_1_High_Value):
if ((value > *pdest) || (inx == 0))
*pdest = value;
break;
/* for scalars, Median not implemented => use average */
case (compressALG_N_to_1_Average):
case (compressALG_N_to_1_Median):
if (inx == 0)
*pdest = value;
else {
*pdest += value;
if (inx + 1 >= prec->n)
*pdest = *pdest / (inx + 1);
}
break;
}
inx++;
if (inx >= prec->n) {
put_value(prec,pdest,1);
prec->inx = 0;
return 0;
} else {
prec->inx = inx;
return 1;
}
}
/*Beginning of record support routines*/
static long init_record(struct dbCommon *pcommon, int pass)
{
struct compressRecord *prec = (struct compressRecord *)pcommon;
if (pass == 0) {
if (prec->nsam < 1)
prec->nsam = 1;
prec->bptr = calloc(prec->nsam, sizeof(double));
reset(prec);
}
return 0;
}
static long process(struct dbCommon *pcommon)
{
struct compressRecord *prec = (struct compressRecord *)pcommon;
long status = 0;
long nelements = 0;
int alg = prec->alg;
prec->pact = TRUE;
if (!dbIsLinkConnected(&prec->inp) ||
dbGetNelements(&prec->inp, &nelements) ||
nelements <= 0) {
recGblSetSevr(prec, LINK_ALARM, INVALID_ALARM);
}
else {
if (!prec->wptr || nelements != prec->inpn) {
if (prec->wptr) {
free(prec->wptr);
reset(prec);
}
prec->wptr = dbCalloc(nelements, sizeof(double));
prec->inpn = nelements;
}
status = dbGetLink(&prec->inp, DBF_DOUBLE, prec->wptr, 0, &nelements);
if (status || nelements <= 0) {
recGblSetSevr(prec, LINK_ALARM, INVALID_ALARM);
status = 0;
}
else if (alg == compressALG_Average) {
status = array_average(prec, prec->wptr, nelements);
}
else if (alg == compressALG_Circular_Buffer) {
put_value(prec, prec->wptr, nelements);
status = 0;
}
else if (nelements > 1) {
status = compress_array(prec, prec->wptr, nelements);
}
else if (nelements == 1){
status = compress_scalar(prec, prec->wptr);
}
else
status = 1;
}
/* check event list */
if (status != 1) {
prec->udf = FALSE;
recGblGetTimeStamp(prec);
monitor(prec);
/* process the forward scan link record */
recGblFwdLink(prec);
}
prec->pact = FALSE;
return 0;
}
static long special(DBADDR *paddr, int after)
{
compressRecord *prec = (compressRecord *) paddr->precord;
int special_type = paddr->special;
if (!after)
return 0;
if (special_type == SPC_RESET) {
reset(prec);
return 0;
}
recGblDbaddrError(S_db_badChoice, paddr, "compress: special");
return S_db_badChoice;
}
static long cvt_dbaddr(DBADDR *paddr)
{
compressRecord *prec = (compressRecord *) paddr->precord;
paddr->pfield = prec->bptr;
paddr->no_elements = prec->nsam;
paddr->field_type = DBF_DOUBLE;
paddr->field_size = sizeof(double);
paddr->dbr_field_type = DBF_DOUBLE;
if (prec->balg == bufferingALG_LIFO)
paddr->special = SPC_NOMOD;
return 0;
}
static long get_array_info(DBADDR *paddr, long *no_elements, long *offset)
{
/* offset indicates the next element which would be written.
* In FIFO mode offset-1 is the last valid element
* In LIFO mode offset is the first valid element
* (*offset) should be set to the index of the first valid element
*/
compressRecord *prec = (compressRecord *) paddr->precord;
epicsUInt32 off = prec->off;
epicsUInt32 nuse = prec->nuse;
epicsUInt32 nsam = prec->nsam;
*no_elements = nuse;
if (prec->balg == bufferingALG_FIFO) {
*offset = (off - nuse) % nsam;
} else {
*offset = off;
}
return 0;
}
static long put_array_info(DBADDR *paddr, long nNew)
{
compressRecord *prec = (compressRecord *) paddr->precord;
if (prec->balg == bufferingALG_FIFO)
prec->off = (prec->off + nNew) % prec->nsam;
prec->nuse += nNew;
if (prec->nuse > prec->nsam)
prec->nuse = prec->nsam;
return 0;
}
static long get_units(DBADDR *paddr, char *units)
{
compressRecord *prec = (compressRecord *) paddr->precord;
if (paddr->pfldDes->field_type == DBF_DOUBLE ||
dbGetFieldIndex(paddr) == indexof(VAL)) {
strncpy(units, prec->egu, DB_UNITS_SIZE);
}
return 0;
}
static long get_precision(const DBADDR *paddr, long *precision)
{
compressRecord *prec = (compressRecord *) paddr->precord;
*precision = prec->prec;
if (dbGetFieldIndex(paddr) != indexof(VAL))
recGblGetPrec(paddr,precision);
return 0;
}
static long get_graphic_double(DBADDR *paddr, struct dbr_grDouble *pgd)
{
compressRecord *prec = (compressRecord *) paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
case indexof(IHIL):
case indexof(ILIL):
pgd->upper_disp_limit = prec->hopr;
pgd->lower_disp_limit = prec->lopr;
break;
default:
recGblGetGraphicDouble(paddr,pgd);
}
return 0;
}
static long get_control_double(DBADDR *paddr, struct dbr_ctrlDouble *pcd)
{
compressRecord *prec = (compressRecord *) paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
case indexof(IHIL):
case indexof(ILIL):
pcd->upper_ctrl_limit = prec->hopr;
pcd->lower_ctrl_limit = prec->lopr;
break;
default:
recGblGetControlDouble(paddr, pcd);
}
return 0;
}
@@ -0,0 +1,199 @@
#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
=title Compress Record (compress)
The data compression record is used to collect and compress data from arrays.
When the INP field references a data array field, it immediately compresses the
entire array into an element of an array using one of several algorithms,
overwriting the previous element. If the INP field obtains its value from a
scalar-value field, the compression record will collect a new sample each time
the record is processed and add it to the compressed data array as a circular
buffer.
The INP link can also specify a constant; however, if this is the case, the
compression algorithms are ignored, and the record support routines merely
return after checking the FLNK field.
=head2 Record-specific Menus
=head3 Menu compressALG
The ALG field which uses this menu controls the compression algorithm used by
the record.
=menu compressALG
=head3 Menu bufferingALG
The BALG field which uses this menu controls whether new values are inserted at
the beginning or the end of the VAL array.
=menu bufferingALG
=head2 Parameter Fields
The record-specific fields are described below.
=recordtype compress
...
=cut
menu(compressALG) {
choice(compressALG_N_to_1_Low_Value,"N to 1 Low Value")
choice(compressALG_N_to_1_High_Value,"N to 1 High Value")
choice(compressALG_N_to_1_Average,"N to 1 Average")
choice(compressALG_Average,"Average")
choice(compressALG_Circular_Buffer,"Circular Buffer")
choice(compressALG_N_to_1_Median,"N to 1 Median")
}
menu(bufferingALG) {
choice(bufferingALG_FIFO, "FIFO Buffer")
choice(bufferingALG_LIFO, "LIFO Buffer")
}
recordtype(compress) {
=fields VAL
=cut
include "dbCommon.dbd"
field(VAL,DBF_NOACCESS) {
prompt("Value")
asl(ASL0)
special(SPC_DBADDR)
pp(TRUE)
extra("void * val")
#=type DOUBLE[]
#=read Yes
#=write Yes
}
field(INP,DBF_INLINK) {
prompt("Input Specification")
promptgroup("40 - Input")
interest(1)
}
field(RES,DBF_SHORT) {
prompt("Reset")
asl(ASL0)
special(SPC_RESET)
interest(3)
}
field(ALG,DBF_MENU) {
prompt("Compression Algorithm")
promptgroup("30 - Action")
special(SPC_RESET)
interest(1)
menu(compressALG)
}
field(BALG,DBF_MENU) {
prompt("Buffering Algorithm")
promptgroup("30 - Action")
special(SPC_RESET)
interest(1)
menu(bufferingALG)
}
field(NSAM,DBF_ULONG) {
prompt("Number of Values")
promptgroup("30 - Action")
special(SPC_NOMOD)
interest(1)
initial("1")
}
field(N,DBF_ULONG) {
prompt("N to 1 Compression")
promptgroup("30 - Action")
special(SPC_RESET)
interest(1)
initial("1")
}
field(IHIL,DBF_DOUBLE) {
prompt("Init High Interest Lim")
promptgroup("30 - Action")
interest(1)
}
field(ILIL,DBF_DOUBLE) {
prompt("Init Low Interest Lim")
promptgroup("30 - Action")
interest(1)
}
field(HOPR,DBF_DOUBLE) {
prompt("High Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(LOPR,DBF_DOUBLE) {
prompt("Low Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(PREC,DBF_SHORT) {
prompt("Display Precision")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(EGU,DBF_STRING) {
prompt("Engineering Units")
promptgroup("80 - Display")
interest(1)
size(16)
prop(YES)
}
field(OFF,DBF_ULONG) {
prompt("Offset")
special(SPC_NOMOD)
}
field(NUSE,DBF_ULONG) {
prompt("Number Used")
special(SPC_NOMOD)
}
field(OUSE,DBF_ULONG) {
prompt("Old Number Used")
special(SPC_NOMOD)
}
field(BPTR,DBF_NOACCESS) {
prompt("Buffer Pointer")
special(SPC_NOMOD)
interest(4)
extra("double *bptr")
}
field(SPTR,DBF_NOACCESS) {
prompt("Summing Buffer Ptr")
special(SPC_NOMOD)
interest(4)
extra("double *sptr")
}
field(WPTR,DBF_NOACCESS) {
prompt("Working Buffer Ptr")
special(SPC_NOMOD)
interest(4)
extra("double *wptr")
}
field(INPN,DBF_LONG) {
prompt("Number of elements in Working Buffer")
special(SPC_NOMOD)
interest(4)
}
field(CVB,DBF_DOUBLE) {
prompt("Compress Value Buffer")
special(SPC_NOMOD)
interest(3)
}
field(INX,DBF_ULONG) {
prompt("Compressed Array Inx")
special(SPC_NOMOD)
interest(3)
}
}
@@ -0,0 +1,321 @@
/*************************************************************************\
* Copyright (c) 2002 Southeastern Universities Research Association, as
* Operator of Thomas Jefferson National Accelerator Facility.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* recDfanout.c - Record Support Routines for Dfanout records */
/*
* Original Author: Matt Bickley (Sometime in 1994)
*
* Modification Log:
* -----------------
* .01 1994 mhb Started with longout record to make the data fanout
* .02 May 10, 96 jt Bug Fix
* .03 11SEP2000 mrk LONG=>DOUBLE, add SELL,SELN,SELM
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "dbDefs.h"
#include "epicsPrint.h"
#include "epicsMath.h"
#include "alarm.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "dbFldTypes.h"
#include "devSup.h"
#include "errMdef.h"
#include "recSup.h"
#include "recGbl.h"
#include "special.h"
#include "menuOmsl.h"
#define GEN_SIZE_OFFSET
#include "dfanoutRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
#define special NULL
#define get_value NULL
#define cvt_dbaddr NULL
#define get_array_info NULL
#define put_array_info NULL
static long get_units(DBADDR *, char *);
static long get_precision(const DBADDR *, long *);
#define get_enum_str NULL
#define get_enum_strs NULL
#define put_enum_str NULL
static long get_graphic_double(DBADDR *,struct dbr_grDouble *);
static long get_control_double(DBADDR *,struct dbr_ctrlDouble *);
static long get_alarm_double(DBADDR *,struct dbr_alDouble *);
rset dfanoutRSET={
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double
};
epicsExportAddress(rset,dfanoutRSET);
static void checkAlarms(dfanoutRecord *);
static void monitor(dfanoutRecord *);
static void push_values(dfanoutRecord *);
#define OUT_ARG_MAX 8
static long init_record(struct dbCommon *pcommon, int pass)
{
struct dfanoutRecord *prec = (struct dfanoutRecord *)pcommon;
if (pass==0)
return 0;
recGblInitConstantLink(&prec->sell, DBF_USHORT, &prec->seln);
/* get the initial value dol is a constant*/
if (recGblInitConstantLink(&prec->dol, DBF_DOUBLE, &prec->val))
prec->udf = isnan(prec->val);
return 0;
}
static long process(struct dbCommon *pcommon)
{
struct dfanoutRecord *prec = (struct dfanoutRecord *)pcommon;
long status=0;
if (!prec->pact &&
!dbLinkIsConstant(&prec->dol) &&
prec->omsl == menuOmslclosed_loop) {
status = dbGetLink(&prec->dol, DBR_DOUBLE, &prec->val, 0, 0);
if (!dbLinkIsConstant(&prec->dol) && !status)
prec->udf = isnan(prec->val);
}
prec->pact = TRUE;
recGblGetTimeStamp(prec);
/* Push out the data to all the forward links */
dbGetLink(&(prec->sell),DBR_USHORT,&(prec->seln),0,0);
checkAlarms(prec);
push_values(prec);
monitor(prec);
recGblFwdLink(prec);
prec->pact=FALSE;
return(status);
}
#define indexof(field) dfanoutRecord##field
static long get_units(DBADDR *paddr,char *units)
{
dfanoutRecord *prec=(dfanoutRecord *)paddr->precord;
if(paddr->pfldDes->field_type == DBF_DOUBLE) {
strncpy(units,prec->egu,DB_UNITS_SIZE);
}
return(0);
}
static long get_precision(const DBADDR *paddr,long *precision)
{
dfanoutRecord *prec=(dfanoutRecord *)paddr->precord;
*precision = prec->prec;
if (dbGetFieldIndex(paddr) == indexof(VAL)) return(0);
recGblGetPrec(paddr,precision);
return(0);
}
static long get_graphic_double(DBADDR *paddr,struct dbr_grDouble *pgd)
{
dfanoutRecord *prec=(dfanoutRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
case indexof(HIHI):
case indexof(HIGH):
case indexof(LOW):
case indexof(LOLO):
case indexof(LALM):
case indexof(ALST):
case indexof(MLST):
pgd->upper_disp_limit = prec->hopr;
pgd->lower_disp_limit = prec->lopr;
break;
default:
recGblGetGraphicDouble(paddr,pgd);
}
return(0);
}
static long get_control_double(DBADDR *paddr,struct dbr_ctrlDouble *pcd)
{
dfanoutRecord *prec=(dfanoutRecord *)paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
case indexof(LALM):
case indexof(ALST):
case indexof(MLST):
pcd->upper_ctrl_limit = prec->hopr;
pcd->lower_ctrl_limit = prec->lopr;
break;
default:
recGblGetControlDouble(paddr,pcd);
}
return(0);
}
static long get_alarm_double(DBADDR *paddr,struct dbr_alDouble *pad)
{
dfanoutRecord *prec=(dfanoutRecord *)paddr->precord;
if(dbGetFieldIndex(paddr) == indexof(VAL)) {
pad->upper_alarm_limit = prec->hhsv ? prec->hihi : epicsNAN;
pad->upper_warning_limit = prec->hsv ? prec->high : epicsNAN;
pad->lower_warning_limit = prec->lsv ? prec->low : epicsNAN;
pad->lower_alarm_limit = prec->llsv ? prec->lolo : epicsNAN;
} else recGblGetAlarmDouble(paddr,pad);
return(0);
}
static void checkAlarms(dfanoutRecord *prec)
{
double val, hyst, lalm;
double alev;
epicsEnum16 asev;
if (prec->udf) {
recGblSetSevr(prec, UDF_ALARM, prec->udfs);
return;
}
val = prec->val;
hyst = prec->hyst;
lalm = prec->lalm;
/* alarm condition hihi */
asev = prec->hhsv;
alev = prec->hihi;
if (asev && (val >= alev || ((lalm == alev) && (val >= alev - hyst)))) {
if (recGblSetSevr(prec, HIHI_ALARM, asev))
prec->lalm = alev;
return;
}
/* alarm condition lolo */
asev = prec->llsv;
alev = prec->lolo;
if (asev && (val <= alev || ((lalm == alev) && (val <= alev + hyst)))) {
if (recGblSetSevr(prec, LOLO_ALARM, asev))
prec->lalm = alev;
return;
}
/* alarm condition high */
asev = prec->hsv;
alev = prec->high;
if (asev && (val >= alev || ((lalm == alev) && (val >= alev - hyst)))) {
if (recGblSetSevr(prec, HIGH_ALARM, asev))
prec->lalm = alev;
return;
}
/* alarm condition low */
asev = prec->lsv;
alev = prec->low;
if (asev && (val <= alev || ((lalm == alev) && (val <= alev + hyst)))) {
if (recGblSetSevr(prec, LOW_ALARM, asev))
prec->lalm = alev;
return;
}
/* we get here only if val is out of alarm by at least hyst */
prec->lalm = val;
return;
}
static void monitor(dfanoutRecord *prec)
{
unsigned monitor_mask = recGblResetAlarms(prec);
/* check for value change */
recGblCheckDeadband(&prec->mlst, prec->val, prec->mdel, &monitor_mask, DBE_VALUE);
/* check for archive change */
recGblCheckDeadband(&prec->alst, prec->val, prec->adel, &monitor_mask, DBE_ARCHIVE);
/* send out monitors connected to the value field */
if (monitor_mask){
db_post_events(prec,&prec->val,monitor_mask);
}
return;
}
static void push_values(dfanoutRecord *prec)
{
struct link *plink; /* structure of the link field */
int i;
long status;
unsigned short state;
switch (prec->selm){
case (dfanoutSELM_All):
for(i=0, plink=&(prec->outa); i<OUT_ARG_MAX; i++, plink++) {
status=dbPutLink(plink,DBR_DOUBLE,&(prec->val),1);
if(status) recGblSetSevr(prec,LINK_ALARM,MAJOR_ALARM);
}
break;
case (dfanoutSELM_Specified):
if(prec->seln>OUT_ARG_MAX) {
recGblSetSevr(prec,SOFT_ALARM,INVALID_ALARM);
break;
}
if(prec->seln==0) break;
plink=&(prec->outa);
plink += (prec->seln -1);
status=dbPutLink(plink,DBR_DOUBLE,&(prec->val),1);
if(status) recGblSetSevr(prec,LINK_ALARM,MAJOR_ALARM);
break;
case (dfanoutSELM_Mask):
if(prec->seln==0) break;
for(i=0, plink=&(prec->outa), state=prec->seln;
i<OUT_ARG_MAX;
i++, plink++, state>>=1) {
if(state&1) {
status=dbPutLink(plink,DBR_DOUBLE,&(prec->val),1);
if(status) recGblSetSevr(prec,LINK_ALARM,MAJOR_ALARM);
}
}
break;
default:
recGblSetSevr(prec,SOFT_ALARM,INVALID_ALARM);
}
}
@@ -0,0 +1,204 @@
#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
menu(dfanoutSELM) {
choice(dfanoutSELM_All,"All")
choice(dfanoutSELM_Specified,"Specified")
choice(dfanoutSELM_Mask,"Mask")
}
recordtype(dfanout) {
include "dbCommon.dbd"
field(VAL,DBF_DOUBLE) {
prompt("Desired Output")
promptgroup("40 - Input")
asl(ASL0)
pp(TRUE)
}
field(SELM,DBF_MENU) {
prompt("Select Mechanism")
promptgroup("30 - Action")
interest(1)
menu(dfanoutSELM)
}
field(SELN,DBF_USHORT) {
prompt("Link Selection")
interest(1)
initial("1")
}
field(SELL,DBF_INLINK) {
prompt("Link Selection Loc")
promptgroup("30 - Action")
interest(1)
}
field(OUTA,DBF_OUTLINK) {
prompt("Output Spec A")
promptgroup("50 - Output")
interest(1)
}
field(OUTB,DBF_OUTLINK) {
prompt("Output Spec B")
promptgroup("50 - Output")
interest(1)
}
field(OUTC,DBF_OUTLINK) {
prompt("Output Spec C")
promptgroup("50 - Output")
interest(1)
}
field(OUTD,DBF_OUTLINK) {
prompt("Output Spec D")
promptgroup("50 - Output")
interest(1)
}
field(OUTE,DBF_OUTLINK) {
prompt("Output Spec E")
promptgroup("50 - Output")
interest(1)
}
field(OUTF,DBF_OUTLINK) {
prompt("Output Spec F")
promptgroup("50 - Output")
interest(1)
}
field(OUTG,DBF_OUTLINK) {
prompt("Output Spec G")
promptgroup("50 - Output")
interest(1)
}
field(OUTH,DBF_OUTLINK) {
prompt("Output Spec H")
promptgroup("50 - Output")
interest(1)
}
field(DOL,DBF_INLINK) {
prompt("Desired Output Loc")
promptgroup("40 - Input")
interest(1)
}
field(OMSL,DBF_MENU) {
prompt("Output Mode Select")
promptgroup("50 - Output")
interest(1)
menu(menuOmsl)
}
field(EGU,DBF_STRING) {
prompt("Engineering Units")
promptgroup("80 - Display")
interest(1)
size(16)
prop(YES)
}
field(PREC,DBF_SHORT) {
prompt("Display Precision")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(HOPR,DBF_DOUBLE) {
prompt("High Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(LOPR,DBF_DOUBLE) {
prompt("Low Operating Range")
promptgroup("80 - Display")
interest(1)
prop(YES)
}
field(HIHI,DBF_DOUBLE) {
prompt("Hihi Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(LOLO,DBF_DOUBLE) {
prompt("Lolo Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(HIGH,DBF_DOUBLE) {
prompt("High Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(LOW,DBF_DOUBLE) {
prompt("Low Alarm Limit")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
}
field(HHSV,DBF_MENU) {
prompt("Hihi Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(LLSV,DBF_MENU) {
prompt("Lolo Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(HSV,DBF_MENU) {
prompt("High Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(LSV,DBF_MENU) {
prompt("Low Severity")
promptgroup("70 - Alarm")
pp(TRUE)
interest(1)
prop(YES)
menu(menuAlarmSevr)
}
field(HYST,DBF_DOUBLE) {
prompt("Alarm Deadband")
promptgroup("70 - Alarm")
interest(1)
}
field(ADEL,DBF_DOUBLE) {
prompt("Archive Deadband")
promptgroup("80 - Display")
interest(1)
}
field(MDEL,DBF_DOUBLE) {
prompt("Monitor Deadband")
promptgroup("80 - Display")
interest(1)
}
field(LALM,DBF_DOUBLE) {
prompt("Last Value Alarmed")
special(SPC_NOMOD)
interest(3)
}
field(ALST,DBF_DOUBLE) {
prompt("Last Value Archived")
special(SPC_NOMOD)
interest(3)
}
field(MLST,DBF_DOUBLE) {
prompt("Last Val Monitored")
special(SPC_NOMOD)
interest(3)
}
}
+219
View File
@@ -0,0 +1,219 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* recEvent.c - Record Support Routines for Event records */
/*
* Author: Janet Anderson
* Date: 12-13-91
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "dbDefs.h"
#include "epicsPrint.h"
#include "alarm.h"
#include "callback.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "dbScan.h"
#include "dbFldTypes.h"
#include "devSup.h"
#include "errMdef.h"
#include "recSup.h"
#include "recGbl.h"
#include "special.h"
#include "menuYesNo.h"
#define GEN_SIZE_OFFSET
#include "eventRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
static long special(DBADDR *, int);
#define get_value NULL
#define cvt_dbaddr NULL
#define get_array_info NULL
#define put_array_info NULL
#define get_units NULL
#define get_precision NULL
#define get_enum_str NULL
#define get_enum_strs NULL
#define put_enum_str NULL
#define get_graphic_double NULL
#define get_control_double NULL
#define get_alarm_double NULL
rset eventRSET={
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double
};
epicsExportAddress(rset,eventRSET);
struct eventdset { /* event input dset */
long number;
DEVSUPFUN dev_report;
DEVSUPFUN init;
DEVSUPFUN init_record; /*returns: (-1,0)=>(failure,success)*/
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_event;/*(0)=> success */
};
static void monitor(eventRecord *);
static long readValue(eventRecord *);
static long init_record(struct dbCommon *pcommon, int pass)
{
struct eventRecord *prec = (struct eventRecord *)pcommon;
struct eventdset *pdset;
long status=0;
if (pass == 0) return 0;
recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
recGblInitConstantLink(&prec->siol, DBF_STRING, &prec->sval);
if( (pdset=(struct eventdset *)(prec->dset)) && (pdset->init_record) )
status=(*pdset->init_record)(prec);
prec->epvt = eventNameToHandle(prec->val);
return(status);
}
static long process(struct dbCommon *pcommon)
{
struct eventRecord *prec = (struct eventRecord *)pcommon;
struct eventdset *pdset = (struct eventdset *)(prec->dset);
long status=0;
unsigned char pact=prec->pact;
if((pdset!=NULL) && (pdset->number >= 5) && pdset->read_event )
status=readValue(prec); /* read the new value */
/* check if device support set pact */
if ( !pact && prec->pact ) return(0);
prec->pact = TRUE;
postEvent(prec->epvt);
recGblGetTimeStampSimm(prec, prec->simm, &prec->siol);
/* check event list */
monitor(prec);
/* process the forward scan link record */
recGblFwdLink(prec);
prec->pact=FALSE;
return(status);
}
static long special(DBADDR *paddr, int after)
{
eventRecord *prec = (eventRecord *)paddr->precord;
if (dbGetFieldIndex(paddr) == eventRecordSIMM) {
if (!after)
recGblSaveSimm(prec->sscn, &prec->oldsimm, prec->simm);
else
recGblCheckSimm((dbCommon *)prec, &prec->sscn, prec->oldsimm, prec->simm);
return 0;
}
if (!after) return 0;
if (dbGetFieldIndex(paddr) == eventRecordVAL) {
prec->epvt = eventNameToHandle(prec->val);
}
return 0;
}
static void monitor(eventRecord *prec)
{
unsigned short monitor_mask;
/* get previous stat and sevr and new stat and sevr*/
monitor_mask = recGblResetAlarms(prec);
db_post_events(prec,&prec->val,monitor_mask|DBE_VALUE);
return;
}
static long readValue(eventRecord *prec)
{
struct eventdset *pdset = (struct eventdset *) prec->dset;
long status = 0;
if (!prec->pact) {
status = recGblGetSimm((dbCommon *)prec, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
if (status) return status;
}
switch (prec->simm) {
case menuYesNoNO:
status = pdset->read_event(prec);
break;
case menuYesNoYES: {
recGblSetSevr(prec, SIMM_ALARM, prec->sims);
if (prec->pact || (prec->sdly < 0.)) {
status = dbGetLink(&prec->siol, DBR_STRING, &prec->sval, 0, 0);
if (status == 0) {
if (strcmp(prec->sval, prec->val) != 0) {
strcpy(prec->val, prec->sval);
prec->epvt = eventNameToHandle(prec->val);
}
prec->udf = FALSE;
}
prec->pact = FALSE;
} else { /* !prec->pact && delay >= 0. */
CALLBACK *pvt = prec->simpvt;
if (!pvt) {
pvt = calloc(1, sizeof(CALLBACK)); /* very lazy allocation of callback structure */
prec->simpvt = pvt;
}
if (pvt) callbackRequestProcessCallbackDelayed(pvt, prec->prio, prec, prec->sdly);
prec->pact = TRUE;
}
break;
}
default:
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
status = -1;
}
return status;
}
@@ -0,0 +1,82 @@
#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
recordtype(event) {
include "dbCommon.dbd"
field(VAL,DBF_STRING) {
prompt("Event Name To Post")
promptgroup("40 - Input")
special(SPC_MOD)
asl(ASL0)
size(40)
}
%#include "dbScan.h"
field(EPVT, DBF_NOACCESS) {
prompt("Event private")
special(SPC_NOMOD)
interest(4)
extra("EVENTPVT epvt")
}
field(INP,DBF_INLINK) {
prompt("Input Specification")
promptgroup("40 - Input")
interest(1)
}
field(SIOL,DBF_INLINK) {
prompt("Simulation Input Link")
promptgroup("90 - Simulate")
interest(1)
}
field(SVAL,DBF_STRING) {
prompt("Simulation Value")
size(40)
}
field(SIML,DBF_INLINK) {
prompt("Simulation Mode Link")
promptgroup("90 - Simulate")
interest(1)
}
field(SIMM,DBF_MENU) {
prompt("Simulation Mode")
special(SPC_MOD)
interest(1)
menu(menuYesNo)
}
field(SIMS,DBF_MENU) {
prompt("Simulation Mode Severity")
promptgroup("90 - Simulate")
interest(2)
menu(menuAlarmSevr)
}
field(OLDSIMM,DBF_MENU) {
prompt("Prev. Simulation Mode")
special(SPC_NOMOD)
interest(4)
menu(menuSimm)
}
field(SSCN,DBF_MENU) {
prompt("Sim. Mode Scan")
promptgroup("90 - Simulate")
interest(1)
menu(menuScan)
initial("65535")
}
field(SDLY,DBF_DOUBLE) {
prompt("Sim. Mode Async Delay")
promptgroup("90 - Simulate")
interest(2)
initial("-1.0")
}
%#include "callback.h"
field(SIMPVT,DBF_NOACCESS) {
prompt("Sim. Mode Private")
special(SPC_NOMOD)
interest(4)
extra("CALLBACK *simpvt")
}
}
+157
View File
@@ -0,0 +1,157 @@
/*************************************************************************\
* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Original Author: Bob Dalesio
* Date: 12-20-88
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "dbDefs.h"
#include "epicsPrint.h"
#include "alarm.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "dbFldTypes.h"
#include "errMdef.h"
#include "epicsTypes.h"
#include "recSup.h"
#include "recGbl.h"
#include "dbCommon.h"
#define GEN_SIZE_OFFSET
#include "fanoutRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
#define NLINKS 16
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
#define special NULL
#define get_value NULL
#define cvt_dbaddr NULL
#define get_array_info NULL
#define put_array_info NULL
#define get_units NULL
#define get_precision NULL
#define get_enum_str NULL
#define get_enum_strs NULL
#define put_enum_str NULL
#define get_graphic_double NULL
#define get_control_double NULL
#define get_alarm_double NULL
rset fanoutRSET = {
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double
};
epicsExportAddress(rset,fanoutRSET);
static long init_record(struct dbCommon *pcommon, int pass)
{
struct fanoutRecord *prec = (struct fanoutRecord *)pcommon;
if (pass == 0)
return 0;
recGblInitConstantLink(&prec->sell, DBF_USHORT, &prec->seln);
return 0;
}
static long process(struct dbCommon *pcommon)
{
struct fanoutRecord *prec = (struct fanoutRecord *)pcommon;
struct link *plink;
epicsUInt16 seln, events;
int i;
epicsUInt16 oldn = prec->seln;
prec->pact = TRUE;
/* fetch link selection */
dbGetLink(&prec->sell, DBR_USHORT, &prec->seln, 0, 0);
seln = prec->seln;
switch (prec->selm) {
case fanoutSELM_All:
plink = &prec->lnk0;
for (i = 0; i < NLINKS; i++, plink++) {
dbScanFwdLink(plink);
}
break;
case fanoutSELM_Specified:
i = seln + prec->offs;
if (i < 0 || i >= NLINKS) {
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
break;
}
plink = &prec->lnk0 + i;
dbScanFwdLink(plink);
break;
case fanoutSELM_Mask:
i = prec->shft;
if (i < -15 || i > 15) {
/* Shifting by more than the number of bits in the
* value produces undefined behavior in C */
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
break;
}
seln = (i >= 0) ? seln >> i : seln << -i;
if (seln == 0)
break;
plink = &prec->lnk0;
for (i = 0; i < NLINKS; i++, seln >>= 1, plink++) {
if (seln & 1)
dbScanFwdLink(plink);
}
break;
default:
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
}
prec->udf = FALSE;
recGblGetTimeStamp(prec);
/* post monitors */
events = recGblResetAlarms(prec);
if (events)
db_post_events(prec, &prec->val, events);
if (prec->seln != oldn)
db_post_events(prec, &prec->seln, events | DBE_VALUE | DBE_LOG);
/* finish off */
recGblFwdLink(prec);
prec->pact = FALSE;
return 0;
}
@@ -0,0 +1,129 @@
#*************************************************************************
# Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
menu(fanoutSELM) {
choice(fanoutSELM_All,"All")
choice(fanoutSELM_Specified,"Specified")
choice(fanoutSELM_Mask,"Mask")
}
recordtype(fanout) {
include "dbCommon.dbd"
field(VAL,DBF_LONG) {
prompt("Used to trigger")
asl(ASL0)
pp(TRUE)
}
field(SELM,DBF_MENU) {
prompt("Select Mechanism")
promptgroup("30 - Action")
interest(1)
menu(fanoutSELM)
}
field(SELN,DBF_USHORT) {
prompt("Link Selection")
interest(1)
initial("1")
}
field(SELL,DBF_INLINK) {
prompt("Link Selection Loc")
promptgroup("30 - Action")
interest(1)
}
field(OFFS,DBF_SHORT) {
prompt("Offset for Specified")
promptgroup("30 - Action")
interest(1)
initial("0")
}
field(SHFT,DBF_SHORT) {
prompt("Shift for Mask mode")
promptgroup("30 - Action")
interest(1)
initial("-1")
}
field(LNK0,DBF_FWDLINK) {
prompt("Forward Link 0")
promptgroup("51 - Output 0-7")
interest(1)
}
field(LNK1,DBF_FWDLINK) {
prompt("Forward Link 1")
promptgroup("51 - Output 0-7")
interest(1)
}
field(LNK2,DBF_FWDLINK) {
prompt("Forward Link 2")
promptgroup("51 - Output 0-7")
interest(1)
}
field(LNK3,DBF_FWDLINK) {
prompt("Forward Link 3")
promptgroup("51 - Output 0-7")
interest(1)
}
field(LNK4,DBF_FWDLINK) {
prompt("Forward Link 4")
promptgroup("51 - Output 0-7")
interest(1)
}
field(LNK5,DBF_FWDLINK) {
prompt("Forward Link 5")
promptgroup("51 - Output 0-7")
interest(1)
}
field(LNK6,DBF_FWDLINK) {
prompt("Forward Link 6")
promptgroup("51 - Output 0-7")
interest(1)
}
field(LNK7,DBF_FWDLINK) {
prompt("Forward Link 7")
promptgroup("51 - Output 0-7")
interest(1)
}
field(LNK8,DBF_FWDLINK) {
prompt("Forward Link 8")
promptgroup("52 - Output 8-F")
interest(1)
}
field(LNK9,DBF_FWDLINK) {
prompt("Forward Link 9")
promptgroup("52 - Output 8-F")
interest(1)
}
field(LNKA,DBF_FWDLINK) {
prompt("Forward Link 10")
promptgroup("52 - Output 8-F")
interest(1)
}
field(LNKB,DBF_FWDLINK) {
prompt("Forward Link 11")
promptgroup("52 - Output 8-F")
interest(1)
}
field(LNKC,DBF_FWDLINK) {
prompt("Forward Link 12")
promptgroup("52 - Output 8-F")
interest(1)
}
field(LNKD,DBF_FWDLINK) {
prompt("Forward Link 13")
promptgroup("52 - Output 8-F")
interest(1)
}
field(LNKE,DBF_FWDLINK) {
prompt("Forward Link 14")
promptgroup("52 - Output 8-F")
interest(1)
}
field(LNKF,DBF_FWDLINK) {
prompt("Forward Link 15")
promptgroup("52 - Output 8-F")
interest(1)
}
}
@@ -0,0 +1,490 @@
/*************************************************************************\
* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* histogramRecord.c - Record Support Routines for Histogram records */
/*
* Author: Janet Anderson
* Date: 5/20/91
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include "dbDefs.h"
#include "epicsPrint.h"
#include "alarm.h"
#include "callback.h"
#include "dbAccess.h"
#include "dbEvent.h"
#include "epicsPrint.h"
#include "dbFldTypes.h"
#include "devSup.h"
#include "errMdef.h"
#include "special.h"
#include "recSup.h"
#include "recGbl.h"
#include "menuYesNo.h"
#define GEN_SIZE_OFFSET
#include "histogramRecord.h"
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
#define indexof(field) histogramRecord##field
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
static long init_record(struct dbCommon *, int);
static long process(struct dbCommon *);
static long special(DBADDR *, int);
#define get_value NULL
static long cvt_dbaddr(DBADDR *);
static long get_array_info(DBADDR *, long *, long *);
#define put_array_info NULL
static long get_units(DBADDR *, char *);
static long get_precision(const DBADDR *paddr,long *precision);
#define get_enum_str NULL
#define get_enum_strs NULL
#define put_enum_str NULL
#define get_alarm_double NULL
static long get_graphic_double(DBADDR *paddr,struct dbr_grDouble *pgd);
static long get_control_double(DBADDR *paddr,struct dbr_ctrlDouble *pcd);
rset histogramRSET = {
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_units,
get_precision,
get_enum_str,
get_enum_strs,
put_enum_str,
get_graphic_double,
get_control_double,
get_alarm_double
};
epicsExportAddress(rset,histogramRSET);
int histogramSDELprecision = 2;
epicsExportAddress(int, histogramSDELprecision);
struct histogramdset { /* histogram input dset */
long number;
DEVSUPFUN dev_report;
DEVSUPFUN init;
DEVSUPFUN init_record; /*returns: (-1,0)=>(failure,success)*/
DEVSUPFUN get_ioint_info;
DEVSUPFUN read_histogram;/*(0,2)=> success and add_count, don't add_count)*/
/* if add_count then sgnl added to array */
DEVSUPFUN special_linconv;
};
/* control block for callback*/
typedef struct myCallback {
CALLBACK callback;
histogramRecord *prec;
} myCallback;
static long add_count(histogramRecord *);
static long clear_histogram(histogramRecord *);
static void monitor(histogramRecord *);
static long readValue(histogramRecord *);
static void wdogCallback(CALLBACK *arg)
{
myCallback *pcallback;
histogramRecord *prec;
callbackGetUser(pcallback, arg);
prec = pcallback->prec;
/* force post events for any count change */
if (prec->mcnt > 0){
dbScanLock((struct dbCommon *)prec);
recGblGetTimeStamp(prec);
db_post_events(prec, prec->bptr, DBE_VALUE | DBE_LOG);
prec->mcnt = 0;
dbScanUnlock((struct dbCommon *)prec);
}
if (prec->sdel > 0) {
/* restart timer */
callbackRequestDelayed(&pcallback->callback, prec->sdel);
}
return;
}
static long wdogInit(histogramRecord *prec)
{
myCallback *pcallback;
if (!prec->wdog && prec->sdel > 0) {
/* initialize a callback object */
pcallback = calloc(1, sizeof(myCallback));
pcallback->prec = prec;
if (!pcallback)
return -1;
callbackSetCallback(wdogCallback, &pcallback->callback);
callbackSetUser(pcallback, &pcallback->callback);
callbackSetPriority(priorityLow, &pcallback->callback);
prec->wdog = pcallback;
}
if (!prec->wdog)
return -1;
pcallback = prec->wdog;
if (!pcallback)
return -1;
if (prec->sdel > 0) {
/* start new timer on monitor */
callbackRequestDelayed(&pcallback->callback, prec->sdel);
}
return 0;
}
static long init_record(struct dbCommon *pcommon, int pass)
{
struct histogramRecord *prec = (struct histogramRecord *)pcommon;
struct histogramdset *pdset;
if (pass == 0) {
/* allocate space for histogram array */
if (!prec->bptr) {
if (prec->nelm <= 0)
prec->nelm = 1;
prec->bptr = calloc(prec->nelm, sizeof(epicsUInt32));
}
/* calulate width of array element */
prec->wdth = (prec->ulim - prec->llim) / prec->nelm;
return 0;
}
wdogInit(prec);
recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
recGblInitConstantLink(&prec->siol, DBF_DOUBLE, &prec->sval);
/* must have device support defined */
pdset = (struct histogramdset *) prec->dset;
if (!pdset) {
recGblRecordError(S_dev_noDSET, prec, "histogram: init_record");
return S_dev_noDSET;
}
/* must have read_histogram function defined */
if (pdset->number < 6 || !pdset->read_histogram) {
recGblRecordError(S_dev_missingSup, prec, "histogram: init_record");
return S_dev_missingSup;
}
/* call device support init_record */
if (pdset->init_record) {
long status = pdset->init_record(prec);
if (status)
return status;
}
return 0;
}
static long process(struct dbCommon *pcommon)
{
struct histogramRecord *prec = (struct histogramRecord *)pcommon;
struct histogramdset *pdset = (struct histogramdset *) prec->dset;
int pact = prec->pact;
long status;
if (!pdset || !pdset->read_histogram) {
prec->pact = TRUE;
recGblRecordError(S_dev_missingSup, prec, "read_histogram");
return S_dev_missingSup;
}
status = readValue(prec); /* read the new value */
/* check if device support set pact */
if (!pact && prec->pact)
return 0;
prec->pact = TRUE;
recGblGetTimeStampSimm(prec, prec->simm, &prec->siol);
if (status == 0)
add_count(prec);
else if (status == 2)
status = 0;
monitor(prec);
recGblFwdLink(prec);
prec->pact=FALSE;
return status;
}
static long special(DBADDR *paddr, int after)
{
histogramRecord *prec = (histogramRecord *) paddr->precord;
if (paddr->special == SPC_MOD && dbGetFieldIndex(paddr) == histogramRecordSIMM) {
if (!after)
recGblSaveSimm(prec->sscn, &prec->oldsimm, prec->simm);
else
recGblCheckSimm((dbCommon *)prec, &prec->sscn, prec->oldsimm, prec->simm);
return 0;
}
if (!after)
return 0;
switch (paddr->special) {
case SPC_CALC:
if (prec->cmd <= 1) {
clear_histogram(prec);
prec->cmd = 0;
}
else if (prec->cmd == 2) {
prec->csta = TRUE;
prec->cmd = 0;
}
else if (prec->cmd == 3) {
prec->csta = FALSE;
prec->cmd = 0;
}
return 0;
case SPC_MOD:
/* increment frequency in histogram array */
add_count(prec);
return 0;
case SPC_RESET:
if (dbGetFieldIndex(paddr) == histogramRecordSDEL) {
wdogInit(prec);
}
else {
prec->wdth = (prec->ulim - prec->llim) / prec->nelm;
clear_histogram(prec);
}
return 0;
default:
recGblDbaddrError(S_db_badChoice, paddr, "histogram: special");
return S_db_badChoice;
}
}
static void monitor(histogramRecord *prec)
{
unsigned short monitor_mask = recGblResetAlarms(prec);
/* post events for count change */
if (prec->mcnt > prec->mdel){
monitor_mask |= DBE_VALUE | DBE_LOG;
/* reset counts since monitor */
prec->mcnt = 0;
}
/* send out monitors connected to the value field */
if (monitor_mask)
db_post_events(prec, prec->bptr, monitor_mask);
return;
}
static long cvt_dbaddr(DBADDR *paddr)
{
histogramRecord *prec = (histogramRecord *) paddr->precord;
paddr->pfield = prec->bptr;
paddr->no_elements = prec->nelm;
paddr->field_type = DBF_ULONG;
paddr->field_size = sizeof(epicsUInt32);
paddr->dbr_field_type = DBF_ULONG;
return 0;
}
static long get_array_info(DBADDR *paddr, long *no_elements, long *offset)
{
histogramRecord *prec = (histogramRecord *) paddr->precord;
*no_elements = prec->nelm;
*offset = 0;
return 0;
}
static long add_count(histogramRecord *prec)
{
double temp;
epicsUInt32 *pdest;
int i;
if (prec->csta == FALSE)
return 0;
if (prec->llim >= prec->ulim) {
if (prec->nsev < INVALID_ALARM) {
prec->stat = SOFT_ALARM;
prec->sevr = INVALID_ALARM;
return -1;
}
}
if (prec->sgnl < prec->llim ||
prec->sgnl >= prec->ulim)
return 0;
temp = prec->sgnl - prec->llim;
for (i = 1; i <= prec->nelm; i++){
if (temp <= (double) i * prec->wdth)
break;
}
pdest = prec->bptr + i - 1;
if (*pdest == (epicsUInt32) UINT_MAX)
*pdest = 0;
(*pdest)++;
prec->mcnt++;
return 0;
}
static long clear_histogram(histogramRecord *prec)
{
int i;
for (i = 0; i < prec->nelm; i++)
prec->bptr[i] = 0;
prec->mcnt = prec->mdel + 1;
prec->udf = FALSE;
return 0;
}
static long readValue(histogramRecord *prec)
{
struct histogramdset *pdset = (struct histogramdset *) prec->dset;
long status = 0;
if (!prec->pact) {
status = recGblGetSimm((dbCommon *)prec, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
if (status) return status;
}
switch (prec->simm) {
case menuYesNoNO:
status = pdset->read_histogram(prec);
break;
case menuYesNoYES: {
recGblSetSevr(prec, SIMM_ALARM, prec->sims);
if (prec->pact || (prec->sdly < 0.)) {
status = dbGetLink(&prec->siol, DBR_DOUBLE, &prec->sval, 0, 0);
if (status == 0) {
prec->sgnl = prec->sval;
prec->udf = FALSE;
}
prec->pact = FALSE;
} else { /* !prec->pact && delay >= 0. */
CALLBACK *pvt = prec->simpvt;
if (!pvt) {
pvt = calloc(1, sizeof(CALLBACK)); /* very lazy allocation of callback structure */
prec->simpvt = pvt;
}
if (pvt) callbackRequestProcessCallbackDelayed(pvt, prec->prio, prec, prec->sdly);
prec->pact = TRUE;
}
break;
}
default:
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
status = -1;
}
return status;
}
static long get_units(DBADDR *paddr, char *units)
{
if (dbGetFieldIndex(paddr) == indexof(SDEL)) {
strcpy(units,"s");
}
/* We should have EGU for other DOUBLE values or probably get it from input link SVL */
return 0;
}
static long get_precision(const DBADDR *paddr,long *precision)
{
histogramRecord *prec = (histogramRecord *) paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(ULIM):
case indexof(LLIM):
case indexof(SGNL):
case indexof(SVAL):
case indexof(WDTH):
*precision = prec->prec;
break;
case indexof(SDEL):
*precision = histogramSDELprecision;
break;
default:
recGblGetPrec(paddr,precision);
}
return 0;
}
static long get_graphic_double(DBADDR *paddr,struct dbr_grDouble *pgd)
{
histogramRecord *prec = (histogramRecord *) paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
pgd->upper_disp_limit = prec->hopr;
pgd->lower_disp_limit = prec->lopr;
break;
case indexof(WDTH):
pgd->upper_disp_limit = prec->ulim - prec->llim;
pgd->lower_disp_limit = 0.0;
break;
default:
recGblGetGraphicDouble(paddr,pgd);
}
return 0;
}
static long get_control_double(DBADDR *paddr,struct dbr_ctrlDouble *pcd)
{
histogramRecord *prec = (histogramRecord *) paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
pcd->upper_ctrl_limit = prec->hopr;
pcd->lower_ctrl_limit = prec->lopr;
break;
case indexof(WDTH):
pcd->upper_ctrl_limit = prec->ulim - prec->llim;
pcd->lower_ctrl_limit = 0.0;
break;
default:
recGblGetControlDouble(paddr, pcd);
}
return 0;
}
Loaded 100 of 562 files, more files were not shown because too many files have changed in this diff. Show more