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:
@ -679,7 +679,6 @@ static void ErrReport(pEVControl self)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pRes->pDes->GetInterface = EVIInterface;
|
pRes->pDes->GetInterface = EVIInterface;
|
||||||
pRes->pDes->SaveStatus = EVSaveStatus;
|
|
||||||
|
|
||||||
/* new Drivable interface */
|
/* new Drivable interface */
|
||||||
pRes->pDrivInt = CreateDrivableInterface();
|
pRes->pDrivInt = CreateDrivableInterface();
|
||||||
@ -780,6 +779,7 @@ static void ErrReport(pEVControl self)
|
|||||||
if(self->pDes)
|
if(self->pDes)
|
||||||
{
|
{
|
||||||
DeleteDescriptor(self->pDes);
|
DeleteDescriptor(self->pDes);
|
||||||
|
self->pDes = NULL;
|
||||||
}
|
}
|
||||||
if(self->pDrivInt)
|
if(self->pDrivInt)
|
||||||
{
|
{
|
||||||
@ -1196,6 +1196,7 @@ static void ErrReport(pEVControl self)
|
|||||||
}
|
}
|
||||||
self->errorScript = strdup(pBueffel);
|
self->errorScript = strdup(pBueffel);
|
||||||
SCSendOK(pCon);
|
SCSendOK(pCon);
|
||||||
|
SCparChange(pCon);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
iRet = Tcl_GetDouble(pSics->pTcl,argv[2],&dVal);
|
iRet = Tcl_GetDouble(pSics->pTcl,argv[2],&dVal);
|
||||||
@ -1209,20 +1210,46 @@ static void ErrReport(pEVControl self)
|
|||||||
if(iRet)
|
if(iRet)
|
||||||
{
|
{
|
||||||
SCSendOK(pCon);
|
SCSendOK(pCon);
|
||||||
|
SCparChange(pCon);
|
||||||
}
|
}
|
||||||
return iRet;
|
return iRet;
|
||||||
}
|
}
|
||||||
return 0; /* not reached */
|
return 0; /* not reached */
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
int EVSaveStatus(void *pData, char *name, FILE *fil)
|
static int EVSaveStatus(void *pData, char *name, FILE *fil)
|
||||||
{
|
{
|
||||||
pEVControl evc = pData;
|
pEVControl evc = pData;
|
||||||
if (evc->creationArgs) {
|
pEVDriver pD = evc->pDriv;
|
||||||
fprintf(fil, "evfactory replace %s %s\n", name, evc->creationArgs);
|
|
||||||
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
/* standard method for saving parameters */
|
||||||
|
static int EVCSaveStd(void *pData, char *name, FILE *fil)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,
|
pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,
|
||||||
ObjectFunc wrapper, int argc, char *argv[])
|
ObjectFunc wrapper, int argc, char *argv[])
|
||||||
@ -1238,12 +1265,15 @@ pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,
|
|||||||
}
|
}
|
||||||
pNew = CreateEVController(pDriv,argv[0],&status);
|
pNew = CreateEVController(pDriv,argv[0],&status);
|
||||||
if (status != 1) {
|
if (status != 1) {
|
||||||
|
printf("CEVC error\n");
|
||||||
SCWrite(pCon,"ERROR: failed to initialize device", eError);
|
SCWrite(pCon,"ERROR: failed to initialize device", eError);
|
||||||
pDriv->GetError(pDriv,&status,pError,sizeof pError -1);
|
pDriv->GetError(pDriv,&status,pError,sizeof pError -1);
|
||||||
|
printf("HW %s\n", pError);
|
||||||
sprintf(pBueffel,"HW reported: %s",pError);
|
sprintf(pBueffel,"HW reported: %s",pError);
|
||||||
SCWrite(pCon,pBueffel,eError);
|
SCWrite(pCon,pBueffel,eError);
|
||||||
}
|
}
|
||||||
if (pNew == NULL) {
|
if (pNew == NULL) {
|
||||||
|
printf("CEVC failed\n");
|
||||||
SCWrite(pCon,"ERROR: failed to create environment device object",
|
SCWrite(pCon,"ERROR: failed to create environment device object",
|
||||||
eError);
|
eError);
|
||||||
DeleteEVDriver(pDriv);
|
DeleteEVDriver(pDriv);
|
||||||
@ -1368,6 +1398,29 @@ static pEVControl InstallCommonControllers(SicsInterp *pSics,
|
|||||||
}
|
}
|
||||||
return pNew;
|
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
|
EVControlFactory implements a SICS command which creates and deletes
|
||||||
Controllers at run-time. Syntax:
|
Controllers at run-time. Syntax:
|
||||||
@ -1405,26 +1458,12 @@ static pEVControl InstallCommonControllers(SicsInterp *pSics,
|
|||||||
strtolower(argv[1]);
|
strtolower(argv[1]);
|
||||||
if(strcmp(argv[1],"del") == 0) /* delete */
|
if(strcmp(argv[1],"del") == 0) /* delete */
|
||||||
{
|
{
|
||||||
if(!pServ->pExecutor)
|
if (RemoveEVController(pCon, argv[2])) {
|
||||||
{
|
|
||||||
SCSendOK(pCon);
|
SCSendOK(pCon);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else {
|
||||||
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);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
SCSendOK(pCon);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
else if(strcmp(argv[1],"new") == 0 || strcmp(argv[1], "replace") == 0)
|
else if(strcmp(argv[1],"new") == 0 || strcmp(argv[1], "replace") == 0)
|
||||||
/* make a new one */
|
/* make a new one */
|
||||||
@ -1441,8 +1480,9 @@ static pEVControl InstallCommonControllers(SicsInterp *pSics,
|
|||||||
strtolower(argv[3]);
|
strtolower(argv[3]);
|
||||||
if (FindCommandData(pSics, argv[2], "Environment Controller")) {
|
if (FindCommandData(pSics, argv[2], "Environment Controller")) {
|
||||||
if (strcmp(argv[1], "replace") == 0) {
|
if (strcmp(argv[1], "replace") == 0) {
|
||||||
RemoveCommand(pSics, argv[2]);
|
if (!RemoveEVController(pCon, argv[2])) {
|
||||||
EVUnregister(FindEMON(pSics),argv[2]);
|
return 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sprintf(pBueffel,
|
sprintf(pBueffel,
|
||||||
"ERROR: environment device %s already installed, delete first",
|
"ERROR: environment device %s already installed, delete first",
|
||||||
@ -1475,8 +1515,13 @@ static pEVControl InstallCommonControllers(SicsInterp *pSics,
|
|||||||
/* error message is already written */
|
/* error message is already written */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Arg2Text(argc-3, argv+3, pBueffel, sizeof pBueffel);
|
if (pNew->pDriv->SavePars) {
|
||||||
pNew->creationArgs = strdup(pBueffel);
|
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);
|
EVRegisterController(FindEMON(pSics),argv[2],pNew, pCon);
|
||||||
pNew->driverName = strdup(argv[3]);
|
pNew->driverName = strdup(argv[3]);
|
||||||
|
@ -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
|
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
|
#define SICSEVCONTROL
|
||||||
#include "varlog.h"
|
#include "varlog.h"
|
||||||
|
|
||||||
#line 146 "evcontroller.w"
|
#line 148 "evcontroller.w"
|
||||||
|
|
||||||
/*--------------------------- live & death --------------------------------*/
|
/*--------------------------- live & death --------------------------------*/
|
||||||
typedef struct __EVControl *pEVControl;
|
typedef struct __EVControl *pEVControl;
|
||||||
@ -24,7 +24,6 @@
|
|||||||
void DeleteEVController(void *pData);
|
void DeleteEVController(void *pData);
|
||||||
pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,
|
pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,
|
||||||
ObjectFunc wrapper, int argc, char *argv[]);
|
ObjectFunc wrapper, int argc, char *argv[]);
|
||||||
int EVSaveStatus(void *pData, char *name, FILE *fil);
|
|
||||||
/*-------------------------- driving ---------------------------------*/
|
/*-------------------------- driving ---------------------------------*/
|
||||||
int EVCDrive(pEVControl self,SConnection *pCon, float fNew);
|
int EVCDrive(pEVControl self,SConnection *pCon, float fNew);
|
||||||
int EVCGetPos(pEVControl self, SConnection *pCon,float *fVal);
|
int EVCGetPos(pEVControl self, SConnection *pCon,float *fVal);
|
||||||
@ -46,6 +45,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#line 239 "evcontroller.w"
|
#line 240 "evcontroller.w"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#line 243 "evcontroller.w"
|
#line 244 "evcontroller.w"
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
Environment controller datastructure
|
Environment controller datastructure
|
||||||
@ -47,5 +47,5 @@
|
|||||||
void (*KillPrivate)(void *pData);
|
void (*KillPrivate)(void *pData);
|
||||||
} EVControl;
|
} EVControl;
|
||||||
|
|
||||||
#line 261 "evcontroller.w"
|
#line 262 "evcontroller.w"
|
||||||
|
|
||||||
|
@ -112,6 +112,7 @@ $\langle$evdriv {\footnotesize ?}$\rangle\equiv$
|
|||||||
\mbox{}\verb@ int (*GetError)(pEVDriver self, int *iCode,@\\
|
\mbox{}\verb@ int (*GetError)(pEVDriver self, int *iCode,@\\
|
||||||
\mbox{}\verb@ char *pError, int iErrLen);@\\
|
\mbox{}\verb@ char *pError, int iErrLen);@\\
|
||||||
\mbox{}\verb@ int (*TryFixIt)(pEVDriver self, int iCode);@\\
|
\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 (*Init)(pEVDriver self);@\\
|
||||||
\mbox{}\verb@ int (*Close)(pEVDriver self);@\\
|
\mbox{}\verb@ int (*Close)(pEVDriver self);@\\
|
||||||
\mbox{}\verb@ void *pPrivate;@\\
|
\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
|
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
|
problem and DEVREDO if TryFixIt manged to fix the problem but requires the
|
||||||
last command to be resent.
|
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 [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
|
\item [Close] Close is meant to close the driver and bring the device into a
|
||||||
safe state.
|
safe state.
|
||||||
@ -181,7 +183,6 @@ $\langle$dvfunc {\footnotesize ?}$\rangle\equiv$
|
|||||||
\mbox{}\verb@ void DeleteEVController(void *pData);@\\
|
\mbox{}\verb@ void DeleteEVController(void *pData);@\\
|
||||||
\mbox{}\verb@ pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,@\\
|
\mbox{}\verb@ pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,@\\
|
||||||
\mbox{}\verb@ ObjectFunc wrapper, int argc, char *argv[]);@\\
|
\mbox{}\verb@ ObjectFunc wrapper, int argc, char *argv[]);@\\
|
||||||
\mbox{}\verb@ int EVSaveStatus(void *pData, char *name, FILE *fil);@\\
|
|
||||||
\mbox{}\verb@/*-------------------------- driving ---------------------------------*/@\\
|
\mbox{}\verb@/*-------------------------- driving ---------------------------------*/@\\
|
||||||
\mbox{}\verb@ int EVCDrive(pEVControl self,SConnection *pCon, float fNew);@\\
|
\mbox{}\verb@ int EVCDrive(pEVControl self,SConnection *pCon, float fNew);@\\
|
||||||
\mbox{}\verb@ int EVCGetPos(pEVControl self, SConnection *pCon,float *fVal);@\\
|
\mbox{}\verb@ int EVCGetPos(pEVControl self, SConnection *pCon,float *fVal);@\\
|
||||||
|
@ -95,6 +95,7 @@ used:
|
|||||||
int (*GetError)(pEVDriver self, int *iCode,
|
int (*GetError)(pEVDriver self, int *iCode,
|
||||||
char *pError, int iErrLen);
|
char *pError, int iErrLen);
|
||||||
int (*TryFixIt)(pEVDriver self, int iCode);
|
int (*TryFixIt)(pEVDriver self, int iCode);
|
||||||
|
int (*SavePars)(pEVDriver self, FILE *fil);
|
||||||
int (*Init)(pEVDriver self);
|
int (*Init)(pEVDriver self);
|
||||||
int (*Close)(pEVDriver self);
|
int (*Close)(pEVDriver self);
|
||||||
void *pPrivate;
|
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
|
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
|
problem and DEVREDO if TryFixIt manged to fix the problem but requires the
|
||||||
last command to be resent.
|
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 [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
|
\item [Close] Close is meant to close the driver and bring the device into a
|
||||||
safe state.
|
safe state.
|
||||||
@ -152,7 +154,6 @@ data structure as first parameter.
|
|||||||
void DeleteEVController(void *pData);
|
void DeleteEVController(void *pData);
|
||||||
pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,
|
pEVControl MakeEVController(pEVDriver pDriv, SConnection *pCon,
|
||||||
ObjectFunc wrapper, int argc, char *argv[]);
|
ObjectFunc wrapper, int argc, char *argv[]);
|
||||||
int EVSaveStatus(void *pData, char *name, FILE *fil);
|
|
||||||
/*-------------------------- driving ---------------------------------*/
|
/*-------------------------- driving ---------------------------------*/
|
||||||
int EVCDrive(pEVControl self,SConnection *pCon, float fNew);
|
int EVCDrive(pEVControl self,SConnection *pCon, float fNew);
|
||||||
int EVCGetPos(pEVControl self, SConnection *pCon,float *fVal);
|
int EVCGetPos(pEVControl self, SConnection *pCon,float *fVal);
|
||||||
|
@ -39,10 +39,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "fortify.h"
|
#include "fortify.h"
|
||||||
|
|
||||||
typedef struct __EVDriver *pEVDriver;
|
#include "evdriver.h"
|
||||||
#include "evdriver.i"
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
pEVDriver CreateEVDriver(int argc, char *argv[])
|
pEVDriver CreateEVDriver(int argc, char *argv[])
|
||||||
@ -56,6 +56,7 @@
|
|||||||
}
|
}
|
||||||
memset(pNew,0,sizeof(EVDriver));
|
memset(pNew,0,sizeof(EVDriver));
|
||||||
pNew->GetValues = NULL; /* method will be replaced by default when NULL */
|
pNew->GetValues = NULL; /* method will be replaced by default when NULL */
|
||||||
|
pNew->SavePars = NULL; /* no save by default */
|
||||||
return pNew;
|
return pNew;
|
||||||
}
|
}
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
12
evdriver.h
Normal file
12
evdriver.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef EVDRIVER_H
|
||||||
|
#define EVDRIVER_H
|
||||||
|
|
||||||
|
#ifndef SICSEVCONTROL
|
||||||
|
|
||||||
|
typedef struct __EVDriver *pEVDriver;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <evdriver.i>
|
||||||
|
|
||||||
|
#endif
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#line 264 "evcontroller.w"
|
#line 265 "evcontroller.w"
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
Environment device driver datastructure
|
Environment device driver datastructure
|
||||||
@ -24,13 +24,14 @@
|
|||||||
int (*GetError)(pEVDriver self, int *iCode,
|
int (*GetError)(pEVDriver self, int *iCode,
|
||||||
char *pError, int iErrLen);
|
char *pError, int iErrLen);
|
||||||
int (*TryFixIt)(pEVDriver self, int iCode);
|
int (*TryFixIt)(pEVDriver self, int iCode);
|
||||||
|
int (*SavePars)(pEVDriver self, FILE *fil);
|
||||||
int (*Init)(pEVDriver self);
|
int (*Init)(pEVDriver self);
|
||||||
int (*Close)(pEVDriver self);
|
int (*Close)(pEVDriver self);
|
||||||
void *pPrivate;
|
void *pPrivate;
|
||||||
void (*KillPrivate)(void *pData);
|
void (*KillPrivate)(void *pData);
|
||||||
} EVDriver;
|
} EVDriver;
|
||||||
|
|
||||||
#line 275 "evcontroller.w"
|
#line 276 "evcontroller.w"
|
||||||
|
|
||||||
/*-------------------- life & death of a driver --------------------------*/
|
/*-------------------- life & death of a driver --------------------------*/
|
||||||
pEVDriver CreateEVDriver(int argc, char *argv[]);
|
pEVDriver CreateEVDriver(int argc, char *argv[]);
|
||||||
|
22
network.c
22
network.c
@ -54,6 +54,10 @@
|
|||||||
#define SOCKET 2
|
#define SOCKET 2
|
||||||
#define UDP 3
|
#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.
|
Redefine this function if another means of error reporting is necessary.
|
||||||
*/
|
*/
|
||||||
@ -216,10 +220,12 @@ CreateSocketAdress(
|
|||||||
mkChannel *NETConnect(char *name, int port)
|
mkChannel *NETConnect(char *name, int port)
|
||||||
{
|
{
|
||||||
mkChannel *pRes = NULL;
|
mkChannel *pRes = NULL;
|
||||||
int iRet, i;
|
int iRet, i, cnt;
|
||||||
char pBueffel[80];
|
char pBueffel[80];
|
||||||
struct hostent *pServer = NULL;
|
struct hostent *pServer = NULL;
|
||||||
struct linger lili;
|
struct linger lili;
|
||||||
|
struct timeval now;
|
||||||
|
long dif;
|
||||||
|
|
||||||
assert(port > 0);
|
assert(port > 0);
|
||||||
|
|
||||||
@ -248,9 +254,18 @@ CreateSocketAdress(
|
|||||||
free(pRes);
|
free(pRes);
|
||||||
return NULL;
|
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),
|
iRet = connect(pRes->sockid,(struct sockaddr *)&(pRes->adresse),
|
||||||
sizeof(struct sockaddr_in));
|
sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
if(iRet < 0)
|
if(iRet < 0)
|
||||||
{
|
{
|
||||||
free(pRes);
|
free(pRes);
|
||||||
@ -518,7 +533,7 @@ int NETReadTillTermNew(mkChannel *self, long timeout,
|
|||||||
{
|
{
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
dif = (now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
|
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)
|
if(dif > timeout)
|
||||||
{
|
{
|
||||||
return 0; /* 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);
|
iRet = close(self->sockid);
|
||||||
|
gettimeofday(&lastclose, NULL);
|
||||||
self->iType = 0;
|
self->iType = 0;
|
||||||
self->sockid = 0;
|
self->sockid = 0;
|
||||||
if(iRet < 0)
|
if(iRet < 0)
|
||||||
|
4
simev.c
4
simev.c
@ -47,9 +47,7 @@
|
|||||||
#include "servlog.h"
|
#include "servlog.h"
|
||||||
#include "fortify.h"
|
#include "fortify.h"
|
||||||
|
|
||||||
typedef struct __EVDriver *pEVDriver;
|
#include "evdriver.h"
|
||||||
|
|
||||||
#include "evdriver.i"
|
|
||||||
#include "simev.h"
|
#include "simev.h"
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
Reference in New Issue
Block a user