Clean up the space/tab mess and trailing whitespace
This commit is contained in:
@ -76,11 +76,11 @@ static int asciiToUnicode(char *input, char **output){
|
|||||||
len = strlen(input);
|
len = strlen(input);
|
||||||
result = (char *)malloc(2*len*sizeof(char));
|
result = (char *)malloc(2*len*sizeof(char));
|
||||||
if(result == NULL){
|
if(result == NULL){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memset(result,0,2*len*sizeof(char));
|
memset(result,0,2*len*sizeof(char));
|
||||||
for(i = 0; i < len; i++){
|
for(i = 0; i < len; i++){
|
||||||
result[i*2] = input[i];
|
result[i*2] = input[i];
|
||||||
}
|
}
|
||||||
*output = result;
|
*output = result;
|
||||||
return 2*len;
|
return 2*len;
|
||||||
@ -96,11 +96,11 @@ static int unicodeToAscii(char *input, int len, char **output){
|
|||||||
|
|
||||||
result = (char *)malloc((alen+1)*sizeof(char));
|
result = (char *)malloc((alen+1)*sizeof(char));
|
||||||
if(result == NULL){
|
if(result == NULL){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memset(result,0,(alen+1)*sizeof(char));
|
memset(result,0,(alen+1)*sizeof(char));
|
||||||
for(i = 0; i < alen; i++){
|
for(i = 0; i < alen; i++){
|
||||||
result[i] = input[i*2];
|
result[i] = input[i*2];
|
||||||
}
|
}
|
||||||
*output = result;
|
*output = result;
|
||||||
return alen;
|
return alen;
|
||||||
@ -108,7 +108,7 @@ static int unicodeToAscii(char *input, int len, char **output){
|
|||||||
#endif
|
#endif
|
||||||
/*----------------------------------------------------------------*/
|
/*----------------------------------------------------------------*/
|
||||||
static int tcpDoChoSend(pTcpDoCho self, char *command, int choNum,
|
static int tcpDoChoSend(pTcpDoCho self, char *command, int choNum,
|
||||||
char *value){
|
char *value){
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
int sendlen, status;
|
int sendlen, status;
|
||||||
|
|
||||||
@ -117,22 +117,22 @@ static int tcpDoChoSend(pTcpDoCho self, char *command, int choNum,
|
|||||||
*/
|
*/
|
||||||
self->lastError = 0;
|
self->lastError = 0;
|
||||||
if(choNum < 0){
|
if(choNum < 0){
|
||||||
snprintf(buffer,1023,"#SOS#%s \r\n",command);
|
snprintf(buffer,1023,"#SOS#%s \r\n",command);
|
||||||
} else if(value != NULL){
|
} else if(value != NULL){
|
||||||
snprintf(buffer,1023,"#SOS#%s%1.1d: %s\r\n",command, choNum,
|
snprintf(buffer,1023,"#SOS#%s%1.1d: %s\r\n",command, choNum,
|
||||||
value);
|
value);
|
||||||
} else {
|
} else {
|
||||||
snprintf(buffer,1023,"#SOS#%s%1.1d:\r\n",command, choNum);
|
snprintf(buffer,1023,"#SOS#%s%1.1d:\r\n",command, choNum);
|
||||||
}
|
}
|
||||||
sendlen = strlen(buffer);
|
sendlen = strlen(buffer);
|
||||||
if(sendlen == 0){
|
if(sendlen == 0){
|
||||||
self->lastError = BADCONVERSION;
|
self->lastError = BADCONVERSION;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
status = send(self->controller->pSock->sockid,buffer,sendlen,0);
|
status = send(self->controller->pSock->sockid,buffer,sendlen,0);
|
||||||
if(status < 0){
|
if(status < 0){
|
||||||
self->lastError = BADWRITE;
|
self->lastError = BADWRITE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -147,14 +147,14 @@ static int statusComplete(char *statusMessage){
|
|||||||
*/
|
*/
|
||||||
pPtr = strstr(statusMessage,"TIME");
|
pPtr = strstr(statusMessage,"TIME");
|
||||||
if(pPtr != NULL){
|
if(pPtr != NULL){
|
||||||
pPtr = strstr(pPtr+6,"#");
|
pPtr = strstr(pPtr+6,"#");
|
||||||
if(pPtr != NULL){
|
if(pPtr != NULL){
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------*/
|
/*---------------------------------------------------------------*/
|
||||||
@ -164,7 +164,7 @@ static int readChopperNum(char *entry){
|
|||||||
|
|
||||||
pPtr = strstr(entry,"CH");
|
pPtr = strstr(entry,"CH");
|
||||||
if(pPtr == NULL){
|
if(pPtr == NULL){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sscanf(pPtr+3,"%d",&num);
|
sscanf(pPtr+3,"%d",&num);
|
||||||
return num;
|
return num;
|
||||||
@ -209,12 +209,12 @@ static int parseStatus(pTcpDoCho self, char *statusMessage){
|
|||||||
|
|
||||||
choNum = readChopperNum(entry);
|
choNum = readChopperNum(entry);
|
||||||
if(choNum < 0){
|
if(choNum < 0){
|
||||||
self->lastError = BADRESPONSE;
|
self->lastError = BADRESPONSE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
while((pPtr = stptok(pPtr,entry,79,"#")) != NULL){
|
while((pPtr = stptok(pPtr,entry,79,"#")) != NULL){
|
||||||
addEntry(self,choNum,entry);
|
addEntry(self,choNum,entry);
|
||||||
memset(entry,0,80);
|
memset(entry,0,80);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -229,45 +229,45 @@ static int tcpDoChoReceive(pTcpDoCho self){
|
|||||||
bytesRead = 0;
|
bytesRead = 0;
|
||||||
memset(buffer,0,1024*sizeof(char));
|
memset(buffer,0,1024*sizeof(char));
|
||||||
while(time(NULL) < endTime){
|
while(time(NULL) < endTime){
|
||||||
if(availableRS232(self->controller)){
|
if(availableRS232(self->controller)){
|
||||||
bytesRead += recv(self->controller->pSock->sockid,buffer+bufferStart,
|
bytesRead += recv(self->controller->pSock->sockid,buffer+bufferStart,
|
||||||
1024 - bytesRead,0);
|
1024 - bytesRead,0);
|
||||||
if(bytesRead < 0){
|
if(bytesRead < 0){
|
||||||
self->lastError = BADREAD;
|
self->lastError = BADREAD;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(strstr(buffer,"State") != NULL){
|
if(strstr(buffer,"State") != NULL){
|
||||||
if(statusComplete(buffer) == 0) {
|
if(statusComplete(buffer) == 0) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
status = parseStatus(self,buffer);
|
status = parseStatus(self,buffer);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(strstr(buffer,"ACCEPT") != NULL){
|
if(strstr(buffer,"ACCEPT") != NULL){
|
||||||
return 1;
|
return 1;
|
||||||
} else if(strstr(buffer,"NCCEPT") != NULL){
|
} else if(strstr(buffer,"NCCEPT") != NULL){
|
||||||
self->lastError = FAILEDCOMMAND;
|
self->lastError = FAILEDCOMMAND;
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
self->lastError = BADRESPONSE;
|
self->lastError = BADRESPONSE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SicsWait(1);
|
SicsWait(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self->lastError = TIMEOUT;
|
self->lastError = TIMEOUT;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------------*/
|
/*-----------------------------------------------------------------*/
|
||||||
static int tcpDoChoCommand(pTcpDoCho self, char *command, int choNum,
|
static int tcpDoChoCommand(pTcpDoCho self, char *command, int choNum,
|
||||||
char *value){
|
char *value){
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
status = tcpDoChoSend(self,command,choNum,value);
|
status = tcpDoChoSend(self,command,choNum,value);
|
||||||
if(status == 0){
|
if(status == 0){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return tcpDoChoReceive(self);
|
return tcpDoChoReceive(self);
|
||||||
}
|
}
|
||||||
@ -283,8 +283,8 @@ static int TcpDoChoConnect(pTcpDoCho self){
|
|||||||
|
|
||||||
status = initRS232(self->controller);
|
status = initRS232(self->controller);
|
||||||
if(status != 1){
|
if(status != 1){
|
||||||
self->lastError = status;
|
self->lastError = status;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
setRS232Timeout(self->controller,5);
|
setRS232Timeout(self->controller,5);
|
||||||
|
|
||||||
@ -297,13 +297,13 @@ static int TcpDoChoConnect(pTcpDoCho self){
|
|||||||
snprintf(buffer,255,"user:%s\r\n",self->user);
|
snprintf(buffer,255,"user:%s\r\n",self->user);
|
||||||
sendLen = strlen(buffer);
|
sendLen = strlen(buffer);
|
||||||
if(sendLen == 0){
|
if(sendLen == 0){
|
||||||
self->lastError = BADCONVERSION;
|
self->lastError = BADCONVERSION;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
status = send(self->controller->pSock->sockid,buffer,sendLen,0);
|
status = send(self->controller->pSock->sockid,buffer,sendLen,0);
|
||||||
if(status < 0){
|
if(status < 0){
|
||||||
self->lastError = BADSEND;
|
self->lastError = BADSEND;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
readLen = 255;
|
readLen = 255;
|
||||||
readRS232(self->controller,(void *)buffer,&readLen);
|
readRS232(self->controller,(void *)buffer,&readLen);
|
||||||
@ -314,13 +314,13 @@ static int TcpDoChoConnect(pTcpDoCho self){
|
|||||||
snprintf(buffer,255,"password:%s\r\n",self->pword);
|
snprintf(buffer,255,"password:%s\r\n",self->pword);
|
||||||
sendLen = strlen(buffer);
|
sendLen = strlen(buffer);
|
||||||
if(sendLen == 0){
|
if(sendLen == 0){
|
||||||
self->lastError = BADCONVERSION;
|
self->lastError = BADCONVERSION;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
status = send(self->controller->pSock->sockid,buffer,sendLen,0);
|
status = send(self->controller->pSock->sockid,buffer,sendLen,0);
|
||||||
if(status < 0){
|
if(status < 0){
|
||||||
self->lastError = BADSEND;
|
self->lastError = BADSEND;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
readLen = 255;
|
readLen = 255;
|
||||||
readRS232(self->controller,(void *)buffer,&readLen);
|
readRS232(self->controller,(void *)buffer,&readLen);
|
||||||
@ -348,32 +348,32 @@ static int TcpChopperTask(void *pData){
|
|||||||
assert(pPriv);
|
assert(pPriv);
|
||||||
|
|
||||||
if(pPriv->stop == 1){
|
if(pPriv->stop == 1){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(time(NULL) > pPriv->nextRefresh){
|
if(time(NULL) > pPriv->nextRefresh){
|
||||||
if(pPriv->lastError != 0){
|
if(pPriv->lastError != 0){
|
||||||
self->GetError(self,&code,buffer,79);
|
self->GetError(self,&code,buffer,79);
|
||||||
snprintf(error,511,"WARNING: chopper tries to fix: %s",buffer);
|
snprintf(error,511,"WARNING: chopper tries to fix: %s",buffer);
|
||||||
WriteToCommandLog("Chopper-task:>>", error);
|
WriteToCommandLog("Chopper-task:>>", error);
|
||||||
status = self->TryFixIt(self,code);
|
status = self->TryFixIt(self,code);
|
||||||
if(status == CHFAIL){
|
if(status == CHFAIL){
|
||||||
pPriv->nextRefresh = time(NULL) + pPriv->iRefreshIntervall;
|
pPriv->nextRefresh = time(NULL) + pPriv->iRefreshIntervall;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pPriv->busy = 1;
|
|
||||||
for(i = 0; i < pPriv->numChoppers; i++){
|
|
||||||
status = tcpDoChoCommand(pPriv,"STATE ", i+1,NULL);
|
|
||||||
if(status != 1){
|
|
||||||
/*
|
|
||||||
force error correction
|
|
||||||
*/
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pPriv->nextRefresh = time(NULL) + pPriv->iRefreshIntervall;
|
} else {
|
||||||
pPriv->busy = 0;
|
pPriv->busy = 1;
|
||||||
|
for(i = 0; i < pPriv->numChoppers; i++){
|
||||||
|
status = tcpDoChoCommand(pPriv,"STATE ", i+1,NULL);
|
||||||
|
if(status != 1){
|
||||||
|
/*
|
||||||
|
force error correction
|
||||||
|
*/
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pPriv->nextRefresh = time(NULL) + pPriv->iRefreshIntervall;
|
||||||
|
pPriv->busy = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -388,13 +388,13 @@ static int TcpDoChoKill(pCodri self){
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if(pPriv->controller != NULL){
|
if(pPriv->controller != NULL){
|
||||||
KillRS232(pPriv->controller);
|
KillRS232(pPriv->controller);
|
||||||
}
|
}
|
||||||
if(pPriv->parameters != NULL){
|
if(pPriv->parameters != NULL){
|
||||||
DeleteStringDict(pPriv->parameters);
|
DeleteStringDict(pPriv->parameters);
|
||||||
}
|
}
|
||||||
if(pPriv->config != NULL){
|
if(pPriv->config != NULL){
|
||||||
free(pPriv->config);
|
free(pPriv->config);
|
||||||
}
|
}
|
||||||
free(pPriv);
|
free(pPriv);
|
||||||
return 1;
|
return 1;
|
||||||
@ -411,11 +411,11 @@ static int TcpDoChoConfigure(pCodri pDriv){
|
|||||||
assert(self != NULL);
|
assert(self != NULL);
|
||||||
|
|
||||||
if(self->config != NULL){
|
if(self->config != NULL){
|
||||||
pPtr = self->config;
|
pPtr = self->config;
|
||||||
while( (pPtr = stptok(pPtr,command,79,"\n")) != NULL){
|
while( (pPtr = stptok(pPtr,command,79,"\n")) != NULL){
|
||||||
status = tcpDoChoCommand(self,command,-1,NULL);
|
status = tcpDoChoCommand(self,command,-1,NULL);
|
||||||
if(status != 1){
|
if(status != 1){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -436,22 +436,22 @@ static int TcpDoChoInit(pCodri pDriv){
|
|||||||
|
|
||||||
status = TcpDoChoConnect(self);
|
status = TcpDoChoConnect(self);
|
||||||
if(status != 1){
|
if(status != 1){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = TcpDoChoConfigure(pDriv);
|
status = TcpDoChoConfigure(pDriv);
|
||||||
if(status != 1){
|
if(status != 1){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
/* start the update task */
|
/* start the update task */
|
||||||
if(self->lTask == 0){
|
if(self->lTask == 0){
|
||||||
self->lTask = TaskRegister(pServ->pTasker,
|
self->lTask = TaskRegister(pServ->pTasker,
|
||||||
TcpChopperTask,
|
TcpChopperTask,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
pDriv,
|
pDriv,
|
||||||
1);
|
1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
@ -462,11 +462,11 @@ static void waitForBusy(pTcpDoCho self){
|
|||||||
|
|
||||||
endTime = time(NULL) + 10 *60; /* max 10 min */
|
endTime = time(NULL) + 10 *60; /* max 10 min */
|
||||||
while(time(NULL) < endTime){
|
while(time(NULL) < endTime){
|
||||||
if(self->busy == 1){
|
if(self->busy == 1){
|
||||||
SicsWait(3);
|
SicsWait(3);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WriteToCommandLog("Chopper-task>> ","WARNING: timeout on busy flag, flag forced");
|
WriteToCommandLog("Chopper-task>> ","WARNING: timeout on busy flag, flag forced");
|
||||||
self->busy = 0;
|
self->busy = 0;
|
||||||
@ -481,8 +481,8 @@ static int TcpDoChoClose(pCodri pDriv){
|
|||||||
|
|
||||||
self->stop = 1;
|
self->stop = 1;
|
||||||
if(self->controller != NULL){
|
if(self->controller != NULL){
|
||||||
KillRS232(self->controller);
|
KillRS232(self->controller);
|
||||||
self->controller = NULL;
|
self->controller = NULL;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -492,12 +492,12 @@ static int dissectName(char *name, char par[80], int *num){
|
|||||||
|
|
||||||
pPtr = strrchr(name,(int)'_');
|
pPtr = strrchr(name,(int)'_');
|
||||||
if(pPtr == NULL){
|
if(pPtr == NULL){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memset(par,0,80*sizeof(char));
|
memset(par,0,80*sizeof(char));
|
||||||
strncpy(par,name,pPtr - name);
|
strncpy(par,name,pPtr - name);
|
||||||
if(sscanf(pPtr+1,"%d",num) != 1){
|
if(sscanf(pPtr+1,"%d",num) != 1){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -538,37 +538,37 @@ static int TcpDoChoSetPar2(pCodri pDriv, char *parname, char *value){
|
|||||||
to make the stored status represent the new target values
|
to make the stored status represent the new target values
|
||||||
*/
|
*/
|
||||||
if(dissectName(parname,par,&choNum)){
|
if(dissectName(parname,par,&choNum)){
|
||||||
/*
|
/*
|
||||||
check for emergency stop
|
check for emergency stop
|
||||||
*/
|
*/
|
||||||
snprintf(buffer,79,"State_%1.1d",choNum);
|
snprintf(buffer,79,"State_%1.1d",choNum);
|
||||||
memset(state,0,80*sizeof(char));
|
memset(state,0,80*sizeof(char));
|
||||||
StringDictGet(self->parameters,buffer,state,79);
|
StringDictGet(self->parameters,buffer,state,79);
|
||||||
if(strstr(state,"E-Stop") != NULL){
|
if(strstr(state,"E-Stop") != NULL){
|
||||||
self->lastError = ESTOP;
|
self->lastError = ESTOP;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(par,"speed") == 0){
|
if(strcmp(par,"speed") == 0){
|
||||||
waitForBusy(self);
|
waitForBusy(self);
|
||||||
status = tcpDoChoCommand(self,"SPEED ",choNum,trim(value));
|
status = tcpDoChoCommand(self,"SPEED ",choNum,trim(value));
|
||||||
tcpDoChoCommand(self,"STATE ",choNum,NULL);
|
tcpDoChoCommand(self,"STATE ",choNum,NULL);
|
||||||
if(status != 1){
|
if(status != 1){
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else if(strcmp(par,"phase") == 0){
|
} else if(strcmp(par,"phase") == 0){
|
||||||
waitForBusy(self);
|
waitForBusy(self);
|
||||||
if (errno != 0)
|
if (errno != 0)
|
||||||
return 0;
|
return 0;
|
||||||
status = tcpDoChoCommand(self,"PHASE ",choNum,trim(value));
|
status = tcpDoChoCommand(self,"PHASE ",choNum,trim(value));
|
||||||
tcpDoChoCommand(self,"STATE ",choNum,NULL);
|
tcpDoChoCommand(self,"STATE ",choNum,NULL);
|
||||||
if(status != 1){
|
if(status != 1){
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self->lastError = UNDRIVABLE;
|
self->lastError = UNDRIVABLE;
|
||||||
@ -601,12 +601,12 @@ static int TcpDoChoSetPar(pCodri pDriv, char *parname, float fValue){
|
|||||||
assert(self != NULL);
|
assert(self != NULL);
|
||||||
|
|
||||||
if(dissectName(parname,par,&choNum)){
|
if(dissectName(parname,par,&choNum)){
|
||||||
if(strcmp(par,"speed") == 0){
|
if(strcmp(par,"speed") == 0){
|
||||||
snprintf(value,79,"%5.1f", fValue);
|
snprintf(value,79,"%5.1f", fValue);
|
||||||
return TcpDoChoSetPar2(pDriv,parname,value);
|
return TcpDoChoSetPar2(pDriv,parname,value);
|
||||||
} else if(strcmp(par,"phase") == 0){
|
} else if(strcmp(par,"phase") == 0){
|
||||||
snprintf(value,79,"%6.2f",fValue);
|
snprintf(value,79,"%6.2f",fValue);
|
||||||
return TcpDoChoSetPar2(pDriv,parname,value);
|
return TcpDoChoSetPar2(pDriv,parname,value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(strcmp(parname,"updateintervall") == 0){
|
if(strcmp(parname,"updateintervall") == 0){
|
||||||
@ -615,8 +615,8 @@ static int TcpDoChoSetPar(pCodri pDriv, char *parname, float fValue){
|
|||||||
self->iRefreshIntervall = (int)fValue;
|
self->iRefreshIntervall = (int)fValue;
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
snprintf(value,79,"%f",fValue);
|
snprintf(value,79,"%f",fValue);
|
||||||
return TcpDoChoSetPar2(pDriv,parname,value);
|
return TcpDoChoSetPar2(pDriv,parname,value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------*/
|
||||||
@ -744,10 +744,10 @@ static int TcpDoChoCheckPar(pCodri pDriv, char *parname){
|
|||||||
check for flags first
|
check for flags first
|
||||||
*/
|
*/
|
||||||
if(self->busy){
|
if(self->busy){
|
||||||
return HWBusy;
|
return HWBusy;
|
||||||
}
|
}
|
||||||
if(self->lastError != 0) {
|
if(self->lastError != 0) {
|
||||||
return HWFault;
|
return HWFault;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -764,38 +764,38 @@ static int TcpDoChoCheckPar(pCodri pDriv, char *parname){
|
|||||||
memset(state,0,80*sizeof(char));
|
memset(state,0,80*sizeof(char));
|
||||||
StringDictGet(self->parameters,buffer,state,79);
|
StringDictGet(self->parameters,buffer,state,79);
|
||||||
if(strstr(state,"E-Stop") != NULL){
|
if(strstr(state,"E-Stop") != NULL){
|
||||||
self->lastError = HWFault;
|
self->lastError = HWFault;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(par,0,80);
|
memset(par,0,80);
|
||||||
dissectName(parname,par,&choNum);
|
dissectName(parname,par,&choNum);
|
||||||
if(strcmp(par,"speed") == 0){
|
if(strcmp(par,"speed") == 0){
|
||||||
snprintf(buffer,79,"RSPEED_%1.1d", choNum);
|
snprintf(buffer,79,"RSPEED_%1.1d", choNum);
|
||||||
StringDictGet(self->parameters,buffer,csoll,79);
|
StringDictGet(self->parameters,buffer,csoll,79);
|
||||||
sscanf(csoll,"%f",&soll);
|
sscanf(csoll,"%f",&soll);
|
||||||
snprintf(buffer,79,"ASPEED_%1.1d", choNum);
|
snprintf(buffer,79,"ASPEED_%1.1d", choNum);
|
||||||
StringDictGet(self->parameters,buffer,value,79);
|
StringDictGet(self->parameters,buffer,value,79);
|
||||||
sscanf(value,"%f",&val);
|
sscanf(value,"%f",&val);
|
||||||
delta = ABS(soll - val);
|
delta = ABS(soll - val);
|
||||||
if(delta > SPEEDTOL){
|
if(delta > SPEEDTOL){
|
||||||
return HWBusy;
|
return HWBusy;
|
||||||
} else {
|
} else {
|
||||||
return HWIdle;
|
return HWIdle;
|
||||||
}
|
}
|
||||||
} else if(strcmp(par,"phase") == 0){
|
} else if(strcmp(par,"phase") == 0){
|
||||||
snprintf(buffer,79,"RPHASE_%1.1d", choNum);
|
snprintf(buffer,79,"RPHASE_%1.1d", choNum);
|
||||||
StringDictGet(self->parameters,buffer,csoll,79);
|
StringDictGet(self->parameters,buffer,csoll,79);
|
||||||
sscanf(value,"%f",&soll);
|
sscanf(value,"%f",&soll);
|
||||||
snprintf(buffer,79,"APHASE_%1.1d", choNum);
|
snprintf(buffer,79,"APHASE_%1.1d", choNum);
|
||||||
StringDictGet(self->parameters,buffer,value,79);
|
StringDictGet(self->parameters,buffer,value,79);
|
||||||
sscanf(value,"%f",&val);
|
sscanf(value,"%f",&val);
|
||||||
delta = ABS(soll - val);
|
delta = ABS(soll - val);
|
||||||
if(delta > PHASETOL){
|
if(delta > PHASETOL){
|
||||||
return HWBusy;
|
return HWBusy;
|
||||||
} else {
|
} else {
|
||||||
return HWIdle;
|
return HWIdle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self->lastError = BADPAR;
|
self->lastError = BADPAR;
|
||||||
return HWFault;
|
return HWFault;
|
||||||
@ -810,36 +810,36 @@ static int TcpDoChoError(pCodri pDriv, int *iCode, char *pError, int iLen){
|
|||||||
|
|
||||||
*iCode = self->lastError;
|
*iCode = self->lastError;
|
||||||
switch(self->lastError){
|
switch(self->lastError){
|
||||||
case WRONGMODE:
|
case WRONGMODE:
|
||||||
strncpy(pError,"Chopper in wrong mode",iLen);
|
strncpy(pError,"Chopper in wrong mode",iLen);
|
||||||
break;
|
break;
|
||||||
case BADCONVERSION:
|
case BADCONVERSION:
|
||||||
strncpy(pError,"Bad ASCII to unicode conversion",iLen);
|
strncpy(pError,"Bad ASCII to unicode conversion",iLen);
|
||||||
break;
|
break;
|
||||||
case FAILEDCOMMAND:
|
case FAILEDCOMMAND:
|
||||||
strncpy(pError,"Command not accepted",iLen);
|
strncpy(pError,"Command not accepted",iLen);
|
||||||
break;
|
break;
|
||||||
case BADWRITE:
|
case BADWRITE:
|
||||||
strncpy(pError,"Failed to write to chopper controller",iLen);
|
strncpy(pError,"Failed to write to chopper controller",iLen);
|
||||||
break;
|
break;
|
||||||
case BADRESPONSE:
|
case BADRESPONSE:
|
||||||
strncpy(pError,"Chopper controller send invalid command",iLen);
|
strncpy(pError,"Chopper controller send invalid command",iLen);
|
||||||
break;
|
break;
|
||||||
case UNDRIVABLE:
|
case UNDRIVABLE:
|
||||||
strncpy(pError,"Parameter cannot be changed",iLen);
|
strncpy(pError,"Parameter cannot be changed",iLen);
|
||||||
break;
|
break;
|
||||||
case BADPAR:
|
case BADPAR:
|
||||||
strncpy(pError,"No such parameter",iLen);
|
strncpy(pError,"No such parameter",iLen);
|
||||||
break;
|
break;
|
||||||
case BADVALUE:
|
case BADVALUE:
|
||||||
strncpy(pError,"Invalid parameter value",iLen);
|
strncpy(pError,"Invalid parameter value",iLen);
|
||||||
break;
|
break;
|
||||||
case ESTOP:
|
case ESTOP:
|
||||||
strncpy(pError,"Emergency stop is engaged",iLen);
|
strncpy(pError,"Emergency stop is engaged",iLen);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
getRS232Error(self->lastError,pError,iLen);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
getRS232Error(self->lastError,pError,iLen);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -856,26 +856,26 @@ static int TcpDoChoFix(pCodri pDriv, int iCode){
|
|||||||
|
|
||||||
self->lastError = 0;
|
self->lastError = 0;
|
||||||
switch(iCode){
|
switch(iCode){
|
||||||
case BADCONVERSION:
|
case BADCONVERSION:
|
||||||
case BADRESPONSE:
|
case BADRESPONSE:
|
||||||
return CHREDO;
|
return CHREDO;
|
||||||
break;
|
break;
|
||||||
case WRONGMODE:
|
case WRONGMODE:
|
||||||
case FAILEDCOMMAND:
|
case FAILEDCOMMAND:
|
||||||
case UNDRIVABLE:
|
case UNDRIVABLE:
|
||||||
case BADPAR:
|
case BADPAR:
|
||||||
case ESTOP:
|
case ESTOP:
|
||||||
return CHFAIL;
|
return CHFAIL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
closeRS232(self->controller);
|
closeRS232(self->controller);
|
||||||
status = TcpDoChoConnect(self);
|
status = TcpDoChoConnect(self);
|
||||||
if(status == 1){
|
if(status == 1){
|
||||||
return CHREDO;
|
return CHREDO;
|
||||||
} else {
|
} else {
|
||||||
return CHFAIL;
|
return CHFAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return CHFAIL;
|
return CHFAIL;
|
||||||
}
|
}
|
||||||
@ -888,21 +888,21 @@ pCodri MakeTcpDoChoDriver(char *tclArray, SConnection *pCon){
|
|||||||
int port, i, count;
|
int port, i, count;
|
||||||
Tcl_DString pars;
|
Tcl_DString pars;
|
||||||
char *parnames[] = {"State",
|
char *parnames[] = {"State",
|
||||||
"ASPEED",
|
"ASPEED",
|
||||||
"RSPEED",
|
"RSPEED",
|
||||||
"APHASE",
|
"APHASE",
|
||||||
"RPHASE",
|
"RPHASE",
|
||||||
"AVETO",
|
"AVETO",
|
||||||
"DIR",
|
"DIR",
|
||||||
"MONIT",
|
"MONIT",
|
||||||
"FLOWR",
|
"FLOWR",
|
||||||
"WTEMP",
|
"WTEMP",
|
||||||
"MTEMP",
|
"MTEMP",
|
||||||
"MVIBR",
|
"MVIBR",
|
||||||
"MVACU",
|
"MVACU",
|
||||||
"speed",
|
"speed",
|
||||||
"phase",
|
"phase",
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -919,19 +919,19 @@ pCodri MakeTcpDoChoDriver(char *tclArray, SConnection *pCon){
|
|||||||
/* port and host name */
|
/* port and host name */
|
||||||
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"port",TCL_GLOBAL_ONLY);
|
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"port",TCL_GLOBAL_ONLY);
|
||||||
if(!pPtr){
|
if(!pPtr){
|
||||||
SCWrite(pCon,"ERROR: port not found in configuration array for TCP Dornier Chopper",
|
SCWrite(pCon,"ERROR: port not found in configuration array for TCP Dornier Chopper",
|
||||||
eError);
|
eError);
|
||||||
free(pNew);
|
free(pNew);
|
||||||
free(self);
|
free(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
sscanf(pPtr,"%d",&port);
|
sscanf(pPtr,"%d",&port);
|
||||||
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"host",TCL_GLOBAL_ONLY);
|
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"host",TCL_GLOBAL_ONLY);
|
||||||
if(!pPtr){
|
if(!pPtr){
|
||||||
SCWrite(pCon,"ERROR: host not found in configuration array for TCP Dornier Chopper",
|
SCWrite(pCon,"ERROR: host not found in configuration array for TCP Dornier Chopper",
|
||||||
eError);
|
eError);
|
||||||
free(pNew);
|
free(pNew);
|
||||||
free(self);
|
free(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(buffer,0,132);
|
memset(buffer,0,132);
|
||||||
@ -941,27 +941,27 @@ pCodri MakeTcpDoChoDriver(char *tclArray, SConnection *pCon){
|
|||||||
/* number of choppers */
|
/* number of choppers */
|
||||||
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"nchopper",TCL_GLOBAL_ONLY);
|
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"nchopper",TCL_GLOBAL_ONLY);
|
||||||
if(!pPtr){
|
if(!pPtr){
|
||||||
SCWrite(pCon,"ERROR: nchopper not found in configuration array for TCP Dornier Chopper",
|
SCWrite(pCon,"ERROR: nchopper not found in configuration array for TCP Dornier Chopper",
|
||||||
eError);
|
eError);
|
||||||
free(pNew);
|
free(pNew);
|
||||||
free(self);
|
free(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
sscanf(pPtr,"%d",&port);
|
sscanf(pPtr,"%d",&port);
|
||||||
if(port < 0 || port > 8){
|
if(port < 0 || port > 8){
|
||||||
SCWrite(pCon,"ERROR: number of choppers not in range 1 - 8",eError);
|
SCWrite(pCon,"ERROR: number of choppers not in range 1 - 8",eError);
|
||||||
free(pNew);
|
free(pNew);
|
||||||
free(self);
|
free(self);
|
||||||
}
|
}
|
||||||
self->numChoppers = port;
|
self->numChoppers = port;
|
||||||
|
|
||||||
/* timeout */
|
/* timeout */
|
||||||
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"timeout",TCL_GLOBAL_ONLY);
|
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"timeout",TCL_GLOBAL_ONLY);
|
||||||
if(!pPtr){
|
if(!pPtr){
|
||||||
SCWrite(pCon,"ERROR: timeout not found in configuration array for TCP Dornier Chopper",
|
SCWrite(pCon,"ERROR: timeout not found in configuration array for TCP Dornier Chopper",
|
||||||
eError);
|
eError);
|
||||||
free(pNew);
|
free(pNew);
|
||||||
free(self);
|
free(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
sscanf(pPtr,"%d",&port);
|
sscanf(pPtr,"%d",&port);
|
||||||
@ -970,19 +970,19 @@ pCodri MakeTcpDoChoDriver(char *tclArray, SConnection *pCon){
|
|||||||
/* username and password */
|
/* username and password */
|
||||||
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"user",TCL_GLOBAL_ONLY);
|
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"user",TCL_GLOBAL_ONLY);
|
||||||
if(!pPtr){
|
if(!pPtr){
|
||||||
SCWrite(pCon,"ERROR: user not found in configuration array for TCP Dornier Chopper",
|
SCWrite(pCon,"ERROR: user not found in configuration array for TCP Dornier Chopper",
|
||||||
eError);
|
eError);
|
||||||
free(pNew);
|
free(pNew);
|
||||||
free(self);
|
free(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strncpy(self->user,pPtr, 131);
|
strncpy(self->user,pPtr, 131);
|
||||||
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"password",TCL_GLOBAL_ONLY);
|
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"password",TCL_GLOBAL_ONLY);
|
||||||
if(!pPtr){
|
if(!pPtr){
|
||||||
SCWrite(pCon,"ERROR: password not found in configuration array for TCP Dornier Chopper",
|
SCWrite(pCon,"ERROR: password not found in configuration array for TCP Dornier Chopper",
|
||||||
eError);
|
eError);
|
||||||
free(pNew);
|
free(pNew);
|
||||||
free(self);
|
free(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strncpy(self->pword,pPtr, 131);
|
strncpy(self->pword,pPtr, 131);
|
||||||
@ -992,16 +992,16 @@ pCodri MakeTcpDoChoDriver(char *tclArray, SConnection *pCon){
|
|||||||
*/
|
*/
|
||||||
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"config",TCL_GLOBAL_ONLY);
|
pPtr = Tcl_GetVar2(pServ->pSics->pTcl,tclArray,"config",TCL_GLOBAL_ONLY);
|
||||||
if(pPtr != NULL){
|
if(pPtr != NULL){
|
||||||
self->config = strdup(pPtr);
|
self->config = strdup(pPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* initialize some more */
|
/* initialize some more */
|
||||||
self->parameters = CreateStringDict();
|
self->parameters = CreateStringDict();
|
||||||
if(self->parameters == NULL || self->controller == NULL){
|
if(self->parameters == NULL || self->controller == NULL){
|
||||||
SCWrite(pCon,"ERROR: out of memory in MakeTcpDoCho",eError);
|
SCWrite(pCon,"ERROR: out of memory in MakeTcpDoCho",eError);
|
||||||
free(pNew);
|
free(pNew);
|
||||||
free(self);
|
free(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
self->iRefreshIntervall = 60;
|
self->iRefreshIntervall = 60;
|
||||||
@ -1025,11 +1025,11 @@ pCodri MakeTcpDoChoDriver(char *tclArray, SConnection *pCon){
|
|||||||
count = 0;
|
count = 0;
|
||||||
Tcl_DStringAppend(&pars,"updateintervall",15);
|
Tcl_DStringAppend(&pars,"updateintervall",15);
|
||||||
while(parnames[count] != NULL){
|
while(parnames[count] != NULL){
|
||||||
for(i = 0; i < self->numChoppers; i++){
|
for(i = 0; i < self->numChoppers; i++){
|
||||||
snprintf(buffer,131,",%s_%1.1d", parnames[count], i + 1);
|
snprintf(buffer,131,",%s_%1.1d", parnames[count], i + 1);
|
||||||
Tcl_DStringAppend(&pars,buffer,strlen(buffer));
|
Tcl_DStringAppend(&pars,buffer,strlen(buffer));
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
pNew->pParList = strdup(Tcl_DStringValue(&pars));
|
pNew->pParList = strdup(Tcl_DStringValue(&pars));
|
||||||
Tcl_DStringFree(&pars);
|
Tcl_DStringFree(&pars);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
L A K E S H O R E 3 4 0 D R I V
|
L A K E S H O R E 3 4 0 D R I V
|
||||||
|
|
||||||
This file contains the implementation of a driver for the
|
This file contains the implementation of a driver for the
|
||||||
Lakeshore 340 Temperature controller.
|
Lakeshore 340 Temperature controller.
|
||||||
@ -369,8 +369,8 @@
|
|||||||
pMe = (pLAKESHORE340Driv )self->pPrivate;
|
pMe = (pLAKESHORE340Driv )self->pPrivate;
|
||||||
assert(pMe);
|
assert(pMe);
|
||||||
|
|
||||||
/* For the LAKESHORE340 allow selection of internal or external control
|
/* For the LAKESHORE340 allow selection of internal or external control
|
||||||
where iControl==1 to 4 for A,B,C,D respectively. */
|
where iControl==1 to 4 for A,B,C,D respectively. */
|
||||||
if( (iSensor < 1) || (iSensor > 4) )
|
if( (iSensor < 1) || (iSensor > 4) )
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
@ -448,7 +448,7 @@
|
|||||||
pMe = (pLAKESHORE340Driv )self->pPrivate;
|
pMe = (pLAKESHORE340Driv )self->pPrivate;
|
||||||
assert(pMe);
|
assert(pMe);
|
||||||
|
|
||||||
/* The LAKESHORE340 doesn't need divisor, force to 1.0 */
|
/* The LAKESHORE340 doesn't need divisor, force to 1.0 */
|
||||||
pMe->fDiv = 1.0; /* fDiv */;
|
pMe->fDiv = 1.0; /* fDiv */;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -472,7 +472,7 @@
|
|||||||
pMe = (pLAKESHORE340Driv )self->pPrivate;
|
pMe = (pLAKESHORE340Driv )self->pPrivate;
|
||||||
assert(pMe);
|
assert(pMe);
|
||||||
|
|
||||||
/* The LAKESHORE340 doesn't need multiplier, force to 1.0 */
|
/* The LAKESHORE340 doesn't need multiplier, force to 1.0 */
|
||||||
pMe->fMult = 1.0; /* fDiv */;
|
pMe->fMult = 1.0; /* fDiv */;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user