This commit is contained in:
cvs
2000-04-10 14:33:07 +00:00
parent c70f0b7cb8
commit d4974b94e8
11 changed files with 236 additions and 164 deletions

View File

@ -101,9 +101,70 @@ int CocTryCmd(CocConn *conn)
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
int CocCmd(CocConn *conn, const char *rwList) int CocCmdWithRetry(CocConn *conn) {
{ int iret, cnt, setmode, i; int cnt, iret;
char *err; char *err;
cnt=3;
while (1) {
cnt--;
if (cnt<=0) {
ERR_I(CocTryCmd(conn));
break;
}
iret=CocTryCmd(conn);
if (iret>=0) break;
close(conn->fd);
conn->fd=-1;
if (ErrCode!=ECONNRESET && ErrCode!=EPIPE) goto OnError;
ErrWrite("try again, error was");
}
ERR_P(err=str_get_str(conn->resbuf, NULL));
if (*err!='\0') { ErrMsg(err); ErrTxt(": (response from server)",0 ); goto OnError; }
return(0);
OnError: return(-1);
}
/*-------------------------------------------------------------------------*/
int CocSet(CocConn *conn, const char *name, const char *value) {
assert(conn!=NULL);
str_put_start(conn->cmdbuf);
ERR_I(str_put_str(conn->cmdbuf, "["));
ERR_I(str_put_str(conn->cmdbuf, name));
ERR_I(str_put_str(conn->cmdbuf, value));
ERR_I(str_put_str(conn->cmdbuf, "]"));
ERR_I(CocCmdWithRetry(conn));
ERR_I(str_get_end(conn->resbuf));
return(0);
OnError: return(-1);
}
/*-------------------------------------------------------------------------*/
int CocGetN(CocConn *conn, const char *name, char *value, int reslen) {
assert(conn!=NULL);
str_put_start(conn->cmdbuf);
ERR_I(str_put_str(conn->cmdbuf, name));
ERR_I(CocCmdWithRetry(conn));
ERR_P(str_nget_str(conn->resbuf, value, reslen));
ERR_I(str_get_end(conn->resbuf));
return(0);
OnError: return(-1);
}
/*-------------------------------------------------------------------------*/
int CocCmd(CocConn *conn, const char *rwList)
{ int setmode, i;
const char *t, *s; const char *t, *s;
char nam[32]; char nam[32];
CocVar *var; CocVar *var;
@ -137,22 +198,7 @@ int CocCmd(CocConn *conn, const char *rwList)
s=t+1; s=t+1;
} while (*t!='\0'); } while (*t!='\0');
cnt=3; ERR_I(CocCmdWithRetry(conn));
while (1) {
cnt--;
if (cnt<=0) {
ERR_I(CocTryCmd(conn));
break;
}
iret=CocTryCmd(conn);
if (iret>=0) break;
close(conn->fd);
conn->fd=-1;
if (ErrCode!=ECONNRESET && ErrCode!=EPIPE) goto OnError;
ErrWrite("try again, error was");
}
ERR_P(err=str_get_str(conn->resbuf, NULL));
if (*err!='\0') { ErrMsg(err); ErrTxt(": (response from server)",0 ); goto OnError; }
/* read values */ /* read values */
s=rwList; s=rwList;

View File

