From 190883982c2f7d445acc47970211bacf8820d515 Mon Sep 17 00:00:00 2001 From: zolliker Date: Fri, 23 Feb 2007 12:36:28 +0000 Subject: [PATCH] - removed a 0.2 sec delay when communicating with the TecsServer --- tecsdriv.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/tecsdriv.c b/tecsdriv.c index 390ce4a..2d1edd0 100644 --- a/tecsdriv.c +++ b/tecsdriv.c @@ -61,12 +61,14 @@ #include "tecs/myc_str.h" #include "tecs/myc_err.h" #include +#include "statistics.h" /*-----------------------------------------------------------------------*/ typedef struct { void *pData; char *lastError; - time_t lastGet; + time_t lastGet, lastGetX; + float lastValue, lastPos, lastDelta; int iLastError, port; int (*EVLimits)(void *, float , char *, int); char server[256]; @@ -225,7 +227,9 @@ void outFunc(char *str, void *arg) { pTecsDriv pMe = NULL; int iRet; time_t now; - + static Statistics *stat = NULL; + Statistics *old; + assert(self); pMe = (pTecsDriv)self->pPrivate; assert(pMe); @@ -233,12 +237,20 @@ void outFunc(char *str, void *arg) { time(&now); if (now!=pMe->lastGet) { /* TecsGet was not yet called within this second */ pMe->lastGet=now; - } else { - CocDelay(200); /* wait 0.2 sec. (seems that SICS has nothing else to do then reading temperatures) */ + } else { /* do not call tecs again, as we have already quite recent values */ + *fPos = pMe->lastValue; + pMe->iLastError=0; + return 1; } + if (stat == NULL) stat = StatisticsNew("TecsGet"); + old = StatisticsBegin(stat); + /* get temperature */ iRet = TeccGet(pMe->pData, fPos); + StatisticsEnd(old); + + pMe->lastValue = *fPos; if(iRet < 0) { pMe->lastError = ErrMessage; pMe->iLastError=1; /* severe */ @@ -254,20 +266,32 @@ void outFunc(char *str, void *arg) { pTecsDriv pMe = NULL; int iRet; time_t now; + static Statistics *stat = NULL; + Statistics *old; assert(self); pMe = (pTecsDriv)self->pPrivate; assert(pMe); time(&now); - if (now!=pMe->lastGet) { /* TecsGet was not yet called within this second */ - pMe->lastGet=now; - } else { - CocDelay(200); /* wait 0.2 sec. (seems that SICS has nothing else to do then reading temperatures) */ + if (now!=pMe->lastGetX) { /* TecsGetX was not yet called within this second */ + pMe->lastGetX=now; + } else { /* do not call tecs again, as we have already quite recent values */ + *fPos = pMe->lastPos; + *fDelta = pMe->lastDelta; + pMe->iLastError=0; + return 1; } - /* get temperature */ + if (stat == NULL) stat = StatisticsNew("TecsGetX"); + old = StatisticsBegin(stat); + + /* get temperatures */ iRet = TeccGetX(pMe->pData, fTarget, fPos, fDelta); + StatisticsEnd(old); + + pMe->lastPos = *fPos; + pMe->lastDelta = *fDelta; if(iRet < 0) { pMe->lastError = ErrMessage; pMe->iLastError=1; /* severe */