implement motor "trace_switches" command

r2507 | dcl | 2008-05-08 16:47:34 +1000 (Thu, 08 May 2008) | 2 lines
This commit is contained in:
Douglas Clowes
2008-05-08 16:47:34 +10:00
parent c7794c4092
commit f7d9d06484

View File

@@ -211,6 +211,7 @@ struct __MoDriv {
};
int DMC2280MotionControl = 1; /* defaults to enabled */
static bool trace_switches = false;
#define AIR_POLL_TIMER 1000
#define MOTOR_POLL_FAST 100
@@ -1398,6 +1399,51 @@ static int rspStatus(pDMC2280Driv self, const char* text) {
&iStopCode, &iIOByte, &iXQ0);
if (iRet != 7)
return 0;
if ((trace_switches || self->debug) && self->currFlags != iFlags) {
char line[CMDLEN];
char *sw;
if ((self->currFlags & (8 + 4)) != (iFlags & (8 + 4))) {
switch (iFlags & (8 + 4)) {
case (8 + 4): sw = "none"; break;
case (8 ): sw = "reverse"; break;
case ( 4): sw = "forward"; break;
case ( 0 ): sw = "both"; break;
}
snprintf(line, CMDLEN, "Motor %s limits: %s", self->name, sw);
if (trace_switches)
ServerWriteGlobal(line, eStatus);
else
SICSLogWrite(line, eStatus);
}
if ((self->currFlags & (32)) != (iFlags & (32))) {
if (iFlags & (32)) {
sw = "off";
}
else
{
sw = "on";
}
snprintf(line, CMDLEN, "Motor %s motor: %s", self->name, sw);
if (trace_switches)
ServerWriteGlobal(line, eStatus);
else
SICSLogWrite(line, eStatus);
}
if ((self->currFlags & (128)) != (iFlags & (128))) {
if (iFlags & (128)) {
sw = "moving";
}
else
{
sw = "stopped";
}
snprintf(line, CMDLEN, "Motor %s motor: %s", self->name, sw);
if (trace_switches)
ServerWriteGlobal(line, eStatus);
else
SICSLogWrite(line, eStatus);
}
}
self->currFlags = iFlags;
self->currSteps = iSteps;
self->currCounts = iCounts;
@@ -1847,7 +1893,10 @@ static void DMCState_Idle(pDMC2280Driv self, pEvtEvent event) {
set_lastMotion(self, self->currSteps, self->currCounts);
report_motion(self);
}
DMC_SetTimer(self, MOTOR_POLL_SLOW);
if (trace_switches || self->debug)
DMC_SetTimer(self, MOTOR_POLL_FAST);
else
DMC_SetTimer(self, MOTOR_POLL_SLOW);
self->subState = 0;
return;
}
@@ -4057,6 +4106,17 @@ int DMC2280Action(SConnection *pCon, SicsInterp *pSics, void *pData,
}
return 1;
}
else if(strcasecmp("trace_switches", argv[1]) == 0) {
if (argc > 2 && strcasecmp("on", argv[2]) == 0) {
trace_switches = true;
SCWrite(pCon, "TRACE SWITCHES ON", eValue);
}
else {
trace_switches = false;
SCWrite(pCon, "TRACE SWITCHES OFF", eValue);
}
return 1;
}
else if(strcasecmp("unit2count", argv[1]) == 0) {
char line[132];
if (argc > 2) {