- Added makefile_slinux
- Changed mesure to be a silver bullet
This commit is contained in:
@@ -37,6 +37,10 @@ typedef struct {
|
||||
NoBeam and Counting status if the beam goes off
|
||||
*/
|
||||
char *badReply;
|
||||
int readErrorCount; /* need to remember failed reads: on RDOE, upper level
|
||||
code will see busy's and thus not catch the case of
|
||||
multiple failures
|
||||
*/
|
||||
} EL737hp, *pEL737hp;
|
||||
/*--------------------- ERROR CODES -------------------------------------*/
|
||||
#define OFFLINE -1
|
||||
@@ -49,6 +53,7 @@ typedef struct {
|
||||
#define BADREPLY -10
|
||||
#define SELECTFAIL -11
|
||||
#define TIMEOUT737 -12
|
||||
#define TOMANYREADERRORS -23
|
||||
/*---------------------------------------------------------------------*/
|
||||
static void setBadReply(pEL737hp self, char *reply){
|
||||
if(self->badReply != NULL){
|
||||
@@ -133,20 +138,24 @@ static int readRS(pEL737hp pPriv, int *RS){
|
||||
status = readRS232TillTerm(pPriv->controller,
|
||||
reply,&len);
|
||||
if(status < 0) {
|
||||
pPriv->readErrorCount++;
|
||||
pPriv->errorCode = status;
|
||||
return 0;
|
||||
}
|
||||
status = checkEL737Error(reply);
|
||||
if(status < 0){
|
||||
pPriv->readErrorCount++;
|
||||
pPriv->errorCode = status;
|
||||
return 0;
|
||||
}
|
||||
status = sscanf(reply,"%d",RS);
|
||||
if(status < 1){
|
||||
pPriv->readErrorCount++;
|
||||
pPriv->errorCode = BADREPLY;
|
||||
setBadReply(pPriv,reply);
|
||||
return 0;
|
||||
}
|
||||
pPriv->readErrorCount = 0;
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------*/
|
||||
@@ -239,7 +248,11 @@ static int EL737Status(struct __COUNTER *self, float *fControl){
|
||||
handle STATSEND mode
|
||||
*/
|
||||
if(pPriv->statusMode == STATSEND){
|
||||
writeRS232(pPriv->controller,"RS\r",3);
|
||||
status = writeRS232(pPriv->controller,"RS\r",3);
|
||||
if(status < 0){
|
||||
pPriv->errorCode = status;
|
||||
return HWFault;
|
||||
}
|
||||
pPriv->statusMode = STATRECEIVE;
|
||||
pPriv->startRequest = time(NULL);
|
||||
*fControl = pPriv->cachedControl;
|
||||
@@ -253,6 +266,7 @@ static int EL737Status(struct __COUNTER *self, float *fControl){
|
||||
if(time(NULL) > pPriv->startRequest + 10){
|
||||
pPriv->statusMode = STATSEND;
|
||||
pPriv->errorCode = TIMEOUT737;
|
||||
pPriv->readErrorCount++;
|
||||
return HWFault;
|
||||
}
|
||||
|
||||
@@ -285,6 +299,14 @@ static int EL737Status(struct __COUNTER *self, float *fControl){
|
||||
returnValue = decodeRS(pPriv,RS);
|
||||
pPriv->lastStatus = returnValue;
|
||||
|
||||
/*
|
||||
check for excessive failed reads
|
||||
*/
|
||||
if(pPriv->readErrorCount > 3){
|
||||
pPriv->errorCode = TOMANYREADERRORS;
|
||||
return HWFault;
|
||||
}
|
||||
|
||||
/*
|
||||
check if we update the monitors and do it
|
||||
*/
|
||||
@@ -310,6 +332,7 @@ static int EL737Start(struct __COUNTER *self){
|
||||
pPriv = (pEL737hp)self->pData;
|
||||
|
||||
fixMode(pPriv);
|
||||
pPriv->readErrorCount = 0;
|
||||
if(self->eMode == ePreset){
|
||||
snprintf(pCommand,49,"MP %d\r",(int)self->fPreset);
|
||||
} else {
|
||||
@@ -414,8 +437,13 @@ static int EL737GetError(struct __COUNTER *self, int *iCode,
|
||||
break;
|
||||
case SELECTFAIL:
|
||||
strncpy(pError,"select system call failed, network trouble",errLen);
|
||||
break;
|
||||
case TIMEOUT737:
|
||||
strncpy(pError,"timeout waiting for status repsonse",errLen);
|
||||
strncpy(pError,"timeout or network problem while waiting for status repsonse",errLen);
|
||||
break;
|
||||
case TOMANYREADERRORS:
|
||||
strncpy(pError,"Failed more then three times to read counter box",errLen);
|
||||
break;
|
||||
default:
|
||||
getRS232Error(pPriv->errorCode,pError,errLen);
|
||||
}
|
||||
@@ -428,29 +456,39 @@ static int EL737FixIt(struct __COUNTER *self, int iCode){
|
||||
char pReply[50];
|
||||
char buffer[256];
|
||||
int dataLen = 255;
|
||||
int i;
|
||||
|
||||
assert(self);
|
||||
pPriv = (pEL737hp)self->pData;
|
||||
|
||||
switch(iCode){
|
||||
case TIMEOUT:
|
||||
case BADPARAM:
|
||||
case NOPARAM:
|
||||
case BADRANGE:
|
||||
case BADTRANGE:
|
||||
case TIMEOUT737:
|
||||
return COREDO;
|
||||
break;
|
||||
case BADREPLY:
|
||||
/*
|
||||
try to read away all the garbage which may still be in the line
|
||||
*/
|
||||
if(availableRS232(pPriv->controller) > 0){
|
||||
memset(buffer,0,256);
|
||||
readRS232(pPriv->controller,buffer,&dataLen);
|
||||
printf("EL737hpdriv dumped %s after bad reply\n", buffer);
|
||||
case TIMEOUT737:
|
||||
case TIMEOUT:
|
||||
for(i = 0; i < 3; i++){
|
||||
status = readRS232TillTerm(pPriv->controller,buffer,&dataLen);
|
||||
if(status == 1){
|
||||
return COREDO;
|
||||
}
|
||||
}
|
||||
/*
|
||||
If nothing can be read, the only fixable cause is a network breakdown
|
||||
Try to fix this. If this does not work: give up
|
||||
*/
|
||||
closeRS232(pPriv->controller);
|
||||
SicsWait(60);
|
||||
status = initRS232(pPriv->controller);
|
||||
if(status != 1){
|
||||
return COTERM;
|
||||
} else {
|
||||
return COREDO;
|
||||
}
|
||||
return COREDO;
|
||||
break;
|
||||
case OFFLINE:
|
||||
EL737Command(pPriv,"RMT 1\r",pReply,49);
|
||||
@@ -463,12 +501,13 @@ static int EL737FixIt(struct __COUNTER *self, int iCode){
|
||||
break;
|
||||
case TOMANYCOUNTS:
|
||||
case SYSERROR:
|
||||
return COTERM;
|
||||
break;
|
||||
default:
|
||||
/*
|
||||
network problem; try to reopen
|
||||
*/
|
||||
closeRS232(pPriv->controller);
|
||||
SicsWait(60);
|
||||
status = initRS232(pPriv->controller);
|
||||
if(status != 1){
|
||||
return COTERM;
|
||||
|
||||
Reference in New Issue
Block a user