From 3edc4b5c18741d1c17fd93d63498c2fe2bf594da Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 20 Nov 2007 16:44:21 +0000 Subject: [PATCH] Fixed error behaviour. ANSIfied, major cleanup. --- src/rec/subArrayRecord.c | 337 +++++++++++++++++++-------------------- 1 file changed, 163 insertions(+), 174 deletions(-) diff --git a/src/rec/subArrayRecord.c b/src/rec/subArrayRecord.c index ebf04c39e..4c8653d37 100644 --- a/src/rec/subArrayRecord.c +++ b/src/rec/subArrayRecord.c @@ -43,41 +43,41 @@ /* Create RSET - Record Support Entry Table*/ #define report NULL #define initialize NULL -static long init_record(); -static long process(); +static long init_record(subArrayRecord *psa, int pass); +static long process(subArrayRecord *psa); #define special NULL #define get_value NULL -static long cvt_dbaddr(); -static long get_array_info(); -static long put_array_info(); -static long get_units(); -static long get_precision(); +static long cvt_dbaddr(DBADDR *paddr); +static long get_array_info(DBADDR *paddr, long *no_elements, long *offset); +static long put_array_info(DBADDR *paddr, long nNew); +static long get_units(DBADDR *paddr, char *units); +static long get_precision(DBADDR *paddr, long *precision); #define get_enum_str NULL #define get_enum_strs NULL #define put_enum_str NULL -static long get_graphic_double(); -static long get_control_double(); +static long get_graphic_double(DBADDR *paddr, struct dbr_grDouble *pgd); +static long get_control_double(DBADDR *paddr, struct dbr_ctrlDouble *pcd); #define get_alarm_double NULL rset subArrayRSET={ - RSETNUMBER, - report, - initialize, - init_record, - process, - special, - get_value, - cvt_dbaddr, - get_array_info, - put_array_info, - get_units, - get_precision, - get_enum_str, - get_enum_strs, - put_enum_str, - get_graphic_double, - get_control_double, - get_alarm_double + RSETNUMBER, + report, + initialize, + init_record, + process, + special, + get_value, + cvt_dbaddr, + get_array_info, + put_array_info, + get_units, + get_precision, + get_enum_str, + get_enum_strs, + put_enum_str, + get_graphic_double, + get_control_double, + get_alarm_double }; epicsExportAddress(rset,subArrayRSET); @@ -93,229 +93,218 @@ struct sadset { /* subArray dset */ /*sizes of field types*/ static int sizeofTypes[] = {MAX_STRING_SIZE,1,1,2,2,4,4,4,8,2}; -static void monitor(); -static long readValue(); +static void monitor(subArrayRecord *psa); +static long readValue(subArrayRecord *psa); -/*Following from timing system */ -/* -extern unsigned int gts_trigger_counter; -*/ -static long init_record(psa,pass) - struct subArrayRecord *psa; - int pass; +static long init_record(subArrayRecord *psa, int pass) { struct sadset *pdset; - long status; if (pass==0){ - if(psa->malm<=0) psa->malm=1; - - if(psa->ftvl>DBF_ENUM) psa->ftvl=2; - psa->bptr = (char *)calloc(psa->malm,sizeofTypes[psa->ftvl]); + if (psa->malm <= 0) + psa->malm = 1; + if (psa->ftvl > DBF_ENUM) + psa->ftvl = 2; + psa->bptr = calloc(psa->malm, sizeofTypes[psa->ftvl]); psa->nord = 0; - return(0); + return 0; } /* must have dset defined */ - if(!(pdset = (struct sadset *)(psa->dset))) { + if (!(pdset = (struct sadset *)(psa->dset))) { recGblRecordError(S_dev_noDSET,(void *)psa,"sa: init_record"); - return(S_dev_noDSET); + return S_dev_noDSET; } + /* must have read_sa function defined */ - if( (pdset->number < 5) || (pdset->read_sa == NULL) ) { + if ( (pdset->number < 5) || (pdset->read_sa == NULL) ) { recGblRecordError(S_dev_missingSup,(void *)psa,"sa: init_record"); - return(S_dev_missingSup); + return S_dev_missingSup; } - if( pdset->init_record ) { - if((status=(*pdset->init_record)(psa))) return(status); - } - return(0); + + if (pdset->init_record) + return (*pdset->init_record)(psa); + + return 0; } -static long process(psa) - struct subArrayRecord *psa; +static long process(subArrayRecord *psa) { - struct sadset *pdset = (struct sadset *)(psa->dset); - long status; - unsigned char pact=psa->pact; + struct sadset *pdset = (struct sadset *)(psa->dset); + long status; + unsigned char pact=psa->pact; - if( (pdset==NULL) || (pdset->read_sa==NULL) ) { - psa->pact=TRUE; - recGblRecordError(S_dev_missingSup,(void *)psa,"read_sa"); - return(S_dev_missingSup); - } + if ((pdset==NULL) || (pdset->read_sa==NULL)) { + psa->pact=TRUE; + recGblRecordError(S_dev_missingSup, (void *)psa, "read_sa"); + return S_dev_missingSup; + } - if ( pact && psa->busy ) return(0); - status=readValue(psa); /* read the new value */ - if (!pact && psa->pact) return(0); - psa->pact = TRUE; + if (pact && psa->busy) return 0; - psa->udf=FALSE; - recGblGetTimeStamp(psa); - monitor(psa); + status=readValue(psa); /* read the new value */ + if (!pact && psa->pact) return 0; + psa->pact = TRUE; - /* process the forward scan link record */ - recGblFwdLink(psa); + recGblGetTimeStamp(psa); - psa->pact=FALSE; - return(0); + psa->udf = !!status; /* 0 or 1 */ + if (status) + recGblSetSevr(psa, UDF_ALARM, INVALID_ALARM); + + monitor(psa); + + /* process the forward scan link record */ + recGblFwdLink(psa); + + psa->pact=FALSE; + return 0; } -static long cvt_dbaddr(paddr) - struct dbAddr *paddr; +static long cvt_dbaddr(DBADDR *paddr) { - struct subArrayRecord *psa=(struct subArrayRecord *)paddr->precord; + subArrayRecord *psa = (subArrayRecord *) paddr->precord; paddr->pfield = psa->bptr; - if (!psa->udf && psa->nelm > psa->nord) - paddr->no_elements = psa->nord; - else - paddr->no_elements = psa->nelm; + paddr->no_elements = psa->malm; paddr->field_type = psa->ftvl; paddr->field_size = sizeofTypes[psa->ftvl]; paddr->dbr_field_type = psa->ftvl; - return(0); + + return 0; } -static long get_array_info(paddr,no_elements,offset) - struct dbAddr *paddr; - long *no_elements; - long *offset; +static long get_array_info(DBADDR *paddr, long *no_elements, long *offset) { - struct subArrayRecord *psa=(struct subArrayRecord *)paddr->precord; + subArrayRecord *psa = (subArrayRecord *) paddr->precord; - if (!psa->udf && psa->nelm > psa->nord) - *no_elements = psa->nord; + if (psa->udf) + *no_elements = 0; else - *no_elements = psa->nelm; + *no_elements = psa->nord; *offset = 0; - return(0); + + return 0; } -static long put_array_info(paddr,nNew) - struct dbAddr *paddr; - long nNew; +static long put_array_info(DBADDR *paddr, long nNew) { - struct subArrayRecord *psa=(struct subArrayRecord *)paddr->precord; + subArrayRecord *psa = (subArrayRecord *) paddr->precord; - if(nNew > psa->malm) + if (nNew > psa->malm) psa->nord = psa->malm; else psa->nord = nNew; - return(0); + + return 0; } -static long get_units(paddr,units) - struct dbAddr *paddr; - char *units; +static long get_units(DBADDR *paddr, char *units) { - struct subArrayRecord *psa=(struct subArrayRecord *)paddr->precord; + subArrayRecord *psa = (subArrayRecord *) paddr->precord; - strncpy(units,psa->egu,DB_UNITS_SIZE); - return(0); + strncpy(units, psa->egu, DB_UNITS_SIZE); + + return 0; } -static long get_precision(paddr,precision) - struct dbAddr *paddr; - long *precision; +static long get_precision(DBADDR *paddr, long *precision) { - struct subArrayRecord *psa=(struct subArrayRecord *)paddr->precord; - int fieldIndex = dbGetFieldIndex(paddr); + subArrayRecord *psa = (subArrayRecord *) paddr->precord; + int fieldIndex = dbGetFieldIndex(paddr); *precision = psa->prec; - if(fieldIndex == subArrayRecordVAL) return(0); - recGblGetPrec(paddr,precision); - return(0); + + if (fieldIndex != subArrayRecordVAL) + recGblGetPrec(paddr, precision); + + return 0; } -static long get_graphic_double(paddr,pgd) - struct dbAddr *paddr; - struct dbr_grDouble *pgd; +static long get_graphic_double(DBADDR *paddr, struct dbr_grDouble *pgd) { - struct subArrayRecord *psa=(struct subArrayRecord *)paddr->precord; - int fieldIndex = dbGetFieldIndex(paddr); + subArrayRecord *psa = (subArrayRecord *) paddr->precord; - if(fieldIndex == subArrayRecordVAL) { + switch (dbGetFieldIndex(paddr)) { + case subArrayRecordVAL: pgd->upper_disp_limit = psa->hopr; pgd->lower_disp_limit = psa->lopr; - return(0); - } - if(fieldIndex == subArrayRecordINDX) { + break; + + case subArrayRecordINDX: pgd->upper_disp_limit = psa->malm - 1; pgd->lower_disp_limit = 0; - return(0); - } - if(fieldIndex == subArrayRecordNELM) { + break; + + case subArrayRecordNELM: pgd->upper_disp_limit = psa->malm; pgd->lower_disp_limit = 1; - return(0); - } - recGblGetGraphicDouble(paddr,pgd); - return(0); -} -static long get_control_double(paddr,pcd) - struct dbAddr *paddr; - struct dbr_ctrlDouble *pcd; -{ - struct subArrayRecord *psa=(struct subArrayRecord *)paddr->precord; - int fieldIndex = dbGetFieldIndex(paddr); + break; - if(fieldIndex == subArrayRecordVAL) { + default: + recGblGetGraphicDouble(paddr, pgd); + } + + return 0; +} + +static long get_control_double(DBADDR *paddr, struct dbr_ctrlDouble *pcd) +{ + subArrayRecord *psa = (subArrayRecord *) paddr->precord; + + switch (dbGetFieldIndex(paddr)) { + case subArrayRecordVAL: pcd->upper_ctrl_limit = psa->hopr; pcd->lower_ctrl_limit = psa->lopr; - return(0); - } - if(fieldIndex == subArrayRecordINDX) { + break; + + case subArrayRecordINDX: pcd->upper_ctrl_limit = psa->malm - 1; pcd->lower_ctrl_limit = 0; - return(0); - } - if(fieldIndex == subArrayRecordNELM) { + break; + + case subArrayRecordNELM: pcd->upper_ctrl_limit = psa->malm; pcd->lower_ctrl_limit = 1; - return(0); - } - recGblGetControlDouble(paddr,pcd); - return(0); + break; + + default: + recGblGetControlDouble(paddr, pcd); + } + + return 0; } -static void monitor(psa) - struct subArrayRecord *psa; +static void monitor(subArrayRecord *psa) { - unsigned short monitor_mask; + unsigned short monitor_mask; - /* get previous stat and sevr and new stat and sevr*/ - monitor_mask = recGblResetAlarms(psa); + monitor_mask = recGblResetAlarms(psa); + monitor_mask |= (DBE_LOG|DBE_VALUE); - monitor_mask |= (DBE_LOG|DBE_VALUE); - if(monitor_mask) - db_post_events(psa, psa->bptr, monitor_mask); - return; -} - -static long readValue(psa) - struct subArrayRecord *psa; -{ - long status; - struct sadset *pdset = (struct sadset *) (psa->dset); + db_post_events(psa, psa->bptr, monitor_mask); - if (psa->nelm > psa->malm) - { - psa->nelm = psa->malm; - } - if (psa->indx >= psa->malm) - { - psa->indx = psa->malm - 1; - } - status = (*pdset->read_sa)(psa); - - if (psa->nord <= 0) - { - status = -1; - psa->indx = 0; - } - return(status); + return; +} + +static long readValue(subArrayRecord *psa) +{ + long status; + struct sadset *pdset = (struct sadset *) (psa->dset); + + if (psa->nelm > psa->malm) + psa->nelm = psa->malm; + + if (psa->indx >= psa->malm) + psa->indx = psa->malm - 1; + + status = (*pdset->read_sa)(psa); + + if (psa->nord <= 0) + status = -1; + + return status; }