/* * MPSBufferStatus.c * MPSLinkProcessor * * Created by Stephen Norum. * Copyright 2008 Stanford Linear Accelerator Center. All rights reserved. * */ #include #include #include /* for struct subRecord */ #include /* for epicsExport */ #include /* for epicsRegisterFunction */ #include #include "MachineStateBuffer.h" struct privateDataStruct { int (*readFunc)(unsigned int index); unsigned int faultNumber; }; typedef struct privateDataStruct privateData; static int mpsDeviceStateInit(subRecord *psub) { unsigned int faultNumber; unsigned int buffer; privateData *pdpvt; pdpvt = callocMustSucceed(sizeof(privateData), 1, "mpsDeviceStateInit"); faultNumber = (unsigned int) psub->a; buffer = (unsigned int) psub->b; pdpvt->faultNumber = faultNumber; switch (buffer) { case 1: pdpvt->readFunc = getDeviceState; break; case 2: pdpvt->readFunc = isInputByassed; break; case 3: pdpvt->readFunc = getBypassValue; break; default: pdpvt->readFunc = NULL; break; } psub->dpvt = pdpvt; psub->val = 0; return 0; } static long mpsDeviceStateProc(subRecord *psub) { int state; privateData *pdpvt; pdpvt = (privateData *) psub->dpvt; state = 0; if (pdpvt->readFunc != NULL) { state = pdpvt->readFunc(pdpvt->faultNumber); } psub->val = state ? 1 : 0; return 0; } epicsRegisterFunction(mpsDeviceStateInit); epicsRegisterFunction(mpsDeviceStateProc);