37 #include "menuYesNo.h" 39 #define GEN_SIZE_OFFSET 40 #include "histogramRecord.h" 41 #undef GEN_SIZE_OFFSET 44 #define indexof(field) histogramRecord##field 48 #define initialize NULL 50 static long process(
struct dbCommon *);
51 static long special(DBADDR *,
int);
52 #define get_value NULL 55 #define put_array_info NULL 57 static long get_precision(
const DBADDR *paddr,
long *precision);
58 #define get_enum_str NULL 59 #define get_enum_strs NULL 60 #define put_enum_str NULL 61 #define get_alarm_double NULL 96 static long add_count(histogramRecord *);
97 static long clear_histogram(histogramRecord *);
98 static void monitor(histogramRecord *);
99 static long readValue(histogramRecord *);
102 static void wdogCallback(epicsCallback *arg)
105 histogramRecord *
prec;
107 callbackGetUser(pcallback, arg);
108 prec = pcallback->
prec;
111 dbScanLock((
struct dbCommon *)prec);
112 recGblGetTimeStamp(prec);
115 dbScanUnlock((
struct dbCommon *)prec);
118 if (prec->sdel > 0) {
120 callbackRequestDelayed(&pcallback->
callback, prec->sdel);
126 static void wdogInit(histogramRecord *prec)
128 if (prec->sdel > 0) {
138 callbackSetCallback(wdogCallback, &pcallback->
callback);
139 callbackSetUser(pcallback, &pcallback->
callback);
140 callbackSetPriority(priorityLow, &pcallback->
callback);
141 prec->wdog = pcallback;
145 callbackRequestDelayed(&pcallback->
callback, prec->sdel);
149 static long init_record(
struct dbCommon *pcommon,
int pass)
151 struct histogramRecord *prec = (
struct histogramRecord *)pcommon;
152 histogramdset *pdset;
159 prec->bptr = calloc(prec->nelm,
sizeof(
epicsUInt32));
163 prec->wdth = (prec->ulim - prec->llim) / prec->nelm;
169 recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
170 recGblInitConstantLink(&prec->siol,
DBF_DOUBLE, &prec->sval);
173 pdset = (histogramdset *) prec->dset;
175 recGblRecordError(
S_dev_noDSET, prec,
"histogram: init_record");
180 if (pdset->common.number < 6 || !pdset->read_histogram) {
186 if (pdset->common.init_record) {
187 long status = pdset->common.init_record(pcommon);
195 static long process(
struct dbCommon *pcommon)
197 struct histogramRecord *prec = (
struct histogramRecord *)pcommon;
198 histogramdset *pdset = (histogramdset *) prec->dset;
199 int pact = prec->pact;
202 if (!pdset || !pdset->read_histogram) {
208 status = readValue(prec);
211 if (!pact && prec->pact)
215 recGblGetTimeStampSimm(prec, prec->simm, &prec->siol);
219 else if (status == 2)
229 static long special(DBADDR *paddr,
int after)
231 histogramRecord *prec = (histogramRecord *) paddr->precord;
233 if (paddr->special ==
SPC_MOD && dbGetFieldIndex(paddr) == histogramRecordSIMM) {
235 recGblSaveSimm(prec->sscn, &prec->oldsimm, prec->simm);
237 recGblCheckSimm((dbCommon *)prec, &prec->sscn, prec->oldsimm, prec->simm);
244 switch (paddr->special) {
246 if (prec->cmd <= 1) {
247 clear_histogram(prec);
250 else if (prec->cmd == 2) {
254 else if (prec->cmd == 3) {
266 if (dbGetFieldIndex(paddr) == histogramRecordSDEL) {
270 prec->wdth = (prec->ulim - prec->llim) / prec->nelm;
271 clear_histogram(prec);
276 recGblDbaddrError(S_db_badChoice, paddr,
"histogram: special");
277 return S_db_badChoice;
281 static void monitor(histogramRecord *prec)
283 unsigned short monitor_mask = recGblResetAlarms(prec);
286 if (prec->mcnt > prec->mdel){
293 db_post_events(prec, prec->bptr, monitor_mask);
300 histogramRecord *prec = (histogramRecord *) paddr->precord;
302 paddr->pfield = prec->bptr;
303 paddr->no_elements = prec->nelm;
310 static long get_array_info(DBADDR *paddr,
long *no_elements,
long *offset)
312 histogramRecord *prec = (histogramRecord *) paddr->precord;
314 *no_elements = prec->nelm;
319 static long add_count(histogramRecord *prec)
325 if (prec->csta ==
FALSE)
328 if (prec->llim >= prec->ulim) {
335 if (prec->sgnl < prec->llim ||
336 prec->sgnl >= prec->ulim)
339 temp = prec->sgnl - prec->llim;
340 for (i = 1; i <= prec->nelm; i++){
341 if (temp <= (
double) i * prec->wdth)
344 pdest = prec->bptr + i - 1;
353 static long clear_histogram(histogramRecord *prec)
357 for (i = 0; i < prec->nelm; i++)
359 prec->mcnt = prec->mdel + 1;
365 static long readValue(histogramRecord *prec)
367 histogramdset *pdset = (histogramdset *) prec->dset;
371 status = recGblGetSimm((dbCommon *)prec, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml);
372 if (status)
return status;
375 switch (prec->simm) {
377 status = pdset->read_histogram(prec);
382 if (prec->pact || (prec->sdly < 0.)) {
383 status = dbGetLink(&prec->siol,
DBR_DOUBLE, &prec->sval, 0, 0);
385 prec->sgnl = prec->sval;
390 epicsCallback *pvt = prec->simpvt;
392 pvt = calloc(1,
sizeof(epicsCallback));
395 if (pvt) callbackRequestProcessCallbackDelayed(pvt, prec->prio, prec, prec->sdly);
409 static long get_units(DBADDR *paddr,
char *units)
411 if (dbGetFieldIndex(paddr) ==
indexof(SDEL)) {
418 static long get_precision(
const DBADDR *paddr,
long *precision)
420 histogramRecord *prec = (histogramRecord *) paddr->precord;
422 switch (dbGetFieldIndex(paddr)) {
428 *precision = prec->prec;
434 recGblGetPrec(paddr,precision);
441 histogramRecord *prec = (histogramRecord *) paddr->precord;
443 switch (dbGetFieldIndex(paddr)) {
445 pgd->upper_disp_limit = prec->hopr;
446 pgd->lower_disp_limit = prec->lopr;
449 pgd->upper_disp_limit = prec->ulim - prec->llim;
450 pgd->lower_disp_limit = 0.0;
453 recGblGetGraphicDouble(paddr,pgd);
459 histogramRecord *prec = (histogramRecord *) paddr->precord;
461 switch (dbGetFieldIndex(paddr)) {
463 pcd->upper_ctrl_limit = prec->hopr;
464 pcd->lower_ctrl_limit = prec->lopr;
467 pcd->upper_ctrl_limit = prec->ulim - prec->llim;
468 pcd->lower_ctrl_limit = 0.0;
471 recGblGetControlDouble(paddr, pcd);
int histogramSDELprecision
struct myCallback myCallback
Miscellaneous macro definitions.
#define get_control_double
epicsExportAddress(rset, histogramRSET)
#define get_graphic_double