Add instrument readiness and use defined bits

r1607 | dcl | 2007-03-06 09:40:27 +1100 (Tue, 06 Mar 2007) | 2 lines
This commit is contained in:
Douglas Clowes
2007-03-06 09:40:27 +11:00
parent 25f914431d
commit c3b5bb73ca

View File

@@ -186,16 +186,15 @@ static void PLC_Notify(void* context, int event)
static int GetCallback(void* ctx, const char* resp, int resp_len)
{
int iRet;
int iRead;
unsigned int iRead;
pSafetyPLCController self = (pSafetyPLCController) ctx;
iRet = sscanf(resp,"READ %x", &iRead);
iRet = sscanf(resp,"READ %ux", &iRead);
if(iRet != 1) { // Not a number, probably an error response
self->iValue = 0;
}
else {
if (iRead < 0)
iRead = -iRead;
self->iValue = iRead;
if ((iRead & LAMP_TEST_BIT) == 0)
self->iValue = iRead;
}
if ((self->iValue & MOTOR_BOTH_BITS) == 0) /* neither */
DMC2280MotionControl = -1;
@@ -241,9 +240,11 @@ static int PLC_Action(SConnection *pCon, SicsInterp *pSics,
}
if (strcmp(argv[1], "motioncontrol") == 0) {
char* state = "unknown";
if (self->iValue & (1 << 6))
if ((self->iValue & MOTOR_BOTH_BITS) == MOTOR_BOTH_BITS)
state = "invalid";
else if (self->iValue & MOTOR_ENABLED_BIT)
state = "enabled";
else if (self->iValue & (1 << 7))
else if (self->iValue & MOTOR_DISABLED_BIT)
state = "disabled";
snprintf(line, 132, "%s.MotionControl = %s", argv[0], state);
SCWrite(pCon, line, eStatus);
@@ -251,9 +252,11 @@ static int PLC_Action(SConnection *pCon, SicsInterp *pSics,
}
else if (strcmp(argv[1], "secondary") == 0) {
char* state = "unknown";
if (self->iValue & (1 << 2))
if ((self->iValue & SEC_BOTH_BITS) == SEC_BOTH_BITS)
state = "invalid";
if (self->iValue & SEC_OPENED_BIT)
state = "opened";
else if (self->iValue & (1 << 3))
else if (self->iValue & SEC_CLOSED_BIT)
state = "closed";
snprintf(line, 132, "%s.Secondary = %s", argv[0], state);
SCWrite(pCon, line, eStatus);
@@ -261,14 +264,24 @@ static int PLC_Action(SConnection *pCon, SicsInterp *pSics,
}
else if (strcmp(argv[1], "tertiary") == 0) {
char* state = "unknown";
if (self->iValue & (1 << 4))
if ((self->iValue & TER_BOTH_BITS) == TER_BOTH_BITS)
state = "invalid";
if (self->iValue & TER_OPENED_BIT)
state = "opened";
else if (self->iValue & (1 << 5))
else if (self->iValue & TER_CLOSED_BIT)
state = "closed";
snprintf(line, 132, "%s.Tertiary = %s", argv[0], state);
SCWrite(pCon, line, eStatus);
return OKOK;
}
else if (strcmp(argv[1], "instrument") == 0) {
char* state = "unready";
if (self->iValue & INST_READY_BIT)
state = "ready";
snprintf(line, 132, "%s.Instrument = %s", argv[0], state);
SCWrite(pCon, line, eStatus);
return OKOK;
}
}
/* TODO: handle private stuff */
return MultiChanAction(pCon, pSics, self->mcc, argc, argv);