/*============================================================================= Abs: This file contains all subroutine support for the device control and readback subroutine records. Filename: psSub.c Rem: All functions called by the subroutine record get passed one argument: Functions: Description ------------ ---------------------------- psInit General Initialization psInitExplode Init for Record generating polynomial coefficient waveform psInitPoly Init for Records using Poly Coeffs psDbPoly Conversion from physical to raw units psExplode Generate waveform of polynomial coefficients psLimits Set Alarm and Warning Limits for ACT and CON psNumPolyCoef Find Number of Polynomial Coefficients psReversePoly Estimate Value doing Reverse Poly from Raw to Physical (Newton) psPhyDeltas Calc Reverse Polynomial Epsilon, Deltas for alarm & warning limits of physical units psRawDeltas Calc Deltas for Alarm and Warning Limits in Raw Units psStat Generate device status bit-mask for worst-case senerio. All functions return a long integer. 0 = OK, -1 = ERROR. The subroutine record ignores the status returned by the Init routines. For the calculation routines, the record status (STAT) is set to SOFT_ALARM (unless it is already set to LINK_ALARM due to severity maximization) and the severity (SEVR) is set to psub->brsv (BRSV - set by the user in the database though it is expected to be invalid) Side: Place all functions called by the subroutine records in the file psSub.dbd Auth: dd-mmm-yyyy, Author's Name (USERNAME) Rev: dd-mmm-yyyy, Reviewer's Name (USERNAME) -------------------------------------------------------------- Mod: 23-Mar-2023, K. Luchini (LUCHINI): epics V7 upgradereplace dbAccess.h with dbAccessDefs.h remove genSubRecord.h, not used. add basicIoOps.h chg pfield to bptr for waveform chg some "unsigned long" to uint32_t 06-May-2015, K. Luchini (LUCHINI): psReversePoly check for NaN - not a number 20-May-2013, K. Luchini (LUCHINI): Deprecate calibration warning in psStat 10-Mar-2011, K. Luchini (LUCHINI): Copied from magnet application mgntSub.c and modified for phase shifter power supply. ==============================================================*/ #include "copyright_SLAC.h" /* Header files */ #include "debugPrint.h" #include "errlog.h" /* for errlogPrintf() */ #ifdef DEBUG_PRINT #include int psControlSubFlag = DP_INFO; #endif #include /* for calloc */ #include /* for DBADDR */ #include /* for struct subRecord */ #include /* for struct longSubRecord */ #include /* for struct waveformRecord */ #include /* for epicsExport */ #include /* for epicsRegisterFunction */ #include /* NO_ALARM, INVALID_ALARM */ #include /* for S_rec_outMem */ #include /* for S_dev_noDeviceFound */ #include /* for recGblRecordError() */ #include /* for DBF_DOUBLE */ #include /* for callocMustSucceed() */ #include "psSub.h" /* for psWfCoef_ts */ #include "basicIoOps.h" /* for int32_t, uint32_t */ /* prototypes */ static long psInit(struct subRecord *psub); static long psInitExplode(struct subRecord *psub); static long psInitPoly(struct subRecord *psub); static long psDbPoly(struct subRecord *psub); static long psExplode(struct subRecord *psub); static long psLimits(struct subRecord *psub); static long psNumPolyCoef(struct subRecord *psub); static long psRawDeltas(struct subRecord *psub); static long psReversePoly(subRecord *psub); static long psPhyDeltas(struct subRecord *psub); static long psPoly(subRecord *psub); static long psStat (longSubRecord *psub); #define DEBUG 1 // mdunning 8/3/17: define macro dbGetPdbAddrFromLink below, due to its removal in base 3.15 #define dbGetPdbAddrFromLink(PLNK) \ ( ( (PLNK)->type != DB_LINK ) \ ? 0 \ : ( ( (struct dbAddr *)( (PLNK)->value.pv_link.pvt) ) ) ) /*============================================================================= Name: psInit Abs: Pse initialization subroutine record Rem: Side: None Ret: long 0 - Successful (always) ==============================================================================*/ static long psInit(subRecord *psub) { int status=SUCCESS; /* * General purpose initialization required since all subroutine records * require a non-NULL init routine even if no initialization is required. * Note that most subroutines in this file use this routine as an init * routine. If init logic is needed for a specific subroutine, create a * new routine for it - don't modify this one. */ return(status); } /*============================================================================= Name: psInitExplode Abs: Initialize records that use in polynomial coefficients to waveform Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read/write pointer to subroutine record Rem: Init Subroutine for :::COEF2WF Input: -------- INPB = :::POLYCOEF (waveform record) Output: -------- DPVT = Pointer to array of pointers such that ptr[0] = ptr to subrecord :::NUMPOLYCOEF ptr[1] = ptr to waveform record :::POLYCOEF Side: None Ret: long 0 - Successful -1 - for invalid INPA or invalid INPB ==============================================================================*/ static long psInitExplode(subRecord *psub) { int status=SUCCESS; DBADDR *pdbAddr=0; DBADDR *pwfAddr=0; subRecord *prec=0; waveformRecord *pwf=0; psWfCoef_ts *pdpvt=0; /* Check that this pv has not already been initialized */ if (psub->dpvt) return( -1 ); psub->dpvt = 0; pdbAddr = dbGetPdbAddrFromLink(&psub->inpa); if (!pdbAddr) { recGblRecordError(S_dev_noDeviceFound,(void *)psub,"sub: init_record"); return(-1); } /* Create an array of 2 pointers */ pdpvt = callocMustSucceed(1,sizeof(psWfCoef_ts),"calloc failed for psInitExplode"); if (!pdpvt) { recGblRecordError(S_rec_outMem,(void *)psub,"sub: init_record"); return -1; } /* Diagnostic message */ prec = (subRecord *)pdbAddr->precord; pdpvt->pcoef = &prec->a; /* ptr to subroutine record :POLYCOEF.A */ psub->dpvt = pdpvt; /* return private data pointer */ /* Determine if we have a DB_LINK as INPB, if not then we'll have a CONSTANT */ if((psub->inpb).type==CONSTANT) return(status); /* Get the pointer to the record in INPB. * Is this a valid pv? If so, then verify that data type is double. * Later need to verify that this is a wavefore record... */ pwfAddr = dbGetPdbAddrFromLink(&psub->inpb); if (!pwfAddr || (pwfAddr->field_type != DBF_DOUBLE)) return(-1); /* Set the private data information */ pwf = (waveformRecord *)pwfAddr->precord; pdpvt->pdata = (double *)pwf->bptr; /* ptr to data :IVB */ pdpvt->pnord = (uint32_t *)(&pwf->nord); /* ptr to num or coefficients copied to waveform record */ pdpvt->nelem = pwfAddr->no_elements; /* max number of data elements in record */ return(status); } /*============================================================================= Name: psExplode Abs: Populate waveform with polynomial coefficients from subroutine record :::NUMPOLYCOEF.A thru L Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read/write pointer to subroutine record Rem: Init Subroutine for PRIM:LOCA:UNIT:POLYCOEF Input: ------- -------- INPA = :::NUMPOLYCOEF (subroutine record) INPB = :::POLYCOEF (waveform record) DPVT = Pointer to array of pointers such that ptr[0] = ptr to subrecord :::NUMPOLYCOEF ptr[1] = ptr to waveform record :::POLYCOEF Output: -------- INPB = :POLYCOEF (waveform record) write to waveform :POLYCOEF using values from :NUMPOLYCOEF.A thru L, and then set :POLYCOEF.NORD to :NUMPOLYCOEF.VAL Side: None Ret: long 0 - Successful -1 - for invalid INPA or invalid INPB ==============================================================================*/ static long psExplode(subRecord *psub) { int status=SUCCESS; uint32_t i,num; psWfCoef_ts *pdev=psub->dpvt; /* Get the address of wavefor record, and pointer to data */ if (!pdev || !pdev->pdata || psub->a<0) return(-1); if (!pdev->nelem || !psub->a) { #ifdef DEBUG DEBUGPRINT(DP_DEBUG, psSubFlag, ("psExplode: %s No coefficients", psub->name)); #endif errlogPrintf("psExplode: %s No coefficients\n",psub->name); return(status); } /* Popuplate waveform with subroutine record polynomial coefficients */ num = MIN(psub->a,pdev->nelem); for (i=0; ipdata[i] = pdev->pcoef[i]; /* Set the number of elements read from subroutine record */ *pdev->pnord = num; return(status); } /*============================================================================= Name: psInitPoly Abs: Initialize records that use polynomial coefficients. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read/write pointer to subroutine record Rem: Init Subroutine for :::REQ :::ACT Input: -------- INPB = Number of polynomial coefficients - used to access the coefficients themselves Output: -------- DPVT = Pointer to polynomial coefficients Side: None Ret: long 0 - Successful -1 - for invalid INPB ==============================================================================*/ static long psInitPoly(subRecord *psub) { int status = SUCCESS; /* * Get polynomial coeffs - assume INPB is from a subRecord and * A through L are contiguous. Assume A is the constant term * and B to L are the higher order terms. */ DBADDR *pdbAddr = dbGetPdbAddrFromLink(&psub->inpb); psub->dpvt = 0; if (!pdbAddr) return -1; psub->dpvt = &((subRecord *)pdbAddr->precord)->a; return(status); } /*============================================================================= Name: psNumPolyCoef Abs: Find Number of Polynomial Coefficients. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read/write pointer to subroutine record Input: ------- A to L - Polynomial Coefficients Output: ------- VAL = Number of Coefficients Rem: Subroutine for :::NUMPOLYCOEF Side: Ret: long 0 - Successful (always) ==============================================================================*/ static long psNumPolyCoef(subRecord *psub) { long status = SUCCESS; /* return stsatus */ int i; /* index */ double *polyCoef_a; /* Countdown until the most significant non-zero coefficient is found. */ /* Note: * for (i = PS_MAX_POLY_COEF, polyCoef_a = &psub->l; * (i > 0) && (polyCoef_a[i] == 0); i--) { } doesn't work */ polyCoef_a = &psub->l; for (i = POLY_MAX_COEF;(i > 0) && (*polyCoef_a== 0); i--, polyCoef_a--) { /* do nothing */ } psub->val = (double)i; #ifdef DEBUG DEBUGPRINT(DP_DEBUG, psSubFlag, ("psNumPolyCoef for %s = %d.\n", psub->name, i)); #endif return(status); } /*============================================================================= Name: psDbPoly Abs: Convert Physical Units to Raw Units using polynomial conversion. Use same algorithm as ref_rmx_dbs:dbpoly.a38 - see PDL in header at top of module. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read/write pointer to subroutine record Input: -------- VAL = Value in Physical Units A = Point at which the polynomial is to be evaluated B = Number of polynomial coefficients C = Polynomial Coeff A (offset if linear) D = Polynomial Coeff B (slope if linear) DPVT = Pointer to polynomial coefficients (set by psInitPoly) Output: ------- K = V in raw units L = Slope of the polynomial at the DES value Rem: Called by psPoly and psReversePoly. Subroutine for :::P2VDES Subroutine for :::PACT E = Point at which the polynomial is to be evaluated. K = Will receive the value of the polynomial at X. L = Will receive the value of the 1st derivative of the polynomial at X. Method: Suppose N is the degree + 1, and the A's are the coefficients, where A(1) is the constant term and A(N) is the highest-order coefficient. Then the algorithm is: L = 0 K = COEF(N) DO IDX = N-1,1,-1 L = L*X + K K = K*X + COEF(IDX) ENDDO Side: None Ret: long 0 - Successful -1 - if B is invalid or invalid pointer to poly coeffs. ==============================================================================*/ static long psDbPoly(subRecord *psub) { long status = POLY_CONVERGED; /* return status */ int i=0; /* index */ /* Simple linear conversion */ if (psub->b == POLY_LINEAR_COEF_NUM) { psub->l = psub->d; psub->k = psub->c + (psub->val * psub->d); } else { /* * Must have a valid number of coefficients and a valid poly coeff array */ if ((psub->bb>POLY_MAX_COEF) || !psub->dpvt){ if (!psub->dpvt) { DEBUGPRINT(DP_INFO, psSubFlag, ("psDbPoly for %s: Invalid coef array.\n", psub->name)); } else { DEBUGPRINT(DP_INFO, psSubFlag, ("psDbPoly for %s: Invalid poly coef.\n", psub->name)); } DEBUGPRINT(DP_INFO, psSubFlag, ("psDbPoly for %s: Invalid coef array; b: %f dpvt: %p\n", psub->name,psub->b, psub->dpvt )); status = ERROR; } else { /* * Do polynomial conversion using algorithm from ref_rmx_dbs:dbpoly.a38. * Find first derivative of the polynomial at the input value - * it'll be used to find reasonable alarm limits later. */ psub->k = 0.0; psub->l = 0.0; for (i = psub->b-1; i >=0; i--) { psub->l = (psub->l * psub->val) + psub->k; psub->k = (psub->k * psub->val) + ((double *)psub->dpvt)[i]; } #ifdef DEBUG DEBUGPRINT(DP_DEBUG, psSubFlag, ("psDbPoly for %s: after loop- l: %f k: %f val: %f\n", psub->name, psub->l,psub->k,psub->val )); #endif } } return(status); } /*============================================================================= Name: psPoly Abs: Convert Physical Units to Raw Units using polynomial conversion. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read/write pointer to subroutine record Input: -------- A = Point at which the polynomial is to be evaluated B = Number of polynomial coefficients C = Polynomial Coeff A (offset if linear) D = Polynomial Coeff B (slope if linear) E = Upper Limit F = Lower Limit DPVT = Pointer to polynomial coefficients (set by psInitPoly) Output: -------- J = Convergence status K = Value in Raw Units L = Slope of the polynomial at the DES value VAL = Value in Raw units. Rem: Subroutine for :::DES Side: None Ret: long 0 - Successful -1 - If bad return from psDbPoly. ==============================================================================*/ static long psPoly(subRecord *psub) { long status = SUCCESS; /* Adjust VAL if it's outside of reasonable limits */ psub->j = POLY_CONVERGED; psub->val = psub->a; if (psub->val > psub->e) psub->val = psub->e; else if (psub->val < psub->f) psub->val = psub->f; /* Perform conversion */ if (psDbPoly(psub)) { DEBUGPRINT(DP_INFO, psSubFlag, ("psPoly returning -1 for %s:\n", psub->name)); psub->j = POLY_ERROR; status = ERROR; } psub->val = psub->k; return(status); } /*============================================================================= Name: psReversePoly Abs: Estimate Physical Units Value from Raw Value. Use same algorithm as ref_rmx_reentrant:reverse_dbpoly.c.86. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read/write pointer to subroutine record Input: ------- VAL = Initial Guess of Physical Units Value A = linear calculation of PACT evaluated at raw value B = Number of polynomial coefficients (2-12) C = Polynomial Coeff A (offset if linear) D = Polynomial Coeff B (slope if linear) E = Point at which the polynomial is to be evaluated (raw value) F = Epsilon - desired accuracy of the Estimated Value G = Maximum iteration count (from slc 100) DPVT = Pointer to polynomial coefficients (set by psInitPoly) Output: ------- H = Previous Estimate of Value in Physical Units I = Number of iterations J = Convergence Status (see defines at the top of the file) K = Value in Physical Units corresponding to raw units L = Slope of the polynomial at the DES value VAL = Final Estimate of Value in Physical Units Rem: Subroutine for :::PACT Side: None Ret: long 0 - Successful 1 - Failure ==============================================================================*/ static long psReversePoly(subRecord *psub) { long status = SUCCESS; /* Simple linear conversion */ if (psub->val != psub->val) psub->val = 0.0; /* check for NaN - not a number */ else psub->h = psub->val; psub->j = POLY_CONVERGED; if (psub->b == 2) { psub->i = 0; /* number of iterations */ psub->l = psub->d; /* slope at DES */ psub->val = psub->a = (psub->e - psub->c)/psub->d; } else { double diff = psub->f + 1; double prev_diff = psub->f; /* * Iterate until we get close enough. */ for (psub->i = 0.0; (psub->i <= psub->g) && (psub->j == POLY_CONVERGED);psub->i += 1.0) { if (psDbPoly(psub)==ERROR) { psub->j = POLY_ERROR; } else if ((psub->l > -POLY_MIN_SLOPE) && (psub->l < POLY_MIN_SLOPE)) { psub->j = POLY_ZERO_SLOPE; } else if (diff <= psub->f) { #ifdef DEBUG DEBUGPRINT(DP_DEBUG, psSubFlag, ("psReversePoly for %s completed in %f iterations!!!\n", psub->name,psub->i )); #endif break; } else { /* save previous difference for verifying convergence */ prev_diff = diff; diff = POLY_CHICKEN_FACTOR * (psub->e - psub->k)/psub->l; /* need a new guess: slide on the slope towards answer */ psub->h = psub->val; psub->val += diff; if (diff < 0) diff *= -1; /* checking for NaN - not a number */ if ( psub->val != psub->val ) { if (psub->h == psub->h ) psub->val = psub->h; else psub->val = 0; psub->j = POLY_NO_CONVERGENCE; psub->stat = CALC_ALARM; psub->sevr = INVALID_ALARM; break; } } } /* End of FOR loop */ /* * Are we here because we ran into an error or ran out of iterations? */ if (psub->j != POLY_CONVERGED) { #ifdef DEBUG DEBUGPRINT(DP_DEBUG, psSubFlag, ("psReversePoly for %s: No convergence; J= %f\n", psub->name, psub->j)); #endif status = ERROR; } else if (psub->i > psub->g) { /* * Were we still on our way towards an answer? */ if (diff <= prev_diff) { psub->j = POLY_ALMOST_CONVERGED; #ifdef DEBUG DEBUGPRINT(DP_DEBUG, psSubFlag, ("psReversePoly for %s: almost converged; J= %f\n", psub->name, psub->j)); #endif } else { psub->j = POLY_NO_CONVERGENCE; #ifdef DEBUG DEBUGPRINT(DP_DEBUG, psSubFlag, ("psReversePoly for %s: convergence; J= %f\n",psub->name, psub->j)); #endif } status = ERROR; } } if (psub->val > psub->hopr) psub->val = psub->hopr; else if (psub->val < psub->lopr) psub->val = psub->lopr; return(status); } /*============================================================================= Name: psPhyDelta Abs: Calculate deltas used for alarm and warning limits and epsilon used in the reverse polynomial calculation. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read/write pointer to subroutine record Inputs: -------- A = Desired Value B = Minimum Warning Limit Delta (abs tol for small abs(B)) C = Fraction of DES for ACT Warning Limit D = Minimum Alarm Limit Delta (abs tol) E = Fraction of DES for ACT Alarm Limit NOTE: B,C,D,E same as TOLS in the SLC database (TOLS = B,D abs tol; C,E fractional; B,C for trim; D,E for check) Trim tol translates to Warning limits; Check tol to alarm limits F = G = Divisor of alarm limit delta to find epsilon (slc hardcoded 30) H = Actual Value Outputs: --------- I = PACT warning delta, "TOLMX" for trim in magtrck.f86 J = PACT alarm delta, "CHCK_TOL*" for check (E*A initially; D if < D) K = Out of tolerance (for trim; ="1" if out-of-tol) VAL = Epsilon Rem: Calculate deltas used for alarm and warning limits for primary (ACT) readback. Calculate epsilon used in the reverse polynomial calculation. Side: Warning and alarm deltas for ACT are fractions of DES. Also check that the deltas are not too small (for small values of DES). Ret: long 0 - Successful (always) ==============================================================================*/ static long psPhyDeltas(struct subRecord *psub) { long status = SUCCESS; /* Trim tolearances */ if ((psub->b > 0.0) || (psub->c > 0.0)) { psub->i = psub->c * psub->a; if (psub->i < 0) psub->i *= -1; if (psub->i < psub->b) psub->i = psub->b; } else psub->i = 0.0; /* CHCK tolerances */ if ((psub->d > 0.0) || (psub->e > 0.0)) { psub->j = psub->e * psub->a; if (psub->j < 0) psub->j *= -1; if (psub->j < psub->d) psub->j = psub->d; } else psub->j = 0.0; /* * Epsilon must be a fraction of the ACT alarm delta. */ psub->val = psub->j; if (psub->g > 1.0) { psub->val /= psub->g; } /* see if pds-bact> tolmax (i) */ psub->k = psub->a - psub->h; if (psub->k < 0) psub->k *= -1; if ( (psub->k) > psub-> i ){ psub->k = 1; /* set out of tol */ } else psub->k = 0; /* reset out of tol */ return(status); } /*============================================================================= Name: psRawDeltas Abs: Calculate deltas used for alarm and warning limits Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read/write pointer to subroutine record Inputs: -------- A = Desired Value B = C = D = Physical PACT Warning Delta (PDELTAS.I) E = Physical PACT Alarm Delta (PDELTAS.J) F = G = H = Raw/Physical Slope from mgntPoly (BDES.L ) Outputs: ----------- I = ACT warning delta (slc TOLMX) J = ACT alarm delta (slc CURR_TOL) K = L = VAL = Rem: Calculate deltas used for alarm and warning limits for primary (ACT) Side: None Ret: long 0 - Successful (always) ==============================================================================*/ static long psRawDeltas(struct subRecord *psub) { long status = SUCCESS; /* * Check for zero input deltas. Otherwise, multiply by slope to * get approximate raw deltas corresponding to physical deltas. * * Calculate warning limits. */ if (psub->d > 0.0) psub->i = psub->d * psub->h; else psub->i = 0.0; /* Calculate alarm limits */ if (psub->e > 0.0) psub->j = psub->e * psub->h; else psub->j = 0.0; return(status); } /*============================================================================= Name: psLimits Abs: Calculate alarm and warning limits from deltas. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read/write pointer to subroutine record Input: -------- A = Desired Field / Current B = Maximum (DRVH) $(WDEL) C = Minimum (DRVL) $(WFRAC) D = Warning Delta (0 = disable) E = Alarm Delta (0 = disable) F = Disable Alarm Checking (ie, setpoint currently changing) (0=no, 1=yes) (0=calc limits, 1=set limits to min/max) G = Power Supply On/Off state (1=On, 0=Off) H = Power Supply in-service (0=in-service, 1=out-of-service) Outputs: --------- I = HIGH value J = LOW value K = HIHI value L = LOLO value VAL = Not Used Rem: Calculate B alarm and warning limits from deltas. If the disable alarms flag is set or the supply is off, then use max/min values to disable alarms. Side: None Ret: long 0 - Successful (always) ==============================================================================*/ static long psLimits(struct subRecord *psub) { long status = SUCCESS; psub->i = psub->b+1; psub->j = psub->c-1; psub->k = psub->b+1; psub->l = psub->c-1; /* * If alarm checking is enabled and the power supply is on * and the supply is in-service and its in-service * then set the alarm and warning limits */ if ((psub->f < 0.01) && ((psub->g > 0.01) && (psub-> h < 0.01))) { if (psub->d > 0.0) { psub->i = psub->a + psub->d; psub->j = psub->a - psub->d; } if (psub->e > 0.0) { psub->k = psub->a + psub->e; psub->l = psub->a - psub->e; } } return(status); } /*============================================================================= Name: psStat Abs: Formulates slc status given relevant control bo's and SEVR/STAT inputs Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- longSubRecord * psub read point to subroutine record Input: --------- INPA - $(DEV):PACT.STAT INPB - $(DEV):PDES.STAT INPC - INPD - $(ADEV):VSETPT.STAT INPE - $(ADEV):VACT.STAT INPF - INPG - $(DEV):PACT.SERV INPH - $(DEV):PDES.SEVR INPI - INPJ - $(DEV):VSETPT.SEVR INPK - $(DEV):VACT.SEVR INPL - INPM - :STAT bitmask (use only first 16-bits) Rem: Subroutine for $(DEV):STATSUB Ret: long - SUCCESS (always) ==============================================================================*/ static long psStat (longSubRecord *psub) { unsigned long status = SUCCESS; unsigned long stat = 0; /* Is the device set offline? */ if (psub->p) psub->val = STAT_DEAD; else { /* establish w and x as worst case EPICS status and severity */ psub->w = psub->a; /* set worst case status to PACT.STAT */ psub->x = psub->g; /* set worst case severity to PDES.SEVR */ if ( psub->g == MINOR_ALARM ) stat = STAT_OK; /* Substandard but OK */ else if ( psub->g == MAJOR_ALARM ) stat = STAT_OUTOFTOL; /* Out of tolerance */ else if ( psub->g > MAJOR_ALARM ) stat = STAT_ERR; /* In trouble */ /* does PDES to VDES conversion have a worse severity than PACT? */ if (psub->h > psub->x) { psub->w = psub->b; /* set the worst case severity */ psub->x = psub->h; /* set the worst case status */ if (psub->h == MINOR_ALARM ) stat = STAT_CVTWARN; /* almost converged */ else stat = STAT_DBERR; /* database error */ } /* Is the DAC output severity worse? */ if (psub->j > psub->x) { psub->w = psub->d; /* set worst case severity locally */ psub->x = psub->j; /* set worst case severity locally */ stat = STAT_BAD_DAC; } /* Is the ADC severity worse? */ if (psub->k > psub->x) { psub->w = psub->e; /* set worst case severity locally */ psub->x = psub->k; /* set worst cse status locally */ stat = STAT_BAD_DAC; } /* Deprected: May 20, 2013 * If calibration is enabled and the device is * not successfully calibrated, then we have a * calibration warning. * if (!psub->r && !psub->o) stat |= STAT_CALBWARN; ************************************/ psub->val = stat; } if (psub->val > STAT_MASK){ DEBUGPRINT(DP_ERROR, psSubFlag, ("psStat stat ERROR for %s = 0x%lx\n", psub->name, psub->val )); } return(status); } epicsRegisterFunction(psInit); epicsRegisterFunction(psInitExplode); epicsRegisterFunction(psInitPoly); epicsRegisterFunction(psExplode); epicsRegisterFunction(psLimits); epicsRegisterFunction(psNumPolyCoef); epicsRegisterFunction(psReversePoly); epicsRegisterFunction(psRawDeltas); epicsRegisterFunction(psPhyDeltas); epicsRegisterFunction(psPoly); epicsRegisterFunction(psStat); /* Note - when adding a funciton, also add to psSub.dbd */ /* End of file */