diff --git a/tecs/tecs.c b/tecs/tecs.c index f96a758d..513c2fe7 100644 --- a/tecs/tecs.c +++ b/tecs/tecs.c @@ -508,6 +508,7 @@ int PeriodicTask(void) { char buf[256], lbuf[16]; char *res; int i, k; + time_t putTim; float t2[2], p, d, w; ERR_P(LscCmd(ser, "DIOST?>cod1,out1;DOUT 3,29;HTR?>htr;BUSY?>busy")); @@ -552,8 +553,13 @@ int PeriodicTask(void) { if (cryo.dirty==0 && samp.dirty==0 && noResp==0 && tim>logTime) { t2[0]=cryo.temp; t2[1]=samp.temp; - DlogPut(&dset, tim, 2, t2); DlogUpd(&dset); - logTime=(tim/logPeriod+1)*logPeriod; + time(&putTim); + DlogPut(&dset, putTim, 2, t2); DlogUpd(&dset); + logTime=(putTim/logPeriod+1)*logPeriod; + time(&tim); + if (tim-putTim>1) { + logfileOut(LOG_MAIN, "needed %d sec. for filling in dlog\n", tim-putTim); + } } if (samp.nSens>0 && cryo.nSens>0 && controlMode==2 && tempC!=0) { d=(tempH-cryo.temp)/cryo.temp-1.0; /* relative difference */ @@ -842,6 +848,8 @@ int mainBody(void) if (!noResp) logfileOut(LOG_MAIN ,"no response\n"); per=period+10000; /* long period if no response */ noResp=1; + cryo.temp=0; + samp.temp=0; return(0); } return(-1); @@ -994,7 +1002,7 @@ int main(int argc, char *argv[]) logfileOut(LOG_INFO, "opened\n"); } logfileWrite(logMask); - ERR_P(LscCmd(ser, "MODE:[mode]")); + LscCmd(ser, "MODE:[mode]"); per=period; cntError=0; while (!quit) { diff --git a/tecs/tecs_dlog.c b/tecs/tecs_dlog.c index f10af1b5..896fd8d0 100644 --- a/tecs/tecs_dlog.c +++ b/tecs/tecs_dlog.c @@ -31,6 +31,46 @@ int DlogWrite(DlogSet *dset, int idx, void *data) { return(-1); } +#define FILL_BUF_SIZE 1024 + +int DlogFill(DlogSet *dset, int from, int to) { + int p, q, e, i, size; + float fill[FILL_BUF_SIZE]; + + for (i=0;iundef; + e = 0; + if (to-from>=dset->nlen) { /* fill all */ + p = dset->headsize; + q = dset->headsize + dset->nlen * dset->fsize; + } else { + p = dset->headsize + (from % dset->nlen) * dset->fsize; + q = dset->headsize + (to % dset->nlen) * dset->fsize; + if (qheadsize + dset->nlen * dset->fsize; + } + } + ERR_SI(lseek(dset->fd, p, SEEK_SET)); + for (i=p; ifd, fill, sizeof(fill))); + } + if (q>i) ERR_SI(write(dset->fd, fill, q-i)); + + if (e>0) { + p = dset -> headsize; + ERR_SI(lseek(dset->fd, p, SEEK_SET)); + for (i=p; ifd, fill, sizeof(fill))); + } + if (e>i) ERR_SI(write(dset->fd, fill, q-i)); + } + dset->pos = -1; /* set position to undefined */ + return(0); + OnError: + return(-1); +} + +/* int DlogRead(DlogSet *dset, int idx, void *data) { int p; @@ -44,6 +84,25 @@ int DlogRead(DlogSet *dset, int idx, void *data) { OnError: return(-1); } +*/ + +int DlogRead(DlogSet *dset, int idx, int max, void *data) { + int i, p, m; + + i = idx % dset->nlen; + p = dset->headsize + i * dset->fsize; + if (max > dset->nlen - i) { + max = dset->nlen - i; + } + if (p!=dset->pos) { + ERR_SI(lseek(dset->fd, p, SEEK_SET)); + } + ERR_SI(read(dset->fd, data, dset->fsize * max)); + dset->pos = p + dset->fsize * max; + return(max); + OnError: + return(-1); +} int DlogOpenOld(DlogSet *dset, char *name, int write) { int i, p, np, fd, flags; @@ -122,7 +181,7 @@ int DlogOpenWrt(DlogSet *dset, char *name, time_t start, int nset, int nlen, int return(-1); } -int DlogPut(DlogSet *dset, time_t time, int nset, float val[]) { +int DlogPut(DlogSet *dset, time_t tim, int nset, float val[]) { int i, i0, j; float f[DLOG_MAX_SET], f0[DLOG_MAX_SET]; @@ -131,11 +190,11 @@ int DlogPut(DlogSet *dset, time_t time, int nset, float val[]) { for (j=0; j < nset; j++) { f[j]=val[j]; } for (j=nset; j < dset->nset; j++) { f[j]=dset->undef; } - i = ( time - dset->start ) / dset->period; + i = ( tim - dset->start ) / dset->period; i0 = ( dset->last - dset->start ) / dset->period; if (i0==i) { - ERR_I(DlogRead(dset, i, f0)); + ERR_I(DlogRead(dset, i, 1, f0)); for (j=0; jf[j] || /* take maximum (for odd i) */ @@ -143,23 +202,20 @@ int DlogPut(DlogSet *dset, time_t time, int nset, float val[]) { ) f[j]=f0[j]; /* of f0 and f0 */ } } else if (i0nset; j++) { f0[j]=dset->undef; } - i0++; - while (i0last=time; + dset->last=tim; return(0); OnError: return(-1); } +#define RD_BUF_SIZE 1024 + int DlogGet(DlogSet *dset, int iset, int nmax, double *starttime, float x[], float y[]) { - int i0, i1, i, n, undef; - float f[DLOG_MAX_SET]; + int j, i0, i1, i, n, nread, undef; + float f, fbuf[RD_BUF_SIZE+1]; if (iset<0) ERR_MSG("illegal iset"); if (iset>=dset->nset) return(0); @@ -176,21 +232,24 @@ int DlogGet(DlogSet *dset, int iset, int nmax, double *starttime, float x[], flo n=0; undef=2; while (i0<=i) { - if (n>=nmax) return(n); - ERR_I(DlogRead(dset, i0, f)); - i0++; - if (DEFINED(f[iset])) { - x[n]=(float)(i0-i1)*dset->period; - y[n]=f[iset]; - n++; - undef=0; - } else if (undef==0) { - undef=1; - } else if (undef==1) { - undef=2; - x[n]=0; - y[n]=0; - n++; + ERR_I(nread=DlogRead(dset, i0, RD_BUF_SIZE/dset->nset, fbuf)); + for (j=0; j=nmax) return(n); + f=fbuf[j * dset->nset + iset]; + i0++; + if (DEFINED(f)) { + x[n]=(float)(i0-i1)*dset->period; + y[n]=f; + n++; + undef=0; + } else if (undef==0) { + undef=1; + } else if (undef==1) { + undef=2; + x[n]=0; + y[n]=0; + n++; + } } } return(n); diff --git a/tecs/test.for b/tecs/test.for index 6ab12354..e272f21b 100644 --- a/tecs/test.for +++ b/tecs/test.for @@ -16,7 +16,7 @@ print *,'device set cryo device' print *,' show parameter' print *,' set parameter' - print *,'quit close TecsServer and exit' + print *,'kill close TecsServer and exit' print *,'exit exit, but do not close TecsServer' print *,'help show list of parameters and cryo devices' print * @@ -39,8 +39,8 @@ if (k .eq. 0) then ! empty line call tecs_get_temp(6, temp) call tecs_get_par(6, 'device', device) - print '(x,3(a,f8.3),2a)','tempX=', temp(2),', tempP=',temp(3) - 1 ,', tempC=',temp(1), ', device=',device + print '(x,3(a,f8.3),2a)','tempX=', temp(3),', tempP=',temp(2) + 1 ,', set=',temp(1), ', device=',device goto 1 endif @@ -57,7 +57,7 @@ ! simple query - if (cmd .eq. 'quit') then + if (cmd .eq. 'kill') then call tecs_quit(6) goto 9 elseif (cmd .eq. 'exit') then diff --git a/tecsdriv.c b/tecsdriv.c index b524850e..108dfaf6 100644 --- a/tecsdriv.c +++ b/tecsdriv.c @@ -117,8 +117,8 @@ } return 1; } else { /* get case or command without parameter */ - if (0==strcasecmp(argv[1], "quit")) { - iRet=CocSet(pMe->pData,argv[1],"1"); /* send quit flag */ + if (0==strcasecmp(argv[1], "kill")) { + iRet=CocSet(pMe->pData,"quit","1"); /* send quit flag */ strcpy(result, "1"); } else { iRet=CocGet(pMe->pData,argv[1],result); /* get parameter */