Dynamically allocate errmsg buffer.

Don't overwrite errorcode from read char fn.

r1057 | ffr | 2006-08-10 16:50:39 +1000 (Thu, 10 Aug 2006) | 3 lines
This commit is contained in:
Ferdi Franceschini
2006-08-10 16:50:39 +10:00
committed by Douglas Clowes
parent b61c088873
commit ab368d47a7

View File

@@ -81,6 +81,7 @@ typedef struct __MoDriv {
/* DMC-2280 specific fields */
prs232 controller;
int errorCode;
char *errorMsg; /**< Points to memory for error messages */
char units[256]; /**< physical units for axis */
float speed; /**< physical units per second */
float maxSpeed; /**< physical units per second */
@@ -244,7 +245,6 @@ static int DMC2280Send(pDMC2280Driv self, char *command) {
}
if (FAILURE == (status = DMC2280ReadChar(self, &cmdValid))) {
self->errorCode = status;
return FAILURE;
} else {
switch (cmdValid) {
@@ -569,8 +569,24 @@ static void DMC2280Error(void *pData, int *iCode, char *error, int errLen){
self = (pDMC2280Driv)pData;
assert(self != NULL);
/* Allocate errLen bytes for error messages */
if (self->errorMsg == NULL) {
self->errorMsg = (char *) malloc(errLen);
if (self->errorMsg == NULL) {
*iCode = 0;
return;
}
}
error = self->errorMsg;
*iCode = self->errorCode;
switch(*iCode){
case NOTCONNECTED:
case TIMEOUT:
case BADSEND:
case BADMEMORY:
case INCOMPLETE:
getRS232Error(*iCode, error, errLen);
break;
case BADADR:
strncpy(error,"Bad address",(size_t)errLen);
break;
@@ -618,6 +634,7 @@ static void DMC2280Error(void *pData, int *iCode, char *error, int errLen){
/* FIXME What's the default */
break;
}
self->errorCode = 0;
}
/** \brief Attempts to recover from an error. Implements the TryAndFixIt
@@ -644,6 +661,10 @@ static int DMC2280Fix(void *pData, int iCode,/*@unused@*/ float fValue){
case BADPAR:
return MOTFAIL;
case POSFAULT:
case BADSEND:
case TIMEOUT:
case BADMEMORY: /* Won't happen if MonConnect sets the send terminator */
case INCOMPLETE:
return MOTREDO;
case NOTCONNECTED:
initRS232(self->controller);
@@ -887,7 +908,10 @@ static void KillDMC2280(/*@only@*/void *pData){
pDMC2280Driv self = NULL;
self = (pDMC2280Driv)pData;
assert(self != NULL);
free(self->name);
if (self->name)
free(self->name);
if (self->errorMsg)
free(self->errorMsg);
free(self);
return;
}
@@ -973,6 +997,7 @@ static void KillDMC2280(/*@only@*/void *pData){
pNew->controller = NULL;
pNew->name = NULL;
pNew->errorCode = 0;
pNew->errorMsg = NULL;
pNew->lastCmd[0] = '\0';
pNew->dmc2280Error[0] = '\0';
pNew->absEncHome = 0;