diff --git a/src/devOpt/devXxDig500Msg232.c b/src/devOpt/devXxDig500Msg232.c index 01d29f982..b8c38658c 100644 --- a/src/devOpt/devXxDig500Msg232.c +++ b/src/devOpt/devXxDig500Msg232.c @@ -27,6 +27,7 @@ * Modification Log: * ----------------- * .01 09-30-91 jrw created + * .02 05-26-92 jrw added new record type enumerations * */ @@ -43,14 +44,18 @@ #include #include +#include +#include #include #include #include #include #include #include +#include "/home/phebos/WINANS/appl/record-3.5/bprecH/rec/brownpileRecord.h" #include +#include #include #define DSET_AI devAidig500Msg232 @@ -65,66 +70,580 @@ #define DSET_SO devSodig500Msg232 #define DSET_WF devWfdig500Msg232 +#define DSET_BP devBpdig500Msg232 + + +int dig500MsgDebug = 0; static long init(), report(); static msgParmBlock parmBlock; +/***************************************************************************** + * + * custom support routines that are not provided by the generic message driver + * + ******************************************************************************/ +static msgRecEnum local_bp = { "PE dig500" }; + +static long +local_initBp(pbp) +struct brownpileRecord *pbp; +{ + char message[100]; + long status; + + if (dig500MsgDebug) + printf("local_initBp entered\n"); + + pbp->dpvt = drvMsg_genXact(((struct msgDset *)(pbp->dset))->pparmBlock, &(pbp->inp), pbp); + + if (pbp->dpvt != NULL) + { + status = drvMsg_checkParm(pbp, "Perkin Elmer"); + if (status == 0) + drvMsg_initCallback(pbp); + else + pbp->pact = 1; + return(status); + } + pbp->pact = 1; + return(S_db_badField); +} + +/*****************************************************************************/ +static long +local_procBp(pbp) +struct brownpileRecord *pbp; +{ + if (dig500MsgDebug > 10) + printf("local_procBp entered\n"); + + return(drvMsg_proc(pbp, 0)); +} + msgDset DSET_AI = { 6, { report, init, drvMsg_initAi, NULL, - drvMsg_procAi, NULL}, &parmBlock}; + drvMsg_procAi, NULL}, &parmBlock, &drvMsgAi}; msgDset DSET_AO = { 6, { NULL, NULL, drvMsg_initAo, NULL, - drvMsg_procAo, NULL}, &parmBlock}; + drvMsg_procAo, NULL}, &parmBlock, &drvMsgAo}; msgDset DSET_BI = { 6, { NULL, NULL, drvMsg_initBi, NULL, - drvMsg_procBi, NULL}, &parmBlock}; + drvMsg_procBi, NULL}, &parmBlock, &drvMsgBi}; msgDset DSET_BO = { 6, { NULL, NULL, drvMsg_initBo, NULL, - drvMsg_procBo, NULL}, &parmBlock}; + drvMsg_procBo, NULL}, &parmBlock, &drvMsgBo}; msgDset DSET_MI = { 6, { NULL, NULL, drvMsg_initMi, NULL, - drvMsg_procMi, NULL}, &parmBlock}; + drvMsg_procMi, NULL}, &parmBlock, &drvMsgMi}; msgDset DSET_MO = { 6, { NULL, NULL, drvMsg_initMo, NULL, - drvMsg_procMo, NULL}, &parmBlock}; + drvMsg_procMo, NULL}, &parmBlock, &drvMsgMo}; msgDset DSET_LI = { 6, { NULL, NULL, drvMsg_initLi, NULL, - drvMsg_procLi, NULL}, &parmBlock}; + drvMsg_procLi, NULL}, &parmBlock, &drvMsgLi}; msgDset DSET_LO = { 6, { NULL, NULL, drvMsg_initLo, NULL, - drvMsg_procLo, NULL}, &parmBlock}; + drvMsg_procLo, NULL}, &parmBlock, &drvMsgLo}; msgDset DSET_SI = { 6, { NULL, NULL, drvMsg_initSi, NULL, - drvMsg_procSi, NULL}, &parmBlock}; + drvMsg_procSi, NULL}, &parmBlock, &drvMsgSi}; msgDset DSET_SO = { 6, { NULL, NULL, drvMsg_initSo, NULL, - drvMsg_procSo, NULL}, &parmBlock}; + drvMsg_procSo, NULL}, &parmBlock, &drvMsgSo}; msgDset DSET_WF = { 6, { NULL, NULL, drvMsg_initWf, NULL, - drvMsg_procWf, NULL}, &parmBlock}; + drvMsg_procWf, NULL}, &parmBlock, &drvMsgWf}; -int softMsgDebug = 0; +msgDset DSET_BP = { 6, { NULL, NULL, local_initBp, NULL, + local_procBp, NULL}, &parmBlock, &local_bp}; -static msgStrParm wrParms[] = { - { "RD\r", 3}, - { "SL3\r", -1 } -}; - -static msgFoParm foParms[] = { - { "Parm 1 Value is: %lf\n\r" }, - { "pArM 2 VaLuE iS: %lf\n\r" }, - { "longout value is %ld\n\r" } -}; - -static msgFiParm fiParms[] = { - { "%s %lf", 50 }, - { "%lf", 50 }, - { "%ld", 50 }, -}; - -static msgAkParm akParms[] = { - { "*", 0, 50 } /* see if I have a string that starts with '*' */ -}; +/****************************************************************************** + * + * Custom I/O operations not supported by the drvMsg module required by the + * dig500 record. + * + ******************************************************************************/ +#define LOCAL_OP_PROC MSG_OP_USER+0 static msgCmd cmds[] = { - { &DSET_SI, READ_NDLY, {MSG_OP_WRITE, &wrParms[0]}, {MSG_OP_RSI, NULL}, NULL, -1 }, - { &DSET_BO, READ_NDLY, {MSG_OP_WRITE, &wrParms[1]}, {MSG_OP_ACK, &akParms[0]}, NULL, -1}, + { &local_bp, READ_NDLY, {LOCAL_OP_PROC, NULL}, {MSG_OP_NOP, NULL}, NULL, -1 }, }; +/****************************************************************************** + * + * This function is used to intercept the read-portion of custom opertaion codes + * that are specific to the digitel 500. + * + ******************************************************************************/ + +/* Flag bits set to indicate fields that have been altered. */ +#define MOD_DSPL 0x0001 +#define MOD_KLCK 0x0002 +#define MOD_MODS 0x0004 +#define MOD_SP1S 0x0008 +#define MOD_S1HS 0x0010 +#define MOD_S1MS 0x0020 +#define MOD_S1VS 0x0040 +#define MOD_SP2S 0x0080 +#define MOD_S2HS 0x0100 +#define MOD_S2MS 0x0200 +#define MOD_S2VS 0x0400 + +/* Values for enumerated fields. */ +#define REC_BP_CHOICE_DSPL_VOLT 0 +#define REC_BP_CHOICE_DSPL_CURR 1 +#define REC_BP_CHOICE_DSPL_PRES 2 + +#define REC_BP_CHOICE_KLCK_UNLK 0 +#define REC_BP_CHOICE_KLCK_LOCK 1 + +#define REC_BP_CHOICE_OPER_SBY 0 +#define REC_BP_CHOICE_OPER_BUSY 1 + +#define REC_BP_CHOICE_SP_OFF 0 +#define REC_BP_CHOICE_SP_ON 1 + +#define REC_BP_CHOICE_SPMODE_PRES 0 +#define REC_BP_CHOICE_SPMODE_CURR 1 + +#define REC_BP_CHOICE_HVI_OFF 0 +#define REC_BP_CHOICE_HVI_ON 1 + +#define REC_BP_CHOICE_PUMP_30 0 /* 30 Liter/sec */ +#define REC_BP_CHOICE_PUMP_60 1 /* 60 Liter/sec */ +#define REC_BP_CHOICE_PUMP_120 2 /* 120 Liter/sec */ +#define REC_BP_CHOICE_PUMP_220 3 /* 220 Liter/sec */ + + +static long +local_xactWork(pxact, pop) +msgXact *pxact; +msgCmdOp *pop; +{ + char msg[100]; /* A place to format error messages */ + char buf[100]; /* A place to build & parse strings */ + msgStrParm strParm; /* Room to put the driver's parms */ + struct brownpileRecord *pbp = (struct brownpileRecord *)(pxact->prec); + int dd, hh, mm; + int t1, t2, t3, t4; + + if (pop->op != LOCAL_OP_PROC) + /* Transaction is not a local-custom operation, let drvMsg deal with it. */ + return(drvMsg_xactWork(pxact, pop)); + + strParm.buf = buf; + + /* We have to check to see if any record fields changed and send them out */ + if (pbp->flgs) + { + buf[0] = 'M'; + buf[2] = '\r'; + strParm.len = 3; + + if (pbp->flgs & MOD_DSPL) + { + buf[1] = '3'+pbp->dspl; + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + } + if (pbp->flgs & MOD_KLCK) + { + buf[1] = '8'+pbp->klck; + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + } + if (pbp->flgs & MOD_MODS) + { + buf[1] = '1'+pbp->mods; + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + } + + if (pbp->flgs & MOD_SP1S) + { + sprintf(buf, "S11%.0le", pbp->sp1s); + if (buf[5] == '0') + buf[4] = '0'; + else + buf[4] = buf[6]; + buf[5] = '\r'; + strParm.len = 6; + + if (dig500MsgDebug > 9) + { + buf[6] = '\0'; + printf(">%s< setpoint1 parm = >%s<\n", pbp->name, buf); + } + + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + } + if (pbp->flgs & MOD_S1HS) + { + sprintf(buf, "S12%.0le\r", pbp->s1hs); + if (buf[5] == '0') + buf[4] = '0'; + else + buf[4] = buf[6]; + buf[5] = '\r'; + strParm.len = 6; + + if (dig500MsgDebug > 9) + { + buf[6] = '\0'; + printf(">%s< setpoint1 hysteresis = >%s<\n", pbp->name, buf); + } + + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + } + if (pbp->flgs & (MOD_S1MS|MOD_S1VS)) + { + buf[0] = 'S'; + buf[1] = '1'; + buf[2] = '3'; + if(pbp->s1ms == REC_BP_CHOICE_SPMODE_PRES) + buf[3] = '0'; + else + buf[3] = '1'; + buf[4] = '0'; + if (pbp->s1vs == REC_BP_CHOICE_HVI_OFF) + buf[5] = '1'; + else + buf[5] = '0'; + buf[6] = '0'; + buf[7] = '\r'; + + strParm.len = 8; + + if (dig500MsgDebug > 9) + { + buf[8] = '\0'; + printf(">%s< sp1 options parm = >%s<\n", pbp->name, buf); + } + + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + } + + if (pbp->flgs & MOD_SP2S) + { + sprintf(buf, "S21%.0le\r", pbp->sp2s); + if (buf[5] == '0') + buf[4] = '0'; + else + buf[4] = buf[6]; + buf[5] = '\r'; + strParm.len = 6; + + if (dig500MsgDebug > 9) + { + buf[6] = '\0'; + printf(">%s< setpoint2 parm = >%s<\n", pbp->name, buf); + } + + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + } + if (pbp->flgs & MOD_S2HS) + { + sprintf(buf, "S22%.0le\r", pbp->s2hs); + if (buf[5] == '0') + buf[4] = '0'; + else + buf[4] = buf[6]; + buf[5] = '\r'; + strParm.len = 6; + + if (dig500MsgDebug > 9) + { + buf[6] = '\0'; + printf(">%s< setpoint2 hysteresis = >%s<\n", pbp->name, buf); + } + + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + } + if (pbp->flgs & (MOD_S2MS|MOD_S2VS)) + { + buf[0] = 'S'; + buf[1] = '2'; + buf[2] = '3'; + if(pbp->s2ms == REC_BP_CHOICE_SPMODE_PRES) + buf[3] = '0'; + else + buf[3] = '1'; + buf[4] = '0'; + if (pbp->s2vs == REC_BP_CHOICE_HVI_OFF) + buf[5] = '1'; + else + buf[5] = '0'; + buf[6] = '0'; + buf[7] = '\r'; + + strParm.len = 8; + + if (dig500MsgDebug > 9) + { + buf[8] = '\0'; + printf(">%s< sp2 options parm = >%s<\n", pbp->name, buf); + } + + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + } + pbp->flgs = 0; + } + + /************************************************************************ + * + * Then we have to read all the running parameters back from the dig500 + * + ************************************************************************/ + + buf[0] = 'R'; + buf[1] = 'D'; + buf[2] = '\r'; + strParm.len = 3; + + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + + strParm.len = sizeof(buf); + drvMsg_drvRead(pxact, &strParm); + + if (dig500MsgDebug > 10) + printf(">%s< RD ->%s< pxact->status %d\n", pbp->name, buf, pxact->status); + + if (pxact->status != XACT_OK) + return(pxact->status); + + if (sscanf(buf, "%d %d:%d %ldV%lf", &dd, &hh, &mm, &(pbp->volt), &(pbp->crnt)) != 5) + { + if (dig500MsgDebug) + printf("Dig500: >%s< invalid RD response string >%s<\n", pbp->name, buf); + + pxact->status = XACT_IOERR; + return(pxact->status); + } + if (dig500MsgDebug > 10) + printf("dd %d, hh %d, mm %d, volts %ld, current %lf\n", dd, hh, mm, pbp->volt, pbp->crnt); + pbp->tonl = dd*1440 + hh*60 + mm; + + if(buf[23] == 'H') /* High voltage is on */ + pbp->modr = REC_BP_CHOICE_OPER_BUSY; + else if (buf[23] == '-') + pbp->modr = REC_BP_CHOICE_OPER_SBY; + else + { /* invalid character in response string... go to valid alarm. */ + if (dig500MsgDebug) + printf("Dig500: >%s< invalid RD response string >%s<\n", pbp->name, buf); + + pxact->status = XACT_IOERR; + return(pxact->status); + } + +#if 0 + if(buf[24] == 'C') /* Cooldown mode is active */ + { + } +#endif + + if(buf[26] == '1') /* Setpoint 1 is energized */ + pbp->set1 = REC_BP_CHOICE_SP_ON; + else if (buf[26] == '-') + pbp->set1 = REC_BP_CHOICE_SP_OFF; + else + { /* invalid character in response string... go to valid alarm. */ + if (dig500MsgDebug) + printf("Dig500: >%s< invalid RD response string >%s<\n", pbp->name, buf); + + pxact->status = XACT_IOERR; + return(pxact->status); + } + + if(buf[27] == '2') /* Setpoint 2 is energized */ + pbp->set2 = REC_BP_CHOICE_SP_ON; + else if (buf[27] == '-') + pbp->set2 = REC_BP_CHOICE_SP_OFF; + else + { /* invalid character in response string... go to valid alarm. */ + if (dig500MsgDebug) + printf("Dig500: >%s< invalid RD response string >%s<\n", pbp->name, buf); + + pxact->status = XACT_IOERR; + return(pxact->status); + } + + buf[0] = 'R'; + buf[1] = 'C'; + buf[2] = '\r'; + strParm.len = 3; + + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + + strParm.len = sizeof(buf); + drvMsg_drvRead(pxact, &strParm); + + if (dig500MsgDebug > 10) + printf(">%s< RC ->%s< pxact->status %d\n", pbp->name, buf, pxact->status); + + if (pxact->status != XACT_OK) + return(pxact->status); + + if (sscanf(buf, "%dP %dI %dC %d", &t1, &t2, &t3, &t4) != 4) + { + if (dig500MsgDebug) + printf("Dig500: >%s< invalid RC response string >%s<\n", pbp->name, buf); + + pxact->status = XACT_IOERR; + return(pxact->status); + } + + + pbp->accw = t1 * .444; /* Calculate the accumulated power */ + pbp->acci = t2 * 1.11; /* Calculate the accumulated current */ + pbp->cool = t3; /* Cool period */ + + switch (t4) { + case 1: + pbp->ptyp = REC_BP_CHOICE_PUMP_30; + break; + case 2: + pbp->ptyp = REC_BP_CHOICE_PUMP_60; + break; + case 4: + pbp->ptyp = REC_BP_CHOICE_PUMP_120; + break; + case 8: + pbp->ptyp = REC_BP_CHOICE_PUMP_220; + break; + default: + if (dig500MsgDebug) + printf("Dig500: >%s< invalid RC response string >%s<\n", pbp->name, buf); + + pxact->status = XACT_IOERR; + return(pxact->status); + } + + /* + * Check out the setpoint 1 situation + */ + buf[0] = 'R'; + buf[1] = 'S'; + buf[2] = '1'; + buf[3] = '\r'; + strParm.len = 4; + + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + + strParm.len = sizeof(buf); + drvMsg_drvRead(pxact, &strParm); + + if (dig500MsgDebug > 10) + printf(">%s< RS1 ->%s< pxact->status %d\n", pbp->name, buf, pxact->status); + + if (pxact->status != XACT_OK) + return(pxact->status); + + if (sscanf(buf, "%lf %lf", &(pbp->sp1r), &(pbp->s1hr)) != 2) + { + if (dig500MsgDebug) + printf("Dig500: >%s< invalid RS1 response string >%s<\n", pbp->name, buf); + + pxact->status = XACT_IOERR; + return(pxact->status); + } + + if (buf[14] == '0') + pbp->s1mr = REC_BP_CHOICE_SPMODE_PRES; + else if (buf[14] == '1') + pbp->s1mr = REC_BP_CHOICE_SPMODE_CURR; + else + { + if (dig500MsgDebug) + printf("Dig500: >%s< invalid RS1 response string >%s<\n", pbp->name, buf); + + pxact->status = XACT_IOERR; + return(pxact->status); + } + + if (buf[16] == '0') + pbp->s1vr = REC_BP_CHOICE_HVI_OFF; + else if (buf[16] == '1') + pbp->s1vr = REC_BP_CHOICE_HVI_ON; + else + { + if (dig500MsgDebug) + printf("Dig500: >%s< invalid RS1 response string >%s<\n", pbp->name, buf); + + pxact->status = XACT_IOERR; + return(pxact->status); + } + + /* + * Check out the setpoint 2 situation + */ + buf[0] = 'R'; + buf[1] = 'S'; + buf[2] = '2'; + buf[3] = '\r'; + strParm.len = 4; + + drvMsg_drvWrite(pxact, &strParm); + if (pxact->status != XACT_OK) + return(pxact->status); + + strParm.len = sizeof(buf); + drvMsg_drvRead(pxact, &strParm); + + if (dig500MsgDebug > 10) + printf(">%s< RS2 ->%s< pxact->status %d\n", pbp->name, buf, pxact->status); + + if (pxact->status != XACT_OK) + return(pxact->status); + + sscanf(buf, "%lf %lf", &(pbp->sp2r), &(pbp->s2hr)); + + if (buf[14] == '0') + pbp->s2mr = REC_BP_CHOICE_SPMODE_PRES; + else if (buf[14] == '1') + pbp->s2mr = REC_BP_CHOICE_SPMODE_CURR; + else + { + if (dig500MsgDebug) + printf("Dig500: >%s< invalid RS2 response string >%s<\n", pbp->name, buf); + + pxact->status = XACT_IOERR; + return(pxact->status); + } + + if (buf[16] == '0') + pbp->s2vr = REC_BP_CHOICE_HVI_OFF; + else if (buf[16] == '1') + pbp->s2vr = REC_BP_CHOICE_HVI_ON; + else + { + if (dig500MsgDebug) + printf("Dig500: >%s< invalid RS2 response string >%s<\n", pbp->name, buf); + + pxact->status = XACT_IOERR; + return(pxact->status); + } + + pbp->udf = FALSE; + return(XACT_OK); +} + /****************************************************************************** * * The dev232ParmBlock contains driver specific extensions to the msgParmBlock @@ -139,6 +658,16 @@ static dev232ParmBlock parm232extension = { 2400, /* Baud rate to the machine at */ OPT_7_BIT /* Use 7-bit protocol */ }; + +/****************************************************************************** + * + * Parm block extensions for the bitbus interface. + * + ******************************************************************************/ +static drvBB232ParmBlock parmBB232extension = { + 60, + 9600, +}; /****************************************************************************** * * The parmBlock is used to define the relationship b/w the command table and @@ -146,14 +675,14 @@ static dev232ParmBlock parm232extension = { * ******************************************************************************/ static msgParmBlock parmBlock = { - &softMsgDebug, + &dig500MsgDebug, NULL, cmds, sizeof(cmds) / sizeof(msgCmd), - "Dig500Msg232", - &drv232Block, - drvMsg_xactWork, - &parm232extension + "Dig500MsgBB232", + &drvBB232Block, + local_xactWork, + &parmBB232extension }; static long init(parm)