- Adapted indenation to new agreed upon system

- Added support for second generation scriptcontext based counter
This commit is contained in:
koennecke
2009-02-13 09:00:03 +00:00
parent a3dcad2bfa
commit 91d4af0541
405 changed files with 88101 additions and 88173 deletions

457
velosim.c
View File

@ -60,260 +60,245 @@ typedef struct __VelSelDriv *pVelSelDriv;
#define VSACCEL -7
#define VSFAIL -2
#define FAILURE 1 /* a flat 1% error rate for trouble detection */
#define FAILURE 1 /* a flat 1% error rate for trouble detection */
/* -------- A private datastructure for velocity selector simulation */
typedef struct {
long lTime;
float fPos;
} Simi, *pSimi;
typedef struct {
long lTime;
float fPos;
} Simi, *pSimi;
/*----------------------------------------------------------------------------*/
static float SimRandom(void)
{
float fVal;
fVal = ( (float) rand() / (float)RAND_MAX) * 100.0;
return fVal;
}
/*---------------------------------------------------------------------------*/
static int RunComplete(pVelSelDriv self)
{
time_t tD;
pSimi pDriv;
pDriv = (pSimi)self->pPrivate;
if((int)time(&tD) > pDriv->lTime)
{
return 1;
}
return 0;
}
/*--------------------------------------------------------------------------*/
static int SimInit(pVelSelDriv self, SConnection *pCon)
{
pSimi pDriv;
assert(self);
static float SimRandom(void)
{
float fVal;
pDriv = (pSimi)self->pPrivate;
pDriv->fPos = 0.0;
fVal = ((float) rand() / (float) RAND_MAX) * 100.0;
return fVal;
}
/*---------------------------------------------------------------------------*/
static int RunComplete(pVelSelDriv self)
{
time_t tD;
pSimi pDriv;
pDriv = (pSimi) self->pPrivate;
if ((int) time(&tD) > pDriv->lTime) {
return 1;
}
return 0;
}
/*--------------------------------------------------------------------------*/
static int SimInit(pVelSelDriv self, SConnection * pCon)
{
pSimi pDriv;
assert(self);
pDriv = (pSimi) self->pPrivate;
pDriv->fPos = 0.0;
return 1;
}
/*----------------------------------------------------------------------------*/
static int GetSimPos(pVelSelDriv self, float *fPos)
{
pSimi pDriv;
static int GetSimPos(pVelSelDriv self, float *fPos)
{
assert(self);
if(SimRandom() < FAILURE)
{
*fPos = SimRandom();
return HWFault;
}
pDriv = (pSimi)self->pPrivate;
if(RunComplete(self))
{
*fPos = pDriv->fPos;
}
else /* simulate a selector running at a strange speed */
{
if(SimRandom() < FAILURE)
{
*fPos = pDriv->fPos - 10.;
}
else
{
*fPos = pDriv->fPos;
}
return OKOK;
pSimi pDriv;
assert(self);
if (SimRandom() < FAILURE) {
*fPos = SimRandom();
return HWFault;
}
pDriv = (pSimi) self->pPrivate;
if (RunComplete(self)) {
*fPos = pDriv->fPos;
} else { /* simulate a selector running at a strange speed */
if (SimRandom() < FAILURE) {
*fPos = pDriv->fPos - 10.;
} else {
*fPos = pDriv->fPos;
}
return OKOK;
}
/*----------------------------------------------------------------------------*/
static int SimRun(pVelSelDriv self, float fVal)
{
float fDiff;
time_t tD;
pSimi pDriv;
assert(self);
/* calculate time for completion */
pDriv = (pSimi)self->pPrivate;
fDiff = fVal - pDriv->fPos;
if(fDiff < .0) fDiff = -fDiff;
pDriv->lTime = (int)time(&tD) + (int)(fDiff/10000.);
/* in a fifth the failures, simply die, else simply do not find pos */
if(SimRandom() < (FAILURE/5))
{
return HWFault;
}
else
{
pDriv->fPos = fVal;
return OKOK;
}
}
/*--------------------------------------------------------------------------*/
static int SimError(pVelSelDriv self, int *iCode, char *error, int iErrLen)
{
assert(self);
if(RunComplete(self))
{
*iCode = 56;
strncpy(error,
"ERROR: HW: Simulated selector error on simulated selector",iErrLen);
}
else
{
*iCode = 12;
strncpy(error,"Selector still creeping along",iErrLen-1);
}
return 1;
}
return OKOK;
}
/*----------------------------------------------------------------------------*/
static int SimRun(pVelSelDriv self, float fVal)
{
float fDiff;
time_t tD;
pSimi pDriv;
assert(self);
/* calculate time for completion */
pDriv = (pSimi) self->pPrivate;
fDiff = fVal - pDriv->fPos;
if (fDiff < .0)
fDiff = -fDiff;
pDriv->lTime = (int) time(&tD) + (int) (fDiff / 10000.);
/* in a fifth the failures, simply die, else simply do not find pos */
if (SimRandom() < (FAILURE / 5)) {
return HWFault;
} else {
pDriv->fPos = fVal;
return OKOK;
}
}
/*--------------------------------------------------------------------------*/
static int SimError(pVelSelDriv self, int *iCode, char *error, int iErrLen)
{
assert(self);
if (RunComplete(self)) {
*iCode = 56;
strncpy(error,
"ERROR: HW: Simulated selector error on simulated selector",
iErrLen);
} else {
*iCode = 12;
strncpy(error, "Selector still creeping along", iErrLen - 1);
}
return 1;
}
/*---------------------------------------------------------------------------*/
static int SimFix(pVelSelDriv self, int iError)
{
float fRand;
/* return the three values MOTREDO, MOTFAIL, MOTOK with a third
randomness
*/
assert(self);
fRand = SimRandom();
if(iError == 12)
{
return VELOREDO;
}
SICSLogWrite("Selector dying randomly",eHWError);
if(fRand < 0.3333)
{
return VELOOK;
}
else if(fRand < 0.66666)
{
return VELOREDO;
}
else
{
return VELOFAIL;
}
}
/*--------------------------------------------------------------------------*/
static int SimHalt(pVelSelDriv self)
{
pSimi pDriv;
assert(self);
pDriv = (pSimi)self->pPrivate;
pDriv->lTime = 0;
return OKOK;
}
/*--------------------------------------------------------------------------*/
static int SimStat(pVelSelDriv self, int *iCode, float *fVal)
{
pSimi pDriv;
assert(self);
pDriv = (pSimi)self->pPrivate;
static int SimFix(pVelSelDriv self, int iError)
{
float fRand;
*iCode = ROTMOVE;
if(RunComplete(self))
{
*fVal = pDriv->fPos;
return VSOK;
}
else
{
if(SimRandom() < FAILURE/2)
{
return VSFAIL;
}
else if(SimRandom() < FAILURE)
{
return VSFAIL;
}
*fVal = random()/150678;
return VSACCEL;
}
/* return the three values MOTREDO, MOTFAIL, MOTOK with a third
randomness
*/
assert(self);
fRand = SimRandom();
if (iError == 12) {
return VELOREDO;
}
SICSLogWrite("Selector dying randomly", eHWError);
if (fRand < 0.3333) {
return VELOOK;
} else if (fRand < 0.66666) {
return VELOREDO;
} else {
return VELOFAIL;
}
}
/*--------------------------------------------------------------------------*/
static int SimHalt(pVelSelDriv self)
{
pSimi pDriv;
assert(self);
pDriv = (pSimi) self->pPrivate;
pDriv->lTime = 0;
return OKOK;
}
/*--------------------------------------------------------------------------*/
static int SimStat(pVelSelDriv self, int *iCode, float *fVal)
{
pSimi pDriv;
assert(self);
pDriv = (pSimi) self->pPrivate;
*iCode = ROTMOVE;
if (RunComplete(self)) {
*fVal = pDriv->fPos;
return VSOK;
} else {
if (SimRandom() < FAILURE / 2) {
return VSFAIL;
} else if (SimRandom() < FAILURE) {
return VSFAIL;
}
*fVal = random() / 150678;
return VSACCEL;
}
}
/*-------------------------------------------------------------------------*/
static int SimText(pVelSelDriv self, char *pText, int iTextLen)
{
strncpy(pText,"Simulated Info on a simulated velocity selector",
iTextLen);
return 1;
}
static int SimText(pVelSelDriv self, char *pText, int iTextLen)
{
strncpy(pText, "Simulated Info on a simulated velocity selector",
iTextLen);
return 1;
}
/*------------------------------------------------------------------------*/
static int SimLoss(pVelSelDriv self, float *fLoss)
{
*fLoss = 20.33338;
return 1;
}
/*-------------------------------------------------------------------------*/
static void SimKill(void *pData)
{
free(pData);
}
/*-------------------------------------------------------------------------*/
pVelSelDriv VSCreateSim(void)
{
pVelSelDriv pNew = NULL;
/* business as usual: allocate memory */
pNew = (pVelSelDriv)malloc(sizeof(VelSelDriv));
if(!pNew)
{
return NULL;
}
/* zero the world */
memset(pNew,0,sizeof(VelSelDriv));
pNew->pPrivate = malloc(sizeof(Simi));
if(!pNew->pPrivate)
{
free(pNew);
return NULL;
}
/* initialise function pointers */
pNew->DeletePrivate = SimKill;
pNew->Halt = SimHalt;
pNew->GetError = SimError;
pNew->TryAndFixIt = SimFix;
pNew->GetRotation = GetSimPos;
pNew->SetRotation = SimRun;
pNew->GetStatus = SimStat;
pNew->GetDriverText = SimText;
pNew->GetLossCurrent = SimLoss;
pNew->Init = SimInit;
/* done it */
return pNew;
}
/*--------------------------------------------------------------------------*/
void VSDeleteDriver(pVelSelDriv self)
{
assert(self);
/* try to delete the private parts */
if(self->DeletePrivate)
{
self->DeletePrivate(self->pPrivate);
}
/* now we cleans ourselves */
free(self);
}
static int SimLoss(pVelSelDriv self, float *fLoss)
{
*fLoss = 20.33338;
return 1;
}
/*-------------------------------------------------------------------------*/
static void SimKill(void *pData)
{
free(pData);
}
/*-------------------------------------------------------------------------*/
pVelSelDriv VSCreateSim(void)
{
pVelSelDriv pNew = NULL;
/* business as usual: allocate memory */
pNew = (pVelSelDriv) malloc(sizeof(VelSelDriv));
if (!pNew) {
return NULL;
}
/* zero the world */
memset(pNew, 0, sizeof(VelSelDriv));
pNew->pPrivate = malloc(sizeof(Simi));
if (!pNew->pPrivate) {
free(pNew);
return NULL;
}
/* initialise function pointers */
pNew->DeletePrivate = SimKill;
pNew->Halt = SimHalt;
pNew->GetError = SimError;
pNew->TryAndFixIt = SimFix;
pNew->GetRotation = GetSimPos;
pNew->SetRotation = SimRun;
pNew->GetStatus = SimStat;
pNew->GetDriverText = SimText;
pNew->GetLossCurrent = SimLoss;
pNew->Init = SimInit;
/* done it */
return pNew;
}
/*--------------------------------------------------------------------------*/
void VSDeleteDriver(pVelSelDriv self)
{
assert(self);
/* try to delete the private parts */
if (self->DeletePrivate) {
self->DeletePrivate(self->pPrivate);
}
/* now we cleans ourselves */
free(self);
}