- New drivers for EL737 and EL734 high performance
- Changes to makefiles SKIPPED: psi/dornier2.c psi/el734hp.c psi/el737driv.c psi/el737hpdriv.c psi/make_gen psi/makefile_alpha psi/psi.c psi/velodorn.c psi/velodorn.h psi/velodorn.w psi/hardsup/el737_utility.c psi/hardsup/makefile_alpha psi/tecs/makefile_alpha
This commit is contained in:
@ -16,15 +16,9 @@
|
||||
#include "fortify.h"
|
||||
#include "sics.h"
|
||||
#include "splitter.h"
|
||||
#include "nread.h"
|
||||
#include "rs232controller.h"
|
||||
|
||||
/*
|
||||
own error codes
|
||||
*/
|
||||
#define NOTCONNECTED -2700
|
||||
#define BADMEMORY -2701
|
||||
#define TIMEOUT -2702
|
||||
#define FAILEDCONNECT -2703
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
void setRS232SendTerminator(prs232 self, char *term)
|
||||
@ -70,6 +64,12 @@ void setRS232Timeout(prs232 self, int timeout)
|
||||
assert(self);
|
||||
self->timeout = timeout;
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
void setRS232Debug(prs232 self, int deb)
|
||||
{
|
||||
assert(self);
|
||||
self->debug = deb;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
int writeRS232(prs232 self, void *data, int dataLen)
|
||||
{
|
||||
@ -121,6 +121,11 @@ int writeRS232(prs232 self, void *data, int dataLen)
|
||||
send
|
||||
*/
|
||||
iRet = NETWrite(self->pSock,data,dataLen);
|
||||
if(self->debug > 0)
|
||||
{
|
||||
printf("RS232 OUT: %s",(char *)data);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if(pPtr != NULL)
|
||||
free(pPtr);
|
||||
@ -164,6 +169,11 @@ int readRS232(prs232 self, void *data, int *dataLen)
|
||||
lRead = recv(self->pSock->sockid, data,rLength,0);
|
||||
if(lRead >= 0)
|
||||
{
|
||||
if(self->debug > 0)
|
||||
{
|
||||
printf("RS232 IN: %s",(char *)data);
|
||||
fflush(stdout);
|
||||
}
|
||||
*dataLen = lRead;
|
||||
return 1;
|
||||
}
|
||||
@ -172,11 +182,45 @@ int readRS232(prs232 self, void *data, int *dataLen)
|
||||
return (int)lRead;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
not reached
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
int readRS232TillTerm(prs232 self, void *data, int *datalen){
|
||||
int iRet, replylen;
|
||||
assert(self);
|
||||
|
||||
/*
|
||||
catch an unconnected socket
|
||||
*/
|
||||
if(!self->pSock)
|
||||
{
|
||||
return NOTCONNECTED;
|
||||
}
|
||||
|
||||
memset(data,0,*datalen);
|
||||
replylen = *datalen;
|
||||
iRet = NETReadTillTerm(self->pSock,self->timeout,self->replyTerminator,
|
||||
(char *)data, replylen);
|
||||
if(self->debug > 0)
|
||||
{
|
||||
printf("RS232 IN/TERM: %s",(char *)data);
|
||||
fflush(stdout);
|
||||
}
|
||||
if(iRet == 0)
|
||||
{
|
||||
return TIMEOUT;
|
||||
}
|
||||
else if(iRet == -1)
|
||||
{
|
||||
return INCOMPLETE;
|
||||
}
|
||||
*datalen = strlen((char *)data);
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int availableRS232(prs232 self)
|
||||
{
|
||||
@ -190,7 +234,32 @@ int availableRS232(prs232 self)
|
||||
return NOTCONNECTED;
|
||||
}
|
||||
|
||||
return NETAvailable(self->pSock,self->timeout);
|
||||
return NETAvailable(self->pSock,3);
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int availableNetRS232(prs232 self)
|
||||
{
|
||||
int status;
|
||||
assert(self);
|
||||
|
||||
/*
|
||||
catch an unconnected socket
|
||||
*/
|
||||
if(!self->pSock)
|
||||
{
|
||||
return NOTCONNECTED;
|
||||
}
|
||||
|
||||
if(!self->registered){
|
||||
if(pServ->pReader != NULL){
|
||||
NetReadRegisterUserSocket(pServ->pReader,self->pSock->sockid);
|
||||
self->registered = 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
status = NetReadReadable(pServ->pReader,self->pSock->sockid);
|
||||
NetReadResetUser(pServ->pReader, self->pSock->sockid);
|
||||
return status;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
int transactRS232(prs232 self, void *send, int sendLen,
|
||||
@ -223,10 +292,19 @@ int transactRS232(prs232 self, void *send, int sendLen,
|
||||
memset(reply,0,replyLen);
|
||||
iRet = NETReadTillTerm(self->pSock,self->timeout,self->replyTerminator,
|
||||
reply, replyLen);
|
||||
if(self->debug > 0)
|
||||
{
|
||||
printf("RS232 IN/TRANS: %s",(char *)reply);
|
||||
fflush(stdout);
|
||||
}
|
||||
if(iRet == 0)
|
||||
{
|
||||
return TIMEOUT;
|
||||
}
|
||||
else if(iRet == -1)
|
||||
{
|
||||
return INCOMPLETE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return iRet;
|
||||
@ -262,6 +340,10 @@ void getRS232Error(int iCode, char *errorBuffer,
|
||||
"Failed to connect to terminal server",
|
||||
errorBufferLen);
|
||||
break;
|
||||
case INCOMPLETE:
|
||||
strncpy(errorBuffer,"Did not find terminator in read buffer",
|
||||
errorBufferLen);
|
||||
break;
|
||||
default:
|
||||
strncpy(errorBuffer,strerror(errno),
|
||||
errorBufferLen);
|
||||
@ -277,17 +359,53 @@ int initRS232(prs232 self)
|
||||
|
||||
if(self->pSock != NULL)
|
||||
{
|
||||
if(pServ->pReader != NULL){
|
||||
NetReadRemoveUserSocket(pServ->pReader,self->pSock->sockid);
|
||||
}
|
||||
NETClosePort(self->pSock);
|
||||
self->pSock = NULL;
|
||||
}
|
||||
self->pSock = NETConnect(self->pHost, self->iPort);
|
||||
if(!self->pSock)
|
||||
if(!self->pSock){
|
||||
return FAILEDCONNECT;
|
||||
else
|
||||
} else{
|
||||
if(pServ->pReader != NULL){
|
||||
NetReadRegisterUserSocket(pServ->pReader,self->pSock->sockid);
|
||||
self->registered = 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------*/
|
||||
prs232 createRS232(char *host, int iPort)
|
||||
{
|
||||
prs232 pNew = NULL;
|
||||
|
||||
/*
|
||||
create data structure
|
||||
*/
|
||||
pNew = (prs232)malloc(sizeof(rs232));
|
||||
if(!pNew)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
memset(pNew, 0, sizeof(rs232));
|
||||
|
||||
pNew->pHost = strdup(host);
|
||||
pNew->iPort = iPort;
|
||||
pNew->sendTerminator = strdup("\r");
|
||||
pNew->replyTerminator = strdup("\n");
|
||||
pNew->timeout = 1000;
|
||||
pNew->pDes = CreateDescriptor("RS232 Controller");
|
||||
if(!pNew->pDes || !pNew->pHost ||
|
||||
!pNew->replyTerminator || !pNew->sendTerminator)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
static void KillRS232(void *pData)
|
||||
void KillRS232(void *pData)
|
||||
{
|
||||
prs232 self = (prs232)pData;
|
||||
if(!self)
|
||||
@ -309,6 +427,9 @@ static void KillRS232(void *pData)
|
||||
}
|
||||
if(self->pSock)
|
||||
{
|
||||
if(pServ->pReader != NULL){
|
||||
NetReadRemoveUserSocket(pServ->pReader,self->pSock->sockid);
|
||||
}
|
||||
NETClosePort(self->pSock);
|
||||
}
|
||||
if(self->pHost)
|
||||
@ -590,7 +711,7 @@ int RS232Factory(SConnection *pCon, SicsInterp *pSics,
|
||||
void *pData, int argc, char *argv[])
|
||||
{
|
||||
prs232 pNew = NULL;
|
||||
int iRet;
|
||||
int iRet, status;
|
||||
char pError[256];
|
||||
|
||||
if(argc < 4)
|
||||
@ -623,8 +744,8 @@ int RS232Factory(SConnection *pCon, SicsInterp *pSics,
|
||||
SCWrite(pCon,"ERROR: out of memory in RS232Factory",eError);
|
||||
return 0;
|
||||
}
|
||||
pNew->pSock = NETConnect(pNew->pHost, pNew->iPort);
|
||||
if(!pNew->pSock)
|
||||
status = initRS232(pNew);
|
||||
if(status != 1)
|
||||
{
|
||||
sprintf(pError,"ERROR: failed to connect to %s at port %d",
|
||||
pNew->pHost, pNew->iPort);
|
||||
|
Reference in New Issue
Block a user