Files called from SICServer should now compile under linux

This commit is contained in:
cvs
2000-07-21 13:01:55 +00:00
parent d782d43951
commit 5f5aface14
15 changed files with 401 additions and 115 deletions

View File

@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <assert.h>
#include <sys/timeb.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include "sys_util.h"
@@ -15,7 +16,7 @@
int ftime (struct timeb *__timeptr); /* for some reason not defined in timeb.h with flag -std1 */
#define TABLE_FILE "lsci.tab"
#define TABLE_FILE "tecs.tab"
#define Progress(I) if (configuring) { configuring+=I; }
#define undef -65535.
@@ -25,7 +26,7 @@ static char *binDir=NULL;
static char *logDir=NULL;
typedef struct {
float t, t1, t2, min, max; /* temperatures */
float t, t1, t2, min, max, band; /* temperatures */
int stat1, stat2; /* reading status summary */
int present; /* sensor is present */
int readStat; /* reading status */
@@ -65,6 +66,8 @@ static float
tLimit, maxPower, /* heater parameters */
tLow=0, tHigh=0, /* lower limit of high-T sensor, upper limit of low-T sensor */
tShift=0, /* setpoint shift */
aux, /* auxilliary value, i.e. helium level */
full, /* full value for helium level */
prop, integ, deriv, /* pid */
maxShift=2, /* maximal shift in when controlMode=2 */
tInt=0; /* integral time (sec.) for setpoint shift */
@@ -80,6 +83,7 @@ static int
noResp=2, /* no response */
quit, /* quit server */
controlMode=2, /* 0: control on heater, 1: control on sample, 3: 2nd loop for difference heater-sample */
heliumMode, /* 0: no level meter, 1: constant current, 2: pulsed */
int2=30, /* inegration time for controlMode 2 */
remoteMode, /* 1: local, 2: remote */
maxfld, /* last used display field */
@@ -115,7 +119,10 @@ static char
chan[2], /* actual channel */
alarms[20], /* alarm status */
alarmList[4], /* alarm list */
dlogfile[128];
chanS[4], chanM[4], /* channels in input routine */
helium[80], /* helium level status */
dlogfile[128],
controlChannel[2]="A";
static char
*table=NULL, /* environment devices table */
@@ -217,7 +224,7 @@ int instCurve(char *nam, char *channel, int dispFld) {
points=str_split(intype, t, '\n');
}
if (points==NULL) ERR_MSG("illegal curve file");
if (cache==NULL) { ERR_SP(cache=my_malloc(1,"one")); *cache='\0'; } /* create empty cache if undefined */
if (cache==NULL) { ERR_SP(cache=MALLOC(1)); *cache='\0'; } /* create empty cache if undefined */
start=strchr(cache, '\n'); /* skip permanent data */
if (start==NULL) { start=cache; } else { start++; }
@@ -327,7 +334,7 @@ int instCurve(char *nam, char *channel, int dispFld) {
logfileOut(LOG_MAIN, "curve selected on channel %s\n", chan);
saveTime=tim+30;
}
my_free(crv); crv=NULL;
FREE(crv); crv=NULL;
if (num<=20) return(0); /* standard curve, do not touch cache */
@@ -354,83 +361,95 @@ int instCurve(char *nam, char *channel, int dispFld) {
ERR_SI(fputc('\0', fil));
ERR_SI(fclose(fil));
fil=NULL;
my_free(cache);
FREE(cache);
/* re-read it */
ERR_P(cache=str_read_file(nbuf));
return(0);
OnError:
if (crv!=NULL) my_free(crv);
if (crv!=NULL) FREE(crv);
if (fil!=NULL) fclose(fil);
return(retstat);
}
int configInput(void) {
char *t;
char buf[80], nam[16], nbuf[256], ch0[4], ch[4];
int i, n, nn, dispFld;
char *t, *e;
char buf[80], nam[16], nbuf[256], ch[4];
int i, l, n, nn, dispFld;
int retstat;
char *ext;
Str_Buf sbuf;
retstat=-2; /* errors in following section are severe */
if (tpoint->manual) {
sprintf(buf, "'%s'", tpoint->device);
} else {
sprintf(buf, "%+d ", tpoint->code);
sprintf(buf, "%+d,", tpoint->code);
if (tpoint->code==0) return(0);
}
if (table!=NULL && tim>tableTime+60) { my_free(table); table=NULL; }; /* clear old table */
if (table!=NULL && tim>tableTime+60) { FREE(table); table=NULL; }; /* clear old table */
if (table==NULL) { /* read table */
str_copy(nbuf, binDir);
str_append(nbuf, TABLE_FILE);
ERR_P(table=str_read_file(nbuf));
tableTime=tim;
str_replace_char(table, 9, ' '); /* replace TAB (9) by space in order to find codes terminated by tab */
}
t=strstr(table, buf);
if (t==NULL) ERR_MSG("device not found");
i=sscanf(t, "%79[^\n!]", buf); /* read line */
t=strchr(buf, '\'');
if (t==NULL) ERR_MSG("missing ' in table file");
t++;
e=strchr(t, '\'');
if (e==NULL || e>strchr(t,'\n')) ERR_MSG("missing ' or device name in table file");
t=e+1;
if (tpoint==&samp) {
sens3.present=0;
sens4.present=0;
str_copy(ch, "C");
i=sscanf(t, "%12s %7s %7s", nam, ch0, ch);
if (i<1) ERR_MSG("missing sensor name");
str_copy(ch0, "CD");
ext=".s";
dispFld=2;
} else {
sens1.present=0;
sens2.present=0;
ext=".x";
dispFld=1;
tLow=0; tHigh=0;
controlMode=0;
str_copy(ch, "A");
i=sscanf(t, "%12s %s %s %d %f %d %f %f %f", nam, ch, ch0, &controlMode, &tLimit, &resist, &maxPower, &tLow, &tHigh);
if (i<7) ERR_MSG("missing some sensor parameters");
if (!samp.manual && (NULL!=strchr(ch0,'A') || NULL!=strchr(ch0,'B'))) {
heliumMode=0;
}
chanS[0]='\0';
chanM[0]='\0';
i=sscanf(t, "%12s%n", nam, &l);
if (i<1) ERR_MSG("missing device name");
t+=l;
/* interprete settings until '+' appeares */
i=sscanf(t, "%64s%n", buf, &l);
while (i>0 && buf[0]!='+') {
t+=l;
e=strchr(buf,'=');
if (e==NULL) ERR_MSG("syntax error");
*e='\0';
str_link_buf(&sbuf, e+1, 0, ',');
ERR_I(CocGetVar(serverVarList, &sbuf, buf, 0));
i=sscanf(t, "%64s%n", buf, &l);
}
if (tpoint==&samp) {
str_copy(ch, chanS);
} else {
if (!samp.manual && (NULL!=strchr(chanS,'A') || NULL!=strchr(chanS,'B'))) {
samp.dirty=1; /* sample and heat exchanger are on main plug */
samp.code=cryo.code;
}
str_copy(ch0, "AB");
ext=".x";
dispFld=1;
}
n=strlen(ch);
if (n==1) {
if (ch[0]=='0') {
n=0;
} else if (ch[0]=='1') {
ch[0]=ch0[0];
} else if (ch[0]=='2') {
str_copy(ch, ch0); n=2;
str_copy(ch, chanM);
if (heliumMode==0) {
sprintf(helium, "no He-level meter for '%s", nam);
} else {
sprintf(helium, "He-level meter not yet read", nam);
}
} else if (n>2) {
ERR_MSG("no more than 2 channels per plug allowed");
}
n=strlen(ch);
if (n==0) return(0);
if (n>2) ERR_MSG("no more than 2 channels per plug allowed");
nam[strlen(nam)-1]='\0'; /* strip off quote */
if (!tpoint->manual) { /* set device name */
@@ -443,13 +462,28 @@ int configInput(void) {
tpoint->sensor1->ch[1]='\0';
ERR_I(retstat=instCurve(nam, tpoint->sensor1->ch, dispFld));
tpoint->sensor1->present=1;
tpoint->sensor1->band=10;
if (n==2) {
if (ch[1]<'A' || ch[1]>'D') ERR_MSG("illegal channel");
tpoint->sensor2->ch[0]=ch[1];
tpoint->sensor2->ch[1]='\0';
str_append(nam, "l");
ERR_I(retstat=instCurve(nam, tpoint->sensor2->ch, dispFld+2));
tpoint->sensor2->present=1;
if (ch[1]>='a' && ch[1]<='d') {
tpoint->sensor2->ch[0]=ch[1];
tpoint->sensor2->ch[1]='\0';
str_copy(chan, ch+1);
logfileOut(LOG_MAIN, "auxilliary input on channel %s\n", chan);
if (ch[0]>'b') {
ERR_P(LscCmd(ser, "INTYPE [chan]:0,1,2,1,13;MNMX [chan]:1,3"));
} else {
ERR_P(LscCmd(ser, "INTYPE [chan]:0,1,2,1,12;MNMX [chan]:1,3"));
}
tpoint->sensor2->present=2;
} else {
if (ch[1]<'A' || ch[1]>'D') ERR_MSG("illegal channel");
tpoint->sensor2->ch[0]=ch[1];
tpoint->sensor2->ch[1]='\0';
str_append(nam, "l");
ERR_I(retstat=instCurve(nam, tpoint->sensor2->ch, dispFld+2));
tpoint->sensor2->present=1;
}
tpoint->sensor2->band=10;
}
return(0);
OnError: return(retstat);
@@ -532,12 +566,14 @@ void LogMinMax(int new) {
s2->min=0;
s2->max=0;
}
sprintf(buf, "@%.3f < T < %.3f K", cryo.tMin, cryo.tMax);
if (samp.tMax>0.0) {
sprintf(buf1, " (reg), %.3f < T < %.3f K (samp)", samp.tMin, samp.tMax);
str_append(buf, buf1);
if (cryo.tMax>0.0) {
sprintf(buf, "@%.3f < T < %.3f K", cryo.tMin, cryo.tMax);
if (samp.tMax>0.0) {
sprintf(buf1, " (reg), %.3f < T < %.3f K (samp)", samp.tMin, samp.tMax);
str_append(buf, buf1);
}
logfileOut(LOG_MAIN, "%s\n", buf);
}
logfileOut(LOG_MAIN, "%s\n", buf);
if (new) {
mmInt=60;
} else if (mmInt<600) {
@@ -549,6 +585,7 @@ void LogMinMax(int new) {
int ReadTemp(void) {
char buf[256], bufs[256];
int i, l, ls, stat;
struct tm *tb;
readTemp=0;
@@ -568,17 +605,17 @@ int ReadTemp(void) {
}
}
if (ls>0) {
bufs[ls-1]='\0'; /* strip off ';' */
ERR_P(LscCmd(ser, bufs));
str_append(buf, "MNMXRST");
buf[l-1]='\0'; /* strip off ';' */
ERR_P(LscCmd(ser, buf));
str_append(bufs, "MNMXRST");
ERR_P(LscCmd(ser, bufs));
}
/* check for reading errors */
for (i=1; i<=4; i++) {
sensor=sensors[i];
if (sensor->present) {
stat=sensor->stat1 | sensor->stat2;
stat=(sensor->stat1 | sensor->stat2) & 255;
if (stat != sensor->readStat) {
sensor->readStat=stat;
if (stat & 1) logfileOut(LOG_MAIN, "invalid reading %s\n", sensor->ch);
@@ -591,12 +628,39 @@ int ReadTemp(void) {
if (stat==0) logfileOut(LOG_MAIN, "reading o.k. %s\n", sensor->ch);
}
if (stat==0) {
if (sensor->t1 < 0.8*sensor->t2) {
if (sensor->present==2 && heliumMode==2) {
sensor->t = sensor->t1; /* take minimum only */
} else if (sensor->t2 - sensor->t1 <= sensor->band*2) { /* normal case */
sensor->t = (sensor->t1 + sensor->t2) * 0.5; /* mean of min and max */
sensor->band = sensor->band/2;
} else { /* probably noisy values */
logfileOut(LOG_MAIN, "min/max %s: %f %f\n", sensor->ch, sensor->t1, sensor->t2);
if (fabs(sensor->t1 - sensor->t) < fabs(sensor->t2 - sensor->t) ) {
sensor->t=sensor->t1;
sensor->t2 = sensor->t1;
} else {
sensor->t=sensor->t2;
sensor->t1 = sensor->t1;
}
sensor->t1 = sensor->t;
sensor->t2 = sensor->t;
}
if (sensor->present==2) {
aux=sensor->t; sensor->t=0;
if (full>0 && heliumMode>0) {
tb=localtime(&tim);
if (aux<full && aux>0) {
sprintf(helium, "%5.1f %% (%02d.%02d., %02d:%02d)", 100.0*aux/full
, tb->tm_mday, tb->tm_mon+1, tb->tm_hour, tb->tm_min);
}
}
}
sensor->t = (sensor->t1 + sensor->t2) * 0.5; /* mean of min and max */
if (sensor->t1 < sensor->min || sensor->min==0.0) sensor->min = sensor->t1;
if (sensor->t2 > sensor->max) sensor->max = sensor->t2;
if (sensor->max - sensor->min > sensor->band) {
sensor->band = sensor->max - sensor->min;
}
} else {
sensor->t=0;
}
@@ -604,7 +668,7 @@ int ReadTemp(void) {
sensor->t=0;
}
}
cryo.temp=WeightedAverage(sens1.t, sens2.t)*cryo.scale;
samp.temp=WeightedAverage(sens3.t, sens4.t)*samp.scale;
if (samp.temp==0.0) samp.temp=cryo.temp;
@@ -624,20 +688,22 @@ int SetTemp(int switchOn) {
char *ch;
float scale;
if (tempC>tLimit) tempC=tLimit;
if (tempC>tLimit) {
tempC=tLimit;
logfileOut(LOG_MAIN, "set point too high, reset to %f\n", tempC);
}
if (switchOn) {
ERR_I(ReadTemp());
LogMinMax(1);
logfileOut(LOG_MAIN, "set %.3f\n", tempC);
}
scale=cryo.scale;
ch=sens1.ch;
if (sens2.present && tempC<(tLow+tHigh)/2) ch=sens2.ch;
if (sens2.present==1 && tempC<(tLow+tHigh)/2) ch=sens2.ch;
if (sens3.present) {
if (controlMode==1) { /* control directly on sample sensor */
tShift=0;
ch=sens3.ch;
if (sens2.present && tempC<(tLow+tHigh)/2) ch=sens4.ch;
if (sens3.t!=0) ch=sens3.ch;
if (sens4.present==1 && tempC<(tLow+tHigh)/2 && sens4.t!=0) ch=sens4.ch;
scale=samp.scale;
} else if (controlMode!=2) {
tShift=0;
@@ -660,11 +726,16 @@ int SetTemp(int switchOn) {
ERR_P(LscCmd(ser, "CSET 1:[chan],1,1,0;RANGE:0;SETP 1:0"));
} else if (remoteMode==1) { /* in local mode: do not switch on heater */
ERR_P(LscCmd(ser, "SETP 1:[tempH]"));
ch=controlChannel;
} else if (switchOn || (htrst>=5 && relay==0)) { /* switch on also when bad heater message and no alarms */
ERR_P(LscCmd(ser, "CSET 1:[chan],1,1,0;RANGE:[iRange];SETP 1:[tempH]"));
} else {
ERR_P(LscCmd(ser, "CSET 1:[chan],1;SETP 1:[tempH]"));
}
if (0!=strcmp(ch, controlChannel) || switchOn) {
str_copy(controlChannel, ch);
logfileOut(LOG_MAIN, "set %f (on %s)\n", tempC, ch);
}
return(0);
OnError: return(-1);
}
@@ -690,12 +761,12 @@ int PeriodicTask(void) {
if (0!=strcmp(buf1, "LSCI") || 0!=strcmp(buf2, "MODEL340") || serialNo==0) return(0);
if (k!=serialNo) { /* controller exchanged or we are initializing */
if (!configuring) {
str_copy(status, "controller connected");
logfileOut(LOG_MAIN, "controller connected\n");
}
if (remoteMode==2) configuring++;
tempC=0;
/* reload curve cache: */
if (cache!=NULL) my_free(cache);
if (cache!=NULL) FREE(cache);
sprintf(lbuf, "lsc.%d", serialNo);
str_copy(buf, logDir);
str_append(buf, lbuf);
@@ -797,7 +868,7 @@ int PeriodicTask(void) {
t3[1]=samp.temp;
i=2;
} else {
if (sens2.present) {
if (sens2.present==1) {
t3[1]=sens2.t;
i=2;
} else {
@@ -818,7 +889,7 @@ int PeriodicTask(void) {
if (tempC!=0) {
if (sens1.present && sens3.present && controlMode==2) {
t=sens1.t;
if (sens2.present && tempC<(tLow+tHigh)/2) t=sens2.t;
if (sens2.present==1 && tempC<(tLow+tHigh)/2) t=sens2.t;
d=(tempH-t)/t-1.0; /* relative difference */
w=exp(-d*d*230); /* gaussian */
if (w<0.1) tInt=0; /* reset when far from setpoint (more than 10 %) */
@@ -861,12 +932,12 @@ int PeriodicTask(void) {
if (tpoint->codChanged) { /* code change confirmed */
tpoint->codChanged=0;
Progress(1);
tpoint->manual=0;
if (tpoint->code1==0) {
logfileOut(LOG_MAIN, "%s unplugged\n", tpoint->tname);
} else {
logfileOut(LOG_MAIN, "plugged %d on %s\n", tpoint->code1, tpoint->tname);
}
tpoint->manual=0;
tempC=0;
remoteMode=2; /* set to remote mode */
LscCmd(ser, "MODE:[remoteMode]");
@@ -893,7 +964,11 @@ int PeriodicTask(void) {
ERR_P(LscCmd(ser, "RANGE?>iRange"));
if (iRange==0) tempC=0;
} else {
ERR_P(LscCmd(ser, "RANGE?>iRange;SETP?1>tempC"));
ERR_P(LscCmd(ser, "RANGE?>iRange;CSET?1>,cod1,;SETP?1>tempC"));
if (cod1!=1) {
tempC=0;
logfileOut(LOG_MAIN, "set point was not in K, set to 0\n");
}
}
setFlag=(iRange>0);
}
@@ -921,6 +996,9 @@ int inputSettings(Testpoint *this) {
} else {
if (tpoint->code==0) {
logfileOut(LOG_MAIN ,"reset %s inputs\n", tpoint->tname);
if (cryo.code==0 && samp.code==0) {
logfileOut(LOG_MAIN, "no more sensor connected\n");
}
} else {
logfileOut(LOG_MAIN ,"configure %s inputs for code %+d\n", tpoint->tname, tpoint->code);
}
@@ -988,7 +1066,7 @@ int Display(void) {
s=sensors[i];
if (s->present) {
flds[k]=s->ch[0];
fmt[k]='1';
if (s->present==1) { fmt[k]='1'; } else { fmt[k]='3'; } /* special value */
if (k>maxfld) maxfld=k;
} else {
flds[k]='\0';
@@ -1075,7 +1153,7 @@ int Settings(void) {
p=str_split(buf, p, '\n');
ERR_P(LscCmd(ser, buf));
}
my_free(cfg);
FREE(cfg);
} else {
cryo.scale=1;
samp.scale=1;
@@ -1085,7 +1163,7 @@ int Settings(void) {
}
return(0);
OnError:
if (cfg!=NULL) my_free(cfg);
if (cfg!=NULL) FREE(cfg);
return(-1);
}
@@ -1322,7 +1400,11 @@ int main(int argc, char *argv[])
CocDefFlt(deriv, pidFlag);
CocDefFlt(tempC, setFlag);
CocDefFlt(tempH, CocRD);
CocDefFlt(aux, CocRD);
CocDefFlt(full, CocWR);
CocDefFlt(tLimit, CocRD);
CocDefFlt(tLow, CocRD);
CocDefFlt(tHigh, CocRD);
CocDefFlt(maxShift, CocWR);
CocDefStr(device, deviceFlag);
@@ -1333,6 +1415,9 @@ int main(int argc, char *argv[])
CocDefStr(buf4, CocRD);
CocDefStr(head, CocRD);
CocDefStr(chan, CocRD);
CocDefStr(chanS, CocRD);
CocDefStr(chanM, CocRD);
CocDefStr(helium, CocRD);
CocDefStr(intype, CocRD);
CocDefStr(status, CocRD);
CocDefStr(dlogfile, CocRD);
@@ -1350,6 +1435,7 @@ int main(int argc, char *argv[])
CocDefInt(iAmp, CocRD);
CocDefInt(iRange, CocRD);
CocDefInt(remoteMode, CocRD);
CocDefInt(heliumMode, CocRD);
CocDefInt(htrst, CocRD);
CocDefInt(logPeriod, CocWR);