- A couple of small fixes for memory and initialization problems.

This is to make valgrind happy
This commit is contained in:
koennecke
2005-01-12 08:43:02 +00:00
parent 427855306a
commit 000bb7b4a8
4 changed files with 78 additions and 18 deletions

View File

@ -57,6 +57,7 @@
int oredMsr;
int posCount;
int runCount;
char errorReply[80];
} EL734Driv, *pEL734Driv;
/*------------------- error codes ----------------------------------*/
#define BADADR -1
@ -97,7 +98,10 @@ static int checkResponse(pEL734Driv self, char *pReply){
self->errorCode = BADRNG;
}else if(strstr(pReply,"*es") != NULL){
self->errorCode = BADEMERG;
}else if(strstr(pReply,"*ms") != NULL){
self->errorCode = BADSTP;
} else {
strncpy(self->errorReply,pReply,79);
self->errorCode = BADUNKNOWN;
}
return 0;
@ -295,10 +299,11 @@ static void EL734Error(void *pData, int *iCode, char *error, int errLen){
strncpy(error,"Bad range",errLen);
break;
case BADUNKNOWN:
strncpy(error,"Unknown error condition",errLen);
snprintf(pBueffel,131,"Unknown response: %s",self->errorReply);
strncpy(error,pBueffel,errLen);
break;
case BADSTP:
strncpy(error,"Motor is switeched off at motor controller",errLen);
strncpy(error,"Motor is switched off at motor controller",errLen);
break;
case BADEMERG:
strncpy(error,"Emergency stop is engaged, please release",errLen);
@ -383,17 +388,62 @@ static int EL734Halt(void *pData){
return 1;
}
/*--------------------------------------------------------------------*/
static int EL734GetPar(void *self, char *name,
static int EL734GetPar(void *pData, char *name,
float *fValue){
pEL734Driv self = NULL;
int status;
char pCommand[50],pReply[80];
self = (pEL734Driv)pData;
assert(self);
if(strcmp(name,"speed") == 0){
snprintf(pCommand,79,"J %d\r",self->iMotor);
status = transactRS232(self->controller,pCommand,strlen(pCommand),
pReply,79);
if(status != 1){
self->errorCode = status;
return 0;
}
if(!checkResponse(self,pReply)){
return 0;
}
sscanf(pReply,"%f",fValue);
return 1;
}
return 0;
}
/*--------------------------------------------------------------------*/
static int EL734SetPar(void *self, SConnection *pCon,
static int EL734SetPar(void *pData, SConnection *pCon,
char *name, float newValue){
pEL734Driv self = NULL;
int status;
char pCommand[50],pReply[80];
self = (pEL734Driv)pData;
assert(self);
if(strcmp(name,"speed") == 0){
snprintf(pCommand,79,"J %d %d\r",self->iMotor,(int)newValue);
status = transactRS232(self->controller,pCommand,strlen(pCommand),
pReply,79);
if(status != 1){
self->errorCode = status;
return 0;
}
if(!checkResponse(self,pReply)){
return 0;
}
return 1;
}
return 0;
}
/*--------------------------------------------------------------------*/
static void EL734List(void *self, char *name, SConnection *pCon){
float value;
char pBueffel[256];
EL734GetPar(self,"speed",&value);
snprintf(pBueffel,255,"%s speed = %f",name,value);
SCWrite(pCon,pBueffel,eValue);
return;
}
/*---------------------------------------------------------------------*/
@ -409,7 +459,7 @@ MotorDriver *CreateEL734HP(SConnection *pCon, int argc, char *argv[]){
pEL734Driv pNew = NULL;
int motor, status;
prs232 controller = NULL;
char pCommand[50],pReply[80];
char pCommand[50],pReply[80], pError[255];
/*
check arguments
@ -461,13 +511,21 @@ MotorDriver *CreateEL734HP(SConnection *pCon, int argc, char *argv[]){
snprintf(pCommand,49,"h %d\r",pNew->iMotor);
status = transactRS232(pNew->controller, pCommand,strlen(pCommand),
pReply,79);
if(!status){
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)){
sscanf(pReply,"%f %f",&pNew->fLower,&pNew->fUpper);
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);
}
} else {
SCWrite(pCon,
"ERROR: invalid response when reading HW limits, defaulting..",
@ -476,6 +534,8 @@ MotorDriver *CreateEL734HP(SConnection *pCon, int argc, char *argv[]){
pNew->fUpper = 180.;
}
}
snprintf(pError,255,"EL734 returned HW-limits of: %s", pReply);
SCWrite(pCon,pError,eError);
return (MotorDriver *)pNew;
}