progressive patching

This commit is contained in:
Douglas Clowes
2012-11-28 13:13:20 +11:00
parent e91fdd1808
commit 2f391302b1
9 changed files with 52 additions and 27 deletions

View File

@ -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);
}

View File

@ -17,6 +17,7 @@ typedef struct __CONFVIRTMOT {
float targetValue;
int targetReached;
int posCount;
double last_report_time;
char scriptError[512];
int parseOK;
}ConfigurableVirtualMotor, *pConfigurableVirtualMotor;

View File

@ -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]);

View File

@ -22,6 +22,7 @@ typedef struct __CONFVIRTMOT {
float targetValue;
int targetReached;
int posCount;
double last_report_time;
char scriptError[512];
int parseOK;
}ConfigurableVirtualMotor, *pConfigurableVirtualMotor;

View File

@ -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);

16
costa.c
View File

@ -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;
}

View File

@ -25,5 +25,6 @@ int CostaPop(pCosta self, char **pPtr);
/*----------------------------------------------------------------------*/
void CostaLock(pCosta self);
void CostaUnlock(pCosta self);
int CostaLocked(pCosta self);
#endif

View File

@ -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;

View File

@ -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;