New TECS Version Sept. 2001 M.Z.
This commit is contained in:
@ -7,7 +7,7 @@ LIBR_OBJ= coc_util.o myc_err.o myc_str.o myc_buf.o myc_time.o
|
||||
SERV_OBJ= tecs.o coc_server.o tecs_lsc.o tecs_serial.o coc_logfile.o tecs_data.o $(LIBR_OBJ)
|
||||
CLI_OBJ= tecs_cli.o coc_client.o $(LIBR_OBJ)
|
||||
TCLI_OBJ= sys_aunix.o sys_aunix_c.o $(CLI_OBJ)
|
||||
TECLI_OBJ= tecs_client.o tecs_plot.o tecs_for.o sys_util.o str.o $(TCLI_OBJ)
|
||||
TECLI_OBJ= tecs_client.o tecs_plot.o tecs_for.o sys_util.o str.o instr_hosts.o $(TCLI_OBJ)
|
||||
|
||||
#------------ for DigitalUnix (add -DFORTIFY to CFLAGS for fortified version)
|
||||
CC=cc
|
||||
@ -26,7 +26,7 @@ libtecsl.a: $(CLI_OBJ)
|
||||
ar cr libtecsl.a $(CLI_OBJ)
|
||||
ranlib libtecsl.a
|
||||
|
||||
all: libtecsl.a bin/TecsServer bin/TecsClient rstart keep_running
|
||||
all: libtecsl.a bin/TecsServer bin/TecsClient rstart bin/keep_running
|
||||
|
||||
tecs_plot.o: tecs_plot.f90
|
||||
f90 -c -u -g tecs_plot.f90
|
||||
@ -44,11 +44,17 @@ six: six.c term.c sys_select.c $(LIBR_OBJ)
|
||||
$(CC) $(CFLAGS) -o six six.c term.c sys_select.c $(LIBR_OBJ) \
|
||||
-L/data/lnslib/lib -so_archive -lreadline -ltermcap -lX11 -lXm
|
||||
|
||||
rstart: $(LIBR_OBJ) rstart.c myc_str.o myc_err.o
|
||||
$(CC) $(CFLAGS) -o rstart rstart.c myc_str.o myc_err.o
|
||||
rstart: rstart.c myc_str.o myc_err.o instr_hosts.o
|
||||
$(CC) $(CFLAGS) -o rstart rstart.c myc_str.o myc_err.o instr_hosts.o
|
||||
|
||||
keep_running: keep_running.c
|
||||
$(CC) $(CFLAGS) -o keep_running keep_running.c
|
||||
serverd: serverd.c $(LIBR_OBJ)
|
||||
$(CC) $(CFLAGS) -o serverd serverd.c $(LIBR_OBJ)
|
||||
|
||||
starts: starts.c $(LIBR_OBJ)
|
||||
$(CC) $(CFLAGS) -o starts starts.c $(LIBR_OBJ)
|
||||
|
||||
bin/keep_running: keep_running.c
|
||||
$(CC) $(CFLAGS) -o bin/keep_running keep_running.c
|
||||
|
||||
clean:
|
||||
- rm *.o
|
||||
|
@ -24,16 +24,22 @@ int main(int argc, char *argv[]) {
|
||||
exit(1);
|
||||
}
|
||||
waitpid(pid, &status, 0);
|
||||
if (status==0) {
|
||||
printf("Regular exit\n");
|
||||
if (status==512) { /* kill */
|
||||
return 0;
|
||||
}
|
||||
if (status==256) { /* restart */
|
||||
cnt = MAX_CNT;
|
||||
}
|
||||
time(&tim2);
|
||||
dif = (int) difftime(tim2, tim1);
|
||||
cnt += dif / MIN_PERIOD;
|
||||
if (cnt > MAX_CNT) cnt = MAX_CNT;
|
||||
cnt--;
|
||||
if (dif < MIN_PERIOD) {
|
||||
printf("Status=%d. Died after %d sec", status, dif);
|
||||
} else {
|
||||
printf("Status=%d. Died after %f hours", status, dif/3600.);
|
||||
}
|
||||
if (cnt > 0) {
|
||||
printf(" - %d tries left - retry ...\n", cnt);
|
||||
}
|
||||
|
102
tecs/rstart.c
102
tecs/rstart.c
@ -5,54 +5,17 @@
|
||||
#include <stdio.h>
|
||||
#include <netdb.h>
|
||||
#include "myc_str.h"
|
||||
#include "instr_hosts.h"
|
||||
|
||||
int rexec(char **host, int port, char *user, char *passwd, char *command, int *err_file_desc);
|
||||
|
||||
int wrtRd(int fd, char *cmd, char *res, int res_len) {
|
||||
int i, p, l, cnt;
|
||||
char buf[8192];
|
||||
struct timeval tmo;
|
||||
fd_set rmask;
|
||||
|
||||
if (cmd[0]!='\0') {
|
||||
l=send(fd, cmd, strlen(cmd), 0);
|
||||
if (l<0) return -1;
|
||||
}
|
||||
tmo.tv_sec=2;
|
||||
i=1;
|
||||
p=0;
|
||||
while (i>0 && p<sizeof(buf)-1) {
|
||||
FD_ZERO(&rmask);
|
||||
FD_SET(fd, &rmask);
|
||||
tmo.tv_usec=500000;
|
||||
i=select(fd+1, &rmask, NULL, NULL, &tmo);
|
||||
tmo.tv_sec=0;
|
||||
if (i>0) {
|
||||
l=recv(fd, buf+p, sizeof(buf)-p-1, 0);
|
||||
if (l<0) return -1;
|
||||
p=p+l;
|
||||
if (l==0) i=0;
|
||||
}
|
||||
}
|
||||
if (p >= res_len) p=res_len-1;
|
||||
buf[p]='\0';
|
||||
strcpy(res, buf);
|
||||
return p;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int port, i, j, l, fd;
|
||||
char *host, inst[32], cmd[256], buf[256], path[256];
|
||||
char *instrHosts[]={
|
||||
"DMC","lnsa05.psi.ch",
|
||||
"TOPSI","lnsa07.psi.ch",
|
||||
"SANS","lnsa10.psi.ch",
|
||||
"HRPT","lnsa11.psi.ch",
|
||||
"TRICS","lnsa13.psi.ch",
|
||||
"AMOR","lnsa14.psi.ch",
|
||||
"FOCUS","lnsa16.psi.ch",
|
||||
"ZOLLIKER","lnsa15.psi.ch"
|
||||
};
|
||||
char inst[32], cmd[256], host[256], user[64], pcod[64];
|
||||
char *hostp;
|
||||
struct tm tim;
|
||||
time_t t;
|
||||
|
||||
struct servent s;
|
||||
|
||||
s=*getservbyname("exec", "tcp");
|
||||
@ -61,61 +24,28 @@ int main(int argc, char *argv[]) {
|
||||
printf("not enough arguments\n");
|
||||
return 0;
|
||||
}
|
||||
str_upcase(inst, argv[1]);
|
||||
str_copy(cmd, "\n");
|
||||
i=InstrHost(argv[1], inst, host, user, pcod, sizeof(inst), sizeof(host), sizeof(user), sizeof(pcod));
|
||||
if (i==0) {
|
||||
printf("unknown host/instrument\n");
|
||||
return -1;
|
||||
}
|
||||
str_copy(cmd, "");
|
||||
for (i=2; i<argc; i++) {
|
||||
if (0==strcmp(argv[i], "sics")) {
|
||||
str_append(cmd, "startsics\n");
|
||||
str_append(cmd, "bin/startsics\n");
|
||||
} else if (0==strcmp(argv[i], "tecs")) {
|
||||
str_append(cmd, "startecs\n");
|
||||
str_append(cmd, "bin/startecs\n");
|
||||
} else {
|
||||
printf("unknown server %s\n", argv[i]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
buf[0]='\0';
|
||||
host=NULL;
|
||||
for (i=0; i<sizeof(instrHosts)/sizeof(instrHosts[0]); i+=2) {
|
||||
if (0==strcmp(instrHosts[i], inst)) {
|
||||
host=instrHosts[i+1];
|
||||
} else if (0==strcmp(instrHosts[i+1], argv[1])) {
|
||||
host=argv[1];
|
||||
str_copy(inst,instrHosts[i]);
|
||||
}
|
||||
}
|
||||
if (0==strcmp(inst, "ZOLLIKER")) {
|
||||
str_copy(buf, "69kilo");
|
||||
str_copy(inst, "zolliker");
|
||||
} else if (host==NULL) {
|
||||
printf("unknown instrument: %s\n", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
printf("login to %s\n", host);
|
||||
if (buf[0]=='\0') {
|
||||
str_copy(buf, inst);
|
||||
str_append(buf, "LNS");
|
||||
}
|
||||
fd=rexec(&host, s.s_port, inst, buf, "rlogin 0", &i);
|
||||
hostp=host;
|
||||
fd=rexec(&hostp, s.s_port, user, pcod, cmd, &i);
|
||||
if (fd<0) {
|
||||
perror("rexec"); return -1;
|
||||
}
|
||||
|
||||
if (wrtRd(fd, "\n", buf, sizeof(buf)) < 0) goto Error;
|
||||
if (wrtRd(fd, "\n", buf, sizeof(buf)) < 0) goto Error;
|
||||
if (wrtRd(fd, "\n", buf, sizeof(buf)) < 0) goto Error;
|
||||
if (wrtRd(fd, cmd, buf, sizeof(buf)) < 0) goto Error;
|
||||
printf("%s\n", buf);
|
||||
l=1;
|
||||
while (l>0) {
|
||||
if (l=wrtRd(fd, "", buf, sizeof(buf)) < 0) goto Error;
|
||||
printf("%s", buf);
|
||||
}
|
||||
printf("\n");
|
||||
i=10;
|
||||
while (i>0 && wrtRd(fd, "logout\n", buf, sizeof(buf)) >= 0) {
|
||||
i--;
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
Error: perror("error in wrtRd"); return 0;
|
||||
}
|
||||
|
396
tecs/tecs.c
396
tecs/tecs.c
@ -48,6 +48,7 @@ static SensorT
|
||||
*ctlSens=NULL, /* control sensor */
|
||||
*heliumSens=NULL,
|
||||
*auxSens=NULL,
|
||||
*testSens=NULL,
|
||||
*sens=&sensA;
|
||||
|
||||
typedef struct {
|
||||
@ -89,6 +90,7 @@ static float
|
||||
tm=DATA_UNDEF, /* main temperature */
|
||||
ts=DATA_UNDEF, /* sample temperature */
|
||||
tr=DATA_UNDEF, /* set temperature (read back) */
|
||||
te=DATA_UNDEF, /* test temperature */
|
||||
he=DATA_UNDEF, /* helium level value */
|
||||
aux=DATA_UNDEF, /* auxiliary value */
|
||||
ramp=0,
|
||||
@ -103,7 +105,7 @@ static int
|
||||
logTime, /* next logging time */
|
||||
settingsFlag, /* settings to be done */
|
||||
saveTime, /* time for a CRVSAV command */
|
||||
noResp=2, /* no response */
|
||||
noResp=1, /* no response */
|
||||
quit, /* quit server */
|
||||
controlMode=2, /* 0: control on heater, 1: control on sample, 3: 2nd loop for difference heater-sample */
|
||||
int2=30, /* inegration time for controlMode 2 */
|
||||
@ -125,6 +127,7 @@ static int
|
||||
tim0, /* msec Time */
|
||||
per, /* effective period */
|
||||
mmInt, mmTime, /* interval and time for next min-max logging */
|
||||
cntError,
|
||||
tableTime; /* last time when table was read */
|
||||
|
||||
int tim, rdTim; /* actual time, read Time */
|
||||
@ -142,8 +145,9 @@ static char
|
||||
alarms[20], /* alarm status */
|
||||
alarmChannels[4]=" ",
|
||||
alarmList[4], /* alarm list */
|
||||
config[256], /* special configuration commands */
|
||||
helium[80], /* helium level status */
|
||||
/* send[256], */
|
||||
heUnits[4], /* helium level units */
|
||||
controlChannel[2]="A";
|
||||
|
||||
static char
|
||||
@ -177,7 +181,7 @@ int IdleHdl(int tmo, int fd) {
|
||||
|
||||
iRet=CocHandleRequests(tmo, fd);
|
||||
if (iRet<0) logfileShowErr("CocHandleRequests");
|
||||
return(iRet);
|
||||
return iRet;
|
||||
}
|
||||
|
||||
void *SetClientData(void *data) {
|
||||
@ -198,6 +202,7 @@ void ConcatDevice(void) {
|
||||
str_append(device, "/");
|
||||
str_append(device, plug1.device);
|
||||
}
|
||||
if (device[0]=='\0') return;
|
||||
if (plug0.manual) {
|
||||
str_append(device, " (manual");
|
||||
} else {
|
||||
@ -228,8 +233,8 @@ int PutPermanentData(FILE *fil) {
|
||||
}
|
||||
sprintf(buf, "%s%s/%s%s/%d/%d\n", d1, plug0.device, d2, plug1.device, plug0.code, plug1.code);
|
||||
ERR_SI(fputs(buf, fil));
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int InstalCurve(SensorT *sensor, char *dev) {
|
||||
@ -254,11 +259,9 @@ int InstalCurve(SensorT *sensor, char *dev) {
|
||||
} else {
|
||||
ERR_P(LscCmd(ser, "INTYPE [chan]:0,1,2,1,12;MNMX [chan]:1,3")); /* 5 V Range */
|
||||
}
|
||||
if (sens->type=='h') {
|
||||
/* helium */
|
||||
}
|
||||
ERR_P(LscCmd(ser, "INCRV [chan]:0"));
|
||||
if (settingsFlag==0) sens->present=1;
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fil=NULL;
|
||||
@ -401,7 +404,7 @@ int InstalCurve(SensorT *sensor, char *dev) {
|
||||
|
||||
if (settingsFlag==0) sens->present=1;
|
||||
/*
|
||||
if (num<=20) return(0);
|
||||
if (num<=20) return 0;
|
||||
*/
|
||||
/* standard curve, do not touch cache */
|
||||
|
||||
@ -431,7 +434,6 @@ int InstalCurve(SensorT *sensor, char *dev) {
|
||||
sprintf(lbuf, "lsc.%d", serialNo);
|
||||
str_append(buf, lbuf);
|
||||
rename(nbuf, buf); /* rename to permanent version */
|
||||
logfileOut(LOG_MAIN, buf);
|
||||
fil=NULL;
|
||||
FREE(cache);
|
||||
/* re-read it */
|
||||
@ -443,12 +445,12 @@ int InstalCurve(SensorT *sensor, char *dev) {
|
||||
buf[strlen(buf)-2]='\0'; /* strip off "-1" */
|
||||
rename(buf, buf); /* lower version number */
|
||||
|
||||
return(0);
|
||||
return 0;
|
||||
|
||||
OnError:
|
||||
if (crv!=NULL) FREE(crv);
|
||||
if (fil!=NULL) fclose(fil);
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int PrepInput(char *label) {
|
||||
@ -478,6 +480,7 @@ int PrepInput(char *label) {
|
||||
sensA.lim=0;
|
||||
sensB.lim=0;
|
||||
controlMode=0;
|
||||
config[0]='\0';
|
||||
} else {
|
||||
sensC.present=0;
|
||||
sensD.present=0;
|
||||
@ -488,6 +491,7 @@ int PrepInput(char *label) {
|
||||
}
|
||||
loop=1;
|
||||
resist=10;
|
||||
str_copy(heUnits, "%");
|
||||
|
||||
i=sscanf(t, "%12s%n", nam, &l);
|
||||
if (i<1) ERR_MSG("missing device name");
|
||||
@ -520,7 +524,7 @@ int PrepInput(char *label) {
|
||||
s=sensors[i];
|
||||
typ=chans[i];
|
||||
if (typ=='_') typ='\0';
|
||||
if (NULL==strchr("mnslhx", typ)) ERR_MSG("unknown channel type code");
|
||||
if (NULL==strchr("mnslhxt", typ)) ERR_MSG("unknown channel type code");
|
||||
if (typ!='\0') {
|
||||
s->present=-1;
|
||||
}
|
||||
@ -533,8 +537,8 @@ int PrepInput(char *label) {
|
||||
str_copy(plug->device, nam);
|
||||
ConcatDevice();
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int LoadCache(void) {
|
||||
@ -570,10 +574,10 @@ int LoadCache(void) {
|
||||
ERR_SI(fclose(fil));
|
||||
/* re-read cache */
|
||||
ERR_P(cache=str_read_file(nbuf));
|
||||
return(0);
|
||||
return 0;
|
||||
OnError:
|
||||
if (fil!=NULL) fclose(fil);
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
float WeightedAverage(float tH, float tL, Testpoint *t) {
|
||||
@ -589,19 +593,19 @@ float WeightedAverage(float tH, float tL, Testpoint *t) {
|
||||
tLow=s1->lim;
|
||||
tHigh=s2->lim;
|
||||
if (tL<=tLow) {
|
||||
return(tL);
|
||||
return tL;
|
||||
} else if (tH<tHigh) {
|
||||
p=tHigh-tH;
|
||||
q=tL-tLow;
|
||||
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));
|
||||
return (tL*p*p+tH*q*q)/(p*p+q*q);
|
||||
}
|
||||
}
|
||||
return(tH);
|
||||
return tH ;
|
||||
} else if (tL!=0.0) {
|
||||
return(tL);
|
||||
return tL ;
|
||||
}
|
||||
return(0.0);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void LogMinMax(int new) {
|
||||
@ -638,6 +642,10 @@ void LogMinMax(int new) {
|
||||
sprintf(buf1, " Tr %.5g", tr);
|
||||
str_append(buf, buf1);
|
||||
}
|
||||
if (te!=DATA_UNDEF) {
|
||||
sprintf(buf1, " Te %.5g", te);
|
||||
str_append(buf, buf1);
|
||||
}
|
||||
if (power!=DATA_UNDEF) {
|
||||
sprintf(buf1, " P %.4g", power);
|
||||
str_append(buf, buf1);
|
||||
@ -669,6 +677,42 @@ void LogMinMax(int new) {
|
||||
}
|
||||
}
|
||||
|
||||
float CtlScale(void) {
|
||||
if (ctlSens==NULL) ctlSens=cryo.sensor1;
|
||||
if (controlMode==1) {
|
||||
tShift=0;
|
||||
if (ctlSens==samp.sensor1) {
|
||||
if (set < ctlSens->lim) {
|
||||
ctlSens=samp.sensor2;
|
||||
}
|
||||
} else if (ctlSens==samp.sensor2) {
|
||||
if (set > ctlSens->lim) {
|
||||
ctlSens=samp.sensor1;
|
||||
}
|
||||
} else {
|
||||
ctlSens=samp.sensor1;
|
||||
}
|
||||
} else {
|
||||
if (controlMode!=2) tShift=0;
|
||||
if (ctlSens==cryo.sensor1) {
|
||||
if (set < ctlSens->lim) {
|
||||
ctlSens=cryo.sensor2;
|
||||
}
|
||||
} else if (ctlSens==cryo.sensor2) {
|
||||
if (set > ctlSens->lim) {
|
||||
ctlSens=cryo.sensor1;
|
||||
}
|
||||
} else {
|
||||
ctlSens=cryo.sensor1;
|
||||
}
|
||||
}
|
||||
if (ctlSens==NULL) {
|
||||
return 1.0;
|
||||
} else {
|
||||
return ctlSens->scale;
|
||||
}
|
||||
}
|
||||
|
||||
int ReadTemp(void) {
|
||||
char buf[256], typ, *err;
|
||||
int i, doit, stat;
|
||||
@ -700,12 +744,13 @@ int ReadTemp(void) {
|
||||
if (doit) {
|
||||
if (ramp!=0) {
|
||||
str_append(buf, ";SETP?[loop]>tr");
|
||||
tr=tr*CtlScale();
|
||||
} else {
|
||||
tr=set;
|
||||
if (tr==0) tr=DATA_UNDEF;
|
||||
}
|
||||
str_append(buf, ";MNMXRST");
|
||||
ERR_P(LscCmd(ser, buf));
|
||||
if (tr==0) tr=DATA_UNDEF;
|
||||
}
|
||||
|
||||
/* check for reading errors */
|
||||
@ -738,7 +783,7 @@ int ReadTemp(void) {
|
||||
s->t=he;
|
||||
tfill = tim % (24*3600) / 60; /* min since midnight */
|
||||
dfill = mycDate(tim) % 10000; /* fill date without year */
|
||||
sprintf(helium, "%5.1f %% (%02d.%02d., %02d:%02d)", he
|
||||
sprintf(helium, "%.3g %s (%02d.%02d., %02d:%02d)", he, heUnits
|
||||
, dfill % 100, dfill / 100, tfill / 60, tfill % 60);
|
||||
}
|
||||
}
|
||||
@ -781,17 +826,25 @@ int ReadTemp(void) {
|
||||
if (samp.temp==0.0) {
|
||||
samp.temp=cryo.temp;
|
||||
}
|
||||
} else {
|
||||
tm=(rdTim % 3600) * 1.0e-4;
|
||||
ts=(rdTim % 60) * 60.0e-4+0.5;
|
||||
}
|
||||
if (auxSens != NULL) {
|
||||
aux=auxSens->t * auxSens->scale;
|
||||
} else {
|
||||
aux=DATA_UNDEF;
|
||||
}
|
||||
if (testSens != NULL) {
|
||||
te=testSens->t * testSens->scale;
|
||||
} else {
|
||||
te=DATA_UNDEF;
|
||||
}
|
||||
if (heliumSens == NULL) {
|
||||
he=DATA_UNDEF;
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int ReadHeater(void) {
|
||||
@ -807,11 +860,12 @@ int ReadHeater(void) {
|
||||
power=htr*htr*maxPower*1e-4;
|
||||
}
|
||||
return 0;
|
||||
OnError: return(-1);
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int SetTemp(int switchOn) {
|
||||
int showSet;
|
||||
float scale;
|
||||
|
||||
if (set<0 || set>tLimit) {
|
||||
set=0;
|
||||
@ -821,7 +875,9 @@ int SetTemp(int switchOn) {
|
||||
ERR_I(ReadTemp());
|
||||
LogMinMax(switchOn);
|
||||
}
|
||||
if (cryo.sensor1==NULL) return(0);
|
||||
if (cryo.sensor1==NULL) return 0;
|
||||
scale=CtlScale();
|
||||
|
||||
if (ctlSens==NULL) ctlSens=cryo.sensor1;
|
||||
if (controlMode==1) {
|
||||
tShift=0;
|
||||
@ -856,14 +912,25 @@ int SetTemp(int switchOn) {
|
||||
} else if (tShift<-maxShift) {
|
||||
tShift=-maxShift;
|
||||
}
|
||||
setH=(set+tShift)/ctlSens->scale;
|
||||
if (setH>tLimit) setH=tLimit;
|
||||
if (switchOn) { /* switch off other loop */
|
||||
setH=(set+tShift)/scale;
|
||||
if (setH>tLimit/scale) setH=tLimit/scale;
|
||||
if (switchOn) {
|
||||
/* switch off other loop */
|
||||
if (loop==1) {
|
||||
ERR_P(LscCmd(ser, "CSET 2:[chan],1,0,0"));
|
||||
} else {
|
||||
ERR_P(LscCmd(ser, "CSET 1:[chan],1,0,0"));
|
||||
}
|
||||
if (ramp > 0 && set != 0) {
|
||||
/* take ramp from actual temperature if more than 1 % deviation */
|
||||
ERR_P(LscCmd(ser, "CSET?[loop]>,,cod1;SETP?[loop]>tr"));
|
||||
tr=tr*scale;
|
||||
if (cod1 == 0 || fabsf(ctlSens->t - tr) >= 0.01 * ctlSens->t) {
|
||||
fbuf = ctlSens->t;
|
||||
tr = fbuf * scale;
|
||||
ERR_P(LscCmd(ser, "SETP [loop],[fbuf];RAMP [loop],0,0;SETP [loop],[fbuf]"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (set==0) {
|
||||
ERR_P(LscCmd(ser, "CSET [loop]:[chan],1,1,0"));
|
||||
@ -873,8 +940,6 @@ int SetTemp(int switchOn) {
|
||||
ERR_P(LscCmd(ser, "ANALOG 2:0,0"));
|
||||
}
|
||||
setH=0;
|
||||
} else if (remoteMode==1) {
|
||||
/* in local mode: do not switch on heater */
|
||||
} else if (switchOn) { /* switch on also when bad heater message and no alarms: || (htrst>=5 && relay==0)) */
|
||||
ERR_P(LscCmd(ser, "CSET [loop]:[chan],1,1,0"));
|
||||
if (loop==1) {
|
||||
@ -886,8 +951,9 @@ int SetTemp(int switchOn) {
|
||||
ERR_P(LscCmd(ser, "CSET [loop]:[chan],1"));
|
||||
}
|
||||
showSet=(0!=strcmp(ctlSens->ch, controlChannel) || switchOn);
|
||||
if (ramp==0) {
|
||||
ERR_P(LscCmd(ser, "RAMP [loop],0,0;SETP?[loop]>fbuf"));
|
||||
str_copy(controlChannel, ctlSens->ch);
|
||||
if (ramp==0 || set==0) {
|
||||
ERR_P(LscCmd(ser, "RAMP [loop],0,[ramp];SETP?[loop]>fbuf"));
|
||||
if (fabsf(setH-fbuf) >= (fbuf+setH)*1.0e-5) {
|
||||
ERR_P(LscCmd(ser, "SETP [loop]:[setH]"));
|
||||
if (controlMode!=2 && !showSet) {
|
||||
@ -896,23 +962,26 @@ int SetTemp(int switchOn) {
|
||||
} else {
|
||||
setH=fbuf;
|
||||
}
|
||||
tr=setH*scale;
|
||||
if (showSet) {
|
||||
logfileOut(LOG_MAIN, "set %g (on %s)\n", set, ctlSens->ch);
|
||||
}
|
||||
} else {
|
||||
if (ramp < 0) ramp=-ramp;
|
||||
if (ramp < 0.1) ramp=0.1;
|
||||
ERR_P(LscCmd(ser, "RAMP [loop]:1,[ramp];SETP [loop],[setH];SETP?[loop]>tr"));
|
||||
}
|
||||
tr=tr*scale;
|
||||
if (showSet) {
|
||||
str_copy(controlChannel, ctlSens->ch);
|
||||
if (ramp==0) {
|
||||
logfileOut(LOG_MAIN, "set %g (on %s)\n", set, ctlSens->ch);
|
||||
} else {
|
||||
logfileOut(LOG_MAIN, "set %g (on %s) %g K/min\n", set, ctlSens->ch, ramp);
|
||||
logfileOut(LOG_MAIN, "set %g (on %s) %g K/min, starting from %g\n", set, ctlSens->ch, ramp, tr);
|
||||
}
|
||||
}
|
||||
if (tr==0) tr=DATA_UNDEF;
|
||||
if (showSet) {
|
||||
relay=0;
|
||||
ERR_I(ReadHeater());
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int SetMaxPower(void) {
|
||||
@ -943,13 +1012,14 @@ int SetMaxPower(void) {
|
||||
ERR_P(LscCmd(ser, "CDISP 1:[loop],[resist],1;MOUT [loop]:0;CMODE [loop]:1"));
|
||||
if (slope<0) slope=-slope;
|
||||
if (slope!=0 && slope<0.1) slope=0.1;
|
||||
fbuf=tLimit/CtlScale();
|
||||
if (loop==1) {
|
||||
ERR_P(LscCmd(ser, "CLIMIT 1:[tLimit],[slope],0,[iAmp],[iRange]"));
|
||||
ERR_P(LscCmd(ser, "CLIMIT 1:[fbuf],[slope],0,[iAmp],[iRange]"));
|
||||
} else {
|
||||
ERR_P(LscCmd(ser, "CLIMIT 2:[tLimit],[slope],0"));
|
||||
ERR_P(LscCmd(ser, "CLIMIT 2:[fbuf],[slope],0"));
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
char DisplayFmt(SensorT *s) {
|
||||
@ -966,19 +1036,21 @@ char DisplayFmt(SensorT *s) {
|
||||
}
|
||||
|
||||
int Settings(void) {
|
||||
char nbuf[256], buf[256], typ;
|
||||
char buf[256], typ;
|
||||
char flds[6], fmt[6];
|
||||
char *cfg, *p;
|
||||
int i,k,l;
|
||||
SensorT *s;
|
||||
|
||||
remoteMode=2; /* set to remote mode */
|
||||
ERR_P(LscCmd(ser, "MODE:[remoteMode]"));
|
||||
ERR_P(LscCmd(ser, "PID?[loop]>prop,integ,deriv"));
|
||||
ERR_P(LscCmd(ser, "RAMP?[loop]>,ramp"));
|
||||
for (i=0; i<4; i++) {
|
||||
s=sensors[i];
|
||||
plug=plugs[i/2];
|
||||
if (s->present < 0) {
|
||||
if (settingsFlag) return(0);
|
||||
if (settingsFlag) return 0;
|
||||
ERR_I(InstalCurve(s, plug->device));
|
||||
}
|
||||
}
|
||||
@ -989,6 +1061,7 @@ int Settings(void) {
|
||||
samp.sensor2=NULL;
|
||||
heliumSens=NULL;
|
||||
auxSens=NULL;
|
||||
testSens=NULL;
|
||||
for (i=0; i<4; i++) {
|
||||
s=sensors[i];
|
||||
if (s->present==1) {
|
||||
@ -1009,6 +1082,8 @@ int Settings(void) {
|
||||
heliumSens=s;
|
||||
} else if ('x'==typ) {
|
||||
auxSens=s;
|
||||
} else if ('t'==typ) {
|
||||
testSens=s;
|
||||
}
|
||||
s->band=10;
|
||||
}
|
||||
@ -1021,7 +1096,7 @@ int Settings(void) {
|
||||
samp.sensor2=cryo.sensor2;
|
||||
}
|
||||
|
||||
if (settingsFlag) return(0);
|
||||
if (settingsFlag) return 0;
|
||||
str_copy(statusBuf, "alarms");
|
||||
|
||||
/* alarms */
|
||||
@ -1053,7 +1128,7 @@ int Settings(void) {
|
||||
if (NULL==strchr(alarmList, 'D')) str_append(buf, ";ALARM D:0");
|
||||
if (buf[0]!='\0') ERR_P(LscCmd(ser, buf+1)); /* send without leading semicolon */
|
||||
|
||||
if (settingsFlag) return(0);
|
||||
if (settingsFlag) return 0;
|
||||
str_copy(statusBuf, "display");
|
||||
|
||||
/* display */
|
||||
@ -1064,11 +1139,13 @@ int Settings(void) {
|
||||
flds[k]=cryo.sensor1->ch[0];
|
||||
k++;
|
||||
}
|
||||
if (samp.sensor1 != cryo.sensor1) {
|
||||
fmt[k]=DisplayFmt(samp.sensor1);
|
||||
if (fmt[k]!='\0') {
|
||||
flds[k]=samp.sensor1->ch[0];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
if (cryo.sensor2 != cryo.sensor1) {
|
||||
fmt[k]=DisplayFmt(cryo.sensor2);
|
||||
if (fmt[k]!='\0') {
|
||||
@ -1076,13 +1153,18 @@ int Settings(void) {
|
||||
k++;
|
||||
}
|
||||
}
|
||||
if (samp.sensor2 != samp.sensor1) {
|
||||
if (samp.sensor2 != samp.sensor1 && samp.sensor2 != cryo.sensor2) {
|
||||
fmt[k]=DisplayFmt(samp.sensor2);
|
||||
if (fmt[k]!='\0') {
|
||||
flds[k]=samp.sensor2->ch[0];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
fmt[k]=DisplayFmt(testSens);
|
||||
if (fmt[k]!='\0' && k<=4) {
|
||||
flds[k]=testSens->ch[0];
|
||||
k++;
|
||||
}
|
||||
fmt[k]=DisplayFmt(auxSens);
|
||||
if (fmt[k]!='\0' && k<=4) {
|
||||
flds[k]=auxSens->ch[0];
|
||||
@ -1104,8 +1186,22 @@ int Settings(void) {
|
||||
str_append(buf, "DISPLAY:[maxfld]");
|
||||
ERR_P(LscCmd(ser, buf));
|
||||
}
|
||||
if (config[0] != '\0') {
|
||||
str_copy(buf, binDir);
|
||||
str_append(buf, config);
|
||||
cfg=str_read_file(buf);
|
||||
if (cfg != NULL) {
|
||||
logfileOut(LOG_MAIN, "load %s\n", config);
|
||||
p=cfg;
|
||||
while (p!=NULL) {
|
||||
str_split(buf, p, '\n');
|
||||
ERR_P(LscCmd(ser, buf));
|
||||
}
|
||||
FREE(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
if (settingsFlag) return(0);
|
||||
if (settingsFlag) return 0;
|
||||
str_copy(statusBuf, "reading temperatures");
|
||||
|
||||
if (cryo.sensor1!=NULL) {
|
||||
@ -1113,10 +1209,10 @@ int Settings(void) {
|
||||
} else {
|
||||
ERR_I(ReadTemp());
|
||||
}
|
||||
return(0);
|
||||
logTime=(rdTim / logPeriod + 2) * logPeriod; /* wait before logging "dirty" temperatures */
|
||||
return 0;
|
||||
OnError:
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ConfigByCode(int plugNr) {
|
||||
@ -1136,8 +1232,8 @@ int ConfigByCode(int plugNr) {
|
||||
ERR_I(PrepInput(buf));
|
||||
}
|
||||
settingsFlag=1;
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int ConfigByName(int plugNr) {
|
||||
@ -1153,11 +1249,11 @@ int ConfigByName(int plugNr) {
|
||||
ERR_I(PrepInput(buf));
|
||||
}
|
||||
settingsFlag=1;
|
||||
return(0);
|
||||
return 0;
|
||||
OnError:
|
||||
plug->device[0]='\0';
|
||||
ConcatDevice();
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int PeriodicTask(void) {
|
||||
@ -1174,11 +1270,11 @@ int PeriodicTask(void) {
|
||||
if (noResp) { /* there was no response on an earlier command, or we are initializing */
|
||||
k=serialNo; /* check serial number */
|
||||
ERR_P(LscCmd(ser, "*IDN?>buf1,buf2,serialNo,"));
|
||||
if (0!=strcmp(buf1, "LSCI") || 0!=strcmp(buf2, "MODEL340") || serialNo==0) return(0);
|
||||
if (0!=strcmp(buf1, "LSCI") || 0!=strcmp(buf2, "MODEL340") || serialNo==0) return 0;
|
||||
if (k!=serialNo) { /* controller exchanged or we are initializing */
|
||||
/*
|
||||
if (k!=0) {
|
||||
logfileOut(LOG_MAIN, "controller connected\n");
|
||||
*/
|
||||
}
|
||||
set=0;
|
||||
|
||||
/* reload curve cache: */
|
||||
@ -1200,16 +1296,17 @@ int PeriodicTask(void) {
|
||||
if (next!=NULL) {
|
||||
next=str_split(buf3, next, '/');
|
||||
plug0.code=atoi(buf3);
|
||||
plug0.codChanged=plug0.code != 0;
|
||||
plug0.codChanged=1;
|
||||
if (next!=NULL) {
|
||||
next=str_split(buf3, next, '\n');
|
||||
plug1.code=atoi(buf3);
|
||||
plug1.codChanged=plug1.code != 0;
|
||||
plug1.codChanged=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (buf1[0]=='*') {
|
||||
str_copy(plug0.device, buf1+1);
|
||||
plug0.codChanged=0;
|
||||
ConfigByName(0);
|
||||
} else {
|
||||
if (plug0.code!=0) str_copy(plug0.device, buf1);
|
||||
@ -1217,6 +1314,7 @@ int PeriodicTask(void) {
|
||||
}
|
||||
if (buf2[0]=='*') {
|
||||
str_copy(plug1.device, buf2+1);
|
||||
plug1.codChanged=0;
|
||||
ConfigByName(1);
|
||||
} else {
|
||||
if (plug1.code!=0) str_copy(plug1.device, buf2);
|
||||
@ -1287,12 +1385,12 @@ int PeriodicTask(void) {
|
||||
htrst0=htrst;
|
||||
}
|
||||
|
||||
if (tim>=logTime && cryo.sensor1!=NULL) {
|
||||
if (rdTim>=logTime) {
|
||||
ERR_I(DataPutAll(NULL, rdTim));
|
||||
logTime=(rdTim / logPeriod + 1) * logPeriod;
|
||||
if (tim>mmTime) LogMinMax(0);
|
||||
if (rdTim>mmTime && cryo.sensor1 != NULL) LogMinMax(0);
|
||||
}
|
||||
if (set!=0) {
|
||||
if (set!=0 && remoteMode==2) {
|
||||
if (cryo.sensor1!=samp.sensor1 && controlMode==2) {
|
||||
t=ctlSens->t;
|
||||
d=(setH-t)/t-1.0; /* relative difference */
|
||||
@ -1307,7 +1405,7 @@ int PeriodicTask(void) {
|
||||
}
|
||||
tShift=tShift*(1.0-p)+p*(cryo.temp-samp.temp);
|
||||
ERR_I(SetTemp(0));
|
||||
} else if (remoteMode==2) {
|
||||
} else {
|
||||
ERR_I(SetTemp(0));
|
||||
}
|
||||
}
|
||||
@ -1369,8 +1467,7 @@ int PeriodicTask(void) {
|
||||
ERR_P(LscCmd(ser, "RANGE?>iRange"));
|
||||
if (iRange==0) set=0;
|
||||
} else {
|
||||
ERR_P(LscCmd(ser, "RAMP?[loop]>fbuf,ramp"));
|
||||
if (fbuf==0.0) ramp=0.0;
|
||||
ERR_P(LscCmd(ser, "RAMP?[loop]>,ramp"));
|
||||
ERR_P(LscCmd(ser, "RANGE?>iRange;CSET?[loop]>,cod1,;SETP?[loop]>set"));
|
||||
if (cod1!=1) {
|
||||
set=0;
|
||||
@ -1389,8 +1486,8 @@ int PeriodicTask(void) {
|
||||
}
|
||||
saveTime=0;
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int DeviceHdl(int mode, void *base) {
|
||||
@ -1402,7 +1499,6 @@ int DeviceHdl(int mode, void *base) {
|
||||
t=strchr(device, '/');
|
||||
if (t==NULL) {
|
||||
if (0==strcmp(device, "0") || 0==strcasecmp(device, "auto")) {
|
||||
settingsFlag=1;
|
||||
ERR_I(ConfigByCode(0));
|
||||
ERR_I(ConfigByCode(1));
|
||||
} else {
|
||||
@ -1430,48 +1526,54 @@ int DeviceHdl(int mode, void *base) {
|
||||
}
|
||||
ConcatDevice();
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int SetHdl(int mode, void *base) {
|
||||
if (mode==COC_WR) {
|
||||
if (set<0) {
|
||||
if (remoteMode!=2) {
|
||||
ERR_MSG("controller is in local mode, set to remote first");
|
||||
} else if (set<0) {
|
||||
set=0;
|
||||
} else if (set>tLimit) {
|
||||
set=0;
|
||||
ERR_MSG("set point too high");
|
||||
}
|
||||
return(COC_DWR);
|
||||
return COC_DWR;
|
||||
} else if (mode==COC_DWR) {
|
||||
if (cryo.sensor1!=NULL) {
|
||||
if (cryo.sensor1!=NULL && remoteMode==2) {
|
||||
tInt=0; /* reset integral time */
|
||||
ERR_I(SetTemp(1));
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int PidHdl(int mode, void *base) {
|
||||
if (mode==COC_WR) {
|
||||
return(COC_DWR);
|
||||
return COC_DWR;
|
||||
} else if (mode==COC_DWR) {
|
||||
ERR_P(LscCmd(ser,"PID [loop]:[prop],[integ],[deriv]"));
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int MaxPowerHdl(int mode, void *base) {
|
||||
if (mode==COC_WR) {
|
||||
return(COC_DWR);
|
||||
} else if (mode==COC_DWR) {
|
||||
if (remoteMode==2) {
|
||||
return COC_DWR;
|
||||
}
|
||||
ERR_MSG("controller is in local mode, set to remote first");
|
||||
return 0;
|
||||
} else if (mode==COC_DWR && remoteMode!=2) {
|
||||
ERR_I(SetMaxPower());
|
||||
ERR_I(SetTemp(1));
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int SendHdl(int mode, void *base) {
|
||||
@ -1479,7 +1581,7 @@ int SendHdl(int mode, void *base) {
|
||||
ClientData *data;
|
||||
|
||||
if (mode==COC_WR) {
|
||||
return(COC_DRD);
|
||||
return COC_DRD;
|
||||
} else if (mode==COC_DRD) {
|
||||
data=base;
|
||||
if (NULL!=strchr(data->cmd, '>') || NULL!=strchr(data->cmd, '['))
|
||||
@ -1487,8 +1589,8 @@ int SendHdl(int mode, void *base) {
|
||||
ERR_P(res=LscCmd(ser, data->cmd));
|
||||
str_copy(data->cmd, res);
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int LogHdl(int mode, void *base) {
|
||||
@ -1502,8 +1604,8 @@ int LogHdl(int mode, void *base) {
|
||||
}
|
||||
data->logpos=logfileGetLines(data->logpos, 25, data->logline, sizeof(data->logline));
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int PltHdl(int mode, void *base) {
|
||||
@ -1518,8 +1620,8 @@ int PltHdl(int mode, void *base) {
|
||||
str_copy(names, data->pltdata+l);
|
||||
ERR_I(l=DataGetCoded(names, startTime, endTime, step, 30, data->pltdata, sizeof(data->pltdata)));
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int PutFloat(StrBuf *buf, int prec, float f) {
|
||||
@ -1527,17 +1629,17 @@ int PutFloat(StrBuf *buf, int prec, float f) {
|
||||
int l;
|
||||
|
||||
if (f == DATA_UNDEF) {
|
||||
return(StrPut(buf, "NaN", StrNONE));
|
||||
return StrPut(buf, "NaN", StrNONE);
|
||||
} else {
|
||||
sprintf(fmt, "%%.%dg", prec);
|
||||
sprintf(num, fmt, f);
|
||||
return(StrPut(buf, num, StrNONE));
|
||||
return StrPut(buf, num, StrNONE);
|
||||
}
|
||||
}
|
||||
|
||||
int ShowSensor(StrBuf *buf, SensorT *s, char *name, char *units, char lim) {
|
||||
|
||||
if (s->present!=1) return(0);
|
||||
if (s->present!=1) return 0;
|
||||
ERR_I(StrPut(buf, "\n ", ' '));
|
||||
ERR_I(StrPut(buf, s->ch, ':'));
|
||||
ERR_I(StrPut(buf, "", ' '));
|
||||
@ -1547,6 +1649,7 @@ int ShowSensor(StrBuf *buf, SensorT *s, char *name, char *units, char lim) {
|
||||
} else {
|
||||
ERR_I(StrPut(buf, name, '='));
|
||||
ERR_I(PutFloat(buf, 5, s->t * s->scale));
|
||||
ERR_I(StrPut(buf, " ", StrNONE));
|
||||
ERR_I(StrPut(buf, units, StrNONE));
|
||||
}
|
||||
} else {
|
||||
@ -1555,14 +1658,15 @@ int ShowSensor(StrBuf *buf, SensorT *s, char *name, char *units, char lim) {
|
||||
if (s==ctlSens && tr!=DATA_UNDEF) {
|
||||
ERR_I(StrPut(buf, ", setpoint", '='));
|
||||
ERR_I(PutFloat(buf, 5, tr));
|
||||
ERR_I(StrPut(buf, " ", StrNONE));
|
||||
ERR_I(StrPut(buf, units, StrNONE));
|
||||
}
|
||||
if (s->lim > 0 && lim!=0) {
|
||||
ERR_I(StrPut(buf, ", for T", lim));
|
||||
ERR_I(PutFloat(buf, 5, s->lim));
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int StatusHdl(int mode, void *base) {
|
||||
@ -1572,8 +1676,14 @@ int StatusHdl(int mode, void *base) {
|
||||
SensorT *s;
|
||||
char pendAct[256];
|
||||
|
||||
readTemp=1;
|
||||
StrLink(&buf, status);
|
||||
StrClear(&buf);
|
||||
ERR_I(StrPut(&buf, "\n", StrNONE));
|
||||
if (noResp==3) {
|
||||
ERR_I(StrPut(&buf, "no connection or controller switched off", StrNONE));
|
||||
goto EndStatus;
|
||||
}
|
||||
if (statusBuf[0]!='\0') {
|
||||
ERR_I(StrPut(&buf, "configuring:", ' '));
|
||||
ERR_I(StrPut(&buf, statusBuf, StrNONE));
|
||||
@ -1582,23 +1692,24 @@ int StatusHdl(int mode, void *base) {
|
||||
CocShowHandlers(pendAct, sizeof(pendAct));
|
||||
if (pendAct[0]!='\0') {
|
||||
if (mode==COC_RD) {
|
||||
return (COC_DRD);
|
||||
return COC_DRD;
|
||||
} else {
|
||||
ERR_I(StrPut(&buf, "pending action(s):", ' '));
|
||||
ERR_I(StrPut(&buf, pendAct, StrNONE));
|
||||
goto EndStatus;
|
||||
}
|
||||
}
|
||||
if (noResp==3) {
|
||||
ERR_I(StrPut(&buf, "\nno connection or controller switched off", StrNONE));
|
||||
if (device[0]=='\0') {
|
||||
ERR_I(StrPut(&buf, "no device selected", ' '));
|
||||
goto EndStatus;
|
||||
}
|
||||
if (device[0]!='\0') {
|
||||
ERR_I(StrPut(&buf, "\ndevice:", ' '));
|
||||
ERR_I(StrPut(&buf, device, StrNONE));
|
||||
if (remoteMode==1) {
|
||||
ERR_I(StrPut(&buf, "LOCAL mode, use command 'remote' to enable remote control", '\n'));
|
||||
}
|
||||
ERR_I(StrPut(&buf, "device:", ' '));
|
||||
ERR_I(StrPut(&buf, device, StrNONE));
|
||||
if (set==0) {
|
||||
ERR_I(StrPut(&buf, "\ntemperature control is off", StrNONE));
|
||||
ERR_I(StrPut(&buf, "\nheater off (set=0)", StrNONE));
|
||||
} else {
|
||||
ERR_I(StrPut(&buf, "\ntarget", '='));
|
||||
ERR_I(PutFloat(&buf, 5, set));
|
||||
@ -1615,8 +1726,9 @@ int StatusHdl(int mode, void *base) {
|
||||
ERR_I(StrPut(&buf, ",", ' '));
|
||||
ERR_I(StrPut(&buf, LscHtrStat(htrst), StrNONE));
|
||||
} else {
|
||||
if (power!=DATA_UNDEF) {
|
||||
ERR_I(StrPut(&buf, ", htr power", '='));
|
||||
if (power>=0.5 || power==DATA_UNDEF) {
|
||||
if (power>=0.5) {
|
||||
ERR_I(PutFloat(&buf, 3, power));
|
||||
ERR_I(StrPut(&buf, " W, htr current", '='));
|
||||
} else {
|
||||
@ -1627,6 +1739,7 @@ int StatusHdl(int mode, void *base) {
|
||||
ERR_I(StrPut(&buf, " ", '%'));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (0!=strcmp(alarmChannels," ")) {
|
||||
ERR_I(StrPut(&buf, "\nalarm on channel",' '));
|
||||
ERR_I(StrPut(&buf, alarmChannels, StrNONE));
|
||||
@ -1652,19 +1765,33 @@ int StatusHdl(int mode, void *base) {
|
||||
}
|
||||
ERR_I(ShowSensor(&buf, samp.sensor2, "T", "K", '<'));
|
||||
}
|
||||
if (heliumSens!=NULL) {
|
||||
ERR_I(StrPut(&buf, "\nhelium", ':'));
|
||||
ERR_I(ShowSensor(&buf, heliumSens, "level", " %", 0));
|
||||
if (testSens!=NULL) {
|
||||
ERR_I(StrPut(&buf, "\ntest", ':'));
|
||||
ERR_I(ShowSensor(&buf, testSens, "T", "K", 0));
|
||||
}
|
||||
if (auxSens!=NULL) {
|
||||
ERR_I(StrPut(&buf, "\nauxilliary", ':'));
|
||||
ERR_I(ShowSensor(&buf, auxSens, "U", "V", 0));
|
||||
}
|
||||
if (heliumSens!=NULL) {
|
||||
ERR_I(StrPut(&buf, "\nhelium:", ' '));
|
||||
ERR_I(StrPut(&buf, helium, StrNONE));
|
||||
}
|
||||
EndStatus:
|
||||
ERR_I(StrPut(&buf, "", '\0'));
|
||||
return(0);
|
||||
return 0;
|
||||
OnError:
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int RemoteHdl(int mode, void *base) {
|
||||
if (mode==COC_WR) {
|
||||
return COC_DRD;
|
||||
} else if (mode==COC_DRD) {
|
||||
ERR_P(LscCmd(ser, "MODE:[remoteMode]"));
|
||||
}
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
int ExecuteRequest(void) {
|
||||
@ -1676,9 +1803,9 @@ int ExecuteRequest(void) {
|
||||
ERR_I(Settings());
|
||||
}
|
||||
statusBuf[0]='\0';
|
||||
return(0);
|
||||
return 0;
|
||||
OnError:
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int MainBody(void) {
|
||||
@ -1700,7 +1827,7 @@ int MainBody(void) {
|
||||
logfileWrite(logMask);
|
||||
}
|
||||
tdif = mycMsecSince(tim0);
|
||||
if (tdif>60000) {
|
||||
if (tdif>60000 && cntError < 2) {
|
||||
logfileOut(LOG_MAIN ,"%d seconds lost\n", tdif/1000);
|
||||
}
|
||||
tim0 = mycMsecSince(0)/period*period;
|
||||
@ -1710,28 +1837,28 @@ int MainBody(void) {
|
||||
ERR_I(ExecuteRequest());
|
||||
}
|
||||
|
||||
return(0);
|
||||
return 0;
|
||||
OnError:
|
||||
if (0==strcmp(ErrMessage, "timeout")) {
|
||||
if (noResp==1) { /* this is the second time we have no response */
|
||||
per=period+15000; /* long period if no response */
|
||||
if (noResp==2) { /* this is the second time we have no response */
|
||||
per=1000; /* 1 sec */
|
||||
cryo.temp=0;
|
||||
samp.temp=0;
|
||||
remoteMode=1;
|
||||
noResp=3;
|
||||
} else {
|
||||
} else if (noResp < 2) {
|
||||
logfileOut(LOG_ALL ,"no response\n");
|
||||
noResp=1;
|
||||
noResp=2;
|
||||
per=100; /* try again soon */
|
||||
}
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{ int logIt=0;
|
||||
int i, iret, cntError, use_stdout=0;
|
||||
int main(int argc, char *argv[]) {
|
||||
int logIt=0;
|
||||
int i, iret, use_stdout=0;
|
||||
char *host;
|
||||
char buf[256], opt;
|
||||
int port, msecTmo;
|
||||
@ -1787,7 +1914,7 @@ int main(int argc, char *argv[])
|
||||
logfileOut(LOG_MAIN ,"%s ", argv[i]);
|
||||
}
|
||||
}
|
||||
if (port==0) port=9757;
|
||||
if (port==0) port=9753;
|
||||
if (msecTmo==0) msecTmo=5000;
|
||||
if (logPeriod==0) logPeriod=5;
|
||||
|
||||
@ -1847,6 +1974,7 @@ int main(int argc, char *argv[])
|
||||
CocDefFlt(tm, RD);
|
||||
CocDefFlt(ts, RD);
|
||||
CocDefFlt(tr, RD);
|
||||
CocDefFlt(te, RD);
|
||||
CocDefFlt(aux, RD);
|
||||
CocDefFlt(he, RD);
|
||||
CocDefFlt(fbuf, RD);
|
||||
@ -1872,9 +2000,11 @@ int main(int argc, char *argv[])
|
||||
CocDefStr(head, RD);
|
||||
CocDefStr(chan, RD);
|
||||
CocDefStr(helium, RD);
|
||||
CocDefStr(heUnits, RD);
|
||||
CocDefStr(intype, RD);
|
||||
CocDefStr(status, RD); CocHdl(StatusHdl);
|
||||
CocDefStr(logfile, RD);
|
||||
CocDefStr(config, RD);
|
||||
|
||||
CocDefInt(cod1, RD);
|
||||
CocDefInt(cod2, RD);
|
||||
@ -1886,7 +2016,7 @@ int main(int argc, char *argv[])
|
||||
CocDefInt(resist, RD);
|
||||
CocDefInt(iAmp, RD);
|
||||
CocDefInt(iRange, RD);
|
||||
CocDefInt(remoteMode, RD);
|
||||
CocDefInt(remoteMode, RW); CocHdl(RemoteHdl);
|
||||
CocDefInt(htrst, RD);
|
||||
CocDefInt(loop, RD);
|
||||
CocDefInt(rdTim, RD);
|
||||
@ -1922,6 +2052,7 @@ int main(int argc, char *argv[])
|
||||
ERR_P(DataCreateSet(NULL, "Tm", &tm, 5, LOGLIFETIME, tim));
|
||||
ERR_P(DataCreateSet(NULL, "Ts", &ts, 5, LOGLIFETIME, tim));
|
||||
ERR_P(DataCreateSet(NULL, "Tr", &tr, 5, LOGLIFETIME, tim));
|
||||
ERR_P(DataCreateSet(NULL, "Te", &te, 5, LOGLIFETIME, tim));
|
||||
ERR_P(DataCreateSet(NULL, "He", &he, 5, LOGLIFETIME, tim));
|
||||
ERR_P(DataCreateSet(NULL, "Aux", &aux, 5, LOGLIFETIME, tim));
|
||||
ERR_P(DataCreateSet(NULL, "P", &power, 5, LOGLIFETIME, tim));
|
||||
@ -1973,13 +2104,16 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
LogMinMax(0);
|
||||
logfileWrite(logMask);
|
||||
ERR_MSG("got quit command");
|
||||
if (quit==1) {
|
||||
ERR_MSG("restart by quit command");
|
||||
} else {
|
||||
ERR_MSG("killed by quit command");
|
||||
}
|
||||
OnError:
|
||||
printf("TecsServer exited: %s\n", ErrMessage);
|
||||
logfileShowErr("exit TecsServer");
|
||||
if (ser!=NULL) SerClose(ser);
|
||||
CocCloseServer();
|
||||
logfileClose();
|
||||
if (quit) return 0;
|
||||
return -1;
|
||||
return quit;
|
||||
}
|
||||
|
@ -11,11 +11,11 @@
|
||||
#include "tecs_data.h"
|
||||
|
||||
static char response[COC_RES_LEN];
|
||||
static char *rwCode="rwacs";
|
||||
static char *rdCode="rdacs";
|
||||
|
||||
pTecsClient TeccInit(char *startcmd, int port) {
|
||||
CocConn *conn;
|
||||
static char *rwCode="rwacs";
|
||||
static char *rdCode="rdacs";
|
||||
|
||||
NEW(conn, CocConn);
|
||||
if (startcmd[0]=='#') {
|
||||
@ -64,22 +64,23 @@ int TeccSet(pTecsClient conn, float temp) {
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int TeccQuitServer(pTecsClient conn) {
|
||||
int TeccQuitServer(pTecsClient conn, int kill) {
|
||||
int iret, cnt;
|
||||
|
||||
ERR_I(iret=CocCheck(conn));
|
||||
if (iret==0) {
|
||||
if (iret>0) return iret;
|
||||
CocReset(conn);
|
||||
ERR_I(CocPutInt(conn, "quit", 1));
|
||||
ERR_I(CocDoIt(conn, response, sizeof(response)));
|
||||
ERR_I(CocPutInt(conn, "quit", 1+kill));
|
||||
ERR_I(iret=CocDoIt(conn, response, sizeof(response)));
|
||||
if (iret) ERR_MSG(response);
|
||||
cnt=50;
|
||||
while (iret==0 && cnt>0) {
|
||||
CocDelay(100);
|
||||
ERR_I(iret=CocCheck(conn));
|
||||
cnt--;
|
||||
}
|
||||
}
|
||||
ERR_MSG("Does not quit within 5 seconds");
|
||||
if (iret==0) ERR_MSG("Does not quit within 5 seconds");
|
||||
return 0;
|
||||
OnError:
|
||||
return(-1);
|
||||
}
|
||||
@ -121,6 +122,7 @@ void TeccClose(pTecsClient conn) {
|
||||
#define tecs_get_data_ tecs_get_data
|
||||
#define tecs_date_ tecs_date
|
||||
#define tecs_time_ tecs_time
|
||||
#define tecs_rights_ tecs_rights
|
||||
#endif
|
||||
|
||||
static pTecsClient conn=NULL;
|
||||
@ -200,6 +202,16 @@ int tecs_init_(F_CHAR(startcmd), int *port, int startcmd_len) {
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int tecs_rights_(int write) {
|
||||
if (write) {
|
||||
ERR_I(CocSendMagic(conn, rwCode));
|
||||
} else {
|
||||
ERR_I(CocSendMagic(conn, rdCode));
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int tecs_get_(float *temp) {
|
||||
ERR_I(TeccGet(conn, temp));
|
||||
return(0);
|
||||
@ -227,9 +239,11 @@ void tecs_close_(void) {
|
||||
conn=NULL;
|
||||
}
|
||||
|
||||
int tecs_quit_server_(void) {
|
||||
ERR_I(TeccQuitServer(conn));
|
||||
return(0);
|
||||
int tecs_quit_server_(int *kill) {
|
||||
int iret;
|
||||
|
||||
ERR_I(iret=TeccQuitServer(conn, *kill));
|
||||
return(iret);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
@ -274,7 +288,11 @@ int DataDecode(float *data, int dataSize, char *coded, int *retSize) {
|
||||
dig1=decode[ch];
|
||||
if (dig1 < 0) { /* code is no 64-digit */
|
||||
if (ch=='\0' || ch==',') break;
|
||||
if (ch=='/') { data[i++] = DATA_UNDEF; }
|
||||
if (ch=='/') {
|
||||
data[i++] = DATA_UNDEF;
|
||||
} else if (ch=='.') {
|
||||
data[i++] = DATA_GAP;
|
||||
}
|
||||
} else {
|
||||
ch=coded[p++];
|
||||
dig2=decode[ch];
|
||||
@ -304,13 +322,15 @@ int DataDecode(float *data, int dataSize, char *coded, int *retSize) {
|
||||
}
|
||||
|
||||
|
||||
int tecs_get_data_(F_CHAR(names), int *startTime, int *endTime, int *step, float data[], int *maxLen, int *width
|
||||
int tecs_get_data_(F_CHAR(names), int *startTime, int *endTime, int *step, int *tbase
|
||||
, float xdata[], float ydata[], int *maxLen, int *width
|
||||
, int retLen[], int names_len) {
|
||||
char nam[64];
|
||||
char str[128];
|
||||
char res[COC_RES_LEN];
|
||||
char *cod;
|
||||
int i, l, iret, retSize;
|
||||
float offset, fact, *py;
|
||||
int i, j, k, l, iret, retSize;
|
||||
|
||||
if (*endTime - *startTime > *step * (*maxLen-1)) {
|
||||
printf("maxLen too small\n");
|
||||
@ -328,7 +348,21 @@ int tecs_get_data_(F_CHAR(names), int *startTime, int *endTime, int *step, float
|
||||
if (iret) ERR_MSG(response);
|
||||
cod=res;
|
||||
for (i=0; i < *width; i++) {
|
||||
ERR_I(l=DataDecode(data + i * *maxLen, *maxLen, cod, retLen+i));
|
||||
py = ydata + i * *maxLen;
|
||||
ERR_I(l=DataDecode(py, *maxLen, cod, retLen+i));
|
||||
if (retLen[i]>0) {
|
||||
fact = (float)(*endTime - *startTime) / retLen[i];
|
||||
}
|
||||
offset = *startTime - *tbase;
|
||||
k = i * *maxLen;
|
||||
for (j=0; j<retLen[i]; j++) {
|
||||
if (py[j] != DATA_GAP) {
|
||||
ydata[k] = py[j];
|
||||
xdata[k] = offset + j * fact;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
retLen[i] = k - i * *maxLen;
|
||||
cod+=l;
|
||||
}
|
||||
return 0;
|
||||
|
@ -27,8 +27,8 @@ int TeccSend(pTecsClient conn, char *cmd, char *reply, int replyLen);
|
||||
void TeccClose(pTecsClient conn);
|
||||
/* close connection and free ressources */
|
||||
|
||||
int TeccQuitServer(pTecsClient conn);
|
||||
/* quit the server process */
|
||||
int TeccQuitServer(pTecsClient conn, int kill);
|
||||
/* quit the server process, kill = 0: restart if possible */
|
||||
|
||||
/* Fortran interface:
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
real temp
|
||||
character device*32, init*80, line*80, cmd*16, par*80, response*1024
|
||||
character inst*64, host*64, user*1, pcod*1
|
||||
integer i,j,k,iret,l
|
||||
character cmdpar*128
|
||||
character prompt*32/'tecs>'/
|
||||
@ -12,20 +13,38 @@
|
||||
|
||||
! functions
|
||||
integer tecs_get_par, tecs_quit_server, tecs_set_par, tecs_watch_log
|
||||
integer tecs_get, show_log
|
||||
integer tecs_get, tecs_rights, show_log, instr_host
|
||||
|
||||
call sys_load_env('cho')
|
||||
call sys_getenv('CHOOSER_GDEV', line)
|
||||
if (line .ne. ' ') then
|
||||
call sys_setenv('PGPLOT_DEV', '/'//line)
|
||||
endif
|
||||
|
||||
call sys_getenv('TECS_INIT', init)
|
||||
|
||||
call sys_get_cmdpar(line, l)
|
||||
|
||||
if (l .ne. 0) then
|
||||
if (line(1:l) .eq. 'off' .or. line(1:l) .eq. 'OFF') then
|
||||
call tecs_open(0, ' ', iret)
|
||||
if (iret .lt. 0) goto 91
|
||||
iret=tecs_quit_server()
|
||||
if (iret .lt. 0) goto 91
|
||||
goto 99
|
||||
endif
|
||||
oneCommand=.true.
|
||||
i=instr_host(line, inst, host, user, pcod)
|
||||
else
|
||||
oneCommand=.false.
|
||||
i=0
|
||||
endif
|
||||
|
||||
if (oneCommand .and. line(1:1) .eq. '#') then
|
||||
call tecs_open(0, line, iret)
|
||||
if (i .ne. 0) then
|
||||
call tecs_open(0, '#'//host, iret)
|
||||
oneCommand=.false.
|
||||
prompt='tecs/'//inst(1:i)//'> '
|
||||
promptlen=i+7
|
||||
else if (init .eq. ' ') then
|
||||
call tecs_open(0, line, iret)
|
||||
else
|
||||
@ -48,8 +67,10 @@
|
||||
print *,'plot <var> chart for temperature and <var>'
|
||||
1 ,' var = P (default), He, Aux'
|
||||
print *,'log <n> show last n lines of logfile'
|
||||
print *,'kill close TecsServer and exit'
|
||||
print *,'exit,quit exit, but do not close TecsServer'
|
||||
print *,'remote set to remote mode'
|
||||
print *,'kill shut down TecsServer'
|
||||
print *,'restart restart TecsServer'
|
||||
print *,'exit,quit exit tecs client'
|
||||
print *,'help show list of parameters and cryo devices'
|
||||
print *
|
||||
|
||||
@ -93,20 +114,31 @@
|
||||
|
||||
defcmd='status'
|
||||
|
||||
if (cmd(1:1) .eq. '#') then
|
||||
i=instr_host(line, inst, host, user, pcod)
|
||||
if (i .ne. 0) then
|
||||
call tecs_close
|
||||
call tecs_open(0, cmd, iret)
|
||||
call tecs_open(0, '#'//host, iret)
|
||||
if (iret .lt. 0) goto 91
|
||||
prompt='tecs/'//cmd(2:)
|
||||
promptlen=1
|
||||
do i=1,len(prompt)-2
|
||||
if (prompt(i:i) .ne. ' ') promptlen=i
|
||||
enddo
|
||||
promptlen=promptlen+1
|
||||
prompt(promptlen:promptlen)='>'
|
||||
promptlen=promptlen+1
|
||||
prompt='tecs/'//inst(1:i)//'> '
|
||||
promptlen=i+7
|
||||
else if (cmd .eq. 'kill') then
|
||||
iret=tecs_quit_server()
|
||||
iret=tecs_quit_server(1)
|
||||
if (iret .lt. 0) goto 19
|
||||
if (iret .gt. 0) then
|
||||
print *,'tecs server is not running'
|
||||
endif
|
||||
else if (cmd .eq. 'restart') then
|
||||
iret=tecs_quit_server(0)
|
||||
if (iret .lt. 0) goto 19
|
||||
if (iret .gt. 0) then
|
||||
print *,'tecs server is not running'
|
||||
endif
|
||||
else if (cmd .eq. 'remote') then
|
||||
iret=tecs_set_par('remoteMode', '2', 2)
|
||||
if (iret .lt. 0) goto 19
|
||||
elseif (cmd .eq. 'rwacs') then
|
||||
iret=tecs_rights(1)
|
||||
if (iret .lt. 0) goto 19
|
||||
elseif (cmd .eq. 'exit' .or. cmd .eq. 'quit') then
|
||||
goto 99
|
||||
elseif (cmd .eq. 'status') then
|
||||
@ -116,7 +148,7 @@
|
||||
l=0
|
||||
goto 11
|
||||
elseif (cmd .eq. 'plot') then
|
||||
call tecs_plot('Tm Ts Tr P', 1)
|
||||
call tecs_plot(' ')
|
||||
elseif (cmd .eq. 'help') then
|
||||
print *
|
||||
print *,'Writeable parameters:'
|
||||
@ -131,18 +163,18 @@
|
||||
print *,'deriv PID derivation term'
|
||||
print *,'maxShift maximum (set-tempH) for controlMode=2'
|
||||
print *,'int2 integration time (sec) for controlMode=2'
|
||||
print *,'remoteMode 1: local, 2: remote'
|
||||
print *
|
||||
print *,'Read only parameters:'
|
||||
print *
|
||||
print *,'Tm main temperature'
|
||||
print *,'Ts sample temperature'
|
||||
print *,'setH set-point on regulation'
|
||||
print *,'Tr set-point on regulation'
|
||||
print *,'tLimit temperature limit'
|
||||
print *,'helium helium level'
|
||||
print *,'htr heater current percentage'
|
||||
print *,'resist heater resistance'
|
||||
print *,'logfile name of the logfile'
|
||||
print *,'remoteMode 1: local, 2: remote '
|
||||
1 ,'(switch on with device command)'
|
||||
print *
|
||||
print *,'Ta,Tb,Tc,Td values of channels A,B,C,D'
|
||||
print *
|
||||
@ -152,7 +184,7 @@
|
||||
1 ,'ill5 (maxi)'
|
||||
print *,'cti1, cti2, cti3, cti4, cti5 (maxi), cti6 (focus), apd'
|
||||
print *,'ccr4k (4K closed cycle), hef4c (TriCS 4circle cryo)'
|
||||
print *,'sup4t (supra.magnet 4T)'
|
||||
print *,'sup4t (supra.magnet 4T), ft (tantalum furnace)'
|
||||
print *,'rdr11, rdr12 (LTF dilution 1 & 2, 20kOhm)'
|
||||
print *
|
||||
elseif (cmd .eq. 'log') then
|
||||
@ -184,7 +216,9 @@
|
||||
endif
|
||||
logarg=' '
|
||||
elseif (cmd .eq. 'plot') then
|
||||
call tecs_plot('Tm Ts Tr '//par, 1)
|
||||
call str_lowcase(par, par)
|
||||
call str_upcase(par(1:1), par(1:1))
|
||||
call tecs_plot(par)
|
||||
elseif (cmd .eq. 'watch') then
|
||||
iret=tecs_watch_log(par)
|
||||
if (iret .lt. 0) goto 19
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <assert.h>
|
||||
#include "myc_mem.h"
|
||||
#include "myc_str.h"
|
||||
@ -102,7 +102,7 @@ Set *FindSet(Base *base, char *name) {
|
||||
|
||||
total=0;
|
||||
s = base->head;
|
||||
while (s!=NULL && 0!=strcmp(name, s->set.name)) {
|
||||
while (s!=NULL && 0!=strcasecmp(name, s->set.name)) {
|
||||
s = s->next;
|
||||
}
|
||||
return s;
|
||||
@ -245,7 +245,7 @@ int Put(Set *set, int time, float value) {
|
||||
if (t % 2) {
|
||||
r->data[size]=value; size++; /* put a provisory value */
|
||||
r->endTime += r->step;
|
||||
} else {
|
||||
} else if (t == 2) {
|
||||
PutSum(&set->sum, r->data+size); size+=2;
|
||||
r->endTime += r->step * 2;
|
||||
}
|
||||
@ -469,6 +469,8 @@ int DataEncode(float *data, int dataSize, char *coded, int codedLen) {
|
||||
for (i=0; i<dataSize; i++) {
|
||||
if ( data[i] == DATA_UNDEF ) {
|
||||
coded[p++]='/';
|
||||
} else if ( data[i] == DATA_GAP ) {
|
||||
coded[p++]='.';
|
||||
} else {
|
||||
n=( (data[i] - minD) * 4095 ) / range + 0.5;
|
||||
assert(n>=0 && n <4096);
|
||||
@ -514,7 +516,7 @@ int DataGetCoded(char *names, int startTime, int endTime, int step, int stdStep,
|
||||
}
|
||||
if (set == NULL || start > startTime) {
|
||||
set=CreateSet(&base, nam, NULL, stp, period, startTime);
|
||||
set->end = start;
|
||||
if (set != NULL) set->end = start;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -567,8 +569,20 @@ int DataGetCoded(char *names, int startTime, int endTime, int step, int stdStep,
|
||||
siz2 = halfsiz * 2 - siz1;
|
||||
s1 = startTime + (siz1 * period + halfsiz) / halfsiz / 2;
|
||||
if (siz1 > 0) {
|
||||
halfsiz = (s1 - startTime) / set->step / 2;
|
||||
if (halfsiz * 2 < siz1 && halfsiz > 0) {
|
||||
ERR_I(GetSet(set, startTime, s1, halfsiz*2, data));
|
||||
j = siz1 - 1;
|
||||
for (i = halfsiz * 2-1; i >= 0; i--) { /* expand data */
|
||||
while (j > siz1 / 2 * i / halfsiz) {
|
||||
data[j]=DATA_GAP; j--;
|
||||
}
|
||||
data[j]=data[i]; j--;
|
||||
}
|
||||
} else {
|
||||
ERR_I(GetSet(set, startTime, s1, siz1, data));
|
||||
}
|
||||
}
|
||||
if (siz2 > 0) {
|
||||
ERR_I(GetSet(s, s1, endTime, siz2, data+siz1));
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ int DataGetCoded(char *names, int startTime, int endTime, int step, int stdStep,
|
||||
define DATA_UNDEF as a binary and decimal well defined, hopefully rarely used number
|
||||
*/
|
||||
#define DATA_UNDEF MYC_NAN
|
||||
#define DATA_GAP (MYC_NAN*2)
|
||||
#define DATA_CODE "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[]abcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
#endif /* TECS_DATA_H_ */
|
||||
|
@ -1,45 +1,67 @@
|
||||
subroutine tecs_plot(pars, naux)
|
||||
subroutine tecs_plot(auxpar)
|
||||
|
||||
character(len=*) pars ! parameters to plot
|
||||
integer naux ! number of auxiliary, non-T parameters
|
||||
character(len=*) auxpar
|
||||
|
||||
integer, parameter :: dmax=1000, nmax=5, nmenu=11, chartfreq=1
|
||||
integer, parameter :: dmax=800, nmax=5, tmax=4, amax=3, nmenu=13, chartperiod=5, naux=1
|
||||
integer, parameter :: minRange=60, maxRange=7*24*3600
|
||||
integer, parameter :: oneDay = 24*3600
|
||||
integer, parameter :: zoom=1, right=2, live=3
|
||||
real, parameter :: winmin=60., undef=-1.125/1024./1024./1024.
|
||||
|
||||
real*4 x1,x2,xmin,xmax,ymin(2),ymax(2),window
|
||||
real*4 xd(dmax, nmax),yd(dmax,nmax), yy0(nmax), yy1(nmax)
|
||||
real*4 ylast1,ylast2,y1,y2
|
||||
real*4 ex,ey,fx,fy,row,ticks,tim0,tim1
|
||||
real*4 ex,ey,fx,fy,row,ticks,tim0,tim1,menuwid
|
||||
integer l,j,i,n,t,leng,i1,i2,rl,startday,thisday
|
||||
integer nset
|
||||
integer ncol, nset, mode
|
||||
integer first,last,step,tbase,lastj
|
||||
integer colorList(nmax)/5,3,2,4,8/
|
||||
integer color(nmax)
|
||||
integer retLen(nmax)
|
||||
integer sel/0/, sel1, sel2, auxsel/1/
|
||||
character key*1
|
||||
character text(nmenu)*12/ &
|
||||
'live off','sel. zoom','zoom in','zoom out','show all','n days','n hours','n min','date','file','quit'/
|
||||
character keys*(nmenu)/'LZ+-XDHMTFQ'/
|
||||
character text(2,nmenu)*16/ &
|
||||
'L' ,'live off' &
|
||||
,'z' ,'sel. zoom' &
|
||||
,'+' ,'zoom in' &
|
||||
,'-' ,'zoom out' &
|
||||
,'x' ,'show all' &
|
||||
,'2d' ,'2 days' &
|
||||
,'1h' ,'1 hour' &
|
||||
,'15m' ,'15 min' &
|
||||
,'31.7t','goto date' &
|
||||
,'c' ,'show P/He/Aux' &
|
||||
,'s' ,'select T' &
|
||||
,'f' ,'write file' &
|
||||
,'q' ,'quit'/
|
||||
character weekdays(7)*4/'Mon','Tue','Wed','Thu','Fri','Sat','Sun'/
|
||||
character buf*8, device*8, name*40, filnam*128, numb*16
|
||||
character buf*8, device*8, name*40, filnam*128, numb*16, title*64, pars*64
|
||||
character(len=4) tpar(tmax)/'Te', 'Tr', 'Tm', 'Ts'/
|
||||
character(len=4) apar(amax)/'P', 'He', 'Aux'/
|
||||
character(len=16) parnam(nmax)
|
||||
external tplot_close
|
||||
logical gap, done
|
||||
logical live, xwin, zoom, right, saveit
|
||||
logical saveit
|
||||
integer iret, lund, numl, mon, day
|
||||
|
||||
! functions
|
||||
integer sys_gmt_off, myc_now, myc_time, myc_date, tecs_get_data, tecs_get_mult
|
||||
integer sys_gmt_off, myc_now, myc_time, myc_date, tecs_get_data, tecs_get_mult, tecs_get_par
|
||||
|
||||
data window/0./
|
||||
|
||||
if (window==0) window=1800.
|
||||
saveit=.false.
|
||||
zoom=.false.
|
||||
right=.true.
|
||||
mode=live
|
||||
call pgopen(" ")
|
||||
|
||||
call pgqinf('TYPE', device, l)
|
||||
if (device=='NULL') then
|
||||
print *,'No PGPLOT-Device defined'
|
||||
goto 9
|
||||
endif
|
||||
|
||||
call pgqcol(i,ncol)
|
||||
! print *,i,ncol,' colors ',device
|
||||
if (ncol>=8 .and. device /= 'VT125') then
|
||||
call pgscr(0, 1.0, 1.0, 1.0)
|
||||
call pgscr(1, 0.0, 0.0, 0.0)
|
||||
call pgscr(2, 1.0, 0.0, 0.0)
|
||||
@ -49,53 +71,44 @@ subroutine tecs_plot(pars, naux)
|
||||
call pgscr(6, 1.0, 0.0, 1.0)
|
||||
call pgscr(7, 1.0, 1.0, 0.0)
|
||||
call pgscr(8, 1.0, 0.5, 0.0)
|
||||
|
||||
call pgqinf('TYPE', device, l)
|
||||
if (device=='NULL') then
|
||||
print *,'No PGPLOT-Device defined'
|
||||
goto 9
|
||||
endif
|
||||
live=device(1:1)/='X' ! live switched off by default on X-Windows
|
||||
|
||||
nset=1
|
||||
l=1
|
||||
i=1
|
||||
do while (i <= nmax)
|
||||
do while (l < len(pars) .and. pars(l:l) <= ' ')
|
||||
l=l+1
|
||||
enddo
|
||||
if (pars(l:l) > ' ') then
|
||||
j=l
|
||||
do while (l < len(pars) .and. pars(l:l) > ' ')
|
||||
l=l+1
|
||||
enddo
|
||||
parnam(i)=pars(j:l)
|
||||
nset=i
|
||||
if (l == len(pars)) i=nmax
|
||||
else
|
||||
i=nmax
|
||||
endif
|
||||
i=i+1
|
||||
enddo
|
||||
|
||||
call pgask(.false.)
|
||||
l=0
|
||||
x1=0
|
||||
step=0
|
||||
do i=1,amax
|
||||
if (auxpar == apar(i)) then
|
||||
auxsel=i
|
||||
endif
|
||||
enddo
|
||||
|
||||
1 iret=tecs_get_mult(pars, t, nset, yy0)
|
||||
1 pars=' '
|
||||
nset=0
|
||||
do i=1,tmax
|
||||
nset=nset+1
|
||||
color(nset)=colorList(i)
|
||||
parnam(nset)=tpar(i)
|
||||
pars=trim(pars)//' '//parnam(nset)
|
||||
enddo
|
||||
nset=nset+1
|
||||
color(nset)=colorList(5)
|
||||
parnam(nset)=apar(auxsel)
|
||||
pars=trim(pars)//' '//parnam(nset)
|
||||
|
||||
iret=tecs_get_mult(pars, t, nset, yy0)
|
||||
if (iret < 0) goto 99
|
||||
if (window == 0) then
|
||||
last=t
|
||||
step=maxRange/dmax
|
||||
window=maxRange
|
||||
first=t-min(dmax*step-1,maxRange-step)
|
||||
else if (right .or. live) then
|
||||
else if (mode >= right) then
|
||||
step=window/(dmax-1)+0.99
|
||||
last=t
|
||||
first=t-min(dmax*step-1,nint(window)-step)
|
||||
else
|
||||
if (.not. zoom) then
|
||||
if (mode==zoom) then
|
||||
x2=(x1+x2+window)/2
|
||||
x1=x2-window
|
||||
endif
|
||||
@ -106,42 +119,37 @@ subroutine tecs_plot(pars, naux)
|
||||
endif
|
||||
if (step == 0) step=1
|
||||
|
||||
iret=tecs_get_data(pars, first, last, step, yd, dmax, nmax, retLen)
|
||||
tbase=first-mod(first,7*oneDay)
|
||||
iret=tecs_get_data(pars, first, last, step, tbase, xd, yd, dmax, nmax, retLen)
|
||||
if (iret < 0) goto 99
|
||||
! do i=1,nmax
|
||||
! if (retLen(i) > 0) nset=i
|
||||
! enddo
|
||||
! if (nset == 0) then
|
||||
! retLen(1)=0
|
||||
! nset=1
|
||||
! endif
|
||||
color(1)=2
|
||||
color(2)=4
|
||||
color(3)=3
|
||||
color(4)=5
|
||||
color(5)=8
|
||||
if (naux > 0) color(nset)=8
|
||||
|
||||
tbase=first-mod(first,7*oneDay);
|
||||
x2 = last - tbase;
|
||||
if (right .or. live) then
|
||||
x2 = last - tbase
|
||||
if (mode >= right) then
|
||||
x1=x2-window
|
||||
else
|
||||
x1 = first - tbase;
|
||||
x1 = first - tbase
|
||||
endif
|
||||
tim0=t-tbase
|
||||
do j=1,nset
|
||||
leng=retLen(j)
|
||||
do i=1,leng
|
||||
xd(i,j)=(float(i-1)*(last-tbase)+float(leng-i)*(first-tbase))/(leng-1)
|
||||
do i=1,nset
|
||||
leng=retLen(i)
|
||||
do while (leng > 1 .and. yd(leng,i) == undef)
|
||||
leng=leng-1
|
||||
enddo
|
||||
if (live .and. leng>0) then
|
||||
xd(leng,j)=tim0
|
||||
yd(leng,j)=yy0(j)
|
||||
if (leng == 1) leng=0
|
||||
retLen(i)=leng
|
||||
if (mode==live .and. leng>0) then
|
||||
xd(leng,i)=tim0
|
||||
yd(leng,i)=yy0(i)
|
||||
endif
|
||||
enddo
|
||||
if (sel /= 0) then
|
||||
do while (sel < nset .and. retLen(sel) == 0)
|
||||
sel=sel+1
|
||||
enddo
|
||||
if (sel >= nset) sel = 0
|
||||
endif
|
||||
if (saveit) goto 9
|
||||
if (live) then
|
||||
if (mode==live) then
|
||||
x2=max(tim0,x2)+min(1800., window*0.5)
|
||||
endif
|
||||
|
||||
@ -155,8 +163,15 @@ subroutine tecs_plot(pars, naux)
|
||||
|
||||
i1=1
|
||||
i2=nset-naux
|
||||
if (sel==0) then
|
||||
sel1=i1
|
||||
sel2=i2
|
||||
else
|
||||
sel1=sel
|
||||
sel2=sel
|
||||
endif
|
||||
do rl=1,2
|
||||
if (zoom) then
|
||||
if (mode==zoom) then
|
||||
ymin(1)=y1
|
||||
ymax(1)=y2
|
||||
else
|
||||
@ -164,7 +179,7 @@ subroutine tecs_plot(pars, naux)
|
||||
ymax(rl)=-1e30
|
||||
ylast1=ymin(rl)
|
||||
ylast2=ymax(rl)
|
||||
do i=i1,i2
|
||||
do i=sel1,sel2
|
||||
do j=1,retLen(i)
|
||||
if (yd(j,i)/=undef) then
|
||||
ymin(rl)=min(ymin(rl),yd(j,i))
|
||||
@ -183,7 +198,7 @@ subroutine tecs_plot(pars, naux)
|
||||
fy=abs(ymax(rl))
|
||||
ymax(rl)=ymax(rl)+max(fy*0.0075,ey*0.01)
|
||||
ymin(rl)=ymin(rl)-max(fy*0.005,ey*0.01)
|
||||
if (live) then
|
||||
if (mode==live) then
|
||||
ymin(rl)=min(ymin(rl),max(0.0,ylast1-ey*0.4))
|
||||
ymax(rl)=max(ymax(rl),ylast2+ey*0.4)
|
||||
endif
|
||||
@ -196,11 +211,10 @@ subroutine tecs_plot(pars, naux)
|
||||
ymax(rl)=ymin(rl)*1.00001+1.0
|
||||
ymin(rl)=-1.0e-3
|
||||
endif
|
||||
zoom=.false.
|
||||
|
||||
call set_win(rl,x1,x2,ymin(rl),ymax(rl))
|
||||
|
||||
do i=i2,i1,-1
|
||||
do i=i1,i2
|
||||
call pgsci(color(i))
|
||||
lastj=1
|
||||
do j=1,retLen(i)
|
||||
@ -220,6 +234,7 @@ subroutine tecs_plot(pars, naux)
|
||||
call pgtbox('C', 0.0, 0, ' ', 0.0, 0)
|
||||
ey=0.0
|
||||
do i=i1,i2
|
||||
if (retLen(i) > 0) then
|
||||
name=parnam(i)
|
||||
if (name=="Tm") then
|
||||
name="Main Sensor"
|
||||
@ -228,14 +243,16 @@ subroutine tecs_plot(pars, naux)
|
||||
elseif (name=="Tr") then
|
||||
name="SetPoint"
|
||||
endif
|
||||
if (sel == i) name=trim(name)//'*'
|
||||
call pglen(5, trim(name), fx, fy)
|
||||
call pgsci(color(i))
|
||||
call pgmtxt ('L', 2.5, ey, 0.0, trim(name))
|
||||
ey=ey+fy+0.04
|
||||
endif
|
||||
enddo
|
||||
call pgsci(1)
|
||||
call pgmtxt ('L', 2.5, ey, 0.0, 'T [K]')
|
||||
else if (naux > 0) then
|
||||
else
|
||||
call pgsch(0.7)
|
||||
call pgtbox('ZCIST', ticks, 0, 'BCVINMST', 0.0, 0)
|
||||
call pgtbox('B', 0.0, 0, ' ', 0.0, 0)
|
||||
@ -243,39 +260,46 @@ subroutine tecs_plot(pars, naux)
|
||||
call pgsch(1.0)
|
||||
if (parnam(nset) == 'P' .or. parnam(nset) == 'p') then
|
||||
call pgmtxt ('L', 2.5, 0.5, 0.5, 'Power [W]')
|
||||
elseif (parnam(nset) == 'He') then
|
||||
title='%'
|
||||
iret=tecs_get_par('heUnits', title, 0)
|
||||
call pgmtxt ('L', 2.5, 0.5, 0.5, 'Helium ['//trim(title)//']')
|
||||
else
|
||||
call pgmtxt ('L', 2.5, 0.5, 0.5, parnam(nset))
|
||||
endif
|
||||
endif
|
||||
i1=nset-naux+1
|
||||
i2=nset
|
||||
sel1=i1
|
||||
sel2=i2
|
||||
enddo
|
||||
|
||||
call pgsch(0.8)
|
||||
call pgsch(0.7)
|
||||
rl=1
|
||||
call set_win(rl,x1,x2,ymin(rl),ymax(rl))
|
||||
|
||||
call pgsci(1)
|
||||
call pgsclp(0)
|
||||
if (live) then
|
||||
text(1)='live off'
|
||||
if (mode==live) then
|
||||
text(2,1)='live off'
|
||||
else
|
||||
text(1)='live on'
|
||||
text(2,1)='live on'
|
||||
endif
|
||||
ex=0.0
|
||||
text(2,10)='show '//apar(mod(auxsel,3)+1)
|
||||
menuwid=0.0
|
||||
do i=1,nmenu
|
||||
call pglen(5, trim(text(i)), fx, fy)
|
||||
call pgmtxt('T', 3.0, ex, 0.0, '|'//keys(i:i))
|
||||
call pgmtxt('T', 2.5, ex, 0.0, '|')
|
||||
call pgmtxt('T', 2.0, ex, 0.0, '|'//text(i))
|
||||
ex=ex+fx+0.01
|
||||
call pglen(5, trim(text(2,i)), fx, fy)
|
||||
call pgmtxt('T', 3.0, menuwid, 0.0, '|'//text(1,i))
|
||||
call pgmtxt('T', 2.5, menuwid, 0.0, '|')
|
||||
call pgmtxt('T', 2.0, menuwid, 0.0, '|'//text(2,i))
|
||||
menuwid=menuwid+fx+0.01
|
||||
enddo
|
||||
call pgmtxt('T', 3.0, ex, 0.0, '|')
|
||||
call pgmtxt('T', 2.5, ex, 0.0, '|')
|
||||
call pgmtxt('T', 2.0, ex, 0.0, '|')
|
||||
call pgmtxt('T', 3.0, 0.8, 0.0, 'any digit to enter n')
|
||||
call pgmtxt('T', 2.0, 0.8, 0.0, 'n=')
|
||||
call pgmtxt('T', 3.0, menuwid, 0.0, '|')
|
||||
call pgmtxt('T', 2.5, menuwid, 0.0, '|')
|
||||
call pgmtxt('T', 2.0, menuwid, 0.0, '|')
|
||||
menuwid=menuwid+0.01
|
||||
|
||||
call pgsch(0.8)
|
||||
done=.false.
|
||||
row=(ymax(rl)-ymin(rl))/30.
|
||||
ey=ymin(rl)-row*3.5
|
||||
@ -300,7 +324,7 @@ subroutine tecs_plot(pars, naux)
|
||||
i=i+1
|
||||
enddo
|
||||
if (.not. done) then
|
||||
n=nint(x2)/oneDay*oneDay;
|
||||
n=nint(x2)/oneDay*oneDay
|
||||
i=nint(x1)-n
|
||||
j=nint(x2)-n
|
||||
if (i < 0) then
|
||||
@ -321,17 +345,29 @@ subroutine tecs_plot(pars, naux)
|
||||
call pgmtxt('B', 3.5, ex, ex, weekdays(thisday)//buf(7:8)//'.'//buf(5:6))
|
||||
endif
|
||||
|
||||
iret=tecs_get_par('device', title, 0)
|
||||
if (iret < 0) goto 99
|
||||
i=index(title, '(')
|
||||
if (i > 2 ) then
|
||||
title=title(1:i-1)
|
||||
else
|
||||
title='test - no device'
|
||||
endif
|
||||
|
||||
call pgmtxt('T', -1.5, 0.02, 0.0, title)
|
||||
call pgsclp(1)
|
||||
|
||||
call get_key(key, 0, 0) ! purge buffer
|
||||
call purge_keys ! purge buffer
|
||||
|
||||
numl=0
|
||||
numb=' '
|
||||
7 if (live) then
|
||||
if (device(1:1)=='X') then
|
||||
call pgmtxt('T', 0.5, 0.0, 0.0, 'LIVE MODE (click on text window before pressing any further key)')
|
||||
endif
|
||||
call get_key(key, 0, chartfreq)
|
||||
7 if (mode==live) then
|
||||
! if (device(1:1)=='X') then
|
||||
! call pgmtxt('T', 0.5, 0.0, 0.0, 'LIVE MODE (click on text window before pressing any further key)')
|
||||
! endif
|
||||
! call get_key(key, 0, chartperiod)
|
||||
i=chartperiod-mod(myc_now(), chartperiod)
|
||||
call get_cursor(ex, ey, key, -i)
|
||||
|
||||
do while (key == char(0)) ! no key pressed
|
||||
iret=tecs_get_mult(pars, t, nset, yy1)
|
||||
@ -347,9 +383,9 @@ subroutine tecs_plot(pars, naux)
|
||||
i2=nset-naux
|
||||
do rl=1,2
|
||||
call set_win(rl,x1,x2,ymin(rl),ymax(rl))
|
||||
do i=i2,i1,-1
|
||||
if (yy0(i) .ne. undef .and. yy1(i) .ne. undef) then
|
||||
if (yy1(i) < ymin(rl) .or. yy1(i) > ymax(rl)) then
|
||||
do i=i1,i2
|
||||
if (yy0(i) /= undef .and. yy1(i) /= undef) then
|
||||
if ((sel==0 .or. sel==i) .and. (yy1(i) < ymin(rl) .or. yy1(i) > ymax(rl))) then
|
||||
call pgpage
|
||||
window=x2-x1
|
||||
goto 1
|
||||
@ -366,11 +402,11 @@ subroutine tecs_plot(pars, naux)
|
||||
tim0=tim1
|
||||
|
||||
endif
|
||||
call get_key(key, 0, chartfreq)
|
||||
i=chartperiod-mod(myc_now(), chartperiod)
|
||||
call get_cursor(ex, ey, key, -i)
|
||||
enddo
|
||||
else
|
||||
call pgcurs(ex, ey, key)
|
||||
call must_purge
|
||||
call get_cursor(ex, ey, key, 0)
|
||||
endif
|
||||
rl=1
|
||||
call set_win(rl,x1,x2,ymin(rl),ymax(rl))
|
||||
@ -378,28 +414,51 @@ subroutine tecs_plot(pars, naux)
|
||||
8 if (key>='a') key=char(ichar(key)-32)
|
||||
if (key=='-') then
|
||||
window=min(window*2, 8.0*oneDay)
|
||||
if (mode==zoom) then
|
||||
x1=x1-(x2-x1)/2
|
||||
x2=x2+(x2-x1)/3
|
||||
y1=y1-(y2-y1)/2
|
||||
y2=y2+(y2-y1)/3
|
||||
endif
|
||||
elseif (key=='X') then
|
||||
window=0
|
||||
live=.false.
|
||||
mode=0
|
||||
elseif (key=='+' .or. key==',') then
|
||||
window=max(winmin,window/2)
|
||||
if (mode==zoom) then
|
||||
if (ex==undef) then
|
||||
ex=(x1+x2)/2
|
||||
ey=(min(y1,ymax(1))+max(y1,ymin(1)))/2
|
||||
end if
|
||||
fx=max(winmin,x2-x1)
|
||||
fy=max(y2-y1,1e-3,y2*1e-5)
|
||||
x1=ex-fx/4
|
||||
x2=ex+fx/4
|
||||
y1=ey-fy/4
|
||||
y2=ey+fy/4
|
||||
endif
|
||||
elseif (key=='Z') then
|
||||
call pgsci(1)
|
||||
if (live) then
|
||||
if (ex==undef) then
|
||||
call pgmtxt('T', 0.5, 0.0, 0.0, 'click on two opposite corners of a selection rectangle')
|
||||
call pgcurs(ex, ey, key)
|
||||
call get_cursor(ex, ey, key, 0)
|
||||
else
|
||||
call pgmtxt('T', 0.5, 0.0, 0.0, 'click on second corner of selection rectangle')
|
||||
endif
|
||||
call pgsci(5)
|
||||
call pgsci(6)
|
||||
xmin=x1
|
||||
xmax=x2
|
||||
call pgmove(xmin, ey)
|
||||
call pgdraw(xmax, ey)
|
||||
call pgmove(ex, ymin(rl))
|
||||
call pgdraw(ex, ymax(rl))
|
||||
call pgcurs(fx, fy, key)
|
||||
call must_purge
|
||||
if (device(1:1) .eq. 'X') then
|
||||
fx=ex
|
||||
fy=ey
|
||||
call get_cursor(fx, fy, key, 2)
|
||||
else
|
||||
call get_cursor(fx, fy, key, 0)
|
||||
endif
|
||||
x1=max(xmin,min(ex,fx))
|
||||
x2=min(xmax,max(ex,fx))
|
||||
if (x1>=x2) then
|
||||
@ -413,42 +472,36 @@ subroutine tecs_plot(pars, naux)
|
||||
y1=ymin(1)
|
||||
y2=ymax(1)
|
||||
endif
|
||||
zoom=.true.
|
||||
live=.false.
|
||||
right=.false.
|
||||
mode=zoom
|
||||
elseif (key >= '0' .and. key <= '9' .or. key == '.') then ! number
|
||||
if (numl .lt. len(numb)) then
|
||||
numl=numl+1
|
||||
numb(numl:numl)=key
|
||||
call pgsci(1)
|
||||
call pgsch(0.8)
|
||||
call pgmtxt('T', 2.0, 0.825, 0.0, numb(1:numl))
|
||||
call pgmtxt('T', 2.0, menuwid, 0.0, numb(1:numl))
|
||||
endif
|
||||
if (device(1:1)=='X' .and. .not. live) then
|
||||
call pgcurs(ex, ey, key)
|
||||
call must_purge
|
||||
else
|
||||
call get_key(key, 2, 10)
|
||||
endif
|
||||
if (key/=char(0)) goto 8
|
||||
! call get_cursor(ex, ey, key, -chartperiod)
|
||||
! if (key/=char(0)) goto 8
|
||||
if (mode==zoom) mode=0
|
||||
goto 7
|
||||
elseif (key == 'D') then
|
||||
ex=1
|
||||
read(numb, *, iostat=i) ex
|
||||
window=min(maxRange,max(minRange, nint(oneDay*ex)))
|
||||
right=.true.
|
||||
if (mode < right) mode=right
|
||||
x1=0
|
||||
elseif (key == 'H') then
|
||||
ex=1
|
||||
read(numb, *, iostat=i) ex
|
||||
window=min(maxRange,max(minRange, nint(3600*ex)))
|
||||
right=.true.
|
||||
if (mode < right) mode=right
|
||||
x1=0
|
||||
elseif (key == 'M') then
|
||||
ex=1
|
||||
read(numb, *, iostat=i) ex
|
||||
window=min(maxRange,max(minRange, nint(60*ex)))
|
||||
right=.true.
|
||||
if (mode < right) mode=right
|
||||
x1=0
|
||||
elseif (key == 'T' .or. numl>0 .and. (key==char(13) .or. key==char(10))) then
|
||||
j=index(numb,'.')
|
||||
@ -457,27 +510,32 @@ subroutine tecs_plot(pars, naux)
|
||||
read(numb(1:j-1), *, iostat=i) day
|
||||
mon=0
|
||||
read(numb(j+1:numl), *, iostat=i) mon
|
||||
tbase = myc_time(day+mon*100);
|
||||
tbase = myc_time(day+mon*100)
|
||||
else
|
||||
read(numb, *, iostat=i) day
|
||||
tbase = myc_time(day);
|
||||
tbase = myc_time(day)
|
||||
endif
|
||||
x1=0
|
||||
x2=oneDay
|
||||
window=x2
|
||||
live=.false.
|
||||
right=.false.
|
||||
mode=0
|
||||
elseif (key == 'L') then
|
||||
live=.not. live
|
||||
if (live) then
|
||||
right=.true.
|
||||
if (mode == live) then
|
||||
mode=right
|
||||
else
|
||||
mode=live
|
||||
endif
|
||||
elseif (key == 'F') then
|
||||
saveit=.true.
|
||||
elseif (key=='Q' .or. key==char(13) .or. key==char(10)) then
|
||||
goto 9
|
||||
elseif (key == 'R') then
|
||||
elseif (live) then
|
||||
elseif (key == 'S') then
|
||||
sel=sel+1
|
||||
if (sel > tmax) sel=0
|
||||
elseif (key == 'C') then
|
||||
auxsel=auxsel+1
|
||||
if (auxsel > amax) auxsel=1
|
||||
elseif (mode==live) then
|
||||
goto 7
|
||||
endif
|
||||
numl=0
|
||||
@ -486,8 +544,8 @@ subroutine tecs_plot(pars, naux)
|
||||
goto 1
|
||||
99 call tecs_write_msg(6)
|
||||
9 continue
|
||||
call tplot_close
|
||||
call get_key(key, 0, 0) ! purge type-ahead-buffer
|
||||
call pgclos
|
||||
call purge_keys
|
||||
print *
|
||||
if (saveit) then
|
||||
lund=41
|
||||
@ -525,22 +583,37 @@ subroutine tecs_plot(pars, naux)
|
||||
|
||||
end subroutine
|
||||
|
||||
subroutine get_key(key, tmo1, tmo2)
|
||||
integer tmo1, tmo2
|
||||
character key*1
|
||||
logical purge/.false./
|
||||
subroutine get_cursor(x, y, key, mode)
|
||||
character*1 key
|
||||
real*4 x, y
|
||||
integer mode
|
||||
integer with_timeout/-1/
|
||||
integer l
|
||||
character res*32
|
||||
|
||||
key=char(0)
|
||||
if (purge) then
|
||||
purge=.false.
|
||||
call sys_get_key(key, tmo1)
|
||||
if (key/=char(0) .and. key/=char(13)) return
|
||||
if (with_timeout<0) then
|
||||
with_timeout=0
|
||||
call pgqinf('VERSION', res, l)
|
||||
if (res(l:l)=='+') then
|
||||
call pgqinf('TYPE', res, l)
|
||||
if (res(1:1)=='X') then
|
||||
with_timeout=1
|
||||
end if
|
||||
if (tmo2>0) call sys_get_key(key, tmo2)
|
||||
return
|
||||
end if
|
||||
end if
|
||||
if (with_timeout>0 .or. mode>=0) then
|
||||
call pgband(mode, 0, x, y, x, y, key)
|
||||
else
|
||||
call sys_get_key(key, -mode)
|
||||
endif
|
||||
end subroutine
|
||||
|
||||
entry must_purge
|
||||
purge=.true.
|
||||
subroutine purge_keys
|
||||
character key*1
|
||||
key=' '
|
||||
do while (key/=char(0))
|
||||
call sys_get_key(key, 0)
|
||||
end do
|
||||
end subroutine
|
||||
|
||||
subroutine set_win(rl, x1, x2, y1, y2)
|
||||
@ -555,8 +628,3 @@ subroutine set_win(rl, x1, x2, y1, y2)
|
||||
|
||||
call pgswin(x1,x2,y1,y2)
|
||||
end subroutine
|
||||
|
||||
subroutine tplot_close
|
||||
call pgclos
|
||||
! call dlog_close_r
|
||||
end subroutine
|
||||
|
102
tecsdriv.c
102
tecsdriv.c
@ -38,6 +38,7 @@
|
||||
MODIFICATIONS.
|
||||
----------------------------------------------------------------------------*/
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
@ -57,8 +58,8 @@
|
||||
#include "sicsvar.h"
|
||||
#include "tecs/coc_util.h"
|
||||
#include "tecs/tecs_cli.h"
|
||||
#include "tecs/str_util.h"
|
||||
#include "tecs/err_handling.h"
|
||||
#include "tecs/myc_str.h"
|
||||
#include "tecs/myc_err.h"
|
||||
extern pServer pServ;
|
||||
|
||||
#include "evdriver.i"
|
||||
@ -83,7 +84,6 @@
|
||||
int iRet;
|
||||
pEVDriver pD;
|
||||
pTecsDriv pMe;
|
||||
double fNum;
|
||||
float fVal;
|
||||
|
||||
self = (pEVControl)pData;
|
||||
@ -96,23 +96,66 @@
|
||||
return EVControlWrapper(pCon,pSics,pData,argc,argv);
|
||||
}
|
||||
|
||||
pD=self->pDriv; assert(pD);
|
||||
pMe=pD->pPrivate; assert(pMe);
|
||||
strcpy(pBueffel, " ");
|
||||
strcat(pBueffel, argv[1]);
|
||||
strcat(pBueffel, " ");
|
||||
strtolower(pBueffel);
|
||||
if ( NULL==strstr(" log send list tolerance access errorhandler interrupt interest ", pBueffel)
|
||||
&& NULL==strstr(" upperlimit lowerlimit safevalue currentvalue targetvalue ", pBueffel)
|
||||
) {
|
||||
|
||||
pD=self->pDriv; assert(pD);
|
||||
pMe=pD->pPrivate; assert(pMe);
|
||||
if(argc > 2) { /* set case */
|
||||
iRet=CocSet(pMe->pData,argv[1],argv[2]);
|
||||
if (iRet<0) {
|
||||
sprintf(pBueffel,"ERROR: %s",ErrMessage);
|
||||
if (0==strcmp(pBueffel," targetvalue ")) {
|
||||
if (argc == 2) {
|
||||
iRet=CocGet(pMe->pData,"set",result); /* get parameter */
|
||||
if (iRet<0) goto Error;
|
||||
self->fTarget = atof(result);
|
||||
}
|
||||
return EVControlWrapper(pCon,pSics,pData,argc,argv);
|
||||
} else if (0==strcmp(pBueffel," list ")) {
|
||||
iRet=CocGet(pMe->pData,"set",result); /* get parameter */
|
||||
if (iRet<0) goto Error;
|
||||
self->fTarget = atof(result);
|
||||
iRet = EVControlWrapper(pCon,pSics,pData,argc,argv);
|
||||
if (iRet != 0) {
|
||||
iRet=CocGet(pMe->pData,"tlimit",result); /* get parameter */
|
||||
if (iRet<0) goto Error;
|
||||
fVal = atof(result);
|
||||
if (fVal != 0 && ObVal(self->pParam,UPLIMIT) > fVal) {
|
||||
sprintf(pBueffel,"WARNING: upper limit is above %g, (limit of the device)", fVal);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
}
|
||||
iRet=CocGet(pMe->pData,"status",result); /* get parameter */
|
||||
if (iRet<0) goto Error;
|
||||
SCWrite(pCon,result,eValue);
|
||||
}
|
||||
return iRet;
|
||||
} else if (0==strcmp(pBueffel," upperlimit ")) {
|
||||
if (argc > 2) {
|
||||
iRet=CocGet(pMe->pData,"tlimit",result); /* get parameter */
|
||||
if (iRet<0) goto Error;
|
||||
fVal=atof(result);
|
||||
if (atof(argv[2]) > fVal) {
|
||||
sprintf(pBueffel,"ERROR: upper limit must not be higher than %g", fVal);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return EVControlWrapper(pCon,pSics,pData,argc,argv);
|
||||
} else if (0==strcmp(pBueffel," lowerlimit ")) {
|
||||
if (argc > 2) {
|
||||
if (atof(argv[2]) > ObVal(self->pParam,UPLIMIT)) {
|
||||
SCWrite(pCon,"ERROR: lower limit must not be higher than upperlimit",eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return EVControlWrapper(pCon,pSics,pData,argc,argv);
|
||||
} else if (NULL!=strstr(
|
||||
" log send tolerance access errorhandler interrupt interest safevalue currentvalue "
|
||||
, pBueffel)) {
|
||||
/* forward to standard handler */
|
||||
return EVControlWrapper(pCon,pSics,pData,argc,argv);
|
||||
}
|
||||
if(argc > 2) { /* set case */
|
||||
iRet=CocSet(pMe->pData,argv[1],argv[2]);
|
||||
if (iRet<0) goto Error;
|
||||
return 1;
|
||||
} else { /* get case (or command without parameter) */
|
||||
if (0==strcasecmp(argv[1], "kill")) {
|
||||
@ -121,20 +164,16 @@
|
||||
} else {
|
||||
iRet=CocGet(pMe->pData,argv[1],result); /* get parameter */
|
||||
}
|
||||
if (iRet<0) {
|
||||
sprintf(pBueffel,"ERROR: %s",ErrMessage);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
if (iRet<0) goto Error;
|
||||
sprintf(pBueffel,"%s.%s = %s\n",self->pName,
|
||||
argv[1],result);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
return EVControlWrapper(pCon,pSics,pData,argc,argv);
|
||||
}
|
||||
/* not reached */
|
||||
Error:
|
||||
sprintf(pBueffel,"ERROR: %s",ErrMessage);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -292,7 +331,9 @@
|
||||
pEVDriver pNew = NULL;
|
||||
pTecsDriv pMe = NULL;
|
||||
pSicsVariable pInst = NULL;
|
||||
char *pPort=NULL;
|
||||
char *pPort=NULL, *pPath=NULL;
|
||||
FILE *fil;
|
||||
char buf[256];
|
||||
|
||||
pNew = CreateEVDriver(argc,argv);
|
||||
pMe = (pTecsDriv)malloc(sizeof(TecsDriv));
|
||||
@ -307,10 +348,24 @@
|
||||
/* initalise pTecsDriver */
|
||||
pMe->lastError = NULL;
|
||||
|
||||
pMe->port=0;
|
||||
pMe->server[0]='\0';
|
||||
|
||||
pPath = IFindOption(pSICSOptions, "TecsInit");
|
||||
if (pPath != NULL) {
|
||||
fil=fopen(pPath, "r");
|
||||
if (fil!=NULL) {
|
||||
pPort=fgets(buf, sizeof(buf), fil);
|
||||
if (pPort != NULL) {
|
||||
pMe->port=atoi(pPort);
|
||||
}
|
||||
fgets(buf, sizeof(buf), fil);
|
||||
fgets(pMe->server, sizeof(pMe->server), fil);
|
||||
}
|
||||
}
|
||||
|
||||
if (pMe->port==0) {
|
||||
/* get the port number for tecs */
|
||||
pMe->port=0;
|
||||
pPort = IFindOption(pSICSOptions, "TecsPort");
|
||||
if (pPort!=NULL) {
|
||||
pMe->port=atoi(pPort);
|
||||
@ -318,6 +373,7 @@
|
||||
if (pMe->port==0) {
|
||||
pMe->port=9753;
|
||||
}
|
||||
}
|
||||
|
||||
/* initialise function pointers */
|
||||
pNew->SetValue = TecsRun;
|
||||
|
Reference in New Issue
Block a user