diff --git a/site_ansto/anstohttp.c b/site_ansto/anstohttp.c index f2c80d3f..b75d9ca7 100644 --- a/site_ansto/anstohttp.c +++ b/site_ansto/anstohttp.c @@ -154,10 +154,6 @@ static int AnstoHttpConfigure(pHistDriver self, SConnection *pCon, pPriv = (pAnstoHttp)self->pPriv; assert(pPriv != NULL); - ///SCWrite(pCon,"In AnstoHttpConfigure",eError); // MJL DEBUG - - // Check for FAT value sets - /* * The HM computer address */ @@ -277,21 +273,16 @@ static int AnstoHttpConfigure(pHistDriver self, SConnection *pCon, { if (strncasecmp(pItem,"FAT_",4)==0) { - // Try committing the setting to the histogram server - SCWrite(pCon,"Commit to HS FAT:",eError); // MJL DEBUG - SCWrite(pCon,(char *)pItem,eError); // MJL DEBUG - SCWrite(pCon,pValue,eError); // MJL DEBUG - + // Try committing the setting to the histogram server // Make special http request to set the FAT parameter char modify_FAT_http_request[1024]; - sprintf(modify_FAT_http_request,"/admin/selectdynamicfatmodify.egi?dynamicFATmodifyparamname=%s&dynamicFATmodifyparamvalue=%s", + sprintf(modify_FAT_http_request, + "/admin/selectdynamicfatmodify.egi?dynamicFATmodifyparamname=%s&dynamicFATmodifyparamvalue=%s", pItem+4,pValue); // Send the request. When one doesn't work, drop out of the loop. - //SCWrite(pCon,"httpget",eError); // MJL DEBUG int status = anstoHttpGet(pPriv,modify_FAT_http_request); if(status != 1) return 0; - //SCWrite(pCon,"Done httpget",eError); // MJL DEBUG } } } while(pItem); @@ -330,19 +321,10 @@ static int readStatus(pHistDriver pDriv){ return 1; } /*---------------------------------------------------------------------*/ -// MJL we now force the status daq entry in the dictionary the explicit -// expected value ("Started", "Stopped" or "Paused"), whenever any -// of start, stop, pause or continue is done. I tried reading the status -// back from the server, but because it can respond slowly a delay would -// have been required, which is cumbersome. -// This way, the status read via the list command should be accurate -// provided there are no external factors involved (like users pushing -// start/stop/pause buttons on web page, etc.) -// It would be better to somehow force the status check so we would know -// that the daq entry in the dictonary really reflects the histogrammer -// status... we should discuss with Mark K sometime, maybe we can add this -// feature to the base code. -// +// The status code mow allows pCon==NULL to be passed in. +// This allows the status to be checked from all the start, stop, pause +// and continue callbacks, so we can wait for the server to actually +// change to the correct operating state before continuing. static int AnstoHttpStatus(pHistDriver self,SConnection *pCon){ // pCon=NULL allowed pAnstoHttp pPriv = NULL; ghttp_status httpStatus; @@ -350,8 +332,6 @@ static int AnstoHttpStatus(pHistDriver self,SConnection *pCon){ // pCon=NULL all int status, len; char *pPtr = NULL; -///if (pCon) SCWrite(pCon,"In AnstoHttpStatus",eError); // MJL DEBUG - pPriv = (pAnstoHttp)self->pPriv; assert(pPriv != NULL); @@ -367,7 +347,6 @@ static int AnstoHttpStatus(pHistDriver self,SConnection *pCon){ // pCon=NULL all ghttp_set_sync(pPriv->syncRequest,ghttp_async); ghttp_prepare(pPriv->syncRequest); if(status != 1){ - ///if (pCon) SCWrite(pCon,"HWF1.",eError); // MJL DEBUG return HWFault; } pPriv->asyncRunning = 1; @@ -382,21 +361,18 @@ static int AnstoHttpStatus(pHistDriver self,SConnection *pCon){ // pCon=NULL all if(httpStatus != ghttp_done){ strncpy(pPriv->hmError,"Reconnect", 511); pPriv->errorCode = SERVERERROR; - ///if (pCon) SCWrite(pCon,"HWF2.",eError); // MJL DEBUG return HWFault; pPriv->asyncRunning = 0; } break; case ghttp_not_done: - ///if (pCon) SCWrite(pCon,"HWB.",eError); // MJL DEBUG return HWBusy; break; case ghttp_done: pPriv->asyncRunning = 0; status = anstoHttpCheckResponse(pPriv); if(status != 1){ - ///if (pCon) SCWrite(pCon,"HWF3.",eError); // MJL DEBUG - return HWFault; + return HWFault; } break; } @@ -404,24 +380,19 @@ static int AnstoHttpStatus(pHistDriver self,SConnection *pCon){ // pCon=NULL all status = readStatus(self); if(status != 1){ - ///if (pCon) SCWrite(pCon,"HWF4.",eError); // MJL DEBUG return HWFault; } if(StringDictGet(self->pOption,"daq",daqStatus,20) != 1){ - ///if (pCon) SCWrite(pCon,"Field 'daq' not found!!!",eError); // MJL DEBUG pPriv->errorCode = BADSTATUS; strncpy(pPriv->hmError,"ERROR: status does not contain DAQ field",511); return HWFault; } if(strstr(daqStatus,"Started") != NULL){ - ///if (pCon) SCWrite(pCon,"DAQ Started.",eError); // MJL DEBUG return HWBusy; } else if(strstr(daqStatus,"Paused") != NULL){ - ///if (pCon) SCWrite(pCon,"DAQ Paused.",eError); // MJL DEBUG return HWIdle; } else if(strstr(daqStatus,"Stopped") != NULL){ - ///if (pCon) SCWrite(pCon,"DAQ Stopped.",eError); // MJL DEBUG return HWIdle; } else { pPriv->errorCode = BADSTATUS; @@ -432,6 +403,20 @@ static int AnstoHttpStatus(pHistDriver self,SConnection *pCon){ // pCon=NULL all return HWIdle; } +#define MAX_STATUS_READ_RETRIES 50 +#define STATUS_READ_DELAY_US 100000 +// +static int AnstoHttpStatusWithRetries(pHistDriver self, int requiredstate) +{ + int retries,retcode=HWFault; + for(retries=0;retriespOption, "daq", "Started"); + + AnstoHttpStatusWithRetries(self,HWBusy); + return 1; } /*---------------------------------------------------------------------*/ @@ -460,8 +447,9 @@ static int AnstoHttpHalt(pHistDriver self){ // hmm, why isn't there a pCon like if(status != 1){ return HWFault; } - // MJL force the daq status to the expected value... - StringDictUpdate(self->pOption, "daq", "Stopped"); + + AnstoHttpStatusWithRetries(self,HWIdle); + return 1; } /*---------------------------------------------------------------------*/ @@ -477,8 +465,9 @@ static int AnstoHttpPause(pHistDriver self,SConnection *pCon){ return HWFault; } pPriv->pause = 1; - // MJL force the daq status to the expected value... - StringDictUpdate(self->pOption, "daq", "Paused"); + + AnstoHttpStatusWithRetries(self,HWIdle); + return 1; } /*---------------------------------------------------------------------*/ @@ -494,8 +483,7 @@ static int AnstoHttpContinue(pHistDriver self, SConnection *pCon){ return HWFault; } pPriv->pause = 0; - // MJL force the daq status to the expected value... - StringDictUpdate(self->pOption, "daq", "Started"); + AnstoHttpStatusWithRetries(self,HWBusy); return 1; } /*---------------------------------------------------------------------*/