- JulCho now reads data in tow bunches, speeds and rest for optimization

This commit is contained in:
koennecke
2006-10-20 14:55:25 +00:00
parent ff7896ca53
commit 980efacf6f
5 changed files with 125 additions and 60 deletions

View File

@@ -7,6 +7,11 @@
* copyright: see file COPYRIGHT
*
* Mark Koennecke, June-July 2006
*
* Parameter updating is to slow, therefore it happens in two groups now:
* actspeed and actphase are requested more frequently, so they go separate
*
* Mark Koennecke, October 2006
*/
#include <stdlib.h>
#include <assert.h>
@@ -33,6 +38,9 @@
#define ROPAR -811
#define NOMEM -812
#define HALT -813
/*--------------------- update flags -------------------------------------*/
#define ALL 1
#define SPEED 2
/*------------------------- chopper internal names -----------------------*/
#define CH1N "snail"
#define CH2N "master"
@@ -46,6 +54,7 @@ typedef struct {
int errorCode;
time_t lastUpdate;
int updateIntervall;
int speedUpdate;
int halt;
}JulCho, *pJulCho;
/*------------------------------------------------------------------------*/
@@ -383,12 +392,45 @@ static int ReadJulChoFlags(pJulCho self){
return 1;
}
/*---------------------------------------------------------------------------*/
static int UpdateJulChoParameters(pJulCho self){
static int UpdateJulChoParameters(pJulCho self, int what){
int status, intData[5];
double doubleData[5];
char reply[255];
if(time(NULL) < self->lastUpdate + self->updateIntervall){
assert(what == ALL || what == SPEED);
if(what == SPEED){
if(time(NULL) < self->speedUpdate + self->updateIntervall){
return 1;
}
} else{
if(time(NULL) < self->lastUpdate + self->updateIntervall){
return 1;
}
}
status = JulChoTransact(self,"RAS",reply,255);
if(status < 0){
self->errorCode = status;
return 0;
}
if(!splitJulChoInt(reply,intData)){
self->errorCode = BADREPLY;
}
setJulChoIntPar(self->parNode,"actspeed",intData);
status = JulChoTransact(self,"RAP",reply,255);
if(status < 0){
self->errorCode = status;
return 0;
}
if(!splitJulChoDouble(reply,doubleData)){
self->errorCode = BADREPLY;
}
setJulChoDoublePar(self->parNode,"actphase",doubleData);
if(what != ALL){
self->speedUpdate = time(NULL);
return 1;
}
@@ -402,15 +444,6 @@ static int UpdateJulChoParameters(pJulCho self){
}
setJulChoIntPar(self->parNode,"nomspeed",intData);
status = JulChoTransact(self,"RAS",reply,255);
if(status < 0){
self->errorCode = status;
return 0;
}
if(!splitJulChoInt(reply,intData)){
self->errorCode = BADREPLY;
}
setJulChoIntPar(self->parNode,"actspeed",intData);
status = JulChoTransact(self,"RNP",reply,255);
if(status < 0){
@@ -422,15 +455,6 @@ static int UpdateJulChoParameters(pJulCho self){
}
setJulChoDoublePar(self->parNode,"nomphase",doubleData);
status = JulChoTransact(self,"RAP",reply,255);
if(status < 0){
self->errorCode = status;
return 0;
}
if(!splitJulChoDouble(reply,doubleData)){
self->errorCode = BADREPLY;
}
setJulChoDoublePar(self->parNode,"actphase",doubleData);
status = JulChoTransact(self,"RGW",reply,255);
if(status < 0){
@@ -496,6 +520,7 @@ static int UpdateJulChoParameters(pJulCho self){
status = ReadJulChoFlags(self);
self->lastUpdate = time(NULL);
self->speedUpdate = time(NULL);
return status;
}
/*------------------------------------------------------------------------*/
@@ -551,6 +576,15 @@ static void JulChoErrorcodeToString(int code, char *pError, int iLen){
break;
}
}
/*------------------------------------------------------------------------*/
static int testParGroup(char *name){
if(strstr(name,"actspeed") != NULL ||
strstr(name,"actphase") != NULL){
return SPEED;
} else {
return ALL;
}
}
/*-------------------------------------------------------------------------*/
static int JulChoGetCallback(void *userData, void *callData,
pHdb currentNode, hdbValue v){
@@ -564,7 +598,7 @@ static int JulChoGetCallback(void *userData, void *callData,
assert(self != NULL);
status = UpdateJulChoParameters(self);
status = UpdateJulChoParameters(self,testParGroup(currentNode->name));
if(status != 1 && pCon != NULL){
JulChoErrorcodeToString(self->errorCode, error,127);
snprintf(buffer,255,"ERROR: %s occurred reading par",error);
@@ -966,7 +1000,7 @@ static int JulChoGetPar(pCodri pDriv, char *parname,
self->errorCode = NOTPAR;
return 0;
}
if(!UpdateJulChoParameters(self)){
if(!UpdateJulChoParameters(self,testParGroup(parname))){
return 0;
}
val = formatValue(target->value);