M.Z.
This commit is contained in:
@ -26,7 +26,7 @@
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
int CocConnect(CocConn *conn) {
|
||||
int CocConnect(CocConn *conn) { /* connect, but do not start */
|
||||
int i;
|
||||
struct sockaddr_in sadr;
|
||||
|
||||
@ -43,15 +43,15 @@ int CocConnect(CocConn *conn) {
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int CocOpen(CocConn *conn)
|
||||
{
|
||||
int i, try, tmo, iret=-1;
|
||||
int CocOpen(CocConn *conn) { /* connect and start, if not succsessful */
|
||||
int i, try, tmo;
|
||||
|
||||
ERR_I(i=CocConnect(conn));
|
||||
if (i==0) return(0);
|
||||
/* connection refused */
|
||||
if (conn->startcmd[0]=='\0') {
|
||||
CocDelay(500);
|
||||
ErrTxt("connect",1); return(-2);
|
||||
ErrTxt("connect",1); return(1);
|
||||
}
|
||||
|
||||
printf("Starting TecsServer ...\n\n%s\n", conn->startcmd);
|
||||
@ -69,12 +69,13 @@ int CocOpen(CocConn *conn)
|
||||
}
|
||||
}
|
||||
ERR_MSG("can not start TECS, too many retries");
|
||||
OnError: return(iret);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
int CocInitClient(CocConn *conn, char *host, int port, char *magic, int bufsize, char *startcmd) {
|
||||
int iret;
|
||||
assert(conn!=NULL);
|
||||
if (bufsize==0) bufsize=1024;
|
||||
StrLink(&conn->cmdbuf, conn->cmdbuf_);
|
||||
@ -84,9 +85,15 @@ int CocInitClient(CocConn *conn, char *host, int port, char *magic, int bufsize,
|
||||
ERR_I(str_copy(conn->magic, magic));
|
||||
ERR_I(str_copy(conn->startcmd, startcmd));
|
||||
conn->fd=-1;
|
||||
ERR_I(CocOpen(conn));
|
||||
ERR_I(CocSendMagic(conn, conn->magic));
|
||||
return(0);
|
||||
ERR_I(iret=CocOpen(conn));
|
||||
if (iret==0) {
|
||||
iret=CocSendMagic(conn, conn->magic);
|
||||
if (iret<0) {
|
||||
CocCloseClient(conn);
|
||||
iret=1;
|
||||
}
|
||||
}
|
||||
return(iret);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
@ -129,10 +136,7 @@ int CocTryCmd(CocConn *conn) {
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
if (conn->fd<0) {
|
||||
/*
|
||||
ERR_I(iret=CocOpen(conn));
|
||||
*/
|
||||
ERR_I(iret=CocConnect(conn));
|
||||
ERR_I(iret=CocConnect(conn)); /* was CocOpen earlier */
|
||||
if (iret == 1) {
|
||||
CocDelay(500);
|
||||
ErrTxt("connect",1); return (-1);
|
||||
@ -467,6 +471,7 @@ int CocShowLog(CocConn *conn, char *loglist, int start, int lines) {
|
||||
void CocCloseClient(CocConn *conn) {
|
||||
assert(conn!=NULL);
|
||||
close(conn->fd);
|
||||
conn->fd=-1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,7 +113,7 @@ void logfileStamp(char *text) {
|
||||
fprintf(fil, "---\t%02d:%02d:%02d\n", stamp / 60, stamp % 60, time % 60, text);
|
||||
}
|
||||
} else {
|
||||
fprintf(fil, "\t%02d:%02d:%02d %s", stamp / 60, stamp % 60, time % 60, text);
|
||||
fprintf(fil, "\t%02d:%02d:%02d%s", stamp / 60, stamp % 60, time % 60, text);
|
||||
}
|
||||
dirty=0;
|
||||
lastStamp=stamp;
|
||||
@ -135,7 +135,11 @@ void logfileOut(int mask, const char *fmt, ...)
|
||||
vsprintf(buf, fmt, ap);
|
||||
assert(buf[statusSize]=='\0'); /* check for overflow */
|
||||
if (buf[0]=='@') {
|
||||
if (buf[1]==' ') {
|
||||
str_ncat(statusBuf, buf+2, statusSize);
|
||||
} else {
|
||||
str_ncat(statusBuf, buf+1, statusSize);
|
||||
}
|
||||
} else {
|
||||
str_ncat(statusBuf, buf, statusSize);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ static Instrument list[]={
|
||||
{ "FOCUS", "lnsa16.psi.ch", 9753, "FOCUS" , 1},
|
||||
{ "TASP", "lnsa12.psi.ch", 9753, "TASP", 1},
|
||||
{ "TASP0", "lnsa09.psi.ch", 9753, NULL , 0},
|
||||
{ "RITA", "lnsa08.psi.ch", 9753, NULL , 0},
|
||||
{ "RITA", "rita2.psi.ch", 9753, NULL , 0},
|
||||
{ "PREP", "lnsa01.psi.ch", 9753, NULL , 0},
|
||||
{ "AREA", "lnsa01.psi.ch", 9751, NULL , 0},
|
||||
{ "TEST", "lnsa15.psi.ch", 9753, "lnslib", 2}
|
||||
|
38
tecs/tecs.c
38
tecs/tecs.c
@ -531,7 +531,7 @@ int PrepInput(char *label) {
|
||||
sensD.alarm=0;
|
||||
}
|
||||
loop=1;
|
||||
resist=25;
|
||||
resist=10;
|
||||
str_copy(heUnits, "%");
|
||||
|
||||
i=sscanf(t, "%12s%n", nam, &l);
|
||||
@ -632,6 +632,8 @@ float WeightedAverage(float tH, float tL, Testpoint *t) {
|
||||
float p,q, tLow, tHigh;
|
||||
SensorT *s1, *s2;
|
||||
|
||||
if (tH==DATA_UNDEF) tH=0.0;
|
||||
if (tL==DATA_UNDEF) tL=0.0;
|
||||
s1=t->sensor1;
|
||||
s2=t->sensor2;
|
||||
tH = tH * s1->scale;
|
||||
@ -653,7 +655,7 @@ float WeightedAverage(float tH, float tL, Testpoint *t) {
|
||||
} else if (tL!=0.0) {
|
||||
return tL ;
|
||||
}
|
||||
return 0.0;
|
||||
return DATA_UNDEF;
|
||||
}
|
||||
|
||||
void LogMinMax(int new) {
|
||||
@ -663,6 +665,7 @@ void LogMinMax(int new) {
|
||||
float tbuf;
|
||||
SensorT *s1, *s2;
|
||||
|
||||
sprintf(buf, "@");
|
||||
if (cryo.sensor1!=NULL) { /* at least one sensor is present */
|
||||
for (i=0; i<2; i++) {
|
||||
tpoint=tpoints[i];
|
||||
@ -681,8 +684,11 @@ void LogMinMax(int new) {
|
||||
s2->max=0;
|
||||
}
|
||||
|
||||
sprintf(buf, "@Tm %.5g _ %.5g", cryo.t1, cryo.t2);
|
||||
if (cryo.sensor1!=samp.sensor1) {
|
||||
if (cryo.t1!=DATA_UNDEF) {
|
||||
sprintf(buf1, " Tm %.5g _ %.5g", cryo.t1, cryo.t2);
|
||||
str_append(buf, buf1);
|
||||
}
|
||||
if (cryo.sensor1!=samp.sensor1 && samp.t1!=DATA_UNDEF) {
|
||||
sprintf(buf1, " Ts %.5g _ %.5g", samp.t1, samp.t2);
|
||||
str_append(buf, buf1);
|
||||
}
|
||||
@ -694,9 +700,7 @@ void LogMinMax(int new) {
|
||||
sprintf(buf1, " Te %.5g", te);
|
||||
str_append(buf, buf1);
|
||||
}
|
||||
} else if (nScan>0) {
|
||||
sprintf(buf, "@");
|
||||
} else {
|
||||
} else if (nScan==0) {
|
||||
return;
|
||||
}
|
||||
for (i=4; i<4+nScan; i++) {
|
||||
@ -857,14 +861,14 @@ int ReadTemp(void) {
|
||||
}
|
||||
|
||||
stat=(s->stat1 & s->stat2) & (255-3); /* ignore "old reading" and "invalid reading", error must be on min & max */
|
||||
if (stat != s->readStat) {
|
||||
s->readStat=stat;
|
||||
if (stat > s->readStat || stat==0 && s->readStat>0) {
|
||||
err=LscReadStat(stat);
|
||||
if (*err=='\0') {
|
||||
logfileOut(LOG_MAIN, "reading o.k. %s\n", s->ch);
|
||||
} else {
|
||||
logfileOut(LOG_MAIN, "%s %s\n", err, s->ch);
|
||||
}
|
||||
s->readStat=stat;
|
||||
}
|
||||
if (stat==0) {
|
||||
|
||||
@ -916,7 +920,7 @@ int ReadTemp(void) {
|
||||
if (samp.sensor1!=cryo.sensor1) {
|
||||
ts=samp.temp;
|
||||
}
|
||||
if (samp.temp==0.0) {
|
||||
if (samp.temp==DATA_UNDEF) {
|
||||
samp.temp=cryo.temp;
|
||||
}
|
||||
} else if (nScan==0) {
|
||||
@ -1112,17 +1116,21 @@ void CalcMaxPower(void) {
|
||||
}
|
||||
|
||||
int SetMaxPower(void) {
|
||||
static float p0;
|
||||
static float p0, pold;
|
||||
float plim;
|
||||
|
||||
if (loop == 1) {
|
||||
ERR_P(LscCmd(ser, "CLIMIT?1>,,,iAmp,iRange"));
|
||||
if (iRange>0) {
|
||||
p0=resist*pow(4.0,iAmp)*pow(10.0,iRange)/6.4e6*powFact;
|
||||
plim=2500/resist;
|
||||
pold=p0;
|
||||
if (pold>plim) pold=plim;
|
||||
}
|
||||
CalcMaxPower();
|
||||
}
|
||||
logfileOut(LOG_MAIN, "maxPower changed from %g to %g\n", p0, maxPower);
|
||||
ERR_P(LscCmd(ser, "CDISP 1:[loop],25000,1;MOUT [loop]:0;CMODE [loop]:1"));
|
||||
logfileOut(LOG_MAIN, "maxPower changed from %g to %g\n", pold, maxPower);
|
||||
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();
|
||||
@ -1133,6 +1141,7 @@ int SetMaxPower(void) {
|
||||
ERR_P(LscCmd(ser, "CLIMIT 2:[fbuf],[slope],0"));
|
||||
}
|
||||
p0=scalPower;
|
||||
pold=maxPower;
|
||||
return 0;
|
||||
OnError: return -1;
|
||||
}
|
||||
@ -2117,6 +2126,7 @@ int LogfileHdl(int mode, void *base, int fd) {
|
||||
str_copy(buf, logDir);
|
||||
str_append(buf, serverId);
|
||||
logfile=logfileInit(buf, logIt, use_stdout, logIt && use_stdout);
|
||||
CocDefStr(logfile, COC_RDONLY);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -2275,7 +2285,6 @@ int main(int argc, char *argv[]) {
|
||||
CocDefStr(intype, RD);
|
||||
CocDefStr(status, RD); CocHdl(StatusHdl);
|
||||
CocDefStr(pid, RD); CocHdl(PidSumHdl);
|
||||
CocDefStr(logfile, RD);
|
||||
CocDefStr(config, RD);
|
||||
|
||||
CocDefInt(cod1, RD);
|
||||
@ -2392,6 +2401,7 @@ int main(int argc, char *argv[]) {
|
||||
str_copy(buf, logDir);
|
||||
str_append(buf, serverId);
|
||||
logfile=logfileInit(buf, logIt, use_stdout, logIt && use_stdout);
|
||||
CocDefStr(logfile, RD);
|
||||
logfileOut(LOG_MAIN ,"\n");
|
||||
logfileWrite(logMask);
|
||||
|
||||
|
@ -54,14 +54,15 @@ char *TecsSet(float temp) {
|
||||
}
|
||||
|
||||
char *TecsInit(char *host, int port) {
|
||||
if (port==0) port=9753;
|
||||
int iret;
|
||||
if (conn!=NULL) TeccClose(conn);
|
||||
NEW(conn, CocConn);
|
||||
if (host==NULL || *host=='\0') {
|
||||
ERR_I(CocInitClient(conn, "", port, rwCode, 0, ""));
|
||||
ERR_I(iret=CocInitClient(conn, "", port, rwCode, 0, ""));
|
||||
} else {
|
||||
ERR_I(CocInitClient(conn, host, port, rdCode, 0, ""));
|
||||
ERR_I(iret=CocInitClient(conn, host, port, rdCode, 0, ""));
|
||||
}
|
||||
if (iret==1) ErrShort("TECS_INIT: can not connect to TecsServer");
|
||||
return NULL;
|
||||
OnError:
|
||||
FREE(conn);
|
||||
|
@ -17,25 +17,30 @@ static char *rwCode="rwacs";
|
||||
static char *rdCode="rdacs";
|
||||
|
||||
pTecsClient TeccInit(char *startcmd, int port) {
|
||||
CocConn *conn;
|
||||
CocConn *conn=NULL;
|
||||
char *code, host[64];
|
||||
int iret;
|
||||
|
||||
NEW(conn, CocConn);
|
||||
code=rwCode;
|
||||
if (startcmd[0]=='#') {
|
||||
gethostname(host, sizeof(host));
|
||||
if (0!=strcmp(startcmd+1, host)) code=rdCode;
|
||||
ERR_I(CocInitClient(conn, startcmd+1, port, code, 0, ""));
|
||||
ERR_I(iret=CocInitClient(conn, startcmd+1, port, code, 0, ""));
|
||||
} else {
|
||||
ERR_I(CocInitClient(conn, "", port, code, 0, startcmd));
|
||||
ERR_I(iret=CocInitClient(conn, "", port, code, 0, startcmd));
|
||||
}
|
||||
if (iret==1) ErrShort("TECS_INIT: can not connect to TecsServer");
|
||||
return((pTecsClient)conn);
|
||||
OnError: return(NULL);
|
||||
OnError:
|
||||
if (conn!=NULL) FREE(conn);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
pTecsClient TeccStart(char *startcmd, char *host, int port) {
|
||||
CocConn *conn;
|
||||
char *code, *cmd, thishost[64];
|
||||
int iret;
|
||||
|
||||
NEW(conn, CocConn);
|
||||
code=rwCode;
|
||||
@ -47,7 +52,8 @@ pTecsClient TeccStart(char *startcmd, char *host, int port) {
|
||||
cmd="";
|
||||
}
|
||||
}
|
||||
ERR_I(CocInitClient(conn, host, port, code, 0, cmd));
|
||||
ERR_I(iret=CocInitClient(conn, host, port, code, 0, cmd));
|
||||
if (iret==1) ErrShort("TECS_INIT: can not connect to TecsServer");
|
||||
return((pTecsClient)conn);
|
||||
OnError: return(NULL);
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
program tecs_client
|
||||
|
||||
real temp
|
||||
character device*32, start*80, line*80, cmd*16, par*80, response*1024
|
||||
character inst*64, host*64, user*1, pcod*1
|
||||
integer i,j,k,iret,l,port
|
||||
integer maxfiles
|
||||
real wait
|
||||
parameter (maxfiles=10)
|
||||
integer nfiles/0/, mfiles/0/, idx, luns(0:maxfiles-1)
|
||||
character cmdpar*128
|
||||
character prompt*32/'tecs>'/
|
||||
integer promptlen/6/
|
||||
@ -82,8 +85,25 @@
|
||||
|
||||
l=0
|
||||
1 if (oneCommand) goto 99
|
||||
if (nfiles .gt. 0) then
|
||||
read(luns(idx), '(q,a)', err=22,end=22) l, line
|
||||
print '(x,2a)', prompt(1:promptlen),line(1:max(1,l))
|
||||
else
|
||||
call sys_rd_line(line, l, prompt(1:promptlen))
|
||||
if (l .lt. 0) goto 99
|
||||
endif
|
||||
if (line(1:1) .eq. '@') then
|
||||
nfiles=nfiles+1
|
||||
idx=mod(nfiles, maxfiles)
|
||||
if (nfiles .gt. mfiles+maxfiles) then ! close files which are too much nested
|
||||
close(luns(idx))
|
||||
mfiles=nfiles-maxfiles
|
||||
else
|
||||
call sys_get_lun(luns(idx))
|
||||
endif
|
||||
open(luns(idx), name=line(2:), status='old', readonly)
|
||||
goto 1
|
||||
endif
|
||||
11 l=l+1
|
||||
line(l:l)=' '
|
||||
cmd=' '
|
||||
@ -230,6 +250,10 @@
|
||||
elseif (cmd .eq. 'watch') then
|
||||
iret=tecs_watch_log(par)
|
||||
if (iret .lt. 0) goto 19
|
||||
elseif (cmd .eq. 'wait') then
|
||||
read(par, *, err=17,end=17) wait
|
||||
call sys_wait(wait*60.0)
|
||||
17 continue
|
||||
else
|
||||
iret=tecs_set_par(cmd, par, 2)
|
||||
if (iret .lt. 0) goto 19
|
||||
@ -245,6 +269,18 @@
|
||||
endif
|
||||
goto 1
|
||||
|
||||
22 continue ! end of file
|
||||
close(luns(idx))
|
||||
call sys_free_lun(luns(idx))
|
||||
nfiles=nfiles-1
|
||||
if (nfiles .lt. mfiles) then
|
||||
print *,'too many files nested'
|
||||
mfiles=0
|
||||
nfiles=0
|
||||
endif
|
||||
idx=mod(nfiles,maxfiles)
|
||||
goto 1
|
||||
|
||||
90 call tecs_write_error(6)
|
||||
92 call exit(40) ! Abort
|
||||
|
||||
|
Reference in New Issue
Block a user