/*============================================================================= 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 /* memcmp */ #include /* sqrt,sin */ #include /* for struct subRecord */ #include /* for epicsExport */ #include /* for epicsRegisterFunction */ #include /* DBADDR */ #include #include #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; v = blmGetVal( station, channel, ts_p ); /* 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 ); } else { psub->val = v; } return 0; } epicsRegisterFunction(fbckSupIpkCalc);