@ -16,6 +16,9 @@ typedef struct {
int CocInitClient(CocConn *conn, char *host, int port, char *magic, int bufsize, char *startcmd); int CocInitClient(CocConn *conn, char *host, int port, char *magic, int bufsize, char *startcmd);
int CocSendMagic(CocConn *conn, char *magic); int CocSendMagic(CocConn *conn, char *magic);
int CocCmd(CocConn *conn, const char *rwList); int CocCmd(CocConn *conn, const char *rwList);
int CocSet(CocConn *conn, const char *name, const char *value);
int CocGetN(CocConn *conn, const char *name, char *value, int reslen);
#define CocGet(C,N,V) CocGetN(C,N,V,sizeof(V))
void CocCloseClient(CocConn *conn); void CocCloseClient(CocConn *conn);
#endif /* _COC_CLIENT_H_ */ #endif /* _COC_CLIENT_H_ */

View File

@ -135,7 +135,9 @@ int CocHandle1Request(int tmo_msec, int fd) {
cl->res[0]='\0'; cl->res[0]='\0';
} else { } else {
i=CocGetVar(serverVarList, buf, varname, 1); i=CocGetVar(serverVarList, buf, varname, 1);
if (i<0) { err=ErrMessage; break; } if (i<0) {
err=ErrMessage; break;
}
} }
modified=1; modified=1;
} else { } else {
@ -144,7 +146,9 @@ int CocHandle1Request(int tmo_msec, int fd) {
cl->res[0]='\0'; cl->res[0]='\0';
} else { } else {
i=CocPutVar(serverVarList, bufo, varname, 0); i=CocPutVar(serverVarList, bufo, varname, 0);
if (i<0) { err=ErrMessage; break; } if (i<0) {
err=ErrMessage; break;
}
} }
} }
if (buf->rdpos>=buf->wrpos) { if (buf->rdpos>=buf->wrpos) {

View File

@ -238,7 +238,7 @@ void CocFreeVarList(CocVar **varList) {
p=v; p=v;
v=p->next; v=p->next;
p->next=NULL; p->next=NULL;
printf("my_free %s\n", p->name); /* printf("my_free %s\n", p->name); */
my_free(p); my_free(p);
} }
*varList=NULL; *varList=NULL;

View File

@ -89,23 +89,26 @@ void ErrSetOutFile(FILE *arg) {
outarg=arg; outarg=arg;
} }
void ERR_EXIT(char *text) {
ErrWrite(text); exit(1);
}
void ErrShowFtn_(char *text, int length) {
char buf[256];
if (length>=256) length=255;
strncpy(buf, text, length);
buf[length]='\0';
ErrWrite(buf);
}
#ifdef __VMS #ifdef __VMS
typedef struct { short size, dummy; char *text; } Desc; typedef struct { short size, dummy; char *text; } Desc;
void ErrShowVms(Desc *desc) { void ErrShowFtn(Desc *desc) {
char buf[256]; ErrShowFtn_(desc->text, desc->size);
int l;
l=desc->size;
if (l>=256) l=255;
strncpy(buf, desc->text, l);
buf[l]='\0';
ErrWrite(buf);
} }
#endif #endif
void ERR_EXIT(char *text) {
ErrWrite(text); exit(1);
}

View File

