#define the bits, add some more variables
r1566 | dcl | 2007-03-02 08:27:59 +1100 (Fri, 02 Mar 2007) | 2 lines
This commit is contained in:
@@ -14,6 +14,31 @@
|
||||
|
||||
extern int DMC2280MotionControl;
|
||||
|
||||
#define KEY_ENABLED_BIT (1 << 0)
|
||||
#define KEY_DISABLED_BIT (1 << 1)
|
||||
#define SEC_OPENED_BIT (1 << 2)
|
||||
#define SEC_CLOSED_BIT (1 << 3)
|
||||
#define TER_OPENED_BIT (1 << 4)
|
||||
#define TER_CLOSED_BIT (1 << 5)
|
||||
#define MOTOR_ENABLED_BIT (1 << 6)
|
||||
#define MOTOR_DISABLED_BIT (1 << 7)
|
||||
#define ACCESS_LOCKED_BIT (1 << 8)
|
||||
#define ACCESS_UNLOCKED_BIT (1 << 9)
|
||||
#define DC_POWEROK_BIT (1 << 10)
|
||||
#define EXIT_INPROGRESS_BIT (1 << 11)
|
||||
#define SAFETY_TRIPPED_BIT (1 << 12)
|
||||
#define SAFETY_MALFUNCTION_BIT (1 << 13)
|
||||
#define TER_OPERATE_BIT (1 << 14)
|
||||
#define RELAY_ENABLED_BIT (1 << 15)
|
||||
#define INST_READY_BIT (1 << 16)
|
||||
#define LAMP_TEST_BIT (1 << 17)
|
||||
|
||||
#define KEY_BOTH_BITS (KEY_ENABLED_BIT | KEY_DISABLED_BIT)
|
||||
#define SEC_BOTH_BITS (SEC_OPENED_BIT | SEC_CLOSED_BIT)
|
||||
#define TER_BOTH_BITS (TER_OPENED_BIT | TER_CLOSED_BIT)
|
||||
#define MOTOR_BOTH_BITS (MOTOR_ENABLED_BIT | MOTOR_DISABLED_BIT)
|
||||
#define ACCESS_BOTH_BITS (ACCESS_LOCKED_BIT | ACCESS_UNLOCKED_BIT)
|
||||
|
||||
typedef struct __SafetyPLCController SafetyPLCController, *pSafetyPLCController;
|
||||
|
||||
struct __SafetyPLCController {
|
||||
@@ -163,7 +188,7 @@ static int GetCallback(void* ctx, const char* resp, int resp_len)
|
||||
int iRet;
|
||||
int iRead;
|
||||
pSafetyPLCController self = (pSafetyPLCController) ctx;
|
||||
iRet = sscanf(resp,"READ %0xd",&iRead);
|
||||
iRet = sscanf(resp,"READ %x", &iRead);
|
||||
if(iRet != 1) { // Not a number, probably an error response
|
||||
self->iValue = 0;
|
||||
}
|
||||
@@ -172,9 +197,13 @@ static int GetCallback(void* ctx, const char* resp, int resp_len)
|
||||
iRead = -iRead;
|
||||
self->iValue = iRead;
|
||||
}
|
||||
if ((self->iValue & (1 << 6)))
|
||||
if ((self->iValue & MOTOR_BOTH_BITS) == 0) /* neither */
|
||||
DMC2280MotionControl = -1;
|
||||
else if ((self->iValue & MOTOR_BOTH_BITS) == MOTOR_BOTH_BITS) /* both */
|
||||
DMC2280MotionControl = -1;
|
||||
else if ((self->iValue & MOTOR_ENABLED_BIT)) /* enabled */
|
||||
DMC2280MotionControl = 1;
|
||||
else
|
||||
else /* disabled */
|
||||
DMC2280MotionControl = 0;
|
||||
|
||||
self->iGetOut = 0;
|
||||
@@ -186,8 +215,11 @@ static int MyTimerCallback(void* context, int mode)
|
||||
pSafetyPLCController self = (pSafetyPLCController) context;
|
||||
if (self->iGetOut) {
|
||||
/* TODO error handling */
|
||||
DMC2280MotionControl = 0;
|
||||
if (--self->iGetOut)
|
||||
return 1;
|
||||
DMC2280MotionControl = -1;
|
||||
}
|
||||
self->iGetOut = 100;
|
||||
PLC_SendCmd(self->mcc, "READ", 4,
|
||||
GetCallback, self, 132);
|
||||
return 1;
|
||||
@@ -199,15 +231,44 @@ static int PLC_Action(SConnection *pCon, SicsInterp *pSics,
|
||||
char line[132];
|
||||
pSafetyPLCController self = (pSafetyPLCController) pData;
|
||||
if (argc == 1) {
|
||||
snprintf(line, 132, "%s.iValue = %006x", argv[0], self->iValue & 0xffffff);
|
||||
snprintf(line, 132, "%s.iValue = %06x", argv[0], self->iValue & 0xffffff);
|
||||
SCWrite(pCon, line, eStatus);
|
||||
return OKOK;
|
||||
} else if (argc == 2) {
|
||||
}
|
||||
else if (argc == 2) {
|
||||
if (strcmp(argv[1], "list") == 0) {
|
||||
return OKOK;
|
||||
}
|
||||
if (strcmp(argv[1], "motioncontrol") == 0) {
|
||||
snprintf(line, 132, "%s.MotionControl = %d", argv[0], DMC2280MotionControl);
|
||||
SCWrite(pCon, line, eStatus);
|
||||
return OKOK;
|
||||
}
|
||||
char* state = "unknown";
|
||||
if (self->iValue & (1 << 6))
|
||||
state = "enabled";
|
||||
else if (self->iValue & (1 << 7))
|
||||
state = "disabled";
|
||||
snprintf(line, 132, "%s.MotionControl = %s", argv[0], state);
|
||||
SCWrite(pCon, line, eStatus);
|
||||
return OKOK;
|
||||
}
|
||||
else if (strcmp(argv[1], "secondary") == 0) {
|
||||
char* state = "unknown";
|
||||
if (self->iValue & (1 << 2))
|
||||
state = "opened";
|
||||
else if (self->iValue & (1 << 3))
|
||||
state = "closed";
|
||||
snprintf(line, 132, "%s.Secondary = %s", argv[0], state);
|
||||
SCWrite(pCon, line, eStatus);
|
||||
return OKOK;
|
||||
}
|
||||
else if (strcmp(argv[1], "tertiary") == 0) {
|
||||
char* state = "unknown";
|
||||
if (self->iValue & (1 << 4))
|
||||
state = "opened";
|
||||
else if (self->iValue & (1 << 5))
|
||||
state = "closed";
|
||||
snprintf(line, 132, "%s.Tertiary = %s", argv[0], state);
|
||||
SCWrite(pCon, line, eStatus);
|
||||
return OKOK;
|
||||
}
|
||||
}
|
||||
/* TODO: handle private stuff */
|
||||
return MultiChanAction(pCon, pSics, self->mcc, argc, argv);
|
||||
@@ -215,9 +276,7 @@ static int PLC_Action(SConnection *pCon, SicsInterp *pSics,
|
||||
|
||||
static pSafetyPLCController PLC_Create(const char* pName, int port)
|
||||
{
|
||||
int i;
|
||||
pSafetyPLCController self = NULL;
|
||||
pMultiChan ctlr = NULL;
|
||||
|
||||
self = (pSafetyPLCController) malloc(sizeof(SafetyPLCController));
|
||||
if (self == NULL)
|
||||
@@ -238,14 +297,15 @@ static int PLC_Init(pSafetyPLCController self)
|
||||
/* TODO: Init the controller */
|
||||
if (self->nw_tmr == NULL)
|
||||
NetWatchRegisterTimerPeriodic(&self->nw_tmr,
|
||||
1000, 1000,
|
||||
1000, 100,
|
||||
MyTimerCallback,
|
||||
self);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void PLC_Kill(pSafetyPLCController self)
|
||||
static void PLC_Kill(void* pData)
|
||||
{
|
||||
pSafetyPLCController self = (pSafetyPLCController) pData;
|
||||
if (self->nw_tmr)
|
||||
NetWatchRemoveTimer(self->nw_tmr);
|
||||
free(self);
|
||||
|
||||
Reference in New Issue
Block a user