- Fixes to slsmagnet
- First working version of the new SINQHM http driver
This commit is contained in:
@ -194,7 +194,11 @@ int ECBMOTGetPos(void *pData, float *fPos){
|
|||||||
|
|
||||||
if((int)ObVal(self->driverPar,ENCODER) > 0){
|
if((int)ObVal(self->driverPar,ENCODER) > 0){
|
||||||
status = readEncoder(self, &digits);
|
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);
|
ObVal(self->driverPar,OFFSET);
|
||||||
return status;
|
return status;
|
||||||
} else {
|
} else {
|
||||||
|
71
sinqhttp.c
71
sinqhttp.c
@ -27,7 +27,7 @@ extern char *trim(char *);
|
|||||||
====================================================================*/
|
====================================================================*/
|
||||||
static char startdaq[] = {"/sinqhm/startdaq.egi"};
|
static char startdaq[] = {"/sinqhm/startdaq.egi"};
|
||||||
static char stopdaq[] = {"/sinqhm/stopdaq.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 continuedaq[] = {"/sinqhm/continuedaq.egi"};
|
||||||
static char statusdaq[] = {"/sinqhm/textstatus.egi"};
|
static char statusdaq[] = {"/sinqhm/textstatus.egi"};
|
||||||
static char gethm[] = {"/sinqhm/readhmdata.egi"};
|
static char gethm[] = {"/sinqhm/readhmdata.egi"};
|
||||||
@ -40,6 +40,8 @@ static char configure[] = {"/sinqhm/configure.egi"};
|
|||||||
#define NOBODY -703
|
#define NOBODY -703
|
||||||
#define BODYSHORT -704
|
#define BODYSHORT -704
|
||||||
#define NOTIMPLEMENTED -705
|
#define NOTIMPLEMENTED -705
|
||||||
|
#define SERVERERROR -706
|
||||||
|
#define BADSTATUS -707
|
||||||
/*=====================================================================
|
/*=====================================================================
|
||||||
our driver private data structure
|
our driver private data structure
|
||||||
======================================================================*/
|
======================================================================*/
|
||||||
@ -50,6 +52,7 @@ typedef struct {
|
|||||||
int errorCode;
|
int errorCode;
|
||||||
pStringDict lastStatus;
|
pStringDict lastStatus;
|
||||||
int pause;
|
int pause;
|
||||||
|
int failCount;
|
||||||
}sinqHttp, *pSinqHttp;
|
}sinqHttp, *pSinqHttp;
|
||||||
/*-------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------*/
|
||||||
static int sinqHttpGet(pSinqHttp self, char *request){
|
static int sinqHttpGet(pSinqHttp self, char *request){
|
||||||
@ -59,26 +62,34 @@ static int sinqHttpGet(pSinqHttp self, char *request){
|
|||||||
int len;
|
int len;
|
||||||
|
|
||||||
self->errorCode = 0;
|
self->errorCode = 0;
|
||||||
|
ghttp_clean(self->syncRequest);
|
||||||
memset(self->hmError,0,512*sizeof(char));
|
memset(self->hmError,0,512*sizeof(char));
|
||||||
snprintf(url,511,"%s%s",self->hmAddress,request);
|
snprintf(url,511,"%s%s",self->hmAddress,request);
|
||||||
ghttp_set_type(self->syncRequest,ghttp_type_get);
|
ghttp_set_type(self->syncRequest,ghttp_type_get);
|
||||||
|
ghttp_set_header(self->syncRequest,"connection","keep-alive");
|
||||||
if(ghttp_set_uri(self->syncRequest,url) < 0){
|
if(ghttp_set_uri(self->syncRequest,url) < 0){
|
||||||
self->errorCode = BADURL;
|
self->errorCode = BADURL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ghttp_prepare(self->syncRequest);
|
ghttp_prepare(self->syncRequest);
|
||||||
ghttp_clean(self->syncRequest);
|
|
||||||
httpStatus = ghttp_process(self->syncRequest);
|
httpStatus = ghttp_process(self->syncRequest);
|
||||||
if(httpStatus != ghttp_done){
|
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);
|
pPtr = ghttp_get_body(self->syncRequest);
|
||||||
len = ghttp_get_body_len(self->syncRequest);
|
len = ghttp_get_body_len(self->syncRequest);
|
||||||
if(len > 511){
|
if(len > 511){
|
||||||
len = 510;
|
len = 510;
|
||||||
}
|
}
|
||||||
memset(self->hmError,0,512*sizeof(char));
|
if(strstr(pPtr,"ERROR") != NULL){
|
||||||
strncpy(self->hmError,pPtr, len);
|
memset(self->hmError,0,512*sizeof(char));
|
||||||
self->errorCode = HTTPERROR;
|
strncpy(self->hmError,pPtr, len);
|
||||||
return 0;
|
self->errorCode = HTTPERROR;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -139,24 +150,32 @@ static int SinqHttpConfigure(pHistDriver self, SConnection *pCon,
|
|||||||
/*
|
/*
|
||||||
uplod new configuration to HM
|
uplod new configuration to HM
|
||||||
*/
|
*/
|
||||||
|
ghttp_clean(pPriv->syncRequest);
|
||||||
snprintf(url,511,"%s%s",pPriv->hmAddress,configure);
|
snprintf(url,511,"%s%s",pPriv->hmAddress,configure);
|
||||||
status = ghttp_set_uri(pPriv->syncRequest,url);
|
status = ghttp_set_uri(pPriv->syncRequest,url);
|
||||||
if(status < 0){
|
if(status < 0){
|
||||||
SCWrite(pCon,"ERROR: invalid URI for HM request",eError);
|
SCWrite(pCon,"ERROR: invalid URI for HM request",eError);
|
||||||
return 0;
|
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);
|
confData = (char *)Tcl_GetStringResult(pSics->pTcl);
|
||||||
ghttp_set_body(pPriv->syncRequest,confData,strlen(confData));
|
status = ghttp_set_body(pPriv->syncRequest,confData,
|
||||||
ghttp_prepare(pPriv->syncRequest);
|
strlen(confData));
|
||||||
ghttp_clean(pPriv->syncRequest);
|
status = ghttp_prepare(pPriv->syncRequest);
|
||||||
httpStatus = ghttp_process(pPriv->syncRequest);
|
httpStatus = ghttp_process(pPriv->syncRequest);
|
||||||
|
confData = (char *)ghttp_get_body(pPriv->syncRequest);
|
||||||
if(httpStatus != ghttp_done){
|
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",
|
snprintf(confCommand,511,"ERROR: http error %s occurred",
|
||||||
confData);
|
confData);
|
||||||
SCWrite(pCon,confCommand,eError);
|
SCWrite(pCon,confCommand,eError);
|
||||||
return 0;
|
return 0;
|
||||||
|
} else {
|
||||||
|
if(strstr(confData,"ERROR") != NULL){
|
||||||
|
snprintf(confCommand,511,"%s",confData);
|
||||||
|
SCWrite(pCon,confCommand,eError);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,7 +221,7 @@ static int SinqHttpPause(pHistDriver self,SConnection *pCon){
|
|||||||
if(status != 1){
|
if(status != 1){
|
||||||
return HWFault;
|
return HWFault;
|
||||||
}
|
}
|
||||||
pPriv->pause == 1;
|
pPriv->pause = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------*/
|
||||||
@ -213,11 +232,11 @@ static int SinqHttpContinue(pHistDriver self, SConnection *pCon){
|
|||||||
pPriv = (pSinqHttp)self->pPriv;
|
pPriv = (pSinqHttp)self->pPriv;
|
||||||
assert(pPriv != NULL);
|
assert(pPriv != NULL);
|
||||||
|
|
||||||
pPriv->pause == 0;
|
|
||||||
status = sinqHttpGet(pPriv,continuedaq);
|
status = sinqHttpGet(pPriv,continuedaq);
|
||||||
if(status != 1){
|
if(status != 1){
|
||||||
return HWFault;
|
return HWFault;
|
||||||
}
|
}
|
||||||
|
pPriv->pause = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------*/
|
||||||
@ -249,6 +268,7 @@ static int readStatus(pSinqHttp self){
|
|||||||
/*---------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------*/
|
||||||
static int SinqHttpStatus(pHistDriver self,SConnection *pCon){
|
static int SinqHttpStatus(pHistDriver self,SConnection *pCon){
|
||||||
pSinqHttp pPriv = NULL;
|
pSinqHttp pPriv = NULL;
|
||||||
|
char daqStatus[20];
|
||||||
int status, len;
|
int status, len;
|
||||||
char *pPtr = NULL;
|
char *pPtr = NULL;
|
||||||
|
|
||||||
@ -269,9 +289,20 @@ static int SinqHttpStatus(pHistDriver self,SConnection *pCon){
|
|||||||
return HWFault;
|
return HWFault;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if(StringDictGet(pPriv->lastStatus,"DAQ",daqStatus,20) != 1){
|
||||||
* TODO: evaluate status fields
|
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;
|
return HWIdle;
|
||||||
}
|
}
|
||||||
@ -300,6 +331,14 @@ static int SinqHttpFixIt(pHistDriver self, int code){
|
|||||||
* connection problems... But abort any pending transactions...
|
* connection problems... But abort any pending transactions...
|
||||||
*/
|
*/
|
||||||
ghttp_close(pPriv->syncRequest);
|
ghttp_close(pPriv->syncRequest);
|
||||||
|
if(code == SERVERERROR){
|
||||||
|
pPriv->failCount++;
|
||||||
|
if(pPriv->failCount > 2){
|
||||||
|
return COTERM;
|
||||||
|
} else {
|
||||||
|
return COREDO;
|
||||||
|
}
|
||||||
|
}
|
||||||
return COTERM;
|
return COTERM;
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------*/
|
||||||
|
12
slsmagnet.c
12
slsmagnet.c
@ -121,7 +121,7 @@ static double DSPfloat2double( ULONG input )
|
|||||||
static int communicateSLS(mkChannel *pSock, char msg[6], char reply[6])
|
static int communicateSLS(mkChannel *pSock, char msg[6], char reply[6])
|
||||||
{
|
{
|
||||||
long lVal = 0;
|
long lVal = 0;
|
||||||
int iRet, i, address;
|
int iRet, i, address, status;
|
||||||
|
|
||||||
if(!pSock)
|
if(!pSock)
|
||||||
return NOTCONNECTED;
|
return NOTCONNECTED;
|
||||||
@ -141,7 +141,15 @@ static int communicateSLS(mkChannel *pSock, char msg[6], char reply[6])
|
|||||||
}
|
}
|
||||||
else if(iRet == 1)
|
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)
|
if(lVal >= 6)
|
||||||
{
|
{
|
||||||
return (int)lVal;
|
return (int)lVal;
|
||||||
|
Reference in New Issue
Block a user