Now uses ASCII instead of unicode to reflect changes in Astrium code.
This commit is contained in:
44
tcpdocho.c
44
tcpdocho.c
@ -101,7 +101,6 @@ static int unicodeToAscii(char *input, int len, char **output){
|
|||||||
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];
|
||||||
char *converted;
|
|
||||||
int sendlen, status;
|
int sendlen, status;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -116,13 +115,12 @@ static int tcpDoChoSend(pTcpDoCho self, char *command, int choNum,
|
|||||||
} 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 = asciiToUnicode(buffer,&converted);
|
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,converted,sendlen,0);
|
status = send(self->controller->pSock->sockid,buffer,sendlen,0);
|
||||||
free(converted);
|
|
||||||
if(status < 0){
|
if(status < 0){
|
||||||
self->lastError = BADWRITE;
|
self->lastError = BADWRITE;
|
||||||
return 0;
|
return 0;
|
||||||
@ -208,8 +206,7 @@ static int parseStatus(pTcpDoCho self, char *statusMessage){
|
|||||||
/*-----------------------------------------------------------------*/
|
/*-----------------------------------------------------------------*/
|
||||||
static int tcpDoChoReceive(pTcpDoCho self){
|
static int tcpDoChoReceive(pTcpDoCho self){
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
int len, bytesRead, bytesConverted, bufferStart, status;
|
int len, bytesRead, bufferStart, status;
|
||||||
char *converted = NULL;
|
|
||||||
time_t endTime;
|
time_t endTime;
|
||||||
|
|
||||||
endTime = time(NULL) + self->timeout;
|
endTime = time(NULL) + self->timeout;
|
||||||
@ -224,25 +221,17 @@ static int tcpDoChoReceive(pTcpDoCho self){
|
|||||||
self->lastError = BADREAD;
|
self->lastError = BADREAD;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
bytesConverted = unicodeToAscii(buffer,bytesRead,&converted);
|
if(strstr(buffer,"State") != NULL){
|
||||||
if(bytesConverted == 0){
|
if(statusComplete(buffer) == 0) {
|
||||||
self->lastError = BADCONVERSION;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if(strstr(converted,"State") != NULL){
|
|
||||||
if(statusComplete(converted) == 0) {
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
status = parseStatus(self,converted);
|
status = parseStatus(self,buffer);
|
||||||
free(converted);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(strstr(converted,"ACCEPT") != NULL){
|
if(strstr(buffer,"ACCEPT") != NULL){
|
||||||
free(converted);
|
|
||||||
return 1;
|
return 1;
|
||||||
} else if(strstr(converted,"NCCEPT") != NULL){
|
} else if(strstr(buffer,"NCCEPT") != NULL){
|
||||||
free(converted);
|
|
||||||
self->lastError = FAILEDCOMMAND;
|
self->lastError = FAILEDCOMMAND;
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
@ -270,7 +259,6 @@ static int tcpDoChoCommand(pTcpDoCho self, char *command, int choNum,
|
|||||||
/*---------------------------------------------------------------*/
|
/*---------------------------------------------------------------*/
|
||||||
static int TcpDoChoConnect(pTcpDoCho self){
|
static int TcpDoChoConnect(pTcpDoCho self){
|
||||||
int status, sendLen, readLen;
|
int status, sendLen, readLen;
|
||||||
char *converted = NULL;
|
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
|
|
||||||
status = initRS232(self->controller);
|
status = initRS232(self->controller);
|
||||||
@ -282,48 +270,40 @@ static int TcpDoChoConnect(pTcpDoCho self){
|
|||||||
|
|
||||||
readLen = 255;
|
readLen = 255;
|
||||||
readRS232(self->controller,(void *)buffer,&readLen);
|
readRS232(self->controller,(void *)buffer,&readLen);
|
||||||
unicodeToAscii(buffer,readLen,&converted);
|
|
||||||
free(converted);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
user name
|
user name
|
||||||
*/
|
*/
|
||||||
snprintf(buffer,255,"user:%s\r\n",self->user);
|
snprintf(buffer,255,"user:%s\r\n",self->user);
|
||||||
sendLen = asciiToUnicode(buffer,&converted);
|
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,converted,sendLen,0);
|
status = send(self->controller->pSock->sockid,buffer,sendLen,0);
|
||||||
free(converted);
|
|
||||||
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);
|
||||||
unicodeToAscii(buffer,readLen,&converted);
|
|
||||||
free(converted);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
password
|
password
|
||||||
*/
|
*/
|
||||||
snprintf(buffer,255,"password:%s\r\n",self->pword);
|
snprintf(buffer,255,"password:%s\r\n",self->pword);
|
||||||
sendLen = asciiToUnicode(buffer,&converted);
|
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,converted,sendLen,0);
|
status = send(self->controller->pSock->sockid,buffer,sendLen,0);
|
||||||
free(converted);
|
|
||||||
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);
|
||||||
unicodeToAscii(buffer,readLen,&converted);
|
|
||||||
free(converted);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO: responses should be checked to test for a valid login.
|
TODO: responses should be checked to test for a valid login.
|
||||||
|
Reference in New Issue
Block a user