/* $Id: devWaveformPdu.c,v 1.2 2010/09/04 00:13:37 dayle Exp $ */ /*============================================================================= Name: devWaveformPdu.c Abs: Auth: 23-jun-2010 Dayle Kotturi -----------------------------------------------------------------------------*/ #if 0 #include "copyright_SLAC.h" /* SLAC copyright comments */ #endif /*----------------------------------------------------------------------------- Mod: (see CVS log) =============================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include #define DEVSUPNAM "devWaveformPdu" #define DEBUG_PROC 1 int devWaveformPduDebug = 0; #ifdef DEBUG_PRINT int devWaveformPduFlag = 0; #endif typedef struct waveformPdu_s { int stuff; } waveformPdu_t; /* Forward Declarations */ static long report(int interest) { epicsPrintf(DEVSUPNAM": PDU data into a single waveform\n"); return 0; } static long init(int after) { return 0; } static long init_record(void *record_p) { waveformRecord *waveform_ps = record_p; waveformPdu_t *pwaveformp; /* Check DB configuration */ if ( waveform_ps->ftvl != menuFtypeSHORT ) { epicsPrintf (DEVSUPNAM": Error -- FTVL should be SHORT (is %i)\n", waveform_ps->ftvl); goto egress; } epicsPrintf(DEVSUPNAM": FTVL is SHORT\n"); /* Set NELM to what the driver is configured for free(waveform_ps->bptr);*/ waveform_ps->nelm = 21; epicsPrintf(DEVSUPNAM": NELM is %d\n", (int) waveform_ps->nelm); if ( !(waveform_ps->bptr = calloc(waveform_ps->nelm, sizeof(short))) ) { /* If there's no memory we are unlikely to be able to print something */ goto egress; } if ( VME_IO != waveform_ps->inp.type ) { epicsPrintf(DEVSUPNAM": Error -- INP is not VME_IO (but type %i)\n", waveform_ps->inp.type); goto egress; } epicsPrintf(DEVSUPNAM": INP is VME_IO\n"); /* Allocate the memory for this records private data structure */ pwaveformp = (waveformPdu_t *) malloc(sizeof(waveformPdu_t)); if (pwaveformp == NULL) { return S_dev_noMemory; } waveform_ps->dpvt = pwaveformp; /* Read the DBLINK "out" field to get the routine */ sscanf(pwaveform->out.value.instio.string, "%d", &(paop->stuff)); return 0; egress: waveform_ps->pact = 1; return -1; } static long read_waveform(void *record_p) { waveformRecord *waveform_ps = record_p; waveformPdu_t *pwaveformp = waveform_ps->dpvt; void *data; long rval = 0; int post = 0; int n; struct vmeio *l = &waveform_ps->inp.value.vmeio; int rc; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformPduFlag, ("read_waveform: Record %s has SEVR: %d STAT: %d\n", waveform_ps->name, (int)(waveform_ps->sevr), (int)(waveform_ps->stat))); #endif pl1x=(rf_l1x_station_t*) llrfGetFeedbackStation(dpvt_ps->station_type); if (pl1x == (rf_l1x_station_t*) NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devWaveformPduFlag, ("read_waveform: Record %s got NULL from llrfGetFeedbackStation\n", waveform_ps->name)); #endif return ERROR; } pl1x->Q[0]=*(short*) (waveform_ps->bptr); pl1x->I[0]=*(short*) (waveform_ps->bptr+2); pl1x->Q[1]=*(short*) (waveform_ps->bptr+4); pl1x->I[1]=*(short*) (waveform_ps->bptr+6); pl1x->Q[3]=*(short*) (waveform_ps->bptr+8); pl1x->I[3]=*(short*) (waveform_ps->bptr+10); pl1x->S=*(short*) (waveform_ps->bptr+12); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformPduL1XFlag, ("read_waveform: Record %s has sample0 Q,I=(%hd,%hd) and POC %f \n", waveform_ps->name, pl1x->Q[0], pl1x->I[0], pl1x->phase_offset_correction[0])); DEBUGPRINT(DP_INFO, devWaveformPduL1XFlag, ("read_waveform: Record %s has sample1 Q,I=(%hd,%hd) and POC %f \n", waveform_ps->name, pl1x->Q[1], pl1x->I[1], pl1x->phase_offset_correction[1])); DEBUGPRINT(DP_INFO, devWaveformPduL1XFlag, ("read_waveform: Record %s has sample2 S=%hd\n", waveform_ps->name, pl1x->S)); DEBUGPRINT(DP_INFO, devWaveformPduL1XFlag, ("read_waveform: Record %s has sample3 Q,I=(%hd,%hd) and POC %f \n", waveform_ps->name, pl1x->Q[3], pl1x->I[3], pl1x->phase_offset_correction[3])); #endif if ( post & 1 ) db_post_events(waveform_ps, &waveform_ps->nord, (DBE_VALUE|DBE_LOG)); if ( post & 2 ) db_post_events(waveform_ps, &waveform_ps->rarm, (DBE_VALUE|DBE_LOG)); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devWaveformPduFlag, ("read_waveform: Record %s done\n", waveform_ps->name)); #endif return rval; } struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read; } devWaveformPdu = { 5, report, init, init_record, NULL, read_waveform }; epicsExportAddress(dset, devWaveformPdu);