/* $Id: patSubEntry.c,v 1.3 2012/09/20 20:34:06 khkim Exp $ */ #include #include #include #include #include #include #include #include #include #include #include #if ! defined (EPICS_VERSION) || ! defined(EPICS_REVISION) || ! defined( EPICS_MODIFICATION ) #error "Unable to determine EPICS version" #endif #if EPICS_VERSION < 3 \ || EPICS_VERSION == 3 && EPICS_REVISION < 14 \ || EPICS_VERSION == 3 && EPICS_REVISION == 14 && EPICS_MODIFICATION < 10 static void myCantProceed(const char *fmt, ...) { char buf[256]; va_list ap; va_start( ap, fmt ); epicsVsnprintf( buf, sizeof(buf), fmt, ap ); va_end( ap ); cantProceed( buf ); } #else #define myCantProceed cantProceed #endif #define MAX_NELMS 10 /* Check that various fields hold the values we expect and * calculate the max number of elements in the in/out arrays * (L and VALL, respectively). */ static int sanityCheck(aSubRecord *psub, const char *which, const char *fld) { int i, ni, no; if ( strcmp( psub->rdes->name, "aSub" ) ) { myCantProceed("%s: patSubEntry%s() - cannot be used as %s; record not an 'aSub'\n", psub->name, which, fld ); } /* calculate max. number of elements */ ni = psub->nol; if ( ni > MAX_NELMS ) ni = MAX_NELMS; no = psub->novl; if ( no > MAX_NELMS ) no = MAX_NELMS; if ( ni < no ) no = ni; else ni = no; for ( i = 0; ifta)[i] ) { myCantProceed("FATAL ERROR: %s - field %s not ULONG\n", psub->name, psub->rdes->papFldDes[aSubRecordA + i]->name); } if ( DBR_ULONG != (&psub->ftva)[i] ) { myCantProceed("FATAL ERROR: %s - field %s not ULONG\n", psub->name, psub->rdes->papFldDes[aSubRecordFTVA + i]->name); } } if ( DBR_ULONG != psub->ftl ) { myCantProceed("FATAL ERROR: %s - field %s not ULONG\n", psub->name, psub->rdes->papFldDes[aSubRecordL]->name); } if ( DBR_ULONG != psub->ftvl ) { myCantProceed("FATAL ERROR: %s - field %s not ULONG\n", psub->name, psub->rdes->papFldDes[aSubRecordFTVL]->name); } return ni; } static long patSubEntryInit(aSubRecord *psub) { /* If the check fails it executes cantProceed */ sanityCheck( psub, "Init", "INAM" ); return 0; } static long patSubEntryProc(aSubRecord *psub) { int i, n; epicsUInt32 vi,vo,va; /* Could do these checks in 'init' function only but there is * no guarantee that the user sets INAM correctly or doesn't * modify SNAM at run-time... */ n = sanityCheck( psub, "Proc", "SNAM" ); for ( i = 0; ia)[i]); vo = *(epicsUInt32*)((&psub->vala)[i]); va = ((epicsUInt32*)psub->l)[i]; if ( vo == vi ) { vi = va; } *(epicsUInt32*)((&psub->vala)[i]) = ((epicsUInt32*)psub->vall)[i] = vi; } return 0; } epicsRegisterFunction(patSubEntryInit); epicsRegisterFunction(patSubEntryProc);