From 2f391302b1ba0a60c218b744b0e8b6abcd0333b5 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Wed, 28 Nov 2012 13:13:20 +1100 Subject: [PATCH] progressive patching --- chadapter.c | 4 ++-- confvirtmot.i | 1 + confvirtualmot.c | 29 ++++++++++++++++++++++++----- confvirtualmot.w | 1 + conman.c | 9 ++++++--- costa.c | 16 +++++++--------- costa.h | 1 + countdriv.c | 3 ++- countdriv.h | 15 ++++++++------- 9 files changed, 52 insertions(+), 27 deletions(-) diff --git a/chadapter.c b/chadapter.c index 9e7d3237..cb8557ec 100644 --- a/chadapter.c +++ b/chadapter.c @@ -174,8 +174,8 @@ static void KillAdapter(void *pData) if (self->pInt) free(self->pInt); - if (self->pParName); - free(self->pParName); + if (self->pParName) + free(self->pParName); free(self); } diff --git a/confvirtmot.i b/confvirtmot.i index f1fc5739..931208ab 100644 --- a/confvirtmot.i +++ b/confvirtmot.i @@ -17,6 +17,7 @@ typedef struct __CONFVIRTMOT { float targetValue; int targetReached; int posCount; + double last_report_time; char scriptError[512]; int parseOK; }ConfigurableVirtualMotor, *pConfigurableVirtualMotor; diff --git a/confvirtualmot.c b/confvirtualmot.c index c930f23f..2ff2dc86 100644 --- a/confvirtualmot.c +++ b/confvirtualmot.c @@ -35,6 +35,9 @@ #include "confvirtmot.h" #include "confvirtmot.i" +#define BAD_VALUE (-9999.99) +extern double DoubleTime(void); + extern char *stptok(char *s, char *t, int len, char *brk); /*--------------------------------------------------------------------------- @@ -213,6 +216,7 @@ static long ConfSetValue(void *pData, SConnection * pCon, float newValue) self->targetValue = newValue; self->targetReached = 0; self->posCount = 0; + self->last_report_time = 0.0; status = startMotorList(self, pCon); if (status != OKOK) { @@ -384,12 +388,14 @@ static int ConfCheckStatus(void *pData, SConnection * pCon) InvokeCallBack(self->pCall, MOTDRIVE, &event); } } else if (result == HWBusy) { - self->posCount++; - if (self->posCount >= 10 /*ObVal(self->ParArray,MOVECOUNT) */ ) { + double current_time, skip_time; + current_time = DoubleTime(); + skip_time = 0.500; + if (self->last_report_time + skip_time <= current_time) { event.pName = self->name; event.fVal = self->pDriv->GetValue(self, pCon); InvokeCallBack(self->pCall, MOTDRIVE, &event); - self->posCount = 0; + self->last_report_time = current_time; } } return result; @@ -445,7 +451,7 @@ static void checkMotorValues(pConfigurableVirtualMotor self, static float ConfGetValue(void *pData, SConnection * pCon) { pConfigurableVirtualMotor self = (pConfigurableVirtualMotor) pData; - float currentValue = -9999.99; + float currentValue = BAD_VALUE; assert(self != NULL); @@ -507,6 +513,14 @@ static void KillConfigurableVirtualMotor(void *data) free(self->state); self->state = NULL; } + if (self->pCall != NULL) { + DeleteCallBackInterface(self->pCall); + self->pCall = NULL; + } + if (self->pDriv != NULL) { + free(self->pDriv); + self->pDriv = NULL; + } free(self); self = NULL; } @@ -535,6 +549,7 @@ int MakeConfigurableVirtualMotor(SConnection * pCon, SicsInterp * pSics, pNew->name = strdup(argv[1]); pNew->posCount = 0; + pNew->last_report_time = 0.0; pNew->pDes = CreateDescriptor("ConfigurableVirtualMotor"); pNew->pDriv = CreateDrivableInterface(); pNew->motorList = LLDcreate(sizeof(RealMotor)); @@ -584,7 +599,6 @@ int ConfigurableVirtualMotorAction(SConnection * pCon, SicsInterp * pSics, pConfigurableVirtualMotor self = NULL; char pBueffel[512]; float value; - int iRet; long lID; pRegisteredInfo pRegInfo = NULL; @@ -699,10 +713,15 @@ int ConfigurableVirtualMotorAction(SConnection * pCon, SicsInterp * pSics, } pRegInfo->lastValue = value; + RemoveCallbackCon(self->pCall, pCon); lID = RegisterCallback(self->pCall, MOTDRIVE, InterestCallback, pRegInfo, KillInfo); SCSendOK(pCon); return 1; + } else if(strcmp(argv[1],"uninterest") == 0) { + RemoveCallbackCon(self->pCall, pCon); + SCSendOK(pCon); + return 1; } else { snprintf(pBueffel, 5120, "ERROR: subcommand %s to %s unknown", argv[1], argv[0]); diff --git a/confvirtualmot.w b/confvirtualmot.w index 169ac0c1..f0e501b0 100644 --- a/confvirtualmot.w +++ b/confvirtualmot.w @@ -22,6 +22,7 @@ typedef struct __CONFVIRTMOT { float targetValue; int targetReached; int posCount; + double last_report_time; char scriptError[512]; int parseOK; }ConfigurableVirtualMotor, *pConfigurableVirtualMotor; diff --git a/conman.c b/conman.c index 99969576..3d0d2050 100644 --- a/conman.c +++ b/conman.c @@ -3,7 +3,7 @@ Connection management for SICS. This is one the core files for SICS. Does a lot. See the descriptions with individual functions below. - + Mark Koennecke, October 1996 @@ -622,7 +622,7 @@ int SCPrintf(SConnection * self, int iOut, char *fmt, ...) va_list ap; char buf[256]; char *dyn; - int l; + unsigned int l; int res; va_start(ap, fmt); @@ -765,7 +765,10 @@ int SCNormalWrite(SConnection * self, char *buffer, int iOut) } /* log it for any case */ - SICSLogWrite(buffer, iOut); + if (!(iOut == eInternal + || (buffer[0] == 'O' && buffer[1] == 'K' + && (buffer[2] == '\0' || buffer[2] == '\r' || buffer[2] == '\n')))) + SICSLogWrite(buffer, iOut); testAndWriteCommandLog(self, buffer, iOut); diff --git a/costa.c b/costa.c index 875d80d5..bbdc17a7 100644 --- a/costa.c +++ b/costa.c @@ -108,10 +108,6 @@ int CostaTop(pCosta self, char *pCommand) assert(self); - /* check for lock */ - if (self->iLock) { - return 0; - } /* check Size */ if (self->iCount >= self->iMaxSize) { return 0; @@ -138,11 +134,6 @@ int CostaBottom(pCosta self, char *pCommand) int iRet, iRes = 1; assert(self); - /* check for lock */ - if (self->iLock) { - return 0; - } - /* do not want 0 commands */ if (strlen(pCommand) < 1) { return 1; @@ -187,3 +178,10 @@ void CostaUnlock(pCosta self) { self->iLock = 0; } + +/*--------------------------------------------------------------------------*/ + int CostaLocked(pCosta self) + { + return self->iLock; + } + diff --git a/costa.h b/costa.h index 5703b210..40bd69c2 100644 --- a/costa.h +++ b/costa.h @@ -25,5 +25,6 @@ int CostaPop(pCosta self, char **pPtr); /*----------------------------------------------------------------------*/ void CostaLock(pCosta self); void CostaUnlock(pCosta self); +int CostaLocked(pCosta self); #endif diff --git a/countdriv.c b/countdriv.c index e9a3d6fa..29a46692 100644 --- a/countdriv.c +++ b/countdriv.c @@ -1,6 +1,6 @@ /*------------------------------------------------------------------------ G E N C O U N T - + Some general stuff for handling a CounterDriver. @@ -61,6 +61,7 @@ pCounterDriver CreateCounterDriver(char *name, char *type) pRes->fPreset = 1000.; pRes->fTime = 0.; pRes->iNoOfMonitors = 0; + pRes->iControlMonitor = 0; pRes->iPause = 0; pRes->Start = NULL; pRes->GetStatus = NULL; diff --git a/countdriv.h b/countdriv.h index adf4344b..66b61443 100644 --- a/countdriv.h +++ b/countdriv.h @@ -1,20 +1,20 @@ /*--------------------------------------------------------------------------- C O U N T E R D R I V E R - - + + This is the interface to a Sics-Counter driver. This means a - single counter managing possibly several monitors in one go. - + single counter managing possibly several monitors in one go. + A counter can run for a predefined time or until a predefined monitor count has been reached. - + Mark Koennecke, January 1996 General parameter setting added: - Mark Koennecke, April 1999 + Mark Koennecke, April 1999 copyright: see implementation file. - + ---------------------------------------------------------------------------*/ #ifndef SICSCOUNTERDRIVER #define SICSCOUNTERDRIVER @@ -42,6 +42,7 @@ typedef struct __COUNTER { float fLastCurrent; float fTime; int iNoOfMonitors; + int iControlMonitor; long lCounts[MAXCOUNT]; int iPause; int iErrorCode;