- A couple of small fixes for memory and initialization problems.
This is to make valgrind happy
This commit is contained in:
@ -59,7 +59,7 @@
|
||||
if(pVar)
|
||||
{
|
||||
fVal = pVar->pInter->GetValue(pVar->pObject,self->pCon);
|
||||
pVar->fData[iP] = fVal;
|
||||
AppendScanVar(pVar,fVal);
|
||||
sprintf(pItem,"%-10.10s",pVar->Name);
|
||||
strcat(pHead,pItem);
|
||||
sprintf(pItem,"%-10.3f",fVal);
|
||||
|
74
el734hp.c
74
el734hp.c
@ -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;
|
||||
}
|
||||
|
||||
|
18
tasscan.c
18
tasscan.c
@ -30,6 +30,7 @@
|
||||
#include <scan.i>
|
||||
#include "tas.h"
|
||||
#include "tasu.h"
|
||||
#include "../scanvar.h"
|
||||
#include <evcontroller.h>
|
||||
#include <splitter.h>
|
||||
#include <status.h>
|
||||
@ -233,9 +234,9 @@ static int TASHeader(pScanData self)
|
||||
pVar = (pVarEntry)pPtr;
|
||||
if(pVar)
|
||||
{
|
||||
strncpy(pWork2,pVar->Name,59);
|
||||
strncpy(pWork2,ScanVarName(pVar),59);
|
||||
strtoupper(pWork2);
|
||||
sprintf(pWork,"D%s=%8.4f, ",pWork2,pVar->fStep);
|
||||
sprintf(pWork,"D%s=%8.4f, ",pWork2,ScanVarStep(pVar));
|
||||
strcat(pBueffel,pWork);
|
||||
}
|
||||
}
|
||||
@ -514,9 +515,9 @@ static int TASScanPoint(pScanData self, int iPoint)
|
||||
pVar = (pVarEntry)pPtr;
|
||||
if(pVar)
|
||||
{
|
||||
if(isTASMotor(pVar->Name) >= 0)
|
||||
if(isTASMotor(ScanVarName(pVar)) >= 0)
|
||||
{
|
||||
pMot = FindMotor(self->pSics,pVar->Name);
|
||||
pMot = FindMotor(self->pSics,ScanVarName(pVar));
|
||||
if(pMot)
|
||||
{
|
||||
status = MotorGetSoftPosition(pMot,self->pCon,&fVal);
|
||||
@ -648,13 +649,13 @@ static int TASScanDrive(pScanData self, int iPoint)
|
||||
if(pVar)
|
||||
{
|
||||
/* set variable if QE-variable */
|
||||
if((iPtr = isTASEnergy(pVar->Name)) >= 0)
|
||||
if((iPtr = isTASEnergy(ScanVarName(pVar))) >= 0)
|
||||
{
|
||||
iTAS = 1;
|
||||
pTAS->tasPar[EI+iPtr]->fVal =
|
||||
pVar->fStart + iPoint * pVar->fStep;
|
||||
ScanVarStart(pVar) + iPoint * ScanVarStep(pVar);
|
||||
pTAS->tasPar[ETARGET+iPtr]->fVal =
|
||||
pVar->fStart + iPoint * pVar->fStep;
|
||||
ScanVarStart(pVar) + iPoint * ScanVarStep(pVar);
|
||||
tasMask[iPtr] = 1;
|
||||
}
|
||||
else
|
||||
@ -836,7 +837,7 @@ static int TASScanCount(pScanData self, int iPoint)
|
||||
MotorGetSoftPosition(pMot,self->pCon,&fVal);
|
||||
}
|
||||
}
|
||||
pVar->fData[iPoint] = fVal;
|
||||
AppendScanVar(pVar,fVal);
|
||||
}
|
||||
}
|
||||
|
||||
@ -929,7 +930,6 @@ static int AddTASScanVar(pScanData self, SicsInterp *pSics, SConnection *pCon,
|
||||
pVar.pObject = pData;
|
||||
pVar.fStart = fStart;
|
||||
pVar.fStep = fStep;
|
||||
pVar.fData = NULL;
|
||||
|
||||
/* put it away */
|
||||
DynarPutCopy(self->pScanVar,self->iScanVar,&pVar,sizeof(VarEntry));
|
||||
|
Reference in New Issue
Block a user