@ -31,6 +31,7 @@ typedef struct {
int nSens; /* number of sensors */ int nSens; /* number of sensors */
int codChanged; /* code has changed */ int codChanged; /* code has changed */
int codDefined; /* code is not yet confirmed */ int codDefined; /* code is not yet confirmed */
float scale; /* scale for extreme ranges */
char ch1[2], ch2[2]; /* channels for high/low T */ char ch1[2], ch2[2]; /* channels for high/low T */
char device[16]; /* device name */ char device[16]; /* device name */
char tname[16]; char tname[16];
@ -127,12 +128,12 @@ int instCurve(char *nam, char *channel) {
FILE *fil; FILE *fil;
int retstat; int retstat;
str_copy(chan, channel);
logfileOut(LOG_MAIN, "install curve %s\n", nam);
fil=NULL; fil=NULL;
crv=NULL; crv=NULL;
str_copy(chan, channel);
logfileOut(LOG_MAIN, "install curve %s\n", nam);
/* read curve file */ /* read curve file */
str_copy(nbuf, binDir); str_copy(nbuf, binDir);
str_append(nbuf, nam); str_append(nbuf, nam);
@ -209,6 +210,7 @@ int instCurve(char *nam, char *channel) {
retstat=-1; /* an error could be fixed */ retstat=-1; /* an error could be fixed */
ERR_P(LscCmd(ser, "INTYPE [chan]:[intype];INCRV [chan]:[num];DISPFLD [fld],[chan],1;DISPLAY:[maxfld]")); ERR_P(LscCmd(ser, "INTYPE [chan]:[intype];INCRV [chan]:[num];DISPFLD [fld],[chan],1;DISPLAY:[maxfld]"));
logfileOut(LOG_MAIN, "curve %d on channel %s selected\n", num, chan); logfileOut(LOG_MAIN, "curve %d on channel %s selected\n", num, chan);
Progress(100);
} else { /* header does not match -> download */ } else { /* header does not match -> download */
@ -394,21 +396,22 @@ int loadCache() {
return(-1); return(-1);
} }
float WeightedAverage(int n, float t1, float t2) { float WeightedAverage(int n, float tH, float tL) {
float p,q; float p,q;
if (n==0) { if (n==0) {
return(0.0); return(0.0);
} else if (n<2) { } else if (n<2) {
return(t1); return(tH);
} else { } else {
if (t2<tLow) { if (tL<tLow) {
return(t2); return(tL);
} else if (t1<tHigh) { } else if (tH<tHigh) {
p=tHigh-t1; p=tHigh-tH;
q=t2-tLow; q=tL-tLow;
return((t1*p*p+t2*q*q)/(p*p+q*q)); if (p==0.0 && q==0.0) { p=1; q=1; } /* should not be the case */
return((tL*p*p+tH*q*q)/(p*p+q*q));
} else { } else {
return(t1); return(tH);
} }
} }
} }
@ -480,8 +483,8 @@ int ReadTemp() {
buf[i-1]='\0'; /* strip off ';' */ buf[i-1]='\0'; /* strip off ';' */
ERR_P(LscCmd(ser, buf)); ERR_P(LscCmd(ser, buf));
} }
cryo.temp=WeightedAverage(cryo.nSens, cryo.t1, cryo.t2); cryo.temp=WeightedAverage(cryo.nSens, cryo.t1, cryo.t2)*cryo.scale;
samp.temp=WeightedAverage(samp.nSens, samp.t1, samp.t2); samp.temp=WeightedAverage(samp.nSens, samp.t1, samp.t2)*samp.scale;
if (samp.temp==0.0) samp.temp=cryo.temp; if (samp.temp==0.0) samp.temp=cryo.temp;
if (!deviceFlag if (!deviceFlag
&& !samp.dirty && samp.codDefined && !samp.codChanged && !samp.dirty && samp.codDefined && !samp.codChanged
@ -515,8 +518,8 @@ int PeriodicTask() {
if (k!=serialNo) { if (k!=serialNo) {
if (!configuring) { if (!configuring) {
str_copy(status, "controller connected"); str_copy(status, "controller connected");
configuring=1;
} }
configuring++;
if (cryo.manual || cryo.code!=0) { cryo.dirty=1; } if (cryo.manual || cryo.code!=0) { cryo.dirty=1; }
if (samp.manual || samp.code!=0) { samp.dirty=1; } if (samp.manual || samp.code!=0) { samp.dirty=1; }
ERR_P(LscCmd(ser, "RANGE:0")); /* switch off heater */ ERR_P(LscCmd(ser, "RANGE:0")); /* switch off heater */
@ -581,6 +584,7 @@ int PeriodicTask() {
} else { } else {
if (testpoint->codChanged) { if (testpoint->codChanged) {
testpoint->codChanged=0; testpoint->codChanged=0;
Progress(1);
if (testpoint->code1==0) { if (testpoint->code1==0) {
logfileOut(LOG_MAIN, "%s unplugged\n", testpoint->tname); logfileOut(LOG_MAIN, "%s unplugged\n", testpoint->tname);
} else { } else {
@ -651,7 +655,9 @@ int inputSettings(Testpoint *this) {
int Settings() { int Settings() {
int i, j, k; int i, j, k;
float pa, pr, pw, dif; float pa, pr, pw, dif;
char nbuf[256], buf[256], *cfg, *p;
cfg=NULL;
if (cryo.dirty && cryo.codDefined || samp.dirty && samp.codDefined) { if (cryo.dirty && cryo.codDefined || samp.dirty && samp.codDefined) {
for (i=0; i<2; i++) { for (i=0; i<2; i++) {
@ -703,6 +709,21 @@ int Settings() {
} }
mode=2; mode=2;
str_copy(nbuf, binDir);
str_append(nbuf, cryo.device);
str_append(nbuf, ".cfg");
cfg=str_read_file(nbuf);
if (cfg!=NULL) {
logfileOut(LOG_MAIN, "%s opened\n", nbuf);
p=str_split(buf, cfg, '\n');
sscanf(buf, "%f%f", &cryo.scale, &samp.scale);
while (p!=NULL) {
p=str_split(buf, p, '\n');
ERR_P(LscCmd(ser, buf));
}
my_free(cfg);
}
if (saveTime!=0 && tim>saveTime) { if (saveTime!=0 && tim>saveTime) {
ERR_P(LscCmd(ser, "CRVSAV;BUSY?>busy")); ERR_P(LscCmd(ser, "CRVSAV;BUSY?>busy"));
while (!busy) { while (!busy) {
@ -711,9 +732,12 @@ int Settings() {
} }
saveTime=0; saveTime=0;
} }
ERR_I(ReadTemp());
} }
return(0); return(0);
OnError: return(-1); OnError:
if (cfg!=NULL) my_free(cfg);
return(-1);
} }
int ExecuteRequest() { int ExecuteRequest() {
@ -816,7 +840,7 @@ int mainBody(void)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ int logIt=0; { int logIt=0;
int i, iret, use_stdout=0; int i, iret, cntError, use_stdout=0;
char *host; char *host;
char buf[256], opt; char buf[256], opt;
int port, msecTmo; int port, msecTmo;
@ -828,7 +852,9 @@ int main(int argc, char *argv[])
str_copy(samp.ch1,"C"); str_copy(samp.ch1,"C");
str_copy(samp.ch2,"D"); str_copy(samp.ch2,"D");
cryo.codChanged=1; cryo.codChanged=1;
cryo.scale=1.0;
samp.codChanged=1; samp.codChanged=1;
samp.scale=1.0;
logMask=LOG_MAIN+LOG_INFO; logMask=LOG_MAIN+LOG_INFO;
binDir="bin/"; binDir="bin/";
@ -948,18 +974,25 @@ int main(int argc, char *argv[])
str_copy(buf, logDir); str_copy(buf, logDir);
str_append(buf, serverId); str_append(buf, serverId);
str_append(buf, ".dlog"); str_append(buf, ".dlog");
iret=DlogOpen(&dset, buf, 1); logfileOut(LOG_INFO, "open data log file: %s\n", buf);
if (iret<0) { ERR_I(iret=DlogOpenWrt(&dset, buf, tim0.time, 2, 7*24*60*60/logPeriod, logPeriod, 0.0));
logfileOut(LOG_INFO, "create data log file: %s\n", buf); if (iret==0) {
ERR_I(DlogCreate(&dset, buf, tim0.time, 2, 7*24*60*60/logPeriod, logPeriod, 0.0)); logfileOut(LOG_INFO, "created\n");
} else { } else {
logfileOut(LOG_INFO, "opened data log file: %s\n", buf); logfileOut(LOG_INFO, "opened\n");
} }
logfileWrite(logMask); logfileWrite(logMask);
per=period; per=period;
cntError=0;
while (!quit) { while (!quit) {
iret=mainBody(); iret=mainBody();
if (iret<0) logfileShowErr("error in TecsServer"); if (iret<0) {
cntError++;
if (cntError>10) ERR_MSG("too many errors - quit");
logfileShowErr("error in TecsServer/mainBody");
} else {
if (cntError>0) cntError--;
}
} }
ERR_MSG("got quit command"); ERR_MSG("got quit command");
OnError: OnError:

View File

@ -4,7 +4,7 @@
#include "str_util.h" #include "str_util.h"
#include "tecs_cli.h" #include "tecs_cli.h"
static char device[80], command[80], buffer[132]; static char device[80], command[80];
static int quit, readTemp, configuring; static int quit, readTemp, configuring;
static float tempX, tempP, tempC; static float tempX, tempP, tempC;
@ -17,7 +17,6 @@ pTecsClient TeccInit(char *startcmd, int port) {
CocDefFlt(tempP, CocRD); CocDefFlt(tempP, CocRD);
CocDefFlt(tempX, CocRD); CocDefFlt(tempX, CocRD);
CocDefStr(device, CocWR); CocDefStr(device, CocWR);
CocDefStr(buffer, CocWR);
CocDefInt(configuring, CocRD); CocDefInt(configuring, CocRD);
CocDefInt(quit, CocWR); CocDefInt(quit, CocWR);
CocDefInt(readTemp, CocWR); CocDefInt(readTemp, CocWR);
@ -27,19 +26,6 @@ pTecsClient TeccInit(char *startcmd, int port) {
OnError: return(NULL); OnError: return(NULL);
} }
int TeccSetDev(pTecsClient conn, char *dev) {
str_copy(device, dev);
ERR_I(CocCmd(conn, "[device]"));
return(0);
OnError: return(-1);
}
char *TeccGetDev(pTecsClient conn) {
ERR_I(CocCmd(conn, "device"));
return(device);
OnError: return(NULL);
}
int TeccGet3(pTecsClient conn, float *tC, float *tX, float *tP) { int TeccGet3(pTecsClient conn, float *tC, float *tX, float *tP) {
readTemp=1; readTemp=1;
ERR_I(CocCmd(conn, "tempC,tempX,tempP,[readTemp],configuring")); ERR_I(CocCmd(conn, "tempC,tempX,tempP,[readTemp],configuring"));
@ -62,11 +48,11 @@ int TeccWait(pTecsClient conn) {
last=0; last=0;
cnt=0; cnt=0;
do { do {
CocDelay(100); CocDelay(250);
ERR_I(CocCmd(conn, "configuring")); ERR_I(CocCmd(conn, "configuring"));
if (configuring==last || configuring>1000) { if (configuring==last || configuring>1000) {
cnt++; cnt++;
if (cnt>50) ERR_MSG("configuring timeout"); if (cnt>20) ERR_MSG("configuring timeout");
} else { } else {
cnt=0; cnt=0;
last=configuring; last=configuring;
@ -83,26 +69,6 @@ int TeccSet(pTecsClient conn, float temp) {
OnError: return(-1); OnError: return(-1);
} }
char *TeccGetPar(pTecsClient conn, const char *name) {
CocDefVar(name, buffer, sizeof(buffer), &CocWR);
ERR_I(CocCmd(conn, name));
return(buffer);
OnError: return(NULL);
}
int TeccSetPar(pTecsClient conn, const char *name, const char *value) {
char nbuf[80];
str_copy(buffer, value);
CocDefVar(name, buffer, sizeof(buffer), &CocWR);
str_copy(nbuf, "[");
str_append(nbuf, name);
str_append(nbuf, "]");
ERR_I(CocCmd(conn, nbuf));
return(0);
OnError: return(-1);
}
int TeccSend(pTecsClient conn, char *cmd, char *reply, int replyLen) { int TeccSend(pTecsClient conn, char *cmd, char *reply, int replyLen) {
char *res; char *res;
int cnt; int cnt;
@ -139,64 +105,75 @@ void TeccClose(pTecsClient conn) {
} }
} }
#ifdef __VMS int TeccSetParFtn_(pTecsClient conn, char *name, char *par, int namelen, int parlen) {
char nbuf[64], pbuf[256];
typedef struct { short size, dummy; char *text; } Desc; if (namelen>=sizeof(nbuf)) namelen=sizeof(nbuf)-1;
strncpy(nbuf, name, namelen);
while (namelen>0 && nbuf[namelen-1]==' ') namelen--; /* trim */
nbuf[namelen]='\0';
int TeccSetParVms(pTecsClient conn, Desc *name, Desc *par) { if (parlen>=sizeof(pbuf)) parlen=sizeof(pbuf)-1;
char nbuf[80]; strncpy(pbuf, par, parlen);
int l; while (parlen>0 && pbuf[parlen-1]==' ') parlen--; /* trim */
pbuf[parlen]='\0';
l=par->size; ERR_I(CocSet(conn, nbuf, pbuf));
if (l>=sizeof(nbuf)) l=sizeof(nbuf)-3;
strcpy(nbuf, "[");
strncat(nbuf, par->text, l);
while (l>0 && nbuf[l-1]==' ') l--; /* trim */
strcat(nbuf, "]");
CocDefVar(nbuf, buffer, sizeof(buffer), &CocWR);
ERR_I(CocCmd(conn, nbuf));
return(0); return(0);
OnError: return(-1); OnError: return(-1);
} }
int TeccGetParVms(pTecsClient conn, Desc *name, Desc *par) { int TeccGetParFtn_(pTecsClient conn, char *name, char *par, int namelen, int parlen) {
int l, ld; int l;
char nbuf[64]; char nbuf[64], pbuf[256];
l=par->size; if (namelen>=sizeof(nbuf)) namelen=sizeof(nbuf)-1;
if (l>=sizeof(nbuf)) l=sizeof(nbuf)-1; strncpy(nbuf, name, namelen);
strncpy(nbuf, par->text, l); while (namelen>0 && nbuf[namelen-1]==' ') namelen--; /* trim */
while (l>0 && nbuf[l-1]==' ') l--; /* trim */ nbuf[namelen]='\0';
CocDefVar(nbuf, buffer, sizeof(buffer), &CocWR); ERR_I(CocGet(conn, nbuf, pbuf));
ERR_I(CocCmd(conn, nbuf));
ld=strlen(buffer); l=strlen(pbuf);
l=par->size; if (l>parlen) l=parlen;
if (ld>=l) ld=l; strncpy(par, pbuf, l);
strncpy(par->text, buffer, ld); return(l);
return(ld);
OnError: return(-1); OnError: return(-1);
} }
int TeccSendVms(pTecsClient conn, Desc *cmd, Desc *reply) { int TeccSendFtn_(pTecsClient conn, char *cmd, char *reply, int cmdlen, int replylen) {
int l, lr; int l;
char cbuf[80], rbuf[80]; char cbuf[80], rbuf[80];
l=cmd->size; if (cmdlen>=sizeof(cbuf)) cmdlen=sizeof(cbuf)-1;
if (l>=sizeof(cbuf)) l=sizeof(cbuf)-1; strncpy(cbuf, cmd, cmdlen);
strncpy(cbuf, cmd->text, l); while (cmdlen>0 && cbuf[cmdlen-1]==' ') cmdlen--; /* trim */
while (l>0 && cbuf[l-1]==' ') l--; /* trim */ cbuf[cmdlen]='\0';
cbuf[l]='\0';
ERR_I(TeccSend(conn, cbuf, rbuf, sizeof(rbuf))); ERR_I(TeccSend(conn, cbuf, rbuf, sizeof(rbuf)));
lr=strlen(rbuf);
l=reply->size; l=strlen(rbuf);
if (lr>=l) lr=l; if (l>replylen) l=replylen;
strncpy(reply->text, rbuf, lr); strncpy(reply, rbuf, l);
return(lr); return(l);
OnError: return(-1); OnError: return(-1);
} }
#ifdef __VMS
typedef struct { short size, dummy; char *text; } Desc;
int TeccSetParFtn(pTecsClient conn, Desc *name, Desc *par) {
return(TeccSetParFtn_(conn, name->text, par->text, name->size, par->size));
}
int TeccGetParFtn(pTecsClient conn, Desc *name, Desc *par) {
return(TeccGetParFtn_(conn, name->text, par->text, name->size, par->size));
}
int TeccSendFtn(pTecsClient conn, Desc *cmd, Desc *reply) {
return(TeccSendFtn_(conn, cmd->text, reply->text, cmd->size, reply->size));
}
#endif #endif

View File

@ -23,14 +23,6 @@ int TeccSet(pTecsClient conn, float temp);
/* get temperature /* get temperature
------------------------------------------------------------------------*/ ------------------------------------------------------------------------*/
char *TeccGetPar(pTecsClient conn, const char *name);
/* get any parameter from tecs
------------------------------------------------------------------------*/
int TeccSetPar(pTecsClient conn, const char *name, const char *value);
/* set any parameter of tecs
------------------------------------------------------------------------*/
int TeccWait(pTecsClient conn); int TeccWait(pTecsClient conn);
/* wait until the controller is configured /* wait until the controller is configured
------------------------------------------------------------------------*/ ------------------------------------------------------------------------*/

View File

@ -45,7 +45,7 @@ int DlogRead(DlogSet *dset, int idx, void *data) {
return(-1); return(-1);
} }
int DlogOpen(DlogSet *dset, char *name, int write) { int DlogOpenOld(DlogSet *dset, char *name, int write) {
int i, p, np, fd, flags; int i, p, np, fd, flags;
time_t tim; time_t tim;
struct tm *timp; struct tm *timp;
@ -79,11 +79,22 @@ int DlogOpen(DlogSet *dset, char *name, int write) {
return(-1); return(-1);
} }
int DlogCreate(DlogSet *dset, char *name, time_t start, int nset, int nlen, int period, float undef) { int DlogOpen(DlogSet *dset, char *name) {
int fd, i, j, p; return(DlogOpenOld(dset, name, 0));
}
int DlogOpenWrt(DlogSet *dset, char *name, time_t start, int nset, int nlen, int period, float undef) {
int fd, i, j, p, iret;
va_list ap; va_list ap;
float f[DLOG_MAX_SET]; float f[DLOG_MAX_SET];
iret=DlogOpenOld(dset, name, 1);
if (iret>=0 && dset->nset==nset
&& dset->nlen==nlen
&& dset->last+nlen*period>start
&& dset->undef == undef) {
return(1); /* take old file only if it matches */
}
fd=0; fd=0;
if (nset>DLOG_MAX_SET) ERR_MSG("nset too large"); if (nset>DLOG_MAX_SET) ERR_MSG("nset too large");
dset->nset=nset; dset->nset=nset;
@ -208,7 +219,7 @@ int dlog_get_(char *name, int *nset, int *nmax, double *starttime, float x[], fl
int ntot; int ntot;
/* for compaq unix */ /* for compaq unix */
str_trim(buf, name, namlen); str_trim(buf, name, namlen);
ERR_I(DlogOpen(&dset, buf, 0)); ERR_I(DlogOpen(&dset, buf));
ERR_I(ntot=DlogGetMany(&dset, *nset, *nmax, starttime, x, y, index)); ERR_I(ntot=DlogGetMany(&dset, *nset, *nmax, starttime, x, y, index));
DlogClose(&dset); DlogClose(&dset);
return(ntot); return(ntot);
@ -228,7 +239,7 @@ int DlogUpd(DlogSet *dset) {
dset->pos=sizeof(int); dset->pos=sizeof(int);
#ifdef __VMS #ifdef __VMS
close(dset->fd); close(dset->fd);
DlogOpen(dset, dset->name, 1); ERR_I(DlogOpenOld(dset, dset->name, 1));
#endif #endif
return(0); return(0);
OnError: OnError:

View File

@ -14,11 +14,11 @@ typedef struct {
} DlogSet; } DlogSet;
int DlogOpen(DlogSet *dset, char *name, int write); int DlogOpen(DlogSet *dset, char *name);
/* open existing dlog set */ /* open existing dlog set */
int DlogCreate(DlogSet *dset, char *name, time_t start, int nset, int nlen, int period, float undef); int DlogOpenWrt(DlogSet *dset, char *name, time_t start, int nset, int nlen, int period, float undef);
/* create new dlog file */ /* create or append to new dlog file */
int DlogPut(DlogSet *dset, time_t time, int nset, float val[]); int DlogPut(DlogSet *dset, time_t time, int nset, float val[]);
/* put values to dlog set */ /* put values to dlog set */

View File

@ -69,24 +69,22 @@
typedef struct { typedef struct {
void *pData; void *pData;
char *lastError; char *lastError;
time_t lastGet;
int iLastError, port; int iLastError, port;
char server[256]; char server[256];
} TecsDriv, *pTecsDriv; } TecsDriv, *pTecsDriv;
static time_t lastGet=0;
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
int TecsWrapper(SConnection *pCon, SicsInterp *pSics, void *pData, int TecsWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]) int argc, char *argv[])
{ {
pEVControl self = NULL; pEVControl self = NULL;
char pBueffel[256]; char pBueffel[256], result[256];
int iRet; int iRet;
pEVDriver pD; pEVDriver pD;
pTecsDriv pMe; pTecsDriv pMe;
char *result;
double fNum; double fNum;
float fVal; float fVal;
@ -111,7 +109,7 @@
pD=self->pDriv; assert(pD); pD=self->pDriv; assert(pD);
pMe=pD->pPrivate; assert(pMe); pMe=pD->pPrivate; assert(pMe);
if(argc > 2) { /* set case */ if(argc > 2) { /* set case */
iRet=TeccSetPar(pMe->pData,argv[1],argv[2]); iRet=CocSet(pMe->pData,argv[1],argv[2]);
if (iRet<0) { if (iRet<0) {
sprintf(pBueffel,"ERROR: %s",ErrMessage); sprintf(pBueffel,"ERROR: %s",ErrMessage);
SCWrite(pCon,pBueffel,eError); SCWrite(pCon,pBueffel,eError);
@ -119,8 +117,8 @@
} }
return 1; return 1;
} else { /* get case */ } else { /* get case */
result=TeccGetPar(pMe->pData,argv[1]); iRet=CocGet(pMe->pData,argv[1],result);
if (result==NULL) { if (iRet<0) {
sprintf(pBueffel,"ERROR: %s",ErrMessage); sprintf(pBueffel,"ERROR: %s",ErrMessage);
SCWrite(pCon,pBueffel,eError); SCWrite(pCon,pBueffel,eError);
return 0; return 0;
@ -138,40 +136,45 @@
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
static int TecsGet(pEVDriver self, float *fPos) static int TecsGet(pEVDriver self, float *fPos)
{ {
pTecsDriv pMe = NULL; pTecsDriv pMe = NULL;
int iRet; int iRet;
time_t now; time_t now;
static int configuring;
assert(self); assert(self);
pMe = (pTecsDriv)self->pPrivate; pMe = (pTecsDriv)self->pPrivate;
assert(pMe); assert(pMe);
time(&now); time(&now);
if (now!=lastGet) { /* TecsGet was not yet called within this second */ if (now!=pMe->lastGet) { /* TecsGet was not yet called within this second */
lastGet=now; pMe->lastGet=now;
} else { } else {
CocDelay(200); /* wait 0.2 sec. (seems that SICS has nothing else to do then reading temperatures) */ CocDelay(200); /* wait 0.2 sec. (seems that SICS has nothing else to do then reading temperatures) */
} }
/* get temperature */ /* get temperature */
iRet = TeccGet(pMe->pData, fPos); iRet = TeccGet(pMe->pData, fPos);
if (iRet > 1) { if (iRet > 0) {
if (pMe->iLastError==2) { if (configuring) {
iRet=TeccWait(pMe->pData); iRet = TeccWait(pMe->pData);
iRet = TeccGet(pMe->pData, fPos);
} else { } else {
pMe->lastError = "configuring controller"; pMe->lastError = ": controller busy (configuring)";
pMe->iLastError=2; /* fixable */ pMe->iLastError=2; /* fixable */
configuring=1;
return 0; return 0;
} }
} }
configuring=0;
if(iRet < 0) { if(iRet < 0) {
pMe->lastError = ErrMessage; pMe->lastError = ErrMessage;
pMe->iLastError=1; /* severe */ pMe->iLastError=1; /* severe */
return 0; return 0;
} }
pMe->lastError=0; pMe->iLastError=0;
return 1; return 1;
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -219,7 +222,7 @@
assert(self); assert(self);
pMe = (pTecsDriv )self->pPrivate; pMe = (pTecsDriv )self->pPrivate;
assert(pMe); assert(pMe);
if (pMe->iLastError=1) { /* for Tecs, iLastError means severity level */ if (pMe->iLastError==1) { /* for Tecs, iLastError means severity level */
return(DEVFAULT); /* 1: severe */ return(DEVFAULT); /* 1: severe */
} else { } else {
return(DEVREDO); /* 2: try again, good luck! */ return(DEVREDO); /* 2: try again, good luck! */