/*============================================================ Filename: pduPattern.c Abs: This file contains all support for pdu timing soft processing records. Device Support Description -------------- ---------------------------- pdu_init Gerneric Initalization Rem: All functions called by a subroutine record get passed one argument: rec_ps Pointer to the subroutine record data. Use: pointer Type: struct longSubRecord * 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. 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 rec_ps->brsv (BRSV - set by the user in the database though it is expected to be invalid). Proto: None Auth: 14-Sep-2010, Kristi Luchini (LUCHINI) Rev: dd-mmm-yyyy, Reviewer's Name (USERNAME --------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*------------------------------------------------------------- Mod: (newest to oldest) dd-mmm-yyyy, First Lastname (USERNAME): comment ==============================================================*/ /* Header files */ #include #include #include /* for memset */ #include "subRecord.h" /* for struct subRecord */ #include "longSubRecord.h" /* for struct longSubRecord */ #include "registryFunction.h" /* for epicsExport */ #include "epicsExport.h" /* for epicsRegisterFunctio */ #include "ellLib.h" /* EPICS Linked list library */ #include "debugPrint.h" /* for DEBUGPRINT,EDEF_MAX */ #include "devLib.h" /* S_dev_noDevice */ #include "dbAccess.h" /* for DBADDR */ #include "dbDefs.h" /* min() and max() macros */ #include "recGbl.h" /* for recGblSetServ() macro */ #include "alarm.h" /* WRITE_ALARM, MAJOR_ALARM */ #include "recSup.h" /* for S_rec_outMem */ #include "recGbl.h" /* for recGblRecordError() */ #include "devSup.h" /* for S_dev_noDeviceFound */ #include "dbFldTypes.h" /* for DBF_USHORT */ #include "epicsTypes.h" /* epicsBoolean */ #include "cantProceed.h" /* callocMustSucceed() */ #include "longSubRecord.h" /* for struct longSubRecord */ #include "genSubRecord.h" /* for struct genSubRecord */ #include "waveformRecord.h" /* for struct waveformRecord */ #include "evrTime.h" /* EVENT* defines */ #include "evrPattern.h" /* Various bit masks */ #include "pduPattern.h" /* for pduPattern_ta,etc */ int PDU_SUB_DEBUG = 1; /* Tables and Lists */ static ELLLIST eventRuleList = {{NULL, NULL}, 0}; /* Local prototype */ static long pdu_init(longSubRecord *rec_ps);s ); /* Utilities (not used) */ static eventRuleInfo_ts * findEventRuleByAddr(waveformRecord const * const rec_ps); static eventRuleInfo_ts * findEventRuleByName(char const * const name_c); static eventRuleInfo_ts * addEventRule(waveformRecord const * const rec_ps); static eventRuleInfo_ts * findEventRuleByAddr(waveformRecord const * const rec_ps) { eventRuleInfo_ts *rule_ps = NULL; int done = 0; for ( rule_ps=(eventRuleInfo_ts *)ellFirst(&eventRuleList); rule_ps && rec_ps && !done; rule_ps=(eventRuleInfo_ts *)ellNext((ELLNODE *)rule_ps) ) { if (rule_ps->rec_ps == rec_ps) done = 1; } return(rule_ps); } static eventRuleInfo_ts * findEventRuleByName(char const * const name_c) { eventRuleInfo_ts *rule_ps = NULL; int done = 0; int len = strlen(name_c); for( rule_ps=(eventRuleInfo_ts *)ellFirst(&eventRuleList); rule_ps && len && !done; rule_ps=(eventRuleInfo_ts *)ellNext((ELLNODE *)rule_ps) ) { if ( !strcmp(name_c,(rule_ps->rec_ps)->name) ) { if ( len==strlen((rule_ps->rec_ps)->name) ) done=1; } } return(rule_ps); } static eventRuleInfo_ts * addEventRule(waveformRecord const * const rec_ps) { unsigned long ruleNo= 0; unsigned long len = strlen(GLOBAL_RULE_DEVNAME); eventRuleInfo_ts *rule_ps = NULL; eventRuleInfo_ts *temp_ps = NULL; if ( strlen(rec_ps->name)<= len ) return( rule_ps ); if( 0 == strncmp(GLOBAL_RULE_DEVNAME,rec_ps->name,len) ) { ruleNo = atoi(rec_ps->name + strlen(GLOBAL_RULE_DEVNAME)); if(PDU_SUB_DEBUG) printf("Global Rule Id is %ld for [%s]\n",ruleNo , rec_ps->name); /* Allocate memory for rule information */ rule_ps = callocMustSucceed(1,sizeof(eventRuleInfo_ts),"calloc failed for addEventlRule"); /* Initialize rule info */ rule_ps->lock = epicsMutexMustCreate(); rule_ps->id = ruleNo; rule_ps->rec_ps = (waveformRecord *)rec_ps; rule_ps->pattern_ps = (pduEventPattern_ts *)rec_ps->bptr; /* sort linked list */ for( temp_ps = (eventRuleInfo_ts *)ellFirst(&eventRuleList); temp_ps; temp_ps = (eventRuleInfo_ts *)ellNext((ELLNODE *)temp_ps) ) if(rule_ps->id < temp_ps->id) break; if(temp_ps) { temp_ps=(eventRuleInfo_ts *)ellPrevious((ELLNODE *)temp_ps); ellInsert( &eventRuleList, (ELLNODE *)temp_ps, (ELLNODE *)rule_ps ); } else /* Did not find a larger rule id, so append to the end of the list. */ ellAdd(&eventRuleList, (ELLNODE *)rule_ps); if (PDU_SUB_DEBUG) printf("Add Global Rule %ld \n",rule_ps->id); } return(rule_ps); } /*============================================================================= Name: pdu_init Abs: PDU initialization subroutine record Rem: Side: None Ret: long OK - Successful (always) ==============================================================================*/ static long pdu_init(longSubRecord *rec_ps) { long status=OK; /* * 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); } /* Register these symbols for use by IOC code: */ epicsRegisterFunction(pdu_init); /* End of file */