bug fixes and enhancements related to evcontroller

SKIPPED:
	psi/dilludriv.c
	psi/el755driv.c
	psi/eurodriv.c
	psi/eve.c
	psi/eve.h
	psi/fsm.c
	psi/ipsdriv.c
	psi/itc4driv.c
	psi/itcdriv.c
	psi/lcdriv.c
	psi/logger.c
	psi/logger.h
	psi/slsmagnet.c
This commit is contained in:
zolliker
2005-03-03 14:13:06 +00:00
parent c7bef62242
commit d393a0a357
10 changed files with 118 additions and 44 deletions

View File

@ -679,7 +679,6 @@ static void ErrReport(pEVControl self)
return NULL;
}
pRes->pDes->GetInterface = EVIInterface;
pRes->pDes->SaveStatus = EVSaveStatus;
/* new Drivable interface */
pRes->pDrivInt = CreateDrivableInterface();
@ -780,6 +779,7 @@ static void ErrReport(pEVControl self)
if(self->pDes)
{
DeleteDescriptor(self->pDes);
self->pDes = NULL;
}
if(self->pDrivInt)
{
@ -1196,6 +1196,7 @@ static void ErrReport(pEVControl self)
}
self->errorScript = strdup(pBueffel);
SCSendOK(pCon);
SCparChange(pCon);
return 1;
}
iRet = Tcl_GetDouble(pSics->pTcl,argv[2],&dVal);
@ -1209,20 +1210,46 @@ static void ErrReport(pEVControl self)
if(iRet)
{
SCSendOK(pCon);
SCparChange(pCon);
}
return iRet;
}
return 0; /* not reached */
}
}
/*-----------------------------------------------------------------------*/
int EVSaveStatus(void *pData, char *name, FILE *fil)
static int EVSaveStatus(void *pData, char *name, FILE *fil)
{
pEVControl evc = pData;
if (evc->creationArgs) {
fprintf(fil, "evfactory replace %s %s\n", name, evc->creationArgs);
pEVDriver pD = evc->pDriv;
assert(evc);
assert(pD);
if (evc->creationArgs && pD->SavePars) {
fprintf(fil, "if {[catch { evfactory replace %s %s }] == 0} {\n", name, evc->creationArgs);
if (pD->SavePars(pD, fil) == 1) {
fprintf(fil, " %s %s %g\n",evc->pName, "tolerance", ObVal(evc->pParam,TOLERANCE));
fprintf(fil, " %s %s %g\n",evc->pName, "access", ObVal(evc->pParam,ACCESS));
fprintf(fil, " %s %s %g\n",evc->pName, "ErrorHandler", ObVal(evc->pParam,ERRORHANDLER));
fprintf(fil, " %s %s %g\n",evc->pName, "interrupt", ObVal(evc->pParam,INTERRUPT));
fprintf(fil, " %s %s %g\n",evc->pName, "UpperLimit", ObVal(evc->pParam,UPLIMIT));
fprintf(fil, " %s %s %g\n",evc->pName, "LowerLimit", ObVal(evc->pParam,LOWLIMIT));
fprintf(fil, " %s %s %g\n",evc->pName, "SafeValue", ObVal(evc->pParam,SAFEVALUE));
fprintf(fil, " %s %s %g\n",evc->pName, "MaxWait", ObVal(evc->pParam,MAXWAIT));
fprintf(fil, " %s %s %g\n",evc->pName, "Settle", ObVal(evc->pParam,SETTLE));
if(evc->errorScript != NULL) {
fprintf(fil, " %s errorScript %s\n", evc->pName, evc->errorScript);
}
}
fprintf(fil, "}\n");
}
return 1;
}
/*--------------------------------------------------------------------------*/
/* standard method for saving parameters */
static int EVCSaveStd(void *pData, char *name, FILE *fil)
{
return 1;
}
/*-----------------------------------------------------------------------*/
pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,
ObjectFunc wrapper, int argc, char *argv[])
@ -1238,12 +1265,15 @@ pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,
}
pNew = CreateEVController(pDriv,argv[0],&status);
if (status != 1) {
printf("CEVC error\n");
SCWrite(pCon,"ERROR: failed to initialize device", eError);
pDriv->GetError(pDriv,&status,pError,sizeof pError -1);
printf("HW %s\n", pError);
sprintf(pBueffel,"HW reported: %s",pError);
SCWrite(pCon,pBueffel,eError);
}
if (pNew == NULL) {
printf("CEVC failed\n");
SCWrite(pCon,"ERROR: failed to create environment device object",
eError);
DeleteEVDriver(pDriv);
@ -1368,6 +1398,29 @@ static pEVControl InstallCommonControllers(SicsInterp *pSics,
}
return pNew;
}
int RemoveEVController(SConnection *pCon, char *name) {
char pBueffel[512];
int iRet;
if(!pServ->pExecutor)
{
return 1;
}
if(isInRunMode(pServ->pExecutor))
{
SCWrite(pCon,"ERROR: cannot delete while running",eError);
return 0;
}
EVUnregister(FindEMON(pServ->pSics),name);
iRet = RemoveCommand(pServ->pSics,name);
if(!iRet)
{
sprintf(pBueffel,"ERROR: %s not found, NOT deleted",name);
SCWrite(pCon,pBueffel,eError);
return 0;
}
}
/*-------------------------------------------------------------------------
EVControlFactory implements a SICS command which creates and deletes
Controllers at run-time. Syntax:
@ -1405,26 +1458,12 @@ static pEVControl InstallCommonControllers(SicsInterp *pSics,
strtolower(argv[1]);
if(strcmp(argv[1],"del") == 0) /* delete */
{
if(!pServ->pExecutor)
{
if (RemoveEVController(pCon, argv[2])) {
SCSendOK(pCon);
return 1;
}
if(isInRunMode(pServ->pExecutor))
{
SCWrite(pCon,"ERROR: cannot delete while running",eError);
return 0;
}
EVUnregister(FindEMON(pSics),argv[2]);
iRet = RemoveCommand(pSics,argv[2]);
if(!iRet)
{
sprintf(pBueffel,"ERROR: %s not found, NOT deleted",argv[2]);
SCWrite(pCon,pBueffel,eError);
} else {
return 0;
}
SCSendOK(pCon);
return 1;
}
else if(strcmp(argv[1],"new") == 0 || strcmp(argv[1], "replace") == 0)
/* make a new one */
@ -1441,8 +1480,9 @@ static pEVControl InstallCommonControllers(SicsInterp *pSics,
strtolower(argv[3]);
if (FindCommandData(pSics, argv[2], "Environment Controller")) {
if (strcmp(argv[1], "replace") == 0) {
RemoveCommand(pSics, argv[2]);
EVUnregister(FindEMON(pSics),argv[2]);
if (!RemoveEVController(pCon, argv[2])) {
return 0;
}
} else {
sprintf(pBueffel,
"ERROR: environment device %s already installed, delete first",
@ -1474,9 +1514,14 @@ static pEVControl InstallCommonControllers(SicsInterp *pSics,
if(pNew == NULL){
/* error message is already written */
return 0;
}
Arg2Text(argc-3, argv+3, pBueffel, sizeof pBueffel);
pNew->creationArgs = strdup(pBueffel);
}
if (pNew->pDriv->SavePars) {
Arg2Text(argc-3, argv+3, pBueffel, sizeof pBueffel);
pNew->creationArgs = strdup(pBueffel);
pNew->pDes->SaveStatus = EVSaveStatus;
} else {
pNew->creationArgs = NULL;
}
EVRegisterController(FindEMON(pSics),argv[2],pNew, pCon);
pNew->driverName = strdup(argv[3]);

View File

@ -1,5 +1,5 @@
#line 226 "evcontroller.w"
#line 227 "evcontroller.w"
/*--------------------------------------------------------------------------
E N V I R O N M E N T C O N T R O L L E R
@ -14,7 +14,7 @@
#define SICSEVCONTROL
#include "varlog.h"
#line 146 "evcontroller.w"
#line 148 "evcontroller.w"
/*--------------------------- live & death --------------------------------*/
typedef struct __EVControl *pEVControl;
@ -24,7 +24,6 @@
void DeleteEVController(void *pData);
pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,
ObjectFunc wrapper, int argc, char *argv[]);
int EVSaveStatus(void *pData, char *name, FILE *fil);
/*-------------------------- driving ---------------------------------*/
int EVCDrive(pEVControl self,SConnection *pCon, float fNew);
int EVCGetPos(pEVControl self, SConnection *pCon,float *fVal);
@ -46,6 +45,6 @@
#line 239 "evcontroller.w"
#line 240 "evcontroller.w"
#endif

View File

@ -1,5 +1,5 @@
#line 243 "evcontroller.w"
#line 244 "evcontroller.w"
/*-------------------------------------------------------------------------
Environment controller datastructure
@ -47,5 +47,5 @@
void (*KillPrivate)(void *pData);
} EVControl;
#line 261 "evcontroller.w"
#line 262 "evcontroller.w"

View File

@ -112,6 +112,7 @@ $\langle$evdriv {\footnotesize ?}$\rangle\equiv$
\mbox{}\verb@ int (*GetError)(pEVDriver self, int *iCode,@\\
\mbox{}\verb@ char *pError, int iErrLen);@\\
\mbox{}\verb@ int (*TryFixIt)(pEVDriver self, int iCode);@\\
\mbox{}\verb@ int (*SavePars)(pEVDriver self, FILE *fil);@\\
\mbox{}\verb@ int (*Init)(pEVDriver self);@\\
\mbox{}\verb@ int (*Close)(pEVDriver self);@\\
\mbox{}\verb@ void *pPrivate;@\\
@ -154,6 +155,7 @@ the problem. If so, the apropriate actions are performed. TryFixIt returns
either DEVOK, if the device is OK, DEVFAULT, if TryFixIt cannot fix the
problem and DEVREDO if TryFixIt manged to fix the problem but requires the
last command to be resent.
\item [SavePars] Saves persistent parameters to status file.
\item [Init] Init is meant to initialise or reinitialise the driver.
\item [Close] Close is meant to close the driver and bring the device into a
safe state.
@ -181,7 +183,6 @@ $\langle$dvfunc {\footnotesize ?}$\rangle\equiv$
\mbox{}\verb@ void DeleteEVController(void *pData);@\\
\mbox{}\verb@ pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,@\\
\mbox{}\verb@ ObjectFunc wrapper, int argc, char *argv[]);@\\
\mbox{}\verb@ int EVSaveStatus(void *pData, char *name, FILE *fil);@\\
\mbox{}\verb@/*-------------------------- driving ---------------------------------*/@\\
\mbox{}\verb@ int EVCDrive(pEVControl self,SConnection *pCon, float fNew);@\\
\mbox{}\verb@ int EVCGetPos(pEVControl self, SConnection *pCon,float *fVal);@\\

View File

@ -95,6 +95,7 @@ used:
int (*GetError)(pEVDriver self, int *iCode,
char *pError, int iErrLen);
int (*TryFixIt)(pEVDriver self, int iCode);
int (*SavePars)(pEVDriver self, FILE *fil);
int (*Init)(pEVDriver self);
int (*Close)(pEVDriver self);
void *pPrivate;
@ -130,6 +131,7 @@ the problem. If so, the apropriate actions are performed. TryFixIt returns
either DEVOK, if the device is OK, DEVFAULT, if TryFixIt cannot fix the
problem and DEVREDO if TryFixIt manged to fix the problem but requires the
last command to be resent.
\item [SavePars] Saves persistent parameters to status file.
\item [Init] Init is meant to initialise or reinitialise the driver.
\item [Close] Close is meant to close the driver and bring the device into a
safe state.
@ -152,7 +154,6 @@ data structure as first parameter.
void DeleteEVController(void *pData);
pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,
ObjectFunc wrapper, int argc, char *argv[]);
int EVSaveStatus(void *pData, char *name, FILE *fil);
/*-------------------------- driving ---------------------------------*/
int EVCDrive(pEVControl self,SConnection *pCon, float fNew);
int EVCGetPos(pEVControl self, SConnection *pCon,float *fVal);

View File

@ -39,10 +39,10 @@
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include "fortify.h"
typedef struct __EVDriver *pEVDriver;
#include "evdriver.i"
#include "evdriver.h"
/*------------------------------------------------------------------------*/
pEVDriver CreateEVDriver(int argc, char *argv[])
@ -56,6 +56,7 @@
}
memset(pNew,0,sizeof(EVDriver));
pNew->GetValues = NULL; /* method will be replaced by default when NULL */
pNew->SavePars = NULL; /* no save by default */
return pNew;
}
/*-------------------------------------------------------------------------*/

12
evdriver.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef EVDRIVER_H
#define EVDRIVER_H
#ifndef SICSEVCONTROL
typedef struct __EVDriver *pEVDriver;
#endif
#include <evdriver.i>
#endif

View File

@ -1,5 +1,5 @@
#line 264 "evcontroller.w"
#line 265 "evcontroller.w"
/*-------------------------------------------------------------------------
Environment device driver datastructure
@ -24,13 +24,14 @@
int (*GetError)(pEVDriver self, int *iCode,
char *pError, int iErrLen);
int (*TryFixIt)(pEVDriver self, int iCode);
int (*SavePars)(pEVDriver self, FILE *fil);
int (*Init)(pEVDriver self);
int (*Close)(pEVDriver self);
void *pPrivate;
void (*KillPrivate)(void *pData);
} EVDriver;
#line 275 "evcontroller.w"
#line 276 "evcontroller.w"
/*-------------------- life & death of a driver --------------------------*/
pEVDriver CreateEVDriver(int argc, char *argv[]);

View File

@ -54,6 +54,10 @@
#define SOCKET 2
#define UDP 3
/* wait time [ms] between a close and the next open */
#define WAIT_CLOSE_OPEN 500
struct timeval lastclose={-1,0};
/*-----------------------------------------------------------------------
Redefine this function if another means of error reporting is necessary.
*/
@ -216,10 +220,12 @@ CreateSocketAdress(
mkChannel *NETConnect(char *name, int port)
{
mkChannel *pRes = NULL;
int iRet, i;
int iRet, i, cnt;
char pBueffel[80];
struct hostent *pServer = NULL;
struct linger lili;
struct timeval now;
long dif;
assert(port > 0);
@ -248,9 +254,18 @@ CreateSocketAdress(
free(pRes);
return NULL;
}
if (lastclose.tv_sec >= 0) {
gettimeofday(&now, NULL);
dif = (now.tv_sec-lastclose.tv_sec)*1000+(now.tv_usec-lastclose.tv_usec)/1000;
if (dif < 0) dif += 24*3600*1000;
} else {
dif = 0;
}
if (dif < WAIT_CLOSE_OPEN) {
usleep((WAIT_CLOSE_OPEN-dif)*1000);
}
iRet = connect(pRes->sockid,(struct sockaddr *)&(pRes->adresse),
sizeof(struct sockaddr_in));
if(iRet < 0)
{
free(pRes);
@ -518,7 +533,7 @@ int NETReadTillTermNew(mkChannel *self, long timeout,
{
gettimeofday(&now, NULL);
dif = (now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
if (dif < 0) dif += 24*3600*1000; /* treat midnight correctly */
if(dif > timeout)
{
return 0; /* timeout */
@ -621,6 +636,7 @@ This old version may be removed in some stage. It has two problems:
}
iRet = close(self->sockid);
gettimeofday(&lastclose, NULL);
self->iType = 0;
self->sockid = 0;
if(iRet < 0)

View File

@ -47,9 +47,7 @@
#include "servlog.h"
#include "fortify.h"
typedef struct __EVDriver *pEVDriver;
#include "evdriver.i"
#include "evdriver.h"
#include "simev.h"
/*-----------------------------------------------------------------------*/
typedef struct {