MJL 8/11/06 Improved start/stop/pause status checking.

r1254 | mle | 2006-11-08 16:58:57 +1100 (Wed, 08 Nov 2006) | 2 lines
This commit is contained in:
Mark Lesha
2006-11-08 16:58:57 +11:00
committed by Douglas Clowes
parent 55df3ecd12
commit 3c7c269705

View File

@@ -154,10 +154,6 @@ static int AnstoHttpConfigure(pHistDriver self, SConnection *pCon,
pPriv = (pAnstoHttp)self->pPriv; pPriv = (pAnstoHttp)self->pPriv;
assert(pPriv != NULL); assert(pPriv != NULL);
///SCWrite(pCon,"In AnstoHttpConfigure",eError); // MJL DEBUG
// Check for FAT value sets
/* /*
* The HM computer address * The HM computer address
*/ */
@@ -277,21 +273,16 @@ static int AnstoHttpConfigure(pHistDriver self, SConnection *pCon,
{ {
if (strncasecmp(pItem,"FAT_",4)==0) if (strncasecmp(pItem,"FAT_",4)==0)
{ {
// Try committing the setting to the histogram server // 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
// Make special http request to set the FAT parameter // Make special http request to set the FAT parameter
char modify_FAT_http_request[1024]; 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); pItem+4,pValue);
// Send the request. When one doesn't work, drop out of the loop. // 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); int status = anstoHttpGet(pPriv,modify_FAT_http_request);
if(status != 1) if(status != 1)
return 0; return 0;
//SCWrite(pCon,"Done httpget",eError); // MJL DEBUG
} }
} }
} while(pItem); } while(pItem);
@@ -330,19 +321,10 @@ static int readStatus(pHistDriver pDriv){
return 1; return 1;
} }
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
// MJL we now force the status daq entry in the dictionary the explicit // The status code mow allows pCon==NULL to be passed in.
// expected value ("Started", "Stopped" or "Paused"), whenever any // This allows the status to be checked from all the start, stop, pause
// of start, stop, pause or continue is done. I tried reading the status // and continue callbacks, so we can wait for the server to actually
// back from the server, but because it can respond slowly a delay would // change to the correct operating state before continuing.
// 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.
//
static int AnstoHttpStatus(pHistDriver self,SConnection *pCon){ // pCon=NULL allowed static int AnstoHttpStatus(pHistDriver self,SConnection *pCon){ // pCon=NULL allowed
pAnstoHttp pPriv = NULL; pAnstoHttp pPriv = NULL;
ghttp_status httpStatus; ghttp_status httpStatus;
@@ -350,8 +332,6 @@ static int AnstoHttpStatus(pHistDriver self,SConnection *pCon){ // pCon=NULL all
int status, len; int status, len;
char *pPtr = NULL; char *pPtr = NULL;
///if (pCon) SCWrite(pCon,"In AnstoHttpStatus",eError); // MJL DEBUG
pPriv = (pAnstoHttp)self->pPriv; pPriv = (pAnstoHttp)self->pPriv;
assert(pPriv != NULL); 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_set_sync(pPriv->syncRequest,ghttp_async);
ghttp_prepare(pPriv->syncRequest); ghttp_prepare(pPriv->syncRequest);
if(status != 1){ if(status != 1){
///if (pCon) SCWrite(pCon,"HWF1.",eError); // MJL DEBUG
return HWFault; return HWFault;
} }
pPriv->asyncRunning = 1; pPriv->asyncRunning = 1;
@@ -382,21 +361,18 @@ static int AnstoHttpStatus(pHistDriver self,SConnection *pCon){ // pCon=NULL all
if(httpStatus != ghttp_done){ if(httpStatus != ghttp_done){
strncpy(pPriv->hmError,"Reconnect", 511); strncpy(pPriv->hmError,"Reconnect", 511);
pPriv->errorCode = SERVERERROR; pPriv->errorCode = SERVERERROR;
///if (pCon) SCWrite(pCon,"HWF2.",eError); // MJL DEBUG
return HWFault; return HWFault;
pPriv->asyncRunning = 0; pPriv->asyncRunning = 0;
} }
break; break;
case ghttp_not_done: case ghttp_not_done:
///if (pCon) SCWrite(pCon,"HWB.",eError); // MJL DEBUG
return HWBusy; return HWBusy;
break; break;
case ghttp_done: case ghttp_done:
pPriv->asyncRunning = 0; pPriv->asyncRunning = 0;
status = anstoHttpCheckResponse(pPriv); status = anstoHttpCheckResponse(pPriv);
if(status != 1){ if(status != 1){
///if (pCon) SCWrite(pCon,"HWF3.",eError); // MJL DEBUG return HWFault;
return HWFault;
} }
break; break;
} }
@@ -404,24 +380,19 @@ static int AnstoHttpStatus(pHistDriver self,SConnection *pCon){ // pCon=NULL all
status = readStatus(self); status = readStatus(self);
if(status != 1){ if(status != 1){
///if (pCon) SCWrite(pCon,"HWF4.",eError); // MJL DEBUG
return HWFault; return HWFault;
} }
if(StringDictGet(self->pOption,"daq",daqStatus,20) != 1){ if(StringDictGet(self->pOption,"daq",daqStatus,20) != 1){
///if (pCon) SCWrite(pCon,"Field 'daq' not found!!!",eError); // MJL DEBUG
pPriv->errorCode = BADSTATUS; pPriv->errorCode = BADSTATUS;
strncpy(pPriv->hmError,"ERROR: status does not contain DAQ field",511); strncpy(pPriv->hmError,"ERROR: status does not contain DAQ field",511);
return HWFault; return HWFault;
} }
if(strstr(daqStatus,"Started") != NULL){ if(strstr(daqStatus,"Started") != NULL){
///if (pCon) SCWrite(pCon,"DAQ Started.",eError); // MJL DEBUG
return HWBusy; return HWBusy;
} else if(strstr(daqStatus,"Paused") != NULL){ } else if(strstr(daqStatus,"Paused") != NULL){
///if (pCon) SCWrite(pCon,"DAQ Paused.",eError); // MJL DEBUG
return HWIdle; return HWIdle;
} else if(strstr(daqStatus,"Stopped") != NULL){ } else if(strstr(daqStatus,"Stopped") != NULL){
///if (pCon) SCWrite(pCon,"DAQ Stopped.",eError); // MJL DEBUG
return HWIdle; return HWIdle;
} else { } else {
pPriv->errorCode = BADSTATUS; pPriv->errorCode = BADSTATUS;
@@ -432,6 +403,20 @@ static int AnstoHttpStatus(pHistDriver self,SConnection *pCon){ // pCon=NULL all
return HWIdle; 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;retries<MAX_STATUS_READ_RETRIES&&retcode!=requiredstate;retries++)
{
retcode=AnstoHttpStatus(self,NULL);
usleep(STATUS_READ_DELAY_US);
}
return retcode;
}
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static int AnstoHttpStart(pHistDriver self, SConnection *pCon){ static int AnstoHttpStart(pHistDriver self, SConnection *pCon){
pAnstoHttp pPriv = NULL; pAnstoHttp pPriv = NULL;
@@ -441,11 +426,13 @@ static int AnstoHttpStart(pHistDriver self, SConnection *pCon){
assert(pPriv != NULL); assert(pPriv != NULL);
status = anstoHttpGet(pPriv,startdaq); status = anstoHttpGet(pPriv,startdaq);
if(status != 1){ if(status != 1){
return HWFault; return HWFault;
} }
// MJL force the daq status to the expected value...
StringDictUpdate(self->pOption, "daq", "Started"); AnstoHttpStatusWithRetries(self,HWBusy);
return 1; return 1;
} }
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
@@ -460,8 +447,9 @@ static int AnstoHttpHalt(pHistDriver self){ // hmm, why isn't there a pCon like
if(status != 1){ if(status != 1){
return HWFault; return HWFault;
} }
// MJL force the daq status to the expected value...
StringDictUpdate(self->pOption, "daq", "Stopped"); AnstoHttpStatusWithRetries(self,HWIdle);
return 1; return 1;
} }
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
@@ -477,8 +465,9 @@ static int AnstoHttpPause(pHistDriver self,SConnection *pCon){
return HWFault; return HWFault;
} }
pPriv->pause = 1; pPriv->pause = 1;
// MJL force the daq status to the expected value...
StringDictUpdate(self->pOption, "daq", "Paused"); AnstoHttpStatusWithRetries(self,HWIdle);
return 1; return 1;
} }
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
@@ -494,8 +483,7 @@ static int AnstoHttpContinue(pHistDriver self, SConnection *pCon){
return HWFault; return HWFault;
} }
pPriv->pause = 0; pPriv->pause = 0;
// MJL force the daq status to the expected value... AnstoHttpStatusWithRetries(self,HWBusy);
StringDictUpdate(self->pOption, "daq", "Started");
return 1; return 1;
} }
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/