approved tecs_dlog, added sys_util.c
This commit is contained in:
38
tecs/tecs.c
38
tecs/tecs.c
@@ -5,6 +5,7 @@
|
||||
#include <sys/timeb.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "sys_util.h"
|
||||
#include "err_handling.h"
|
||||
#include "coc_server.h"
|
||||
#include "coc_logfile.h"
|
||||
@@ -16,6 +17,7 @@ int ftime (struct timeb *__timeptr); /* for some reason not defined in timeb.h w
|
||||
|
||||
#define TABLE_FILE "lsci.tab"
|
||||
#define Progress(I) if (configuring) { configuring+=I; }
|
||||
#define undef -65535.
|
||||
|
||||
static SerChannel *ser=NULL;
|
||||
static char *serverId=NULL;
|
||||
@@ -469,7 +471,7 @@ int SetTemp(int switchOn) {
|
||||
tempH=(tempC+tShift)/scale;
|
||||
if (tempC==0) {
|
||||
ERR_P(LscCmd(ser, "CSET 1:[chan],1,1,0;RANGE:0;SETP 1:0"));
|
||||
} else if (remoteMode==1) { /* local mode: do not switch on heater */
|
||||
} else if (remoteMode==1) { /* in local mode: do not switch on heater */
|
||||
ERR_P(LscCmd(ser, "SETP 1:[tempH]"));
|
||||
} else if (switchOn) {
|
||||
ERR_P(LscCmd(ser, "CSET 1:[chan],1,1,0;RANGE:[iRange];SETP 1:[tempH]"));
|
||||
@@ -541,6 +543,7 @@ int PeriodicTask(void) {
|
||||
ERR_P(LscCmd(ser, "DIOST?>cod1,out1;DOUT 3,29;HTR?>htr;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 (noResp) { /* there was no response on an earlier command, or we are initializing */
|
||||
@@ -601,11 +604,21 @@ int PeriodicTask(void) {
|
||||
ERR_I(ReadTemp());
|
||||
|
||||
if (cryo.dirty==0 && samp.dirty==0 && noResp==0 && tim>logTime) {
|
||||
t3[0]=cryo.temp;
|
||||
t3[1]=samp.temp;
|
||||
t3[2]=htr*htr*power*1e-4;
|
||||
if (t3[2]==0.0) t3[2]=1e-20;
|
||||
|
||||
if (cryo.nSens>0) {
|
||||
t3[0]=cryo.temp;
|
||||
} else {
|
||||
t3[0]=undef;
|
||||
}
|
||||
if (samp.nSens>0) {
|
||||
t3[1]=samp.temp;
|
||||
} else {
|
||||
t3[1]=undef;
|
||||
}
|
||||
if (tempC!=0 || htr!=0) {
|
||||
t3[2]=htr*htr*power*1e-4;
|
||||
} else {
|
||||
t3[2]=undef;
|
||||
}
|
||||
time(&putTim);
|
||||
i=3;
|
||||
dlog_put_(&putTim, &i, t3);
|
||||
@@ -616,7 +629,7 @@ int PeriodicTask(void) {
|
||||
d=(tempH-cryo.temp)/cryo.temp-1.0; /* relative difference */
|
||||
w=exp(-d*d*230); /* gaussian */
|
||||
if (w<0.1) tInt=0; /* reset when far from setpoint (more than 10 %) */
|
||||
if (tInt<30000/period) tInt+=w; /* increase integral time until 30 sec. */
|
||||
if (tInt<30000/per) tInt+=w; /* increase integral time until 30 sec. */
|
||||
if (tInt>w) {
|
||||
p=w/tInt;
|
||||
} else {
|
||||
@@ -678,7 +691,12 @@ int PeriodicTask(void) {
|
||||
remoteMode=1;
|
||||
ERR_P(LscCmd(ser, "MODE?>remoteMode"));
|
||||
if (remoteMode==2) { /* user switched to remote mode */
|
||||
ERR_P(LscCmd(ser, "RANGE?>iRange;SETP?1>tempC"));
|
||||
if (controlMode==2) {
|
||||
ERR_P(LscCmd(ser, "RANGE?>iRange"));
|
||||
if (iRange==0) tempC=0;
|
||||
} else {
|
||||
ERR_P(LscCmd(ser, "RANGE?>iRange;SETP?1>tempC"));
|
||||
}
|
||||
setFlag=(iRange>0);
|
||||
}
|
||||
}
|
||||
@@ -981,7 +999,6 @@ int main(int argc, char *argv[])
|
||||
if (port==0) port=9753;
|
||||
if (msecTmo==0) msecTmo=1000;
|
||||
if (logPeriod==0) logPeriod=10;
|
||||
if (logPeriod*1000<period) period=logPeriod*1000;
|
||||
|
||||
str_copy(buf, logDir);
|
||||
str_append(buf, serverId);
|
||||
@@ -1041,6 +1058,7 @@ int main(int argc, char *argv[])
|
||||
CocDefInt(iRange, CocRD);
|
||||
CocDefInt(remoteMode, CocRD);
|
||||
|
||||
CocDefInt(logPeriod, CocWR);
|
||||
CocDefInt(readTemp, CocWR);
|
||||
CocDefInt(controlMode, CocWR);
|
||||
CocDefInt(busy, CocRD);
|
||||
@@ -1057,7 +1075,7 @@ int main(int argc, char *argv[])
|
||||
str_append(dlogfile, serverId);
|
||||
str_append(dlogfile, ".dlog");
|
||||
logfileOut(LOG_INFO, "open data log file: %s\n", dlogfile);
|
||||
dlog_open_write_(dlogfile, 2000); /* max size of 2 MB */
|
||||
dlog_open_write_(dlogfile);
|
||||
logfileWrite(logMask);
|
||||
|
||||
LscCmd(ser, "MODE?>remoteMode");
|
||||
|
||||
Reference in New Issue
Block a user