From 501d336adb4cb1a3ad639e7517b8b1b172d3b2c1 Mon Sep 17 00:00:00 2001 From: cvs Date: Fri, 17 Oct 2003 10:07:04 +0000 Subject: [PATCH] - Fixed prolem wit core dump from commandlog - Added fulltransact which sends a TRANSACTIONSTART meesage in addition to TRANSASCTIONFINISHED - Added parameter to motor which allows to ignore positioning faults - ADDED POLAN support to tasscan --- dornier2.c | 157 +++++++++++++++++++++++++++++++++-------------------- el734hp.c | 1 + tasdrive.c | 1 + tasscan.c | 31 +++++++++++ tdchm.c | 4 ++ 5 files changed, 135 insertions(+), 59 deletions(-) diff --git a/dornier2.c b/dornier2.c index 48f2cde..e4c1d1d 100644 --- a/dornier2.c +++ b/dornier2.c @@ -38,11 +38,16 @@ typedef struct __VelSelDriv *pVelSelDriv; #define VSACCEL -7 #define VSFAIL -2 + +/* start speed */ +#define STARTSPEED 3100 + /*--------- special Dornier conditions*/ #define STARTED -88 #define HALTREQ -77 #define INVALIDSTATUS -7000 #define TARGETREJECTED -7001 +#define NOSTATUS -7002 /*---------- DORNIER status modes */ #define STATSEND 1 @@ -61,6 +66,10 @@ typedef struct __VelSelDriv *pVelSelDriv; int minRPM; /* the minimum control speed of the thing*/ int haltCount; int rejectCount; + int noStatus; /* flag which indicates that no valid status + has yet been read. Solves a starting + problem + */ } Dornier, *pDornier; /*------------------------------------------------------------------*/ static int requestDornierStatus(pDornier pDorn){ @@ -91,6 +100,9 @@ static int readAndInterpretStatus(pDornier pDorn, DornierStatus *DStatus){ } DecodeNewDornierStatus(reply,DStatus); + if(pDorn->noStatus == 1){ + pDorn->noStatus = 0; + } return 1; } /*-----------------------------------------------------------------*/ @@ -99,7 +111,7 @@ static int takeControl(pDornier pDorn){ char pError[80]; setRS232ReplyTerminator(pDorn->controller,"\\"); iRet = transactRS232(pDorn->controller,"REM\n",4,pError,79); - setRS232ReplyTerminator(pDorn->controller,"\r\n"); + setRS232ReplyTerminator(pDorn->controller,"\n"); return iRet; } /*--------------------------------------------------------------------*/ @@ -148,19 +160,83 @@ static int takeControl(pDornier pDorn){ } return 1; } +/*----------------------------------------------------------------------*/ + static int DornierText(pVelSelDriv self, char *pText, int iTextLen) + { + pDornier pDorn = NULL; + int iRet, iErrStat; + DornierStatus sStatus; + char pBueffel[1024]; + char pHelp[80]; + + assert(self); + pDorn = (pDornier)self->pPrivate; + + /* + use cached status while waiting for reply during drive + */ + if(pDorn->statusMode == STATSEND){ + if(!requestDornierStatus(pDorn)){ + return 0; + } + if(!readAndInterpretStatus(pDorn,&sStatus)){ + return 0; + } + pDorn->lastStatus = sStatus; + } else { + sStatus = pDorn->lastStatus; + } + + /* format it to a string */ + sprintf(pHelp,"RPM: %d , should %d\n",sStatus.cur_rpm,sStatus.nom_rpm); + strcpy(pBueffel,pHelp); + sprintf(pHelp,"State: %s\n",sStatus.rm); + strcat(pBueffel,pHelp); + sprintf(pHelp,"Current: %d\n",sStatus.pwr); + strcat(pBueffel,pHelp); + sprintf(pHelp,"Rotor T: %d, Housing T: %d\n",sStatus.rot_temp, + sStatus.cont_temp); + strcat(pBueffel,pHelp); + sprintf(pHelp,"Cooling: In-T: %d, Out-T: %d, Flow: %f\n", + sStatus.inl_temp,sStatus.outl_temp,sStatus.cool_wat); + strcat(pBueffel,pHelp); + sprintf(pHelp,"Vaccum: %f, Accel: %f",sStatus.vacuum, sStatus.accel); + strcat(pBueffel,pHelp); + + strncpy(pText,pBueffel, iTextLen); + return 1; + } /*-------------------------------------------------------------------------*/ static int DornierRun(pVelSelDriv self, float fVal) { int iRet; - char pCommand[50], pAnswer[50]; + char pCommand[50], pAnswer[50], pText[132]; pDornier pDorn = NULL; int startFlag = 0; - + int i; + assert(self); pDorn = (pDornier)self->pPrivate; /* - less then minRPM, means halt in this case. + make sure that a status was read before we do anything here, + otherwise we may be in deep trouble + */ + if(pDorn->noStatus == 1){ + for(i = 0; i < 3; i++){ + DornierText(self,pText,131); + if(pDorn->noStatus == 0){ + break; + } + } + if(pDorn->noStatus == 1){ + pDorn->iLastError = NOSTATUS; + return 0; + } + } + + /* + less then STARTSPEED, means halt in this case. Accept this only after three times, see code in GetError as well. */ if(fVal < 0){ @@ -168,29 +244,33 @@ static int takeControl(pDornier pDorn){ } memset(pCommand,0,50); pDorn->rejectCount = 0; - if(fVal < pDorn->minRPM - 3*self->fTolerance) + + if(fVal < STARTSPEED - 3*self->fTolerance) { if(pDorn->haltCount < 3){ pDorn->iLastError = HALTREQ; return 0; } strcpy(pCommand,"HAL\n"); - setRS232ReplyTerminator(pDorn->controller,"\\"); + setRS232ReplyTerminator(pDorn->controller,"\r"); + pDorn->haltCount = 0; + pDorn->fTarget = fVal; } else { - if(pDorn->lastStatus.cur_rpm < pDorn->minRPM){ + if(pDorn->lastStatus.cur_rpm < STARTSPEED - 3 * self->fTolerance){ strcpy(pCommand,"SST\n"); - setRS232ReplyTerminator(pDorn->controller,"\\"); startFlag = 1; - pDorn->fTarget = pDorn->minRPM; + pDorn->fTarget = STARTSPEED; + setRS232ReplyTerminator(pDorn->controller,"\r"); } else { + setRS232ReplyTerminator(pDorn->controller,"\r"); sprintf(pCommand,"SDR %d\n",(int)fVal); + pDorn->fTarget = fVal; } } - pDorn->fTarget = fVal; iRet = transactRS232(pDorn->controller,pCommand,strlen(pCommand), pAnswer,49); - setRS232ReplyTerminator(pDorn->controller,"\r\n"); + setRS232ReplyTerminator(pDorn->controller,"\n"); if(iRet != 1) { if(iRet != INCOMPLETE){ @@ -233,6 +313,10 @@ static int DornierError(pVelSelDriv self, int *iCode, case TARGETREJECTED: strncpy(error,"VS in local mode or target out of range", iErrLen); break; + case NOSTATUS: + strncpy(error,"No successfull status request after 3 tries", + iErrLen); + break; default: getRS232Error(pDorn->iLastError,error,iErrLen); break; @@ -262,7 +346,7 @@ static int DornierFixIt(pVelSelDriv self, int iCode){ return VELOREDO; break; case TARGETREJECTED: - if(pDorn->rejectCount >= 1){ + if(pDorn->rejectCount >= 3){ pDorn->rejectCount = 0; return VELOFAIL; } @@ -326,7 +410,7 @@ static int evaluateStatus(pVelSelDriv self, int *iCode){ /* This code considers the velocity selector arrived if it reads - four times a difference between requested spped and actual speed + four times a difference between requested speed and actual speed below difference */ pDorn->fLastRPM = sStatus.cur_rpm; @@ -387,52 +471,6 @@ static int DornierStatNew(pVelSelDriv self, int *iCode, float *fCur){ return status; } } -/*----------------------------------------------------------------------*/ - static int DornierText(pVelSelDriv self, char *pText, int iTextLen) - { - pDornier pDorn = NULL; - int iRet, iErrStat; - DornierStatus sStatus; - char pBueffel[1024]; - char pHelp[80]; - - assert(self); - pDorn = (pDornier)self->pPrivate; - - /* - use cached status while waiting for reply during drive - */ - if(pDorn->statusMode == STATSEND){ - if(!requestDornierStatus(pDorn)){ - return 0; - } - if(!readAndInterpretStatus(pDorn,&sStatus)){ - return 0; - } - pDorn->lastStatus = sStatus; - } else { - sStatus = pDorn->lastStatus; - } - - /* format it to a string */ - sprintf(pHelp,"RPM: %d , should %d\n",sStatus.cur_rpm,sStatus.nom_rpm); - strcpy(pBueffel,pHelp); - sprintf(pHelp,"State: %s\n",sStatus.rm); - strcat(pBueffel,pHelp); - sprintf(pHelp,"Current: %d\n",sStatus.pwr); - strcat(pBueffel,pHelp); - sprintf(pHelp,"Rotor T: %d, Housing T: %d\n",sStatus.rot_temp, - sStatus.cont_temp); - strcat(pBueffel,pHelp); - sprintf(pHelp,"Cooling: In-T: %d, Out-T: %d, Flow: %f\n", - sStatus.inl_temp,sStatus.outl_temp,sStatus.cool_wat); - strcat(pBueffel,pHelp); - sprintf(pHelp,"Vaccum: %f, Accel: %f",sStatus.vacuum, sStatus.accel); - strcat(pBueffel,pHelp); - - strncpy(pText,pBueffel, iTextLen); - return 1; - } /*------------------------------------------------------------------------*/ static int DornierLoss(pVelSelDriv self, float *fLoss) { @@ -639,6 +677,7 @@ static int DornierStatNew(pVelSelDriv self, int *iCode, float *fCur){ free(pNew); return NULL; } + pDorn->noStatus = 1; /* initialise function pointers */ pNew->DeletePrivate = DornierKill; diff --git a/el734hp.c b/el734hp.c index 3d0a6a7..5f9aa37 100644 --- a/el734hp.c +++ b/el734hp.c @@ -318,6 +318,7 @@ static int EL734Fix(void *pData, int iCode, float fValue){ initRS232(self->controller); return MOTREDO; case RUNFAULT: + case POSFAULT: return MOTREDO; } return MOTFAIL; diff --git a/tasdrive.c b/tasdrive.c index 0bd123a..c0693c8 100644 --- a/tasdrive.c +++ b/tasdrive.c @@ -114,6 +114,7 @@ int TASDrive(SConnection *pCon, SicsInterp *pSics, void *pData, motorMask[i] = 0; } varPointer = -1; + motorPointer = -1; rStatus = 1; /* parse loop */ diff --git a/tasscan.c b/tasscan.c index ee868ad..7fb57b8 100644 --- a/tasscan.c +++ b/tasscan.c @@ -85,6 +85,33 @@ static void strcenter(char *str, char *target, int iLength) } target[iLength-1] = '\0'; } +/*----------------------------------------------------------------------- + helper function for TASHeader + ------------------------------------------------------------------------*/ +static void writePolFile(FILE *fd, pTASdata pTAS){ + char pLine[132]; + FILE *fpol = NULL; + + assert(fd); + assert(pTAS); + + fpol = fopen(pTAS->tasPar[POLFIL]->text,"r"); + if(!fpol){ + /* + error gets reported anyway later on + */ + return; + } + + while(fgets(pLine,131,fpol) != NULL){ + if(strstr(pLine,"\n") == NULL){ + fprintf(fd,"POLAN: %s\n", pLine); + } else { + fprintf(fd,"POLAN: %s", pLine); + } + } + fclose(fpol); +} /*------------------------------------------------------------------------- TASHeader writes the header of a TAS data file. The format is an obscure format from ILL ( not ill but Institute Laue Langevin). No @@ -307,6 +334,10 @@ static int TASHeader(pScanData self) } fprintf(self->fd,"\n"); + if(pTAS->iPOL >= 0){ + writePolFile(self->fd,pTAS); + } + /* write counter parameters */ diff --git a/tdchm.c b/tdchm.c index 7ff3137..0c890db 100644 --- a/tdchm.c +++ b/tdchm.c @@ -186,6 +186,8 @@ static int clearTdc(pTdc self, unsigned char fill){ static int enableTdc(pTdc self){ Z80_reg in, out; + return 1; + /* range and n are obscure parameters */ @@ -232,6 +234,8 @@ static int TDCStart(pHistDriver self, SConnection *pCon){ static int disableTdc(pTdc self){ Z80_reg in, out; + return 1; + return ecbExecute(self->tdc,132,in,&out); } /*-------------------------------------------------------------------*/