- Many fixes to the triple axis stuff

* update after a1-a6 drive
  * intrduction of targets
- POLDI writing
- Moved HKL calculation 4 TRICS to fourlib
This commit is contained in:
cvs
2002-01-25 14:48:50 +00:00
parent 8c043c8cd1
commit 1e60f3be82
39 changed files with 3513 additions and 1160 deletions

164
docho.c
View File

@@ -13,6 +13,10 @@
Mark Koennecke, January 1999
Modified to support a single chopper only,
Uwe Filges, Mark Koennecke; November 2001
--------------------------------------------------------------------------*/
#include <stdlib.h>
#include <assert.h>
@@ -41,6 +45,8 @@
int iError;
int iBusy;
float fRatio;
int iSingle;
char pError[80];
} DoCho, *pDoCho;
/*
pHost, iPort and iChannel combined are the adress of the chopper
@@ -69,6 +75,9 @@
other parameters, its target value cannot be extracted from the chopper
status message.
iSingle is a flag which is true if only a single chopper is controlled
through this driver. This supports the POLDI single choper case.
*/
/*----------------------------------------------------------------------
ERROR CODES:
@@ -78,13 +87,64 @@
#define PARERROR -8004
#define BADSYNC -8005
#define BADSTOP -8006
#define CHOPERROR -8007
extern char *trim(char *pTrim); /* trim.c */
/*----------------------------------------------------------------------*/
static void SplitChopperReply(pCodri self, char *prefix, char *pBueffel)
{
char pToken[30], pValue[20];
char *pPtr, *pTok, *pVal;
int iCount, iRet;
pDoCho pPriv = NULL;
pPriv = (pDoCho)self->pPrivate;
/* decompose pBueffel and store into string dictionary */
pPtr = strtok(pBueffel,";");
while(pPtr != NULL)
{
iCount = sscanf(pPtr,"%s %s",pToken,pValue);
if(iCount == 2)
{
pTok = trim(pToken);
pVal = trim(pValue);
sprintf(pToken,"%s.%s",prefix,pTok);
iRet = StringDictUpdate(pPriv->pPar,pToken,pVal);
if(!iRet)
{
StringDictAddPair(pPriv->pPar,pToken,pVal);
strcat(self->pParList,pToken);
strcat(self->pParList,",");
}
}
else
{
/* this fixes a bug with oversized messages in dphas */
if(strstr(pPtr,"dphas") != NULL)
{
sprintf(pToken,"%s.dphas",prefix);
iRet = StringDictUpdate(pPriv->pPar,
pToken,pPtr+5);
if(!iRet)
{
StringDictAddPair(pPriv->pPar,pToken,
pPtr+5);
strcat(self->pParList,pToken);
strcat(self->pParList,",");
}
}
}
pPtr = strtok(NULL,";");
}
}
/*-------------------------------------------------------------------------
Well, DoChoStatus sends a status request to the Dornier chopper control
system. There is a gotcha, you need three reads to get the full information.
Then the answer is parsed and decomposed into parameter content for the
string dictionary. The single status components are separated by ;.
-------------------------------------------------------------------------*/
extern char *trim(char *pTrim); /* trim.c */
static int DoChoStatus(pCodri self)
{
@@ -115,86 +175,21 @@ extern char *trim(char *pTrim); /* trim.c */
pPriv->iError = iRet;
return 0;
}
/* decompose pBueffel and store into string dictionary */
pPtr = strtok(pBueffel,";");
while(pPtr != NULL)
{
iCount = sscanf(pPtr,"%s %s",pToken,pValue);
if(iCount == 2)
{
pTok = trim(pToken);
pVal = trim(pValue);
sprintf(pToken,"chopper1.%s",pTok);
iRet = StringDictUpdate(pPriv->pPar,pToken,pVal);
if(!iRet)
{
StringDictAddPair(pPriv->pPar,pToken,pVal);
strcat(self->pParList,pToken);
strcat(self->pParList,",");
}
}
else
{
/* this fixes a bug with oversized messages in dphas */
if(strstr(pPtr,"dphas") != NULL)
{
iRet = StringDictUpdate(pPriv->pPar,
"chopper1.dphas",pPtr+5);
if(!iRet)
{
StringDictAddPair(pPriv->pPar,"chopper1.dphas",
pPtr+5);
strcat(self->pParList,"chopper1.dphas");
strcat(self->pParList,",");
}
}
}
pPtr = strtok(NULL,";");
}
SplitChopperReply(self,"chopper1",pBueffel);
/* second send: get next second chopper line */
iRet = SerialWriteRead(&(pPriv->pData),"",pBueffel,1023);
if(iRet < 0)
if(!pPriv->iSingle)
{
pPriv->iError = iRet;
return 0;
}
/* decompose pBueffel and store into string dictionary */
pPtr = strtok(pBueffel,";");
while(pPtr != NULL)
{
iCount = sscanf(pPtr,"%s %s",pToken,pValue);
if(iCount == 2)
/* second send: get next second chopper line */
iRet = SerialWriteRead(&(pPriv->pData),"",pBueffel,1023);
if(iRet < 0)
{
pTok = trim(pToken);
pVal = trim(pValue);
sprintf(pToken,"chopper2.%s",pTok);
iRet = StringDictUpdate(pPriv->pPar,pToken,pVal);
if(!iRet)
{
StringDictAddPair(pPriv->pPar,pToken,pVal);
strcat(self->pParList,pToken);
strcat(self->pParList,",");
}
pPriv->iError = iRet;
return 0;
}
else
{
/* this fixes a bug with oversized messages in dphas */
if(strstr(pPtr,"dphas") != NULL)
{
iRet = StringDictUpdate(pPriv->pPar,
"chopper2.dphas",pPtr+5);
if(!iRet)
{
StringDictAddPair(pPriv->pPar,"chopper2.dphas",
pPtr+5);
strcat(self->pParList,"chopper2.dphas");
strcat(self->pParList,",");
}
}
}
pPtr = strtok(NULL,";");
SplitChopperReply(self,"chopper2",pBueffel);
}
return 1;
}
/*-------------------------------------------------------------------------*/
@@ -393,7 +388,16 @@ extern char *trim(char *pTrim); /* trim.c */
pPriv->iError = iRet;
return 0;
}
pPriv->iError = 0;
if(strstr(pReply,"error") != NULL)
{
pPriv->iError = CHOPERROR;
strncpy(pPriv->pError,pReply,79);
return 0;
}
else
{
pPriv->iError = 0;
}
pPriv->iBusy = 1;
return 1;
}
@@ -610,6 +614,9 @@ extern char *trim(char *pTrim); /* trim.c */
case BADSYNC:
strncpy(pError,"Cannot drive slave chopper",iLen);
break;
case CHOPERROR:
strncpy(pError,pPriv->pError,iLen);
break;
case BADSTOP:
strncpy(pError,
"User called STOP. WARNING: chopper is still untamed!",
@@ -680,7 +687,7 @@ extern char *trim(char *pTrim); /* trim.c */
return CHFAIL;
}
/*-------------------------------------------------------------------------*/
pCodri MakeDoChoDriver(char *pHost, int iPort, int iChannel)
pCodri MakeDoChoDriver(char *pHost, int iPort, int iChannel, int iSingle)
{
pCodri pNew = NULL;
pDoCho pPriv = NULL;
@@ -706,6 +713,7 @@ extern char *trim(char *pTrim); /* trim.c */
pPriv->iRefreshIntervall = 60;
pPriv->pPar = CreateStringDict();
pPriv->tRefresh = time(NULL);
pPriv->iSingle = iSingle;
if(!pPriv->pPar)
{
free(pText);