#include /* for struct subRecord */ #include /* for epics register function */ #include /* for epicsExport */ #include /* epics timestamp and proto */ #include /* for EVR APIs */ static int errH,errL,sum; static long ts,tn; static long subPulseIdInit(subRecord *prec) { /* nothing to do */ errH=0; errL=0; sum=0; return 0; } static long subPulseId(subRecord *prec) { /* * Get timestamp from EVR for the active timeslot * and, store it to TIME field. * The TSE field should be -2. */ //evrTimeGet(&(prec->time), 0); evrTimeGet(&(prec->time), prec->evnt); /* * Extract pulse ID from the timestamp * and, store it to VAL field. */ if (prec->j == 1) { errH=0; errL=0; sum=0; } prec->k=(double) (prec->time.secPastEpoch-ts); prec->l=(double) prec->time.nsec - (double) tn; if (prec->l < 0) { prec->k--; prec->l=+1000000000; } ts=prec->time.secPastEpoch; tn=prec->time.nsec; prec->b = prec->val; prec->val = PULSEID(prec->time); prec->c = prec->val - prec->b; if (prec->c > prec->d) errH++; if (prec->c < prec->d) errL++; sum++; prec->e=sum; prec->f=errH; prec->g=(double) errH/sum; prec->h=errL; prec->i=(double) errL/sum; return 0; } epicsRegisterFunction(subPulseIdInit); epicsRegisterFunction(subPulseId);