/*============================================================================= Name: fbckSup.c Abs: This file contains all subroutine support for the feedback soft IOC subroutine records. Rem: All functions called by the subroutine record get passed one argument: psub Pointer to the subroutine record data. Use: pointer Type: struct subRecord * Acc: read/write Mech: reference All functions return a long integer. 0 = OK, -1 = ERROR. The subroutine record ignores the status returned by the Init routines. Auth: D. Fairley Rev: -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- Mod: (newest to oldest) 20 MAY 2008 dfairley added fbckSupIpkCalc =============================================================================*/ /* c includes */ #include #include #include /* memcmp */ #include /* sqrt,sin */ #include /* for struct subRecord */ #include /* for epicsExport */ #include /* for epicsRegisterFunction */ #include /* DBADDR */ #include #include #include #include /* for DEBUGPRINT */ #ifdef DEBUG_PRINT int fbckSupFlag = 2; #endif #include /*============================================================================= Name: fbckSupIpkCalc Abs: Fetches the bunch length in peak current (amperes) from the low-level code. The same CALC record supplies calibration coefficients to the low-level code. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read point to subroutine record Rem: Subroutine for :$(BLEN)IMAX Side: INPA to INPH = Coefficients for the given bunch length monitor INPI = divide by number to be used when filter is not in INPJ = filter in state, 1=filter in INPK = station (1-based) INPL = channel (0-based) VAL = the resulting peak current value for the bunchlength monitor Ret: 0 Future: -1 when bunch readout or TMIT value is bad ==============================================================================*/ long fbckSupIpkCalc(subRecord *psub) { double v; int station = (int)psub->k, channel = (int)psub->l; epicsTimeStamp *ts_p; /* Nothing to do - low-level code does dbPutField() */ ts_p = epicsTimeEventDeviceTime == psub->tse ? &psub->time : 0; if(psub->tpro) printf("%s got time %d %d for station %d, channel %d. Requesting Imax.\n", __FUNCTION__, ts_p->secPastEpoch, ts_p->nsec, station, channel); v = blmGetVal( station, channel, ts_p ); if(psub->tpro) printf("%s got %f from blmGetVal\n", __FUNCTION__, v); /* test for NAN */ if ( v != v ) { /* if val is NaN then there was a timeout (or an invalid argument) */ recGblSetSevr( psub, TIMEOUT_ALARM, INVALID_ALARM ); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, fbckSupFlag, ("%s: %s: blmGetVal failed with stn: %d ch: %d\n", __FUNCTION__, psub->name, station, channel)); #endif } else { psub->val = v; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, fbckSupFlag, ("%s: %s: blmGetVal read %f from stn: %d ch: %d\n", __FUNCTION__, psub->name, v, station, channel)); #endif } return 0; } epicsRegisterFunction(fbckSupIpkCalc);