|
|
|
@@ -1,6 +1,6 @@
|
|
|
|
|
/* xxxRecord.c */
|
|
|
|
|
/* Example record support module */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
@@ -40,36 +40,36 @@ static long get_precision(const DBADDR *, long *);
|
|
|
|
|
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 xxxRSET={
|
|
|
|
|
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
|
|
|
|
|
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,xxxRSET);
|
|
|
|
|
|
|
|
|
|
typedef struct xxxset { /* xxx input dset */
|
|
|
|
|
long number;
|
|
|
|
|
DEVSUPFUN dev_report;
|
|
|
|
|
DEVSUPFUN init;
|
|
|
|
|
DEVSUPFUN init_record; /*returns: (-1,0)=>(failure,success)*/
|
|
|
|
|
DEVSUPFUN get_ioint_info;
|
|
|
|
|
DEVSUPFUN read_xxx;
|
|
|
|
|
long number;
|
|
|
|
|
DEVSUPFUN dev_report;
|
|
|
|
|
DEVSUPFUN init;
|
|
|
|
|
DEVSUPFUN init_record; /*returns: (-1,0)=>(failure,success)*/
|
|
|
|
|
DEVSUPFUN get_ioint_info;
|
|
|
|
|
DEVSUPFUN read_xxx;
|
|
|
|
|
}xxxdset;
|
|
|
|
|
|
|
|
|
|
static void checkAlarms(xxxRecord *prec);
|
|
|
|
@@ -77,62 +77,62 @@ static void monitor(xxxRecord *prec);
|
|
|
|
|
|
|
|
|
|
static long init_record(struct dbCommon *pcommon, int pass)
|
|
|
|
|
{
|
|
|
|
|
xxxRecord *prec = (xxxRecord *)pcommon;
|
|
|
|
|
xxxdset *pdset;
|
|
|
|
|
long status;
|
|
|
|
|
xxxRecord *prec = (xxxRecord *)pcommon;
|
|
|
|
|
xxxdset *pdset;
|
|
|
|
|
long status;
|
|
|
|
|
|
|
|
|
|
if (pass==0) return(0);
|
|
|
|
|
|
|
|
|
|
if(!(pdset = (xxxdset *)(prec->dset))) {
|
|
|
|
|
recGblRecordError(S_dev_noDSET,(void *)prec,"xxx: init_record");
|
|
|
|
|
return(S_dev_noDSET);
|
|
|
|
|
recGblRecordError(S_dev_noDSET,(void *)prec,"xxx: init_record");
|
|
|
|
|
return(S_dev_noDSET);
|
|
|
|
|
}
|
|
|
|
|
/* must have read_xxx function defined */
|
|
|
|
|
if( (pdset->number < 5) || (pdset->read_xxx == NULL) ) {
|
|
|
|
|
recGblRecordError(S_dev_missingSup,(void *)prec,"xxx: init_record");
|
|
|
|
|
return(S_dev_missingSup);
|
|
|
|
|
recGblRecordError(S_dev_missingSup,(void *)prec,"xxx: init_record");
|
|
|
|
|
return(S_dev_missingSup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( pdset->init_record ) {
|
|
|
|
|
if((status=(*pdset->init_record)(prec))) return(status);
|
|
|
|
|
if((status=(*pdset->init_record)(prec))) return(status);
|
|
|
|
|
}
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static long process(struct dbCommon *pcommon)
|
|
|
|
|
{
|
|
|
|
|
xxxRecord *prec = (xxxRecord *)pcommon;
|
|
|
|
|
xxxdset *pdset = (xxxdset *)(prec->dset);
|
|
|
|
|
long status;
|
|
|
|
|
unsigned char pact=prec->pact;
|
|
|
|
|
xxxRecord *prec = (xxxRecord *)pcommon;
|
|
|
|
|
xxxdset *pdset = (xxxdset *)(prec->dset);
|
|
|
|
|
long status;
|
|
|
|
|
unsigned char pact=prec->pact;
|
|
|
|
|
|
|
|
|
|
if( (pdset==NULL) || (pdset->read_xxx==NULL) ) {
|
|
|
|
|
prec->pact=TRUE;
|
|
|
|
|
recGblRecordError(S_dev_missingSup,(void *)prec,"read_xxx");
|
|
|
|
|
return(S_dev_missingSup);
|
|
|
|
|
}
|
|
|
|
|
if( (pdset==NULL) || (pdset->read_xxx==NULL) ) {
|
|
|
|
|
prec->pact=TRUE;
|
|
|
|
|
recGblRecordError(S_dev_missingSup,(void *)prec,"read_xxx");
|
|
|
|
|
return(S_dev_missingSup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* pact must not be set until after calling device support */
|
|
|
|
|
status=(*pdset->read_xxx)(prec);
|
|
|
|
|
/* check if device support set pact */
|
|
|
|
|
if ( !pact && prec->pact ) return(0);
|
|
|
|
|
prec->pact = TRUE;
|
|
|
|
|
/* pact must not be set until after calling device support */
|
|
|
|
|
status=(*pdset->read_xxx)(prec);
|
|
|
|
|
/* check if device support set pact */
|
|
|
|
|
if ( !pact && prec->pact ) return(0);
|
|
|
|
|
prec->pact = TRUE;
|
|
|
|
|
|
|
|
|
|
recGblGetTimeStamp(prec);
|
|
|
|
|
/* check for alarms */
|
|
|
|
|
checkAlarms(prec);
|
|
|
|
|
/* check event list */
|
|
|
|
|
monitor(prec);
|
|
|
|
|
/* process the forward scan link record */
|
|
|
|
|
recGblGetTimeStamp(prec);
|
|
|
|
|
/* check for alarms */
|
|
|
|
|
checkAlarms(prec);
|
|
|
|
|
/* check event list */
|
|
|
|
|
monitor(prec);
|
|
|
|
|
/* process the forward scan link record */
|
|
|
|
|
recGblFwdLink(prec);
|
|
|
|
|
|
|
|
|
|
prec->pact=FALSE;
|
|
|
|
|
return(status);
|
|
|
|
|
prec->pact=FALSE;
|
|
|
|
|
return(status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static long get_units(DBADDR *paddr, char *units)
|
|
|
|
|
{
|
|
|
|
|
xxxRecord *prec=(xxxRecord *)paddr->precord;
|
|
|
|
|
xxxRecord *prec=(xxxRecord *)paddr->precord;
|
|
|
|
|
|
|
|
|
|
strncpy(units,prec->egu,DB_UNITS_SIZE);
|
|
|
|
|
return(0);
|
|
|
|
@@ -140,7 +140,7 @@ static long get_units(DBADDR *paddr, char *units)
|
|
|
|
|
|
|
|
|
|
static long get_precision(const DBADDR *paddr, long *precision)
|
|
|
|
|
{
|
|
|
|
|
xxxRecord *prec=(xxxRecord *)paddr->precord;
|
|
|
|
|
xxxRecord *prec=(xxxRecord *)paddr->precord;
|
|
|
|
|
|
|
|
|
|
*precision = prec->prec;
|
|
|
|
|
if(paddr->pfield == (void *)&prec->val) return(0);
|
|
|
|
@@ -150,8 +150,8 @@ static long get_precision(const DBADDR *paddr, long *precision)
|
|
|
|
|
|
|
|
|
|
static long get_graphic_double(DBADDR *paddr,struct dbr_grDouble *pgd)
|
|
|
|
|
{
|
|
|
|
|
xxxRecord *prec=(xxxRecord *)paddr->precord;
|
|
|
|
|
int fieldIndex = dbGetFieldIndex(paddr);
|
|
|
|
|
xxxRecord *prec=(xxxRecord *)paddr->precord;
|
|
|
|
|
int fieldIndex = dbGetFieldIndex(paddr);
|
|
|
|
|
|
|
|
|
|
if(fieldIndex == xxxRecordVAL
|
|
|
|
|
|| fieldIndex == xxxRecordHIHI
|
|
|
|
@@ -168,24 +168,24 @@ static long get_graphic_double(DBADDR *paddr,struct dbr_grDouble *pgd)
|
|
|
|
|
|
|
|
|
|
static long get_control_double(DBADDR *paddr,struct dbr_ctrlDouble *pcd)
|
|
|
|
|
{
|
|
|
|
|
xxxRecord *prec=(xxxRecord *)paddr->precord;
|
|
|
|
|
int fieldIndex = dbGetFieldIndex(paddr);
|
|
|
|
|
xxxRecord *prec=(xxxRecord *)paddr->precord;
|
|
|
|
|
int fieldIndex = dbGetFieldIndex(paddr);
|
|
|
|
|
|
|
|
|
|
if(fieldIndex == xxxRecordVAL
|
|
|
|
|
|| fieldIndex == xxxRecordHIHI
|
|
|
|
|
|| fieldIndex == xxxRecordHIGH
|
|
|
|
|
|| fieldIndex == xxxRecordLOW
|
|
|
|
|
|| fieldIndex == xxxRecordLOLO) {
|
|
|
|
|
pcd->upper_ctrl_limit = prec->hopr;
|
|
|
|
|
pcd->lower_ctrl_limit = prec->lopr;
|
|
|
|
|
pcd->upper_ctrl_limit = prec->hopr;
|
|
|
|
|
pcd->lower_ctrl_limit = prec->lopr;
|
|
|
|
|
} else recGblGetControlDouble(paddr,pcd);
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static long get_alarm_double(DBADDR *paddr,struct dbr_alDouble *pad)
|
|
|
|
|
{
|
|
|
|
|
xxxRecord *prec=(xxxRecord *)paddr->precord;
|
|
|
|
|
int fieldIndex = dbGetFieldIndex(paddr);
|
|
|
|
|
xxxRecord *prec=(xxxRecord *)paddr->precord;
|
|
|
|
|
int fieldIndex = dbGetFieldIndex(paddr);
|
|
|
|
|
|
|
|
|
|
if(fieldIndex == xxxRecordVAL) {
|
|
|
|
|
pad->upper_alarm_limit = prec->hhsv ? prec->hihi : epicsNAN;
|
|
|
|
@@ -198,76 +198,76 @@ static long get_alarm_double(DBADDR *paddr,struct dbr_alDouble *pad)
|
|
|
|
|
|
|
|
|
|
static void checkAlarms(xxxRecord *prec)
|
|
|
|
|
{
|
|
|
|
|
double val, hyst, lalm;
|
|
|
|
|
float hihi, high, low, lolo;
|
|
|
|
|
unsigned short hhsv, llsv, hsv, lsv;
|
|
|
|
|
double val, hyst, lalm;
|
|
|
|
|
float hihi, high, low, lolo;
|
|
|
|
|
unsigned short hhsv, llsv, hsv, lsv;
|
|
|
|
|
|
|
|
|
|
if(prec->udf == TRUE ){
|
|
|
|
|
recGblSetSevr(prec,UDF_ALARM,prec->udfs);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
hihi = prec->hihi; lolo = prec->lolo; high = prec->high; low = prec->low;
|
|
|
|
|
hhsv = prec->hhsv; llsv = prec->llsv; hsv = prec->hsv; lsv = prec->lsv;
|
|
|
|
|
val = prec->val; hyst = prec->hyst; lalm = prec->lalm;
|
|
|
|
|
if(prec->udf == TRUE ){
|
|
|
|
|
recGblSetSevr(prec,UDF_ALARM,prec->udfs);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
hihi = prec->hihi; lolo = prec->lolo; high = prec->high; low = prec->low;
|
|
|
|
|
hhsv = prec->hhsv; llsv = prec->llsv; hsv = prec->hsv; lsv = prec->lsv;
|
|
|
|
|
val = prec->val; hyst = prec->hyst; lalm = prec->lalm;
|
|
|
|
|
|
|
|
|
|
/* alarm condition hihi */
|
|
|
|
|
if (hhsv && (val >= hihi || ((lalm==hihi) && (val >= hihi-hyst)))){
|
|
|
|
|
if (recGblSetSevr(prec,HIHI_ALARM,prec->hhsv)) prec->lalm = hihi;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* alarm condition hihi */
|
|
|
|
|
if (hhsv && (val >= hihi || ((lalm==hihi) && (val >= hihi-hyst)))){
|
|
|
|
|
if (recGblSetSevr(prec,HIHI_ALARM,prec->hhsv)) prec->lalm = hihi;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* alarm condition lolo */
|
|
|
|
|
if (llsv && (val <= lolo || ((lalm==lolo) && (val <= lolo+hyst)))){
|
|
|
|
|
if (recGblSetSevr(prec,LOLO_ALARM,prec->llsv)) prec->lalm = lolo;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* alarm condition lolo */
|
|
|
|
|
if (llsv && (val <= lolo || ((lalm==lolo) && (val <= lolo+hyst)))){
|
|
|
|
|
if (recGblSetSevr(prec,LOLO_ALARM,prec->llsv)) prec->lalm = lolo;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* alarm condition high */
|
|
|
|
|
if (hsv && (val >= high || ((lalm==high) && (val >= high-hyst)))){
|
|
|
|
|
if (recGblSetSevr(prec,HIGH_ALARM,prec->hsv)) prec->lalm = high;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* alarm condition high */
|
|
|
|
|
if (hsv && (val >= high || ((lalm==high) && (val >= high-hyst)))){
|
|
|
|
|
if (recGblSetSevr(prec,HIGH_ALARM,prec->hsv)) prec->lalm = high;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* alarm condition low */
|
|
|
|
|
if (lsv && (val <= low || ((lalm==low) && (val <= low+hyst)))){
|
|
|
|
|
if (recGblSetSevr(prec,LOW_ALARM,prec->lsv)) prec->lalm = low;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* alarm condition low */
|
|
|
|
|
if (lsv && (val <= low || ((lalm==low) && (val <= low+hyst)))){
|
|
|
|
|
if (recGblSetSevr(prec,LOW_ALARM,prec->lsv)) prec->lalm = low;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* we get here only if val is out of alarm by at least hyst */
|
|
|
|
|
prec->lalm = val;
|
|
|
|
|
return;
|
|
|
|
|
/* we get here only if val is out of alarm by at least hyst */
|
|
|
|
|
prec->lalm = val;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void monitor(xxxRecord *prec)
|
|
|
|
|
{
|
|
|
|
|
unsigned short monitor_mask;
|
|
|
|
|
double delta;
|
|
|
|
|
unsigned short monitor_mask;
|
|
|
|
|
double delta;
|
|
|
|
|
|
|
|
|
|
monitor_mask = recGblResetAlarms(prec);
|
|
|
|
|
/* check for value change */
|
|
|
|
|
delta = prec->mlst - prec->val;
|
|
|
|
|
if(delta<0.0) delta = -delta;
|
|
|
|
|
if (delta > prec->mdel) {
|
|
|
|
|
/* post events for value change */
|
|
|
|
|
monitor_mask |= DBE_VALUE;
|
|
|
|
|
/* update last value monitored */
|
|
|
|
|
prec->mlst = prec->val;
|
|
|
|
|
}
|
|
|
|
|
/* check for value change */
|
|
|
|
|
delta = prec->mlst - prec->val;
|
|
|
|
|
if(delta<0.0) delta = -delta;
|
|
|
|
|
if (delta > prec->mdel) {
|
|
|
|
|
/* post events for value change */
|
|
|
|
|
monitor_mask |= DBE_VALUE;
|
|
|
|
|
/* update last value monitored */
|
|
|
|
|
prec->mlst = prec->val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* check for archive change */
|
|
|
|
|
delta = prec->alst - prec->val;
|
|
|
|
|
if(delta<0.0) delta = -delta;
|
|
|
|
|
if (delta > prec->adel) {
|
|
|
|
|
/* post events on value field for archive change */
|
|
|
|
|
monitor_mask |= DBE_LOG;
|
|
|
|
|
/* update last archive value monitored */
|
|
|
|
|
prec->alst = prec->val;
|
|
|
|
|
}
|
|
|
|
|
/* check for archive change */
|
|
|
|
|
delta = prec->alst - prec->val;
|
|
|
|
|
if(delta<0.0) delta = -delta;
|
|
|
|
|
if (delta > prec->adel) {
|
|
|
|
|
/* post events on value field for archive change */
|
|
|
|
|
monitor_mask |= DBE_LOG;
|
|
|
|
|
/* update last archive value monitored */
|
|
|
|
|
prec->alst = prec->val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* send out monitors connected to the value field */
|
|
|
|
|
if (monitor_mask){
|
|
|
|
|
db_post_events(prec,&prec->val,monitor_mask);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
/* send out monitors connected to the value field */
|
|
|
|
|
if (monitor_mask){
|
|
|
|
|
db_post_events(prec,&prec->val,monitor_mask);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|