- Added makefile_slinux

- Changed mesure to be a silver bullet
This commit is contained in:
koennecke
2005-03-03 13:54:22 +00:00
parent 000bb7b4a8
commit 835177dc0a
7 changed files with 137 additions and 68 deletions

118
el734hp.c
View File

@ -18,6 +18,7 @@
#include <assert.h>
#include <string.h>
#include <fortify.h>
#include <time.h>
#include <sics.h>
#include <modriv.h>
#include <rs232controller.h>
@ -58,6 +59,7 @@
int posCount;
int runCount;
char errorReply[80];
time_t valueExpiry;
} EL734Driv, *pEL734Driv;
/*------------------- error codes ----------------------------------*/
#define BADADR -1
@ -115,6 +117,11 @@ static int EL734GetPos(void *pData, float *fPos){
self = (pEL734Driv)pData;
assert(self);
if(time(NULL) < self->valueExpiry){
*fPos = self->lastValue;
return OKOK;
}
snprintf(pCommand,79,"u %d\r",self->iMotor);
status = transactRS232(self->controller,pCommand,strlen(pCommand),
pReply,79);
@ -127,6 +134,7 @@ static int EL734GetPos(void *pData, float *fPos){
}
sscanf(pReply,"%f",fPos);
self->lastValue = *fPos;
self->valueExpiry = time(NULL) + 3;
return OKOK;
}
/*----------------------------------------------------------------------*/
@ -212,39 +220,6 @@ static int decodeMSR(pEL734Driv self, int msr){
}
return HWBusy;
/* inserted above line and commented out lines below M.Zolliker Sep 2004
we do not stop when a minor error message occurs, but treat these with oredMsr
if(msr & 0x10){
self->errorCode = LOWLIM;
return HWFault;
} else if(msr & 0x20){
self->errorCode = HILIM;
return HWFault;
} else if(msr & 0x80){
self->errorCode = RUNFAULT;
return HWPosFault;
} else if(msr & 0x200){
self->errorCode = POSFAULT;
return HWPosFault;
} else if(msr & 0x1000){
self->errorCode = BADCUSHION;
return HWFault;
} else if(msr & 0x8){
self->errorCode = BADSTP;
return HWFault;
} else if(msr & 0x40) {
self->errorCode = BADSTP;
return HWFault;
} else if(msr & 0x100){
self->errorCode = POSFAULT;
return HWFault;
} else if(msr & 0x400){
self->errorCode = POSFAULT;
return HWFault;
} else {
return HWBusy;
}
*/
}
}
/*------------------------------------------------------------------------*/
@ -268,6 +243,7 @@ static int EL734Status(void *pData){
}
sscanf(pReply,"%x",&msr);
self->oredMsr |= msr;
self->valueExpiry = -1;
return decodeMSR(self,msr);
}
/*----------------------------------------------------------------------*/
@ -336,7 +312,7 @@ static void EL734Error(void *pData, int *iCode, char *error, int errLen){
/*----------------------------------------------------------------------*/
static int EL734Fix(void *pData, int iCode, float fValue){
pEL734Driv self = NULL;
int status, msr;
int status, msr, i, len = 49;
char pCommand[50],pReply[80];
self = (pEL734Driv)pData;
@ -345,10 +321,30 @@ static int EL734Fix(void *pData, int iCode, float fValue){
switch(iCode){
case BADADR:
case BADCMD:
case TIMEOUT:
case BADPAR:
case BADBSY:
return MOTREDO;
case TIMEOUT:
for(i = 0; i < 3; i++){
len = 49;
status = readRS232TillTerm(self->controller,pReply,&len);
if(status == 1){
return MOTREDO;
}
}
/*
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(self->controller);
SicsWait(60);
status = initRS232(self->controller);
if(status != 1){
return MOTFAIL;
} else {
return MOTREDO;
}
break;
case BADLOC:
snprintf(pCommand,49,"RMT 1\r");
transactRS232(self->controller,pCommand,strlen(pCommand),pReply,79);
@ -363,6 +359,18 @@ static int EL734Fix(void *pData, int iCode, float fValue){
self->runCount = 0;
self->posCount = 0;
return MOTOK;
case BADSEND:
/*
network problem: try to reopen connection
*/
closeRS232(self->controller);
SicsWait(60);
status = initRS232(self->controller);
if(status != 1){
return MOTFAIL;
} else {
return MOTREDO;
}
}
return MOTFAIL;
}
@ -457,7 +465,7 @@ static void KillEL734(void *pData){
/*------------------------------------------------------------------*/
MotorDriver *CreateEL734HP(SConnection *pCon, int argc, char *argv[]){
pEL734Driv pNew = NULL;
int motor, status;
int motor, status, i, success;
prs232 controller = NULL;
char pCommand[50],pReply[80], pError[255];
@ -509,31 +517,39 @@ MotorDriver *CreateEL734HP(SConnection *pCon, int argc, char *argv[]){
connection will already have been set up, read limits
*/
snprintf(pCommand,49,"h %d\r",pNew->iMotor);
status = transactRS232(pNew->controller, pCommand,strlen(pCommand),
success = 0;
for(i = 0; i < 3; i++){
status = transactRS232(pNew->controller, pCommand,strlen(pCommand),
pReply,79);
if(status != 1){
SCWrite(pCon,"ERROR: failed to read HW limits, defaulting..",eError);
getRS232Error(status,pReply,79);
snprintf(pError,255,"ERROR: %s",pReply);
SCWrite(pCon,pError,eError);
pNew->fLower = -180.;
pNew->fUpper = 180.;
} else {
if(checkResponse(pNew,pReply)){
if(sscanf(pReply,"%f %f",&pNew->fLower,&pNew->fUpper)!= 2){
snprintf(pError,255,
if(status != 1){
getRS232Error(status,pReply,79);
snprintf(pError,255,"ERROR: %s",pReply);
SCWrite(pCon,pError,eError);
closeRS232(pNew->controller);
SicsWait(60);
initRS232(pNew->controller);
} else {
if(checkResponse(pNew,pReply)){
if(sscanf(pReply,"%f %f",&pNew->fLower,&pNew->fUpper)!= 2){
snprintf(pError,255,
"ERROR: received shitty HW limit response from SICS: %s",
pReply);
SCWrite(pCon,pError,eError);
SCWrite(pCon,pError,eError);
} else{
success = 1;
break;
}
}
} else {
}
}
if(success == 0){
SCWrite(pCon,
"ERROR: invalid response when reading HW limits, defaulting..",
eError);
pNew->fLower = -180.;
pNew->fUpper = 180.;
}
}
snprintf(pError,255,"EL734 returned HW-limits of: %s", pReply);
SCWrite(pCon,pError,eError);
return (MotorDriver *)pNew;