There are now zero warnings for weak checking with splint.
Reduced number of splint standard check warnings to 4 r1016 | ffr | 2006-06-01 17:07:33 +1000 (Thu, 01 Jun 2006) | 3 lines
This commit is contained in:
committed by
Douglas Clowes
parent
52b57c96cd
commit
38b6e44306
@@ -36,9 +36,10 @@
|
||||
/*@-incondefs@*/
|
||||
/* XXX Should this also free pData */
|
||||
int readRS232(prs232 self, /*@out@*/void *data, /*@out@*/int *dataLen);
|
||||
int readRS232TillTerm(prs232 self, /*@out@*/void *data, int *datalen);
|
||||
void KillRS232(/*@only@*/ void *pData);
|
||||
/*@only@*/ char *Tcl_GetVar2(Tcl_Interp *interp, char *name1, char *name2, int flags);
|
||||
/*@observer@*/ Tcl_Interp *InterpGetTcl(SicsInterp *pSics);
|
||||
/*@observer@*/ char *Tcl_GetVar2(Tcl_Interp *interp, char *name1, char *name2, int flags);
|
||||
/*@observer@*//*@dependent@*/ Tcl_Interp *InterpGetTcl(SicsInterp *pSics);
|
||||
/*@+incondefs@*/
|
||||
/*-----------------------------------------------------------------------
|
||||
The motor driver structure. Please note that the first set of fields has
|
||||
@@ -48,32 +49,30 @@ typedef struct __MoDriv {
|
||||
/* general motor driver interface
|
||||
fields. _REQUIRED!
|
||||
*/
|
||||
/*@-incondefs@*/
|
||||
float fUpper; /* upper limit */
|
||||
float fLower; /* lower limit */
|
||||
char *name;
|
||||
int (*GetPosition)(void *self,float *fPos);
|
||||
int (*RunTo)(void *self, float fNewVal);
|
||||
int (*GetStatus)(void *self);
|
||||
void (*GetError)(void *self, int *iCode, char *buffer, int iBufLen);
|
||||
int (*TryAndFixIt)(void *self,int iError, float fNew);
|
||||
int (*Halt)(void *self);
|
||||
int (*GetDriverPar)(void *self, char *name,
|
||||
/*@owned@*/char *name;
|
||||
int (*GetPosition)(/*@dependent@*/void *self, float *fPos);
|
||||
int (*RunTo)(/*@dependent@*/void *self, float fNewVal);
|
||||
int (*GetStatus)(/*@dependent@*/void *self);
|
||||
void (*GetError)(/*@dependent@*/void *self, int *iCode, char *buffer, int iBufLen);
|
||||
int (*TryAndFixIt)(/*@dependent@*/void *self,int iError, float fNew);
|
||||
int (*Halt)(/*@dependent@*/void *self);
|
||||
int (*GetDriverPar)(/*@dependent@*/void *self, char *name,
|
||||
float *value);
|
||||
int (*SetDriverPar)(void *self,SConnection *pCon,
|
||||
int (*SetDriverPar)(/*@dependent@*/void *self,SConnection *pCon,
|
||||
char *name, float newValue);
|
||||
void (*ListDriverPar)(void *self, char *motorName,
|
||||
void (*ListDriverPar)(/*@dependent@*/void *self, char *motorName,
|
||||
SConnection *pCon);
|
||||
void (*KillPrivate)(void *self);
|
||||
void (*KillPrivate)(/*@dependent@*/void *self);
|
||||
/*@+incondefs@*/
|
||||
|
||||
|
||||
/* DMC-2280 specific fields */
|
||||
SConnection *pCon;
|
||||
/*@observer@*//*@dependent@*/SConnection *pCon;
|
||||
prs232 controller;
|
||||
int iMotor;
|
||||
int errorCode;
|
||||
int oredMsr;
|
||||
int lastValue;
|
||||
int iConfig;
|
||||
char units[256]; /**< physical units for axis */
|
||||
float speed; /**< physical units per second */
|
||||
float maxSpeed; /**< physical units per second */
|
||||
@@ -134,14 +133,14 @@ typedef struct __MoDriv {
|
||||
#define DECEL "decel"
|
||||
#define MAXDECEL "maxDecel"
|
||||
|
||||
static int DMC2280Receive(pDMC2280Driv self, /*@out@*/ char *reply);
|
||||
static int DMC2280Receive(/*@dependent@*/pDMC2280Driv self, /*@out@*/ char *reply);
|
||||
|
||||
/** \brief Convert motor speed from physical units to steps/sec
|
||||
* \param self (r) provides access to the motor's data structure
|
||||
* \param speed in physical units, eg mm/sec degrees/sec
|
||||
* \return the speed in motor steps/sec
|
||||
*/
|
||||
static int motSpeed(pDMC2280Driv self, float speed) {
|
||||
static int motSpeed(/*@dependent@*/pDMC2280Driv self, float speed) {
|
||||
int motSpeed;
|
||||
motSpeed = abs((int)(speed * self->stepsPerX + 0.5));
|
||||
return motSpeed;
|
||||
@@ -152,7 +151,7 @@ static int motSpeed(pDMC2280Driv self, float speed) {
|
||||
* \param acceleration in physical units, eg mm/sec^2 degrees/sec^2
|
||||
* \return the acceleration in motor steps/sec^2
|
||||
*/
|
||||
static int motAccel(pDMC2280Driv self, float accel) {
|
||||
static int motAccel(/*@dependent@*/pDMC2280Driv self, float accel) {
|
||||
int motAccel;
|
||||
motAccel = abs((int)(accel * self->stepsPerX + 0.5));
|
||||
return motAccel;
|
||||
@@ -163,7 +162,7 @@ static int motAccel(pDMC2280Driv self, float accel) {
|
||||
* \param deceleration in physical units, eg mm/sec^2 degrees/sec^2
|
||||
* \return the deceleration in motor steps/sec^2
|
||||
*/
|
||||
static int motDecel(pDMC2280Driv self, float decel) {
|
||||
static int motDecel(/*@dependent@*/pDMC2280Driv self, float decel) {
|
||||
int motDecel;
|
||||
motDecel = abs((int)(decel * self->stepsPerX + 0.5));
|
||||
return motDecel;
|
||||
@@ -179,8 +178,9 @@ static int motDecel(pDMC2280Driv self, float decel) {
|
||||
* - FAILURE
|
||||
* \see SUCCESS FAILURE
|
||||
*/
|
||||
static int DMC2280ReadChar(pDMC2280Driv self, /*@out@*/char *reply) {
|
||||
static int DMC2280ReadChar(/*@dependent@*/pDMC2280Driv self, /*@out@*/char *reply) {
|
||||
int i, status, retries=20, dataLen=1;
|
||||
reply[0] = '\0';
|
||||
for (i=0; i<retries; i++) {
|
||||
status=readRS232(self->controller, reply, &dataLen);
|
||||
switch (status) {
|
||||
@@ -213,13 +213,15 @@ static int DMC2280ReadChar(pDMC2280Driv self, /*@out@*/char *reply) {
|
||||
/* First character returned by controller is
|
||||
'?' for an invalid command or
|
||||
':' or space for a valid command */
|
||||
static int DMC2280Send(pDMC2280Driv self, /*@unique@*/char *command) {
|
||||
static int DMC2280Send(/*@dependent@*/pDMC2280Driv self, /*@observer@*//*@dependent@*/char *command) {
|
||||
char cmdValid, pError[ERRLEN], reply[256];
|
||||
char *GetEMsg = "TC 1";
|
||||
int status;
|
||||
|
||||
strncpy(self->lastCmd, command, CMDLEN);
|
||||
/*@+matchanyintegral@ let size_t from strlen match int */
|
||||
status = writeRS232(self->controller, command, strlen(command));
|
||||
/*@-matchanyintegral@*/
|
||||
if (status != 1) {
|
||||
self->errorCode = status;
|
||||
return FAILURE;
|
||||
@@ -234,7 +236,9 @@ static int DMC2280Send(pDMC2280Driv self, /*@unique@*/char *command) {
|
||||
case ' ':
|
||||
return SUCCESS;
|
||||
case '?':
|
||||
/*@+matchanyintegral@ let size_t from strlen match int */
|
||||
status = writeRS232(self->controller, GetEMsg, strlen(GetEMsg));
|
||||
/*@-matchanyintegral@*/
|
||||
if (status != 1) {
|
||||
self->errorCode = status;
|
||||
return FAILURE;
|
||||
@@ -264,8 +268,9 @@ static int DMC2280Send(pDMC2280Driv self, /*@unique@*/char *command) {
|
||||
* - FAILURE
|
||||
* \see SUCCESS FAILURE
|
||||
*/
|
||||
static int DMC2280Receive(pDMC2280Driv self, /*@out@*/char *reply) {
|
||||
static int DMC2280Receive(/*@dependent@*/pDMC2280Driv self, /*@out@*/char *reply) {
|
||||
int i, status, retries=20, dataLen=255;
|
||||
reply[0] = '\0';
|
||||
for (i=0; i<retries; i++) {
|
||||
status=readRS232TillTerm(self->controller, reply, &dataLen);
|
||||
switch (status) {
|
||||
@@ -292,7 +297,7 @@ static int DMC2280Receive(pDMC2280Driv self, /*@out@*/char *reply) {
|
||||
* - OKOK request succeeded
|
||||
* - HWFault request failed
|
||||
* */
|
||||
static int DMC2280GetPos(void *pData, float *fPos){
|
||||
static int DMC2280GetPos(/*@dependent@*/void *pData, float *fPos){
|
||||
pDMC2280Driv self = NULL;
|
||||
char reply[1024];
|
||||
char cmd[CMDLEN];
|
||||
@@ -330,7 +335,7 @@ static int DMC2280GetPos(void *pData, float *fPos){
|
||||
* - OKOK request succeeded
|
||||
* - HWFault request failed
|
||||
* */
|
||||
static int DMC2280Run(void *pData,float fValue){
|
||||
static int DMC2280Run(/*@dependent@*/void *pData,float fValue){
|
||||
pDMC2280Driv self = NULL;
|
||||
char axis;
|
||||
char cmd[CMDLEN], SH[CMDLEN], BG[CMDLEN], absPosCmd[CMDLEN];
|
||||
@@ -381,7 +386,7 @@ static int DMC2280Run(void *pData,float fValue){
|
||||
* - HWWarn There is a warning from the controller.
|
||||
* - HWIdle The motor has finished driving and is idle.
|
||||
*/
|
||||
static int DMC2280Status(void *pData){
|
||||
static int DMC2280Status(/*@dependent@*/void *pData){
|
||||
pDMC2280Driv self = NULL;
|
||||
char cmd[CMDLEN];
|
||||
int switches;
|
||||
@@ -462,7 +467,7 @@ static int DMC2280Status(void *pData){
|
||||
* \param *error error message
|
||||
* \param errLen maximum error message length allowed by abstract motor
|
||||
*/
|
||||
static void DMC2280Error(void *pData, int *iCode, char *error, int errLen){
|
||||
static void DMC2280Error(/*@dependent@*/void *pData, int *iCode, char *error, int errLen){
|
||||
pDMC2280Driv self = NULL;
|
||||
self = (pDMC2280Driv)pData;
|
||||
assert(self != NULL);
|
||||
@@ -530,7 +535,7 @@ static void DMC2280Error(void *pData, int *iCode, char *error, int errLen){
|
||||
* - MOTREDO try to redo the last move.
|
||||
* - MOTFAIL move failed, give up.
|
||||
*/
|
||||
static int DMC2280Fix(void *pData, int iCode,/*@unused@*/ float fValue){
|
||||
static int DMC2280Fix(/*@dependent@*/void *pData, int iCode,/*@unused@*/ float fValue){
|
||||
pDMC2280Driv self = NULL;
|
||||
|
||||
self = (pDMC2280Driv)pData;
|
||||
@@ -560,7 +565,7 @@ static int DMC2280Fix(void *pData, int iCode,/*@unused@*/ float fValue){
|
||||
*
|
||||
* XXX Does abstract motor use the return values?
|
||||
*/
|
||||
static int DMC2280Halt(void *pData){
|
||||
static int DMC2280Halt(/*@dependent@*/void *pData){
|
||||
pDMC2280Driv self = NULL;
|
||||
char cmd[CMDLEN];
|
||||
|
||||
@@ -593,7 +598,7 @@ static int DMC2280Halt(void *pData){
|
||||
* - 1 request succeeded
|
||||
* - 0 request failed
|
||||
* */
|
||||
static int DMC2280GetPar(void *pData, char *name,
|
||||
static int DMC2280GetPar(/*@dependent@*/void *pData, char *name,
|
||||
float *fValue){
|
||||
pDMC2280Driv self = NULL;
|
||||
|
||||
@@ -651,7 +656,7 @@ static int DMC2280GetPar(void *pData, char *name,
|
||||
* - 1 request succeeded
|
||||
* - 0 request failed
|
||||
* */
|
||||
static int DMC2280SetPar(void *pData, SConnection *pCon,
|
||||
static int DMC2280SetPar(/*@dependent@*/void *pData, SConnection *pCon,
|
||||
char *name, float newValue){
|
||||
pDMC2280Driv self = NULL;
|
||||
char pError[ERRLEN];
|
||||
@@ -749,7 +754,7 @@ static int DMC2280SetPar(void *pData, SConnection *pCon,
|
||||
* \param *name (r) name of motor.
|
||||
* \param *pCon (r) connection object.
|
||||
*/
|
||||
static void DMC2280List(void *self, char *name, SConnection *pCon){
|
||||
static void DMC2280List(/*@dependent@*/void *self, char *name, SConnection *pCon){
|
||||
char buffer[BUFFLEN];
|
||||
|
||||
snprintf(buffer, BUFFLEN, "%s.axis = %c\n", name, ((pDMC2280Driv)self)->axisLabel);
|
||||
@@ -775,7 +780,7 @@ static void DMC2280List(void *self, char *name, SConnection *pCon){
|
||||
/** \brief Free memory if motor is removed
|
||||
* \param *pData (rw) provides access to the motor's data structure
|
||||
*/
|
||||
static void KillDMC2280(void *pData){
|
||||
static void KillDMC2280(/*@only@*/void *pData){
|
||||
pDMC2280Driv self = NULL;
|
||||
self = (pDMC2280Driv)pData;
|
||||
assert(self != NULL);
|
||||
@@ -790,7 +795,7 @@ static void KillDMC2280(void *pData){
|
||||
* \param port DMC2280 port number
|
||||
* \return controller structure
|
||||
*/
|
||||
/*@null@ @only@*/ static prs232 DMC2280Connect(SConnection *pCon, char *host, int port) {
|
||||
/*@null@*/ /*@only@*/ static prs232 DMC2280Connect(/*@dependent@*/SConnection *pCon, char *host, int port) {
|
||||
prs232 controller=NULL;
|
||||
char pError[ERRLEN];
|
||||
int usecTimeout = 50000; /* 50msec timeout */
|
||||
@@ -828,7 +833,7 @@ static void KillDMC2280(void *pData){
|
||||
* - _OPTIONAL
|
||||
* \return a string with the parameter value
|
||||
*/
|
||||
/*@observer@*/static char *getParam(SConnection *pCon, Tcl_Interp *pTcl, char *params, char *parName, int mustHave ) {
|
||||
/*@observer@*/static char *getParam(/*@dependent@*/SConnection *pCon, Tcl_Interp *pTcl, char *params, char *parName, int mustHave ) {
|
||||
char *pPtr=NULL;
|
||||
char pError[ERRLEN];
|
||||
pPtr = Tcl_GetVar2(pTcl,params,parName,TCL_GLOBAL_ONLY);
|
||||
@@ -837,7 +842,7 @@ static void KillDMC2280(void *pData){
|
||||
SCWrite(pCon,pError, eError);
|
||||
}
|
||||
return pPtr;
|
||||
}
|
||||
}
|
||||
|
||||
/** \brief Create a driver for the DMC2280 Galil controller.
|
||||
*
|
||||
@@ -855,8 +860,8 @@ static void KillDMC2280(void *pData){
|
||||
* \param *params (r) configuration parameter array.
|
||||
* \return a reference to Motordriver structure
|
||||
*/
|
||||
/*@null@*/ MotorDriver *CreateDMC2280(SConnection *pCon, char *motor, char *params){
|
||||
/*@keep@*/ pDMC2280Driv pNew = NULL;
|
||||
/*@only@*//*@null@*/ MotorDriver *CreateDMC2280(/*@observer@*/SConnection *pCon, /*@observer@*/char *motor, /*@observer@*/char *params){
|
||||
pDMC2280Driv pNew = NULL;
|
||||
char *pPtr = NULL;
|
||||
char buffer[132];
|
||||
char pError[ERRLEN];
|
||||
@@ -877,30 +882,39 @@ static void KillDMC2280(void *pData){
|
||||
eError);
|
||||
return NULL;
|
||||
}
|
||||
pNew->controller = NULL;
|
||||
pNew->name = NULL;
|
||||
pNew->errorCode = 0;
|
||||
pNew->lastCmd = NULL;
|
||||
pNew->absEncHome = 0;
|
||||
pNew->cntsPerX = 0;
|
||||
/* Get hostname and port from the list of named parameters */
|
||||
if ((pPtr=getParam(pCon, interp, params,"port",1)) == NULL)
|
||||
goto FailedCreateDMC2280;
|
||||
if ((pPtr=getParam(pCon, interp, params,"port",1)) == NULL) {
|
||||
KillDMC2280(pNew);
|
||||
return NULL;
|
||||
}
|
||||
sscanf(pPtr,"%d",&port);
|
||||
if ((pPtr=getParam(pCon, interp, params,"host",1)) == NULL)
|
||||
goto FailedCreateDMC2280;
|
||||
if ((pPtr=getParam(pCon, interp, params,"host",1)) == NULL) {
|
||||
KillDMC2280(pNew);
|
||||
return NULL;
|
||||
}
|
||||
strncpy(buffer,pPtr, 131);
|
||||
|
||||
/* Connect to the controller */
|
||||
memset(pNew,0,sizeof(DMC2280Driv));
|
||||
pNew->controller = DMC2280Connect(pCon, buffer,port);
|
||||
if( pNew->controller == NULL ) {
|
||||
snprintf(pError, ERRLEN, "\tError occurred when creating DMC2280 motor '%s'", motor);
|
||||
SCWrite(pCon,pError,eError);
|
||||
goto FailedCreateDMC2280;
|
||||
SCWrite(pCon,pError,eError);
|
||||
KillDMC2280(pNew);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*FIXME Tell splint that there's no memory leak because pointers are being initialised here */
|
||||
/*@-mustfreeonly@*/
|
||||
pNew->name = (char *)malloc(sizeof(char)*(strlen(motor)+1));
|
||||
if (pNew->name == NULL) {
|
||||
(void) SCWrite(pCon,"ERROR: no memory to allocate motor driver",
|
||||
eError);
|
||||
free(pNew);
|
||||
KillDMC2280(pNew);
|
||||
return NULL;
|
||||
}
|
||||
strcpy(pNew->name, motor);
|
||||
@@ -918,26 +932,38 @@ static void KillDMC2280(void *pData){
|
||||
pNew->SetDriverPar = DMC2280SetPar;
|
||||
pNew->ListDriverPar = DMC2280List;
|
||||
pNew->KillPrivate = KillDMC2280;
|
||||
if ((pPtr=getParam(pCon, interp, params,UNITS,_REQUIRED)) == NULL)
|
||||
goto FailedCreateDMC2280;
|
||||
if ((pPtr=getParam(pCon, interp, params,UNITS,_REQUIRED)) == NULL) {
|
||||
KillDMC2280(pNew);
|
||||
return NULL;
|
||||
}
|
||||
sscanf(pPtr,"%s",pNew->units);
|
||||
if ((pPtr=getParam(pCon, interp, params,MAXSPEED,_REQUIRED)) == NULL)
|
||||
goto FailedCreateDMC2280;
|
||||
if ((pPtr=getParam(pCon, interp, params,MAXSPEED,_REQUIRED)) == NULL) {
|
||||
KillDMC2280(pNew);
|
||||
return NULL;
|
||||
}
|
||||
sscanf(pPtr,"%f",&(pNew->speed));
|
||||
pNew->maxSpeed = pNew->speed;
|
||||
if ((pPtr=getParam(pCon, interp, params,MAXACCEL,_REQUIRED)) == NULL)
|
||||
goto FailedCreateDMC2280;
|
||||
if ((pPtr=getParam(pCon, interp, params,MAXACCEL,_REQUIRED)) == NULL) {
|
||||
KillDMC2280(pNew);
|
||||
return NULL;
|
||||
}
|
||||
sscanf(pPtr,"%f",&(pNew->accel));
|
||||
pNew->maxAccel = pNew->accel;
|
||||
if ((pPtr=getParam(pCon, interp, params,MAXDECEL,_REQUIRED)) == NULL)
|
||||
goto FailedCreateDMC2280;
|
||||
if ((pPtr=getParam(pCon, interp, params,MAXDECEL,_REQUIRED)) == NULL) {
|
||||
KillDMC2280(pNew);
|
||||
return NULL;
|
||||
}
|
||||
sscanf(pPtr,"%f",&(pNew->decel));
|
||||
pNew->maxDecel = pNew->decel;
|
||||
if ((pPtr=getParam(pCon, interp, params,"axis",_REQUIRED)) == NULL)
|
||||
goto FailedCreateDMC2280;
|
||||
if ((pPtr=getParam(pCon, interp, params,"axis",_REQUIRED)) == NULL) {
|
||||
KillDMC2280(pNew);
|
||||
return NULL;
|
||||
}
|
||||
sscanf(pPtr,"%c",&(pNew->axisLabel));
|
||||
if ((pPtr=getParam(pCon, interp, params,"stepsPerX",_REQUIRED)) == NULL)
|
||||
goto FailedCreateDMC2280;
|
||||
if ((pPtr=getParam(pCon, interp, params,"stepsPerX",_REQUIRED)) == NULL) {
|
||||
KillDMC2280(pNew);
|
||||
return NULL;
|
||||
}
|
||||
sscanf(pPtr,"%d",&(pNew->stepsPerX));
|
||||
if ((pPtr=getParam(pCon, interp, params,"motorHome",_OPTIONAL)) == NULL)
|
||||
pNew->motorHome=0;
|
||||
@@ -956,7 +982,6 @@ static void KillDMC2280(void *pData){
|
||||
else
|
||||
sscanf(pPtr,"%d",&(pNew->cntsPerX));
|
||||
}
|
||||
/*@+mustfreeonly@*/
|
||||
|
||||
/* Set speed */
|
||||
snprintf(cmd,CMDLEN,"SP%c=%d", pNew->axisLabel, motSpeed(pNew, pNew->speed));
|
||||
@@ -972,10 +997,6 @@ static void KillDMC2280(void *pData){
|
||||
exit(EXIT_FAILURE);
|
||||
/* TODO Initialise current position and target to get a sensible initial list output */
|
||||
return (MotorDriver *)pNew;
|
||||
FailedCreateDMC2280:
|
||||
if (NULL != pNew)
|
||||
free(pNew);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user