diff --git a/ecbdriv.c b/ecbdriv.c index 03713ed..78d5596 100644 --- a/ecbdriv.c +++ b/ecbdriv.c @@ -194,7 +194,11 @@ int ECBMOTGetPos(void *pData, float *fPos){ if((int)ObVal(self->driverPar,ENCODER) > 0){ status = readEncoder(self, &digits); - *fPos = digits/ObVal(self->driverPar,DEG2STEP) - + step2degree = ObVal(self->driverPar,DEG2STEP); + if(step2degree == 0.0){ + step2degree = 1; + } + *fPos = (digits/step2degree) - ObVal(self->driverPar,OFFSET); return status; } else { diff --git a/libpsi.a b/libpsi.a index 4b014f3..476d569 100644 Binary files a/libpsi.a and b/libpsi.a differ diff --git a/sinqhttp.c b/sinqhttp.c index fe2e48e..dcfe91f 100644 --- a/sinqhttp.c +++ b/sinqhttp.c @@ -27,7 +27,7 @@ extern char *trim(char *); ====================================================================*/ static char startdaq[] = {"/sinqhm/startdaq.egi"}; static char stopdaq[] = {"/sinqhm/stopdaq.egi"}; -static char pausedaq[] = {"/sinqhm/pausedaq.egi"}; +static char pausedaq[] = {"/sinqhm/stopdaq.egi"}; static char continuedaq[] = {"/sinqhm/continuedaq.egi"}; static char statusdaq[] = {"/sinqhm/textstatus.egi"}; static char gethm[] = {"/sinqhm/readhmdata.egi"}; @@ -40,6 +40,8 @@ static char configure[] = {"/sinqhm/configure.egi"}; #define NOBODY -703 #define BODYSHORT -704 #define NOTIMPLEMENTED -705 +#define SERVERERROR -706 +#define BADSTATUS -707 /*===================================================================== our driver private data structure ======================================================================*/ @@ -50,6 +52,7 @@ typedef struct { int errorCode; pStringDict lastStatus; int pause; + int failCount; }sinqHttp, *pSinqHttp; /*-------------------------------------------------------------------*/ static int sinqHttpGet(pSinqHttp self, char *request){ @@ -59,26 +62,34 @@ static int sinqHttpGet(pSinqHttp self, char *request){ int len; self->errorCode = 0; + ghttp_clean(self->syncRequest); memset(self->hmError,0,512*sizeof(char)); snprintf(url,511,"%s%s",self->hmAddress,request); ghttp_set_type(self->syncRequest,ghttp_type_get); + ghttp_set_header(self->syncRequest,"connection","keep-alive"); if(ghttp_set_uri(self->syncRequest,url) < 0){ self->errorCode = BADURL; return 0; } ghttp_prepare(self->syncRequest); - ghttp_clean(self->syncRequest); httpStatus = ghttp_process(self->syncRequest); if(httpStatus != ghttp_done){ + strncpy(self->hmError,ghttp_get_error(self->syncRequest), 511); + self->errorCode = SERVERERROR; + return 0; + } else { + self->failCount = 0; pPtr = ghttp_get_body(self->syncRequest); len = ghttp_get_body_len(self->syncRequest); if(len > 511){ len = 510; } - memset(self->hmError,0,512*sizeof(char)); - strncpy(self->hmError,pPtr, len); - self->errorCode = HTTPERROR; - return 0; + if(strstr(pPtr,"ERROR") != NULL){ + memset(self->hmError,0,512*sizeof(char)); + strncpy(self->hmError,pPtr, len); + self->errorCode = HTTPERROR; + return 0; + } } return 1; } @@ -139,25 +150,33 @@ static int SinqHttpConfigure(pHistDriver self, SConnection *pCon, /* uplod new configuration to HM */ + ghttp_clean(pPriv->syncRequest); snprintf(url,511,"%s%s",pPriv->hmAddress,configure); status = ghttp_set_uri(pPriv->syncRequest,url); if(status < 0){ SCWrite(pCon,"ERROR: invalid URI for HM request",eError); return 0; } - ghttp_set_type(pPriv->syncRequest,ghttp_type_post); + status = ghttp_set_type(pPriv->syncRequest,ghttp_type_post); confData = (char *)Tcl_GetStringResult(pSics->pTcl); - ghttp_set_body(pPriv->syncRequest,confData,strlen(confData)); - ghttp_prepare(pPriv->syncRequest); - ghttp_clean(pPriv->syncRequest); + status = ghttp_set_body(pPriv->syncRequest,confData, + strlen(confData)); + status = ghttp_prepare(pPriv->syncRequest); httpStatus = ghttp_process(pPriv->syncRequest); + confData = (char *)ghttp_get_body(pPriv->syncRequest); if(httpStatus != ghttp_done){ - confData = (char *)ghttp_get_body(pPriv->syncRequest); + confData = ghttp_get_error(pPriv->syncRequest); snprintf(confCommand,511,"ERROR: http error %s occurred", confData); SCWrite(pCon,confCommand,eError); return 0; - } + } else { + if(strstr(confData,"ERROR") != NULL){ + snprintf(confCommand,511,"%s",confData); + SCWrite(pCon,confCommand,eError); + return 0; + } + } } } return 1; @@ -202,7 +221,7 @@ static int SinqHttpPause(pHistDriver self,SConnection *pCon){ if(status != 1){ return HWFault; } - pPriv->pause == 1; + pPriv->pause = 1; return 1; } /*---------------------------------------------------------------------*/ @@ -213,11 +232,11 @@ static int SinqHttpContinue(pHistDriver self, SConnection *pCon){ pPriv = (pSinqHttp)self->pPriv; assert(pPriv != NULL); - pPriv->pause == 0; status = sinqHttpGet(pPriv,continuedaq); if(status != 1){ return HWFault; } + pPriv->pause = 0; return 1; } /*--------------------------------------------------------------------*/ @@ -249,6 +268,7 @@ static int readStatus(pSinqHttp self){ /*---------------------------------------------------------------------*/ static int SinqHttpStatus(pHistDriver self,SConnection *pCon){ pSinqHttp pPriv = NULL; + char daqStatus[20]; int status, len; char *pPtr = NULL; @@ -268,11 +288,22 @@ static int SinqHttpStatus(pHistDriver self,SConnection *pCon){ if(status != 1){ return HWFault; } - - /* - * TODO: evaluate status fields - */ - + + if(StringDictGet(pPriv->lastStatus,"DAQ",daqStatus,20) != 1){ + pPriv->errorCode = BADSTATUS; + strncpy(pPriv->hmError,"ERROR: status does not contain DAQ field",511); + return HWFault; + } + if(strstr(daqStatus,"1") != NULL){ + return HWBusy; + } else if(strstr(daqStatus,"0") != NULL){ + return HWIdle; + } else { + pPriv->errorCode = BADSTATUS; + snprintf(pPriv->hmError,511,"ERROR: invalid DAQ sttaus %s",daqStatus); + return HWFault; + } + return HWIdle; } /*---------------------------------------------------------------------*/ @@ -300,6 +331,14 @@ static int SinqHttpFixIt(pHistDriver self, int code){ * connection problems... But abort any pending transactions... */ ghttp_close(pPriv->syncRequest); + if(code == SERVERERROR){ + pPriv->failCount++; + if(pPriv->failCount > 2){ + return COTERM; + } else { + return COREDO; + } + } return COTERM; } /*--------------------------------------------------------------------*/ diff --git a/slsmagnet.c b/slsmagnet.c index 210563b..f2c70d8 100644 --- a/slsmagnet.c +++ b/slsmagnet.c @@ -121,7 +121,7 @@ static double DSPfloat2double( ULONG input ) static int communicateSLS(mkChannel *pSock, char msg[6], char reply[6]) { long lVal = 0; - int iRet, i, address; + int iRet, i, address, status; if(!pSock) return NOTCONNECTED; @@ -141,7 +141,15 @@ static int communicateSLS(mkChannel *pSock, char msg[6], char reply[6]) } else if(iRet == 1) { - lVal += NETRead(pSock,reply+lVal,6-lVal,-10); + status = NETRead(pSock,reply+lVal,6-lVal,-10); + if(status >= 0){ + lVal += status; + } else { + /* + * network read error + */ + return status; + } if(lVal >= 6) { return (int)lVal;