/* devSoftInterrupt.c */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "MachineStateBuffer.h" int debugDevMpsGeneralBi = 0; enum devMpsGeneralBiSpecialValues { devMpsGeneralBiPortNameMaxLength = 128 }; typedef int (*biReadFunc)(unsigned int index); struct dpvt { unsigned int faultNumber; biReadFunc readFunc; }; struct dsetStruct { long number; DEVSUPFUN dev_report; DEVSUPFUN init; DEVSUPFUN init_record; /*returns: (-1,0)=>(failure,success)*/ DEVSUPFUN get_ioint_info; DEVSUPFUN read_bi;/*(0,2)=> success and convert, don't convert)*/ /* if convert then raw value stored in rval */ }; static long init(int pass) { return 0; } static long init_record(struct biRecord *prec) { int i; int status; char *pinp = NULL; unsigned int faultNumber; struct dpvt *pdpvt = NULL; static char portName[devMpsGeneralBiPortNameMaxLength + 1]; static const char * portNames[4] = { "devMpsStatusBufferReadback", /* 0 */ "devMpsBypassActiveBufferReadback", /* 1 */ "devMpsBypassValueBufferReadback", /* 2 */ "devMpsLatchedBufferReadback" /* 3 */ }; static biReadFunc readFuncs[4] = { getDeviceState, /* 0 */ inputIsByassed, /* 1 */ getBypassValue, /* 2 */ getLatchedDeviceState /* 3 */ }; pdpvt = callocMustSucceed(1, sizeof(struct dpvt), "devMpsGeneralBi: init_record"); pdpvt->faultNumber = -1; prec->dpvt = (void *) pdpvt; /* point pout to everthing after the OUT field's @ sign */ pinp = prec->inp.value.instio.string; if (pinp == NULL) { return -1; } status = sscanf(pinp, "%s %u", portName, &faultNumber); if (status != 2) { errlogPrintf("devMpsGeneralBi: %s INP error", prec->name); return -1; } pdpvt->faultNumber = faultNumber; pdpvt->readFunc = NULL; for (i = 0; i < sizeof(portNames) / sizeof(portNames[0]); i++) { if (strncmp(portName, portNames[i], devMpsGeneralBiPortNameMaxLength) == 0) { pdpvt->readFunc = readFuncs[i]; break; } } if (pdpvt->readFunc == NULL) { errlogPrintf("devMpsGeneralBi: %s port not found", prec->name); return -1; } if (debugDevMpsGeneralBi) { printf("devMpsGeneralBi: %s = %p(%u)\n", prec->name, pdpvt->readFunc, pdpvt->faultNumber); } return 0; } static long read_bi(struct biRecord *prec) { int status = 0; struct dpvt *pdpvt = NULL; pdpvt = (struct dpvt *) prec->dpvt; status = pdpvt->readFunc(pdpvt->faultNumber); if (status < 0) { prec->rval = 0; return -1; } prec->rval = status; prec->val = status; return 0; } /* Configure and export device support entry table */ struct dsetStruct devMpsGeneralBi = { 5, NULL, init, init_record, NULL, read_bi }; epicsExportAddress(dset,devMpsGeneralBi);