rec: Cleanup of compress & histogram record source code

No functional changes.
This commit is contained in:
Andrew Johnson
2012-10-19 15:06:37 -05:00
parent c9da766e9e
commit 35a2793c23
2 changed files with 385 additions and 358 deletions
+138 -127
View File
@@ -12,7 +12,7 @@
* Original Author: Bob Dalesio
* Date: 7-14-89
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -36,6 +36,8 @@
#undef GEN_SIZE_OFFSET
#include "epicsExport.h"
#define indexof(field) compressRecord##field
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
@@ -55,28 +57,29 @@ 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
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;
@@ -86,7 +89,7 @@ static void reset(compressRecord *prec)
prec->res = 0;
/* allocate memory for the summing buffer for conversions requiring it */
if (prec->alg == compressALG_Average && prec->sptr == 0){
prec->sptr = (double *)calloc(prec->nsam,sizeof(double));
prec->sptr = calloc(prec->nsam, sizeof(double));
}
}
@@ -102,29 +105,29 @@ static void monitor(compressRecord *prec)
db_post_events(prec, prec->bptr, monitor_mask);
}
static void put_value(compressRecord *prec,double *psource, epicsInt32 n)
static void put_value(compressRecord *prec, double *psource, int n)
{
/* treat bptr as pointer to a circular buffer*/
double *pdest;
epicsInt32 offset=prec->off;
epicsInt32 nuse=prec->nuse;
epicsInt32 nsam=prec->nsam;
epicsInt32 i;
epicsInt32 offset = prec->off;
epicsInt32 nuse = prec->nuse;
epicsInt32 nsam = prec->nsam;
double *pdest = prec->bptr + offset;
int i;
pdest = prec->bptr + offset;
for(i=0; i<n; i++, psource++) {
*pdest=*psource;
offset++;
if(offset>=nsam) {
pdest=prec->bptr;
offset=0;
} else pdest++;
}
nuse = nuse+n;
if(nuse>nsam) nuse=nsam;
prec->off = offset;
prec->nuse = nuse;
return;
for (i = 0; i < n; i++) {
*pdest = *psource++;
if (++offset >= nsam) {
pdest = prec->bptr;
offset = 0;
}
else
pdest++;
}
nuse += n;
if (nuse > nsam)
nuse = nsam;
prec->off = offset;
prec->nuse = nuse;
return;
}
/* qsort comparison function (for median calculation) */
@@ -139,7 +142,7 @@ static int compare(const void *arg1, const void *arg2)
}
static int compress_array(compressRecord *prec,
double *psource,epicsInt32 no_elements)
double *psource, int no_elements)
{
epicsInt32 i,j;
epicsInt32 nnew;
@@ -295,137 +298,145 @@ static int compress_scalar(struct compressRecord *prec,double *psource)
/*Beginning of record support routines*/
static long init_record(compressRecord *prec, int pass)
{
if (pass==0){
if(prec->nsam<1) prec->nsam = 1;
prec->bptr = (double *)calloc(prec->nsam,sizeof(double));
if (pass == 0) {
if (prec->nsam < 1)
prec->nsam = 1;
prec->bptr = calloc(prec->nsam, sizeof(double));
reset(prec);
}
return(0);
return 0;
}
static long process(compressRecord *prec)
{
long status=0;
long nelements = 0;
int alg = prec->alg;
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) {
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 = (double *)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) {
(void)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;
}
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);
if (status != 1) {
prec->udf = FALSE;
recGblGetTimeStamp(prec);
monitor(prec);
/* process the forward scan link record */
recGblFwdLink(prec);
}
prec->pact=FALSE;
return(0);
prec->pact = FALSE;
return 0;
}
static long special(DBADDR *paddr, int after)
{
compressRecord *prec = (compressRecord *)(paddr->precord);
int special_type = paddr->special;
compressRecord *prec = (compressRecord *) paddr->precord;
int special_type = paddr->special;
if(!after) return(0);
switch(special_type) {
case(SPC_RESET):
reset(prec);
return(0);
default:
recGblDbaddrError(S_db_badChoice,paddr,"compress: special");
return(S_db_badChoice);
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;
compressRecord *prec = (compressRecord *) paddr->precord;
paddr->pfield = (void *)(prec->bptr);
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;
return(0);
return 0;
}
static long get_array_info(DBADDR *paddr,long *no_elements, long *offset)
static long get_array_info(DBADDR *paddr, long *no_elements, long *offset)
{
compressRecord *prec=(compressRecord *)paddr->precord;
compressRecord *prec = (compressRecord *) paddr->precord;
*no_elements = prec->nuse;
if(prec->nuse==prec->nsam) *offset = prec->off;
else *offset = 0;
return(0);
*no_elements = prec->nuse;
if (prec->nuse == prec->nsam)
*offset = prec->off;
else
*offset = 0;
return 0;
}
static long put_array_info(DBADDR *paddr, long nNew)
{
compressRecord *prec=(compressRecord *)paddr->precord;
compressRecord *prec = (compressRecord *) paddr->precord;
prec->off = (prec->off + nNew) % (prec->nsam);
prec->nuse = (prec->nuse + nNew);
if(prec->nuse > prec->nsam) prec->nuse = prec->nsam;
return(0);
prec->off = (prec->off + nNew) % prec->nsam;
prec->nuse += nNew;
if (prec->nuse > prec->nsam)
prec->nuse = prec->nsam;
return 0;
}
#define indexof(field) compressRecord##field
static long get_units(DBADDR *paddr,char *units)
static long get_units(DBADDR *paddr, char *units)
{
compressRecord *prec=(compressRecord *)paddr->precord;
compressRecord *prec = (compressRecord *) paddr->precord;
if(paddr->pfldDes->field_type == DBF_DOUBLE
|| dbGetFieldIndex(paddr) == indexof(VAL)) {
strncpy(units,prec->egu,DB_UNITS_SIZE);
if (paddr->pfldDes->field_type == DBF_DOUBLE ||
dbGetFieldIndex(paddr) == indexof(VAL)) {
strncpy(units, prec->egu, DB_UNITS_SIZE);
}
return(0);
return 0;
}
static long get_precision(DBADDR *paddr, long *precision)
{
compressRecord *prec=(compressRecord *)paddr->precord;
compressRecord *prec = (compressRecord *) paddr->precord;
*precision = prec->prec;
if(dbGetFieldIndex(paddr) == indexof(VAL)) return(0);
recGblGetPrec(paddr,precision);
return(0);
if (dbGetFieldIndex(paddr) != indexof(VAL))
recGblGetPrec(paddr,precision);
return 0;
}
static long get_graphic_double(DBADDR *paddr,struct dbr_grDouble *pgd)
static long get_graphic_double(DBADDR *paddr, struct dbr_grDouble *pgd)
{
compressRecord *prec=(compressRecord *)paddr->precord;
compressRecord *prec = (compressRecord *) paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
@@ -437,12 +448,12 @@ static long get_graphic_double(DBADDR *paddr,struct dbr_grDouble *pgd)
default:
recGblGetGraphicDouble(paddr,pgd);
}
return(0);
return 0;
}
static long get_control_double(DBADDR *paddr, struct dbr_ctrlDouble *pcd)
{
compressRecord *prec=(compressRecord *)paddr->precord;
compressRecord *prec = (compressRecord *) paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
@@ -452,7 +463,7 @@ static long get_control_double(DBADDR *paddr, struct dbr_ctrlDouble *pcd)
pcd->lower_ctrl_limit = prec->lopr;
break;
default:
recGblGetControlDouble(paddr,pcd);
recGblGetControlDouble(paddr, pcd);
}
return(0);
return 0;
}
+247 -231
View File
@@ -1,5 +1,5 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* 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.
@@ -9,7 +9,7 @@
/* $Revision-Id$ */
/* recHistogram.c - Record Support Routines for Histogram records */
/* histogramRecord.c - Record Support Routines for Histogram records */
/*
* Author: Janet Anderson
* Date: 5/20/91
@@ -41,7 +41,9 @@
#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
@@ -61,25 +63,25 @@ static long get_precision(DBADDR *paddr,long *precision);
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
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);
@@ -96,249 +98,268 @@ struct histogramdset { /* histogram input dset */
/* if add_count then sgnl added to array */
DEVSUPFUN special_linconv;
};
/* control block for callback*/
typedef struct myCallback {
CALLBACK callback;
histogramRecord *prec;
}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;
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);
}
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) {
/* start new watchdog timer on monitor */
callbackRequestDelayed(&pcallback->callback,(double)prec->sdel);
}
if (prec->sdel > 0) {
/* restart timer */
callbackRequestDelayed(&pcallback->callback, prec->sdel);
}
return;
return;
}
static long wdogInit(histogramRecord *prec)
{
myCallback *pcallback;
myCallback *pcallback;
if(prec->wdog==NULL && prec->sdel>0) {
/* initialize a watchdog timer */
pcallback = (myCallback *)(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 = (void *)pcallback;
}
if (!prec->wdog && prec->sdel > 0) {
/* initialize a callback object */
pcallback = calloc(1, sizeof(myCallback));
pcallback->prec = prec;
if (!pcallback)
return -1;
if (!prec->wdog) return -1;
pcallback = (myCallback *)prec->wdog;
if(!pcallback) return -1;
if( prec->sdel>0) {
/* start new watchdog timer on monitor */
callbackRequestDelayed(&pcallback->callback,(double)prec->sdel);
}
return 0;
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(histogramRecord *prec, int pass)
{
struct histogramdset *pdset;
long status;
struct histogramdset *pdset;
if (pass==0){
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));
}
/* allocate space for histogram array */
if(prec->bptr==NULL) {
if(prec->nelm<=0) prec->nelm=1;
prec->bptr = (epicsUInt32 *)calloc(prec->nelm,sizeof(epicsUInt32));
}
/* calulate width of array element */
prec->wdth=(prec->ulim-prec->llim)/prec->nelm;
return(0);
}
/* calulate width of array element */
prec->wdth = (prec->ulim - prec->llim) / prec->nelm;
return 0;
}
wdogInit(prec);
if (prec->siml.type == CONSTANT) {
recGblInitConstantLink(&prec->siml,DBF_USHORT,&prec->simm);
recGblInitConstantLink(&prec->siml, DBF_USHORT, &prec->simm);
}
if (prec->siol.type == CONSTANT) {
recGblInitConstantLink(&prec->siol,DBF_DOUBLE,&prec->sval);
recGblInitConstantLink(&prec->siol, DBF_DOUBLE, &prec->sval);
}
/* must have device support defined */
if(!(pdset = (struct histogramdset *)(prec->dset))) {
recGblRecordError(S_dev_noDSET,(void *)prec,"histogram: init_record");
return(S_dev_noDSET);
}
/* must have read_histogram function defined */
if( (pdset->number < 6) || (pdset->read_histogram == NULL) ) {
recGblRecordError(S_dev_missingSup,(void *)prec,"histogram: init_record");
return(S_dev_missingSup);
}
/* call device support init_record */
if( pdset->init_record ) {
if((status=(*pdset->init_record)(prec))) return(status);
}
return(0);
/* 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(histogramRecord *prec)
{
struct histogramdset *pdset = (struct histogramdset *)(prec->dset);
long status;
unsigned char pact=prec->pact;
struct histogramdset *pdset = (struct histogramdset *) prec->dset;
int pact = prec->pact;
long status;
if( (pdset==NULL) || (pdset->read_histogram==NULL) ) {
prec->pact=TRUE;
recGblRecordError(S_dev_missingSup,(void *)prec,"read_histogram");
return(S_dev_missingSup);
}
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;
status = readValue(prec); /* read the new value */
recGblGetTimeStamp(prec);
/* check if device support set pact */
if (!pact && prec->pact)
return 0;
prec->pact = TRUE;
if(status==0)add_count(prec);
else if(status==2)status=0;
recGblGetTimeStamp(prec);
/* check event list */
monitor(prec);
if (status == 0)
add_count(prec);
else if (status == 2)
status = 0;
/* process the forward scan link record */
recGblFwdLink(prec);
monitor(prec);
recGblFwdLink(prec);
prec->pact=FALSE;
return(status);
prec->pact=FALSE;
return status;
}
static long special(DBADDR *paddr,int after)
static long special(DBADDR *paddr, int after)
{
histogramRecord *prec = (histogramRecord *)(paddr->precord);
int special_type = paddr->special;
int fieldIndex = dbGetFieldIndex(paddr);
histogramRecord *prec = (histogramRecord *) paddr->precord;
if (!after)
return 0;
if(!after) return(0);
switch(special_type) {
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 (fieldIndex == 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);
}
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;
monitor_mask = recGblResetAlarms(prec);
/* post events for count change */
if(prec->mcnt>prec->mdel){
/* post events for count change */
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);
unsigned short monitor_mask = recGblResetAlarms(prec);
return;
/* 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;
histogramRecord *prec = (histogramRecord *) paddr->precord;
paddr->pfield = (void *)(prec->bptr);
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);
return 0;
}
static long get_array_info(DBADDR *paddr, long *no_elements, long *offset)
{
histogramRecord *prec=(histogramRecord *)paddr->precord;
histogramRecord *prec = (histogramRecord *) paddr->precord;
*no_elements = prec->nelm;
*offset = 0;
return(0);
return 0;
}
static long add_count(histogramRecord *prec)
{
double temp;
epicsUInt32 *pdest;
int i;
double temp;
epicsUInt32 *pdest;
int i;
if(prec->csta==FALSE) return(0);
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);
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++;
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);
return 0;
}
static long clear_histogram(histogramRecord *prec)
@@ -350,46 +371,41 @@ static long clear_histogram(histogramRecord *prec)
prec->mcnt = prec->mdel + 1;
prec->udf = FALSE;
return(0);
return 0;
}
static long readValue(histogramRecord *prec)
{
long status;
struct histogramdset *pdset = (struct histogramdset *) (prec->dset);
struct histogramdset *pdset = (struct histogramdset *) prec->dset;
long status;
if (prec->pact == TRUE){
status=(*pdset->read_histogram)(prec);
return(status);
}
status=dbGetLink(&(prec->siml),DBR_USHORT,&(prec->simm),0,0);
if (status)
return(status);
if (prec->simm == menuYesNoNO){
status=(*pdset->read_histogram)(prec);
return(status);
}
if (prec->simm == menuYesNoYES){
status=dbGetLink(&(prec->siol),DBR_DOUBLE,
&(prec->sval),0,0);
if (status==0){
prec->sgnl=prec->sval;
}
} else {
status=-1;
recGblSetSevr(prec,SOFT_ALARM,INVALID_ALARM);
return(status);
}
recGblSetSevr(prec,SIMM_ALARM,prec->sims);
if (prec->pact) {
status = pdset->read_histogram(prec);
return status;
}
status = dbGetLink(&prec->siml, DBR_USHORT, &prec->simm, 0, 0);
if (status)
return(status);
}
#define indexof(field) histogramRecord##field
if (prec->simm == menuYesNoNO) {
status = pdset->read_histogram(prec);
return status;
}
if (prec->simm == menuYesNoYES) {
status = dbGetLink(&prec->siol,DBR_DOUBLE, &prec->sval, 0, 0);
if (status == 0)
prec->sgnl = prec->sval;
}
else {
status = -1;
recGblSetSevr(prec, SOFT_ALARM, INVALID_ALARM);
return status;
}
recGblSetSevr(prec, SIMM_ALARM, prec->sims);
return status;
}
static long get_units(DBADDR *paddr, char *units)
{
@@ -397,12 +413,12 @@ static long get_units(DBADDR *paddr, char *units)
strcpy(units,"s");
}
/* We should have EGU for other DOUBLE values or probably get it from input link SVL */
return(0);
return 0;
}
static long get_precision(DBADDR *paddr,long *precision)
{
histogramRecord *prec=(histogramRecord *)paddr->precord;
histogramRecord *prec = (histogramRecord *) paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(ULIM):
@@ -418,12 +434,12 @@ static long get_precision(DBADDR *paddr,long *precision)
default:
recGblGetPrec(paddr,precision);
}
return(0);
return 0;
}
static long get_graphic_double(DBADDR *paddr,struct dbr_grDouble *pgd)
{
histogramRecord *prec=(histogramRecord *)paddr->precord;
histogramRecord *prec = (histogramRecord *) paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
@@ -431,17 +447,17 @@ static long get_graphic_double(DBADDR *paddr,struct dbr_grDouble *pgd)
pgd->lower_disp_limit = prec->lopr;
break;
case indexof(WDTH):
pgd->upper_disp_limit = prec->ulim-prec->llim;
pgd->upper_disp_limit = prec->ulim - prec->llim;
pgd->lower_disp_limit = 0.0;
break;
default:
recGblGetGraphicDouble(paddr,pgd);
}
return(0);
return 0;
}
static long get_control_double(DBADDR *paddr,struct dbr_ctrlDouble *pcd)
{
histogramRecord *prec=(histogramRecord *)paddr->precord;
histogramRecord *prec = (histogramRecord *) paddr->precord;
switch (dbGetFieldIndex(paddr)) {
case indexof(VAL):
@@ -449,11 +465,11 @@ static long get_control_double(DBADDR *paddr,struct dbr_ctrlDouble *pcd)
pcd->lower_ctrl_limit = prec->lopr;
break;
case indexof(WDTH):
pcd->upper_ctrl_limit = prec->ulim-prec->llim;
pcd->upper_ctrl_limit = prec->ulim - prec->llim;
pcd->lower_ctrl_limit = 0.0;
break;
default:
recGblGetControlDouble(paddr,pcd);
recGblGetControlDouble(paddr, pcd);
}
return(0);
return 0;
}