revision of TecsServer / treat "interest" correctly

This commit is contained in:
cvs
2000-06-02 07:27:19 +00:00
parent 9c093bc2ac
commit 82097034d5
13 changed files with 309 additions and 182 deletions

View File

@@ -25,8 +25,8 @@ static char *binDir=NULL;
static char *logDir=NULL;
typedef struct {
float t, min, max; /* temperatures */
int sMin, sMax; /* reading status summary */
float t, t1, t2, min, max; /* temperatures */
int stat1, stat2; /* reading status summary */
int present; /* sensor is present */
int readStat; /* reading status */
char ch[2]; /* channels */
@@ -61,8 +61,8 @@ Testpoint /* C standard guarantees initialization to zero */
static float
tempC, /* set T (for sample) */
tempH, /* set T on heat exchanger */
htr, /* heat power percentage */
tLimit, power, /* heater parameters */
htr, /* heater current percentage */
tLimit, maxPower, /* heater parameters */
tLow=0, tHigh=0, /* lower limit of high-T sensor, upper limit of low-T sensor */
tShift=0, /* setpoint shift */
prop, integ, deriv, /* pid */
@@ -74,7 +74,7 @@ static int
period=5000, /* default read interval (msec.) */
logTime, /* next logging time */
setFlag, /* temperature to be set */
powerFlag, /* power to be set */
maxPowerFlag, /* maxPower to be set */
pidFlag, /* pid's to be set */
saveTime, /* time for a CRVSAV command */
noResp=2, /* no response */
@@ -84,6 +84,7 @@ static int
remoteMode, /* 1: local, 2: remote */
maxfld, /* last used display field */
busy, /* busy after CRVSAV */
relay, relay0, /* relay status */
deviceFlag, /* device given via net */
num, /* curve number */
fld, /* field number */
@@ -112,6 +113,8 @@ static char
head[64], /* curve header */
intype[64], /* input configuration */
chan[2], /* actual channel */
alarms[20], /* alarm status */
alarmList[4], /* alarm list */
dlogfile[128];
static char
@@ -364,7 +367,7 @@ int instCurve(char *nam, char *channel, int dispFld) {
int configInput(void) {
char *t;
char buf[80], nam[16], nbuf[256];
char buf[80], nam[16], nbuf[256], ch0[4], ch[4];
int i, n, nn, dispFld;
int retstat;
char *ext;
@@ -390,12 +393,13 @@ int configInput(void) {
t=strchr(buf, '\'');
if (t==NULL) ERR_MSG("missing ' in table file");
t++;
n=1;
if (tpoint==&samp) {
sens3.present=0;
sens4.present=0;
i=sscanf(t, "%12s%d%d", nam, &nn, &n);
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 {
@@ -403,23 +407,46 @@ int configInput(void) {
sens2.present=0;
tLow=0; tHigh=0;
controlMode=0;
i=sscanf(t, "%12s%d%d%d%f%d%f%f%f", nam, &n, &nn, &controlMode, &tLimit, &resist, &power, &tLow, &tHigh);
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'))) {
samp.dirty=1; /* sample and heat exchanger are on main plug */
samp.code=cryo.code;
}
str_copy(ch0, "AB");
ext=".x";
dispFld=1;
}
if (n<0 || n>2) ERR_MSG("illegal value for nsensor");
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;
}
} else if (n>2) {
ERR_MSG("no more than 2 channels per plug allowed");
}
if (n==0) return(0);
nam[strlen(nam)-1]='\0'; /* strip off quote */
if (!tpoint->manual) { /* set device name */
str_copy(tpoint->device, nam);
concatDevice();
}
str_append(nam, ext);
if (ch[0]<'A' || ch[0]>'D') ERR_MSG("illegal channel");
tpoint->sensor1->ch[0]=ch[0];
tpoint->sensor1->ch[1]='\0';
ERR_I(retstat=instCurve(nam, tpoint->sensor1->ch, dispFld));
tpoint->sensor1->present=1;
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;
@@ -468,11 +495,11 @@ int loadCache(void) {
return(-1);
}
float WeightedAverage(int presentH, int presentL, float tH, float tL) {
float WeightedAverage(float tH, float tL) {
float p,q;
if (presentH) {
if (presentL) {
if (tH!=0.0) {
if (tL!=0.0) {
if (tL<tLow) {
return(tL);
} else if (tH<tHigh) {
@@ -483,32 +510,60 @@ float WeightedAverage(int presentH, int presentL, float tH, float tL) {
}
}
return(tH);
} else if (presentL) {
} else if (tL!=0.0) {
return(tL);
}
return(0.0);
}
int LogMinMax(int new) {
char buf[256], bufs[256];
int i, j, l, ls, logIt, stat;
float tol, tmin[2], tmax[2];
void LogMinMax(int new) {
char buf[256];
int i;
SensorT *s1, *s2;
buf[0]='\0';
for (i=0; i<2; i++) {
tpoint=tpoints[i];
s1=tpoint->sensor1;
s2=tpoint->sensor2;
tpoint->tMin = WeightedAverage(s1->min, s2->min) * tpoint->scale;
tpoint->tMax = WeightedAverage(s1->max, s2->max) * tpoint->scale;
s1->min=0;
s1->max=0;
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);
}
logfileOut(LOG_MAIN, "%s\n", buf);
if (new) {
mmInt=60;
} else if (mmInt<600) {
mmInt=mmInt+60;
}
mmTime=tim+mmInt;
}
int ReadTemp(void) {
char buf[256], bufs[256];
int i, l, ls, stat;
readTemp=0;
l=0;
ls=0;
for (i=1; i<=4; i++) {
sensor=sensors[i];
sensor->sMin=0;
sensor->sMax=0;
sensor->stat1=0;
sensor->stat2=0;
if (sensor->present) {
assert(l<128);
sprintf(buf+l, "MDAT?[sens%d.ch]>sens%d.min,sens%d.max;", i, i, i);
sprintf(buf+l, "MDAT?[sens%d.ch]>sens%d.t1,sens%d.t2;", i, i, i);
l=strlen(buf);
assert(ls<128);
sprintf(bufs+ls, "MDATST?[sens%d.ch]>sens%d.sMin,sens%d.sMax;", i, i, i);
sprintf(bufs+ls, "MDATST?[sens%d.ch]>sens%d.stat1,sens%d.stat2;", i, i, i);
ls=strlen(bufs);
}
}
@@ -522,40 +577,42 @@ int LogMinMax(int new) {
/* check for reading errors */
for (i=1; i<=4; i++) {
sensor=sensors[i];
stat=sensor->sMin | sensor->sMax;
if (stat != sensor->readStat) {
sensor->readStat=stat;
if (stat & 1) logfileOut(LOG_MAIN, "invalid reading %s\n", sensor->ch);
if (stat & 2) logfileOut(LOG_MAIN, "old reading %s\n", sensor->ch);
if (stat & 12) logfileOut(LOG_MAIN, "unknown reading status %s\n", sensor->ch);
if (stat & 16) logfileOut(LOG_MAIN, "temp underrange %s\n", sensor->ch);
if (stat & 32) logfileOut(LOG_MAIN, "temp overrange %s\n", sensor->ch);
if (stat & 64) logfileOut(LOG_MAIN, "units zero %s\n", sensor->ch);
if (stat &128) logfileOut(LOG_MAIN, "units overrange %s\n", sensor->ch);
if (stat==0) logfileOut(LOG_MAIN, "reading o.k. %s\n", sensor->ch);
if (sensor->present) {
stat=sensor->stat1 | sensor->stat2;
if (stat != sensor->readStat) {
sensor->readStat=stat;
if (stat & 1) logfileOut(LOG_MAIN, "invalid reading %s\n", sensor->ch);
if (stat & 2) logfileOut(LOG_MAIN, "old reading %s\n", sensor->ch);
if (stat & 12) logfileOut(LOG_MAIN, "unknown reading status %s\n", sensor->ch);
if (stat & 16) logfileOut(LOG_MAIN, "temp underrange %s\n", sensor->ch);
if (stat & 32) logfileOut(LOG_MAIN, "temp overrange %s\n", sensor->ch);
if (stat & 64) logfileOut(LOG_MAIN, "units zero %s\n", sensor->ch);
if (stat &128) logfileOut(LOG_MAIN, "units overrange %s\n", sensor->ch);
if (stat==0) logfileOut(LOG_MAIN, "reading o.k. %s\n", sensor->ch);
}
if (stat==0) {
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;
} else {
sensor->t=0;
}
} else {
sensor->t=0;
}
}
logIt=0;
for (i=0; i<2; i++) {
tpoint=tpoints[i];
s1=tpoint->sensor1;
s2=tpoint->sensor2;
tpoint->tMin = WeightedAverage(s1->present, s2->present, s1->min, s2->min) * tpoint->scale;
tpoint->tMax = WeightedAverage(s1->present, s2->present, s1->max, s2->max) * tpoint->scale;
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;
if (!deviceFlag
&& !samp.dirty && samp.codDefined && !samp.codChanged
&& !cryo.dirty && cryo.codDefined && !cryo.codChanged) {
configuring=0;
} else if (configuring==0 && remoteMode==2) {
str_copy(status, "configuring");
configuring=1;
}
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);
if (new) {
mmInt=60;
} else if (mmInt<600) {
mmInt=mmInt+60;
}
mmTime=tim+mmInt;
return(0);
OnError: return(-1);
}
@@ -565,7 +622,8 @@ int SetTemp(int switchOn) {
float scale;
if (switchOn) {
ERR_I(LogMinMax(1));
ERR_I(ReadTemp());
LogMinMax(1);
logfileOut(LOG_MAIN, "set %.3f\n", tempC);
}
scale=cryo.scale;
@@ -606,67 +664,19 @@ int SetTemp(int switchOn) {
OnError: return(-1);
}
int ReadTemp(void) {
char buf[256];
int i, l;
SensorT *sensor;
readTemp=0;
l=0;
for (i=1; i<=4; i++) {
sensor=sensors[i];
if (sensor->present) {
assert(l<128);
sprintf(buf+l, "KRDG?[sens%d.ch]>sens%d.t;", i, i);
l=strlen(buf);
} else {
sensor->t=0.0;
}
}
if (l>0) {
buf[l-1]='\0'; /* strip off ';' */
ERR_P(LscCmd(ser, buf));
}
cryo.temp=WeightedAverage(sens1.present, sens2.present, sens1.t, sens2.t)*cryo.scale;
samp.temp=WeightedAverage(sens3.present, sens4.present, sens3.t, sens4.t)*samp.scale;
if (samp.temp==0.0) samp.temp=cryo.temp;
if (!deviceFlag
&& !samp.dirty && samp.codDefined && !samp.codChanged
&& !cryo.dirty && cryo.codDefined && !cryo.codChanged) {
configuring=0;
} else if (configuring==0 && remoteMode==2) {
str_copy(status, "configuring");
configuring=1;
}
return(0);
OnError: return(-1);
}
int PeriodicTask(void) {
char buf[256], lbuf[16];
char *next;
char *next, *alms;
int i, k;
time_t putTim;
float t3[3], p, d, w, t;
ERR_P(LscCmd(ser, "DIOST?>cod1,out1;DOUT 3,29;HTR?>htr;HTRST?>htrst;BUSY?>busy"));
ERR_P(LscCmd(ser, "DIOST?>cod1,out1;DOUT 3,29;HTR?>htr;HTRST?>htrst;RELAYST?1>relay;BUSY?>busy"));
if (cryo.codDefined && samp.codDefined) {
per=period; /* no timeout on above command and codes are defined: normal period */
if (per>logPeriod*1000) per=logPeriod*1000;
}
if (htrst!=htrst0) {
ERR_I(LogMinMax(0));
if (htrst<0 || htrst>6) {
sprintf(buf, "heater status %d\n", htrst);
logfileOut(LOG_MAIN, buf);
} else {
logfileOut(LOG_MAIN, heaterStatus[htrst]);
}
htrst0=htrst;
}
if (noResp) { /* there was no response on an earlier command, or we are initializing */
if (!configuring) remoteMode=2;
LscCmd(ser, "MODE:[remoteMode]");
@@ -726,8 +736,50 @@ int PeriodicTask(void) {
noResp=0;
}
if (relay) {
if (alarmList[0]!='\0') {
str_copy(buf, "ALARMST?*");
buf[8]=alarmList[0];
if (alarmList[1]!='\0') {
str_append(buf,";ALARMST?*");
buf[18]=alarmList[1];
}
str_append(buf, ";ALMRST");
ERR_P(alms=LscCmd(ser, buf));
if (0!=strcmp(alarms, alms)) {
str_copy(buf, " ");
if (alms[ 0]!='0' || alms[ 2]!='0') buf[0]=alarmList[0];
if (alms[ 4]!='0' || alms[ 6]!='0') buf[1]=alarmList[1];
if (0==strcmp(buf," ")) {
logfileOut(LOG_MAIN, "No more alarms, but relay is on!\n");
} else {
logfileOut(LOG_MAIN, "Alarm on channel %s\n", buf);
}
str_copy(alarms, alms);
}
} else {
if (!relay0) logfileOut(LOG_MAIN, "Relay is on!\n");
alarms[0]='\0';
}
} else {
if (relay0) logfileOut(LOG_MAIN, "No more alarms, relay is off\n");
alarms[0]='\0';
}
relay0=relay;
ERR_I(ReadTemp());
if (htrst!=htrst0) {
LogMinMax(0);
if (htrst<0 || htrst>6) {
sprintf(buf, "heater status %d\n", htrst);
logfileOut(LOG_MAIN, buf);
} else {
logfileOut(LOG_MAIN, heaterStatus[htrst]);
}
htrst0=htrst;
}
if (tim>=logTime) {
i=0;
if (sens1.present) {
@@ -748,7 +800,7 @@ int PeriodicTask(void) {
}
}
if (tempC!=0 || htr!=0) {
t3[2]=htr*htr*power*1e-4;
t3[2]=htr*htr*maxPower*1e-4;
i=3;
} else {
t3[2]=undef;
@@ -756,7 +808,7 @@ int PeriodicTask(void) {
time(&putTim);
if (i>0) ERR_I(dlog_put_(&putTim, &i, t3));
logTime=(putTim/logPeriod+1)*logPeriod;
if (tim>mmTime) ERR_I(LogMinMax(0));
if (tim>mmTime) LogMinMax(0);
}
if (sens1.present && sens3.present && controlMode==2 && tempC!=0) {
t=sens1.t;
@@ -884,29 +936,29 @@ int inputSettings(Testpoint *this) {
OnError: return(-1);
}
int SetPower(void) {
int SetMaxPower(void) {
int i, j;
float pa, pr, pw, dif;
iAmp=1; iRange=0;
if (power>0) {
pa=resist*4; /* max. power */
if (maxPower>0) {
pa=resist*4; /* max. maxPower */
pw=0; dif=1.0e6;
for (i=4; i>0; i--) {
pr=pa;
for (j=5; j>0; j--) {
if (pr>power) {
if (pr/power<dif) { dif=pr/power; pw=pr; iAmp=i; iRange=j; }
if (pr>maxPower) {
if (pr/maxPower<dif) { dif=pr/maxPower; pw=pr; iAmp=i; iRange=j; }
} else {
if (power/pr<dif) { dif=power/pr; pw=pr; iAmp=i; iRange=j; }
if (maxPower/pr<dif) { dif=maxPower/pr; pw=pr; iAmp=i; iRange=j; }
}
pr=pr/10;
}
pa=pa/4;
}
}
power=pw;
logfileOut(LOG_MAIN, "power %f\n", power, iAmp, iRange);
maxPower=pw;
logfileOut(LOG_MAIN, "maxPower %f\n", maxPower, iAmp, iRange);
ERR_P(LscCmd(ser, "CDISP 1:1,[resist],1;MOUT 1:0;CMODE 1:1"));
ERR_P(LscCmd(ser, "CLIMIT 1:[tLimit],0,0,[iAmp],[iRange]"));
ERR_I(SetTemp(1));
@@ -969,7 +1021,6 @@ int Display(void) {
int Settings(void) {
char nbuf[256], buf[256], *cfg, *p;
char alarms[3];
cfg=NULL;
if (cryo.dirty && cryo.codDefined || samp.dirty && samp.codDefined) {
@@ -979,26 +1030,26 @@ int Settings(void) {
ERR_P(LscCmd(ser, "ALARM A:0;ALARM B:0;ALARM C:0;ALARM D:0"));
alarms[0]='\0';
alarms[1]='\0';
alarms[2]='\0';
alarmList[0]='\0';
alarmList[1]='\0';
alarmList[2]='\0';
if (sens1.present) {
ERR_I(SetPower());
str_copy(buf, "ALARM [sens1.ch]:1,1,[tLimit],0,0,1;RELAY 1:1;BEEP:0");
alarms[0]=sens1.ch[0];
ERR_I(SetMaxPower());
str_copy(buf, "ALARM [sens1.ch]:1,1,[tLimit],0,1,1;RELAY 1:1;BEEP:0");
alarmList[0]=sens1.ch[0];
if (sens3.present) {
str_append(buf, ";ALARM [sens3.ch]:1,1,[tLimit],0,0,1");
alarms[1]=sens3.ch[0];
str_append(buf, ";ALARM [sens3.ch]:1,1,[tLimit],0,1,1");
alarmList[1]=sens3.ch[0];
}
ERR_P(LscCmd(ser, buf));
}
/* switch of unused channels */
buf[0]='\0';
if (NULL==strchr(alarms, 'A')) str_append(buf, ";ALARM A:0");
if (NULL==strchr(alarms, 'B')) str_append(buf, ";ALARM B:0");
if (NULL==strchr(alarms, 'C')) str_append(buf, ";ALARM C:0");
if (NULL==strchr(alarms, 'D')) str_append(buf, ";ALARM D:0");
if (NULL==strchr(alarmList, 'A')) str_append(buf, ";ALARM A:0");
if (NULL==strchr(alarmList, 'B')) str_append(buf, ";ALARM B:0");
if (NULL==strchr(alarmList, 'C')) str_append(buf, ";ALARM C:0");
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 */
ERR_I(Display());
@@ -1033,9 +1084,9 @@ int ExecuteRequest(void) {
if (readTemp) ERR_I(ReadTemp());
if (remoteMode==2) ERR_I(Settings());
if (powerFlag) {
powerFlag=0;
ERR_I(SetPower());
if (maxPowerFlag) {
maxPowerFlag=0;
ERR_I(SetMaxPower());
}
if (pidFlag) {
pidFlag=0;
@@ -1245,15 +1296,15 @@ int main(int argc, char *argv[])
CocDefPtr(sensor, SensorT);
CocFltFld(SensorT, t, CocRD);
CocFltFld(SensorT, min, CocRD);
CocFltFld(SensorT, max, CocRD);
CocFltFld(SensorT, t1, CocRD);
CocFltFld(SensorT, t2, CocRD);
CocIntFld(SensorT, readStat, CocRD);
CocIntFld(SensorT, sMin, CocRD);
CocIntFld(SensorT, sMax, CocRD);
CocIntFld(SensorT, stat1, CocRD);
CocIntFld(SensorT, stat2, CocRD);
CocStrFld(SensorT, ch, CocRD);
CocDefFlt(htr, CocRD);
CocDefFlt(power, powerFlag);
CocDefFlt(maxPower, maxPowerFlag);
CocDefFlt(prop, pidFlag);
CocDefFlt(integ, pidFlag);
CocDefFlt(deriv, pidFlag);
@@ -1294,6 +1345,7 @@ int main(int argc, char *argv[])
CocDefInt(controlMode, CocWR);
CocDefInt(int2, CocWR);
CocDefInt(busy, CocRD);
CocDefInt(relay, CocRD);
CocDefInt(serialNo, CocRD);
CocDefInt(configuring, CocRD);
CocDefInt(quit, CocWR);