PSI sics-cvs-psi-2008-10-02
This commit is contained in:
123
evcontroller.c
123
evcontroller.c
@@ -71,20 +71,36 @@
|
||||
static long EVIDrive(void *pData, SConnection *pCon, float fVal)
|
||||
{
|
||||
pEVControl self = NULL;
|
||||
int iRet, iCode, i, iFix;
|
||||
int iRet, iCode, i, iFix, savedStatus;
|
||||
char pError[132], pBueffel[256];
|
||||
|
||||
Tcl_Interp *pTcl = NULL;
|
||||
|
||||
self = (pEVControl)pData;
|
||||
assert(self);
|
||||
assert(pCon);
|
||||
|
||||
if (self->runScript != NULL) {
|
||||
savedStatus = GetStatus();
|
||||
SetStatus(eBatch);
|
||||
pTcl = InterpGetTcl(pServ->pSics);
|
||||
snprintf(pBueffel, sizeof(pBueffel), "%s %f", self->runScript, fVal);
|
||||
iRet = Tcl_Eval(pTcl,pBueffel);
|
||||
SetStatus(savedStatus);
|
||||
if(iRet != TCL_OK)
|
||||
{
|
||||
SCPrintf(pCon, eError,
|
||||
"ERROR: %s while processing runscript for %s",
|
||||
pTcl->result,self->pName);
|
||||
}
|
||||
}
|
||||
|
||||
self->fTarget = fVal;
|
||||
self->eMode = EVDrive;
|
||||
self->iStop = 0;
|
||||
self->start = time(NULL);
|
||||
self->lastt = 0;
|
||||
self->iWarned = 0;
|
||||
SCSave(&self->conn, pCon);
|
||||
self->conn = SCSave(pCon, self->conn);
|
||||
|
||||
/* try at least three times to do it */
|
||||
for(i = 0; i < 3; i++)
|
||||
@@ -276,9 +292,9 @@
|
||||
if (self->lastt > 0) { /* increase tol for hysteresis */
|
||||
tol=tol*1.1001;
|
||||
}
|
||||
tmo = (int)(ObVal(self->pParam, SETTLE));
|
||||
if(fDelta <= tol) /* inside tolerance */
|
||||
{
|
||||
tmo = (int)(ObVal(self->pParam, SETTLE));
|
||||
if (self->lastt <= 0) /* lastt negative: -seconds already waited */
|
||||
{
|
||||
self->lastt += now;
|
||||
@@ -303,9 +319,11 @@
|
||||
else
|
||||
{
|
||||
if (self->lastt > 0) { /* save time already waited */
|
||||
sprintf(pBueffel,"%s outside tolerance, settling time suspended",
|
||||
self->pName);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
if (tmo > 0) {
|
||||
sprintf(pBueffel,"%s outside tolerance, settling time suspended",
|
||||
self->pName);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
}
|
||||
self->lastt -= now;
|
||||
}
|
||||
notifyStatus(self, pCon, HWBusy);
|
||||
@@ -366,17 +384,15 @@ static void ErrWrite(char *txt, SCStore *conn)
|
||||
pExe = GetExecutor();
|
||||
pCon = GetExeOwner(pExe);
|
||||
|
||||
if (!pCon)
|
||||
if (pCon)
|
||||
{
|
||||
pCon = SCLoad(conn);
|
||||
SCWrite(pCon,txt,eWarning);
|
||||
}
|
||||
if(pCon)
|
||||
{
|
||||
SCWrite(pCon,txt,eWarning);
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerWriteGlobal(txt,eWarning);
|
||||
pCon = SCStorePush(conn);
|
||||
SCWrite(pCon, txt, eWarning);
|
||||
SCStorePop(conn);
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
@@ -390,7 +406,7 @@ static void ErrReport(pEVControl self)
|
||||
{
|
||||
sprintf(pBueffel,"WARNING: %s is out of range by %g",
|
||||
self->pName,fDelta);
|
||||
ErrWrite(pBueffel, &self->conn);
|
||||
ErrWrite(pBueffel, self->conn);
|
||||
self->iWarned = 1;
|
||||
}
|
||||
}
|
||||
@@ -463,7 +479,7 @@ static void ErrReport(pEVControl self)
|
||||
snprintf(pBueffel,255,
|
||||
"ERROR: %s while processing errorscript for %s",
|
||||
pTcl->result,self->pName);
|
||||
ErrWrite(pBueffel, &self->conn);
|
||||
ErrWrite(pBueffel, self->conn);
|
||||
}
|
||||
/*
|
||||
assume that everything is fine again after the script
|
||||
@@ -477,7 +493,7 @@ static void ErrReport(pEVControl self)
|
||||
snprintf(pBueffel,255,
|
||||
"ERROR: script error handling requested for %s, but no script given",
|
||||
self->pName);
|
||||
ErrWrite(pBueffel, &self->conn);
|
||||
ErrWrite(pBueffel, self->conn);
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -507,7 +523,7 @@ static void ErrReport(pEVControl self)
|
||||
|
||||
ErrReport(self);
|
||||
|
||||
ErrWrite("Running to safe value", &self->conn);
|
||||
ErrWrite("Running to safe value", self->conn);
|
||||
self->pDriv->SetValue(self->pDriv, ObVal(self->pParam,SAFEVALUE));
|
||||
self->eMode = EVIdle;
|
||||
self->iWarned = 0;
|
||||
@@ -599,7 +615,7 @@ static void ErrReport(pEVControl self)
|
||||
{
|
||||
sprintf(pBueffel,"Environment device %s back in tolerances again",
|
||||
self->pName);
|
||||
ErrWrite(pBueffel, &self->conn);
|
||||
ErrWrite(pBueffel, self->conn);
|
||||
self->iWarned = 0;
|
||||
}
|
||||
return 1;
|
||||
@@ -780,6 +796,7 @@ static void ErrReport(pEVControl self)
|
||||
pRes->pName = strdup(pName);
|
||||
pRes->eMode = EVIdle;
|
||||
pRes->iWarned = 0;
|
||||
pRes->conn = NULL;
|
||||
|
||||
/* a terminal error gives a -1 in iRet */
|
||||
if(iRet < 0)
|
||||
@@ -848,6 +865,14 @@ static void ErrReport(pEVControl self)
|
||||
{
|
||||
free(self->creationArgs);
|
||||
}
|
||||
if (self->runScript != NULL)
|
||||
{
|
||||
free(self->runScript);
|
||||
}
|
||||
if (self->conn != NULL)
|
||||
{
|
||||
SCStoreFree(self->conn);
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -855,7 +880,7 @@ static void ErrReport(pEVControl self)
|
||||
{
|
||||
char pBueffel[256], pError[132];
|
||||
int iRet;
|
||||
|
||||
|
||||
assert(self);
|
||||
assert(pCon);
|
||||
|
||||
@@ -951,12 +976,15 @@ static void ErrReport(pEVControl self)
|
||||
{
|
||||
ObPar *pPar = NULL;
|
||||
char pBueffel[512];
|
||||
int iRet;
|
||||
int iRet, savedStatus;
|
||||
|
||||
assert(self);
|
||||
assert(pCon);
|
||||
|
||||
savedStatus = GetStatus(); /* fool status check in ObParSet (avoid "Cannot change parameter while running" message */
|
||||
SetStatus(eBatch);
|
||||
iRet = ObParSet(self->pParam,self->pName,name,fVal,pCon);
|
||||
SetStatus(savedStatus);
|
||||
if(!iRet)
|
||||
{
|
||||
return iRet;
|
||||
@@ -1025,7 +1053,14 @@ static void ErrReport(pEVControl self)
|
||||
snprintf(pBueffel,255,"%s.errorScript = UNDEFINED", self->pName);
|
||||
}
|
||||
SCWrite(pCon,pBueffel, eValue);
|
||||
|
||||
if(self->runScript != NULL)
|
||||
{
|
||||
SCPrintf(pCon, eValue, "%s.runScript = %s", self->pName, self->runScript);
|
||||
}
|
||||
else
|
||||
{
|
||||
SCPrintf(pCon, eValue, "%s.runScript = none", self->pName);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
@@ -1075,8 +1110,11 @@ static void ErrReport(pEVControl self)
|
||||
iRet = EVCGetPos(self,pCon,&fPos);
|
||||
if(iRet)
|
||||
{
|
||||
/*
|
||||
sprintf(pBueffel,"%s.%s = %g",self->pName,"CurrentValue", fPos);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
*/
|
||||
SCPrintf(pCon, eValue, "%s = %g", argv[0], fPos);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -1161,10 +1199,10 @@ static void ErrReport(pEVControl self)
|
||||
}
|
||||
else /* parameter request */
|
||||
{
|
||||
strtolower(argv[1]);
|
||||
/*
|
||||
catch case of errorScript
|
||||
*/
|
||||
strtolower(argv[1]);
|
||||
if(strcmp(argv[1],"errorscript") == 0)
|
||||
{
|
||||
if(self->errorScript != NULL)
|
||||
@@ -1180,6 +1218,22 @@ static void ErrReport(pEVControl self)
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
catch case of runScript
|
||||
*/
|
||||
if(strcmp(argv[1],"runscript") == 0)
|
||||
{
|
||||
if(self->runScript != NULL)
|
||||
{
|
||||
SCPrintf(pCon, eValue,"%s.runScript = %s",self->pName,
|
||||
self->runScript);
|
||||
}
|
||||
else
|
||||
{
|
||||
SCPrintf(pCon, eValue,"%s.runScript = none",self->pName);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
catch case for drivername
|
||||
*/
|
||||
@@ -1208,10 +1262,10 @@ static void ErrReport(pEVControl self)
|
||||
}
|
||||
else /* try to set parameter */
|
||||
{
|
||||
strtolower(argv[1]);
|
||||
/*
|
||||
first catch case of errorScript
|
||||
*/
|
||||
strtolower(argv[1]);
|
||||
if(strcmp(argv[1],"errorscript") == 0)
|
||||
{
|
||||
if(self->errorScript != NULL)
|
||||
@@ -1223,6 +1277,24 @@ static void ErrReport(pEVControl self)
|
||||
SCparChange(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
catch case of runScript
|
||||
*/
|
||||
if(strcmp(argv[1],"runscript") == 0)
|
||||
{
|
||||
if(self->runScript != NULL)
|
||||
{
|
||||
free(self->runScript);
|
||||
}
|
||||
if (strcasecmp(argv[2],"none") == 0) {
|
||||
self->runScript = NULL;
|
||||
} else {
|
||||
self->runScript = Arg2Tcl(argc-2,&argv[2],NULL,0);
|
||||
}
|
||||
SCSendOK(pCon);
|
||||
SCparChange(pCon);
|
||||
return 1;
|
||||
}
|
||||
iRet = Tcl_GetDouble(pSics->pTcl,argv[2],&dVal);
|
||||
if(iRet != TCL_OK)
|
||||
{
|
||||
@@ -1263,6 +1335,9 @@ static int EVSaveStatus(void *pData, char *name, FILE *fil)
|
||||
if(evc->errorScript != NULL) {
|
||||
fprintf(fil, " %s errorScript %s\n", evc->pName, evc->errorScript);
|
||||
}
|
||||
if(evc->runScript != NULL) {
|
||||
fprintf(fil, " %s runScript %s\n", evc->pName, evc->runScript);
|
||||
}
|
||||
}
|
||||
fprintf(fil, "}\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user