TecsServer no longer restarted by SICS
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
@ -8,6 +9,11 @@
|
||||
#include "coc_client.h"
|
||||
#include "str_util.h"
|
||||
|
||||
/* --- non ANSI signal --- */
|
||||
#ifndef SIGPIPE
|
||||
#define SIGPIPE 13
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
int CocConnect(CocConn *conn) {
|
||||
@ -29,11 +35,14 @@ int CocConnect(CocConn *conn) {
|
||||
|
||||
int CocOpen(CocConn *conn)
|
||||
{
|
||||
int i, try, tmo;
|
||||
int i, try, tmo, iret=-1;
|
||||
|
||||
ERR_I(i=CocConnect(conn));
|
||||
if (i==0) return(0);
|
||||
if (conn->startcmd[0]=='\0') ERR_MSG("TECS is down, can not restart from here");
|
||||
if (conn->startcmd[0]=='\0') {
|
||||
CocDelay(500);
|
||||
ErrTxt("connect",1); return(-2);
|
||||
}
|
||||
|
||||
printf("Starting TecsServer ...\n\n%s\n", conn->startcmd);
|
||||
ERR_I(system(conn->startcmd));
|
||||
@ -50,7 +59,7 @@ int CocOpen(CocConn *conn)
|
||||
}
|
||||
}
|
||||
ERR_MSG("can not start TECS, too many retries");
|
||||
OnError: return(-1);
|
||||
OnError: return(iret);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
@ -104,15 +113,23 @@ int CocCheck(CocConn *conn) {
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
int CocTryCmd(CocConn *conn)
|
||||
{ if (conn->fd<0) {
|
||||
ERR_I(CocOpen(conn));
|
||||
int CocTryCmd(CocConn *conn) {
|
||||
int iret=-1;
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
if (conn->fd<0) {
|
||||
ERR_I(iret=CocOpen(conn));
|
||||
iret=-1;
|
||||
ERR_I(CocSendMagic(conn, conn->magic));
|
||||
}
|
||||
ERR_SI(send(conn->fd, conn->cmdbuf->buf, conn->cmdbuf->wrpos, 0));
|
||||
ERR_I(CocRecv(conn->fd, conn->resbuf));
|
||||
signal(SIGPIPE, SIG_DFL);
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
OnError:
|
||||
signal(SIGPIPE, SIG_DFL);
|
||||
if (ErrCode==ECONNRESET || ErrCode==EPIPE) return(-2);
|
||||
return(iret);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
@ -133,8 +150,9 @@ int CocCmdWithRetry(CocConn *conn) {
|
||||
if (iret>=0) break;
|
||||
close(conn->fd);
|
||||
conn->fd=-1;
|
||||
if (ErrCode!=ECONNRESET && ErrCode!=EPIPE) goto OnError;
|
||||
ErrShow("try again, error was");
|
||||
if (iret==-1) goto OnError; /* severe error */
|
||||
ErrShort(ErrMessage);
|
||||
ErrShort("try to reconnect");
|
||||
}
|
||||
ERR_P(err=str_get_str(conn->resbuf, NULL));
|
||||
if (*err!='\0') { ErrMsg(err); ErrTxt(": (response from server)",0 ); return(-2); }
|
||||
|
@ -76,6 +76,12 @@ void logfileOpen(int first) {
|
||||
fil=fopen(filnam, "a");
|
||||
}
|
||||
#endif
|
||||
if (fil==NULL) {
|
||||
printf("Can not open %s\n", filnam);
|
||||
fil=stdout;
|
||||
str_copy(filnam, "<stdout>");
|
||||
return;
|
||||
}
|
||||
ErrSetOutFile(fil);
|
||||
if (first) {
|
||||
fprintf(fil, "%04d-%02d-%02d opened logfile\n"
|
||||
|
@ -69,12 +69,12 @@ void ErrShow(char *text)
|
||||
outrtn(outarg, "");
|
||||
}
|
||||
|
||||
void ErrShort(void) {
|
||||
void ErrShort(char *msg) {
|
||||
if (outrtn==NULL) {
|
||||
outrtn=ErrOutFil;
|
||||
outarg=stdout;
|
||||
}
|
||||
outrtn(outarg, ErrMessage);
|
||||
outrtn(outarg, msg);
|
||||
}
|
||||
|
||||
void ErrSetOutRtn(void (*rtn)(), void *arg) {
|
||||
@ -125,6 +125,7 @@ void err_msg_(F_CHAR(text), int text_len) {
|
||||
void err_set_outrtn_(void (*rtn)(), void *arg) {
|
||||
ErrSetOutRtn(rtn, arg);
|
||||
}
|
||||
|
||||
void err_short_(void) {
|
||||
ErrShort();
|
||||
ErrShort(ErrMessage);
|
||||
}
|
||||
|
@ -74,9 +74,8 @@ void ErrTxt(char *text, int systemError);
|
||||
void ErrMsg(char *msg);
|
||||
void ErrCod(int code);
|
||||
void ErrShow(char *text); /* write out error message with stack info */
|
||||
void ErrShort(void); /* write out short error message */
|
||||
void ErrShort(char *msg); /* write out short error message */
|
||||
void ERR_EXIT(char *text);
|
||||
void ErrLog(char *text);
|
||||
void ErrSetOutRtn(void (*rtn)(), void *arg);
|
||||
void ErrSetOutFile(FILE *file);
|
||||
|
||||
|
@ -70,7 +70,7 @@ int str_npad(char *dest, const char *src, int ldest) {
|
||||
dest[i]=' ';
|
||||
}
|
||||
}
|
||||
return;
|
||||
return(lsrc);
|
||||
}
|
||||
|
||||
char *str_nsplit(char *dst, const char *src, char sep, int dstlen) {
|
||||
|
37
tecs/tecs.c
37
tecs/tecs.c
@ -591,6 +591,9 @@ 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) {
|
||||
logfileOut(LOG_MAIN, "min/max %s: %f %f\n", sensor->ch, sensor->t1, sensor->t2);
|
||||
}
|
||||
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;
|
||||
@ -621,6 +624,7 @@ int SetTemp(int switchOn) {
|
||||
char *ch;
|
||||
float scale;
|
||||
|
||||
if (tempC>tLimit) tempC=tLimit;
|
||||
if (switchOn) {
|
||||
ERR_I(ReadTemp());
|
||||
LogMinMax(1);
|
||||
@ -651,6 +655,7 @@ int SetTemp(int switchOn) {
|
||||
tShift=-maxShift;
|
||||
}
|
||||
tempH=(tempC+tShift)/scale;
|
||||
if (tempH>tLimit) tempH=tLimit;
|
||||
if (tempC==0) {
|
||||
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 */
|
||||
@ -810,21 +815,25 @@ int PeriodicTask(void) {
|
||||
logTime=(putTim/logPeriod+1)*logPeriod;
|
||||
if (tim>mmTime) LogMinMax(0);
|
||||
}
|
||||
if (sens1.present && sens3.present && controlMode==2 && tempC!=0) {
|
||||
t=sens1.t;
|
||||
if (sens2.present && 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 %) */
|
||||
if (int2<1) int2=1;
|
||||
if (tInt<int2*1000/per) tInt+=w; /* increase integral time until int2 sec. */
|
||||
if (tInt>w) {
|
||||
p=w/tInt;
|
||||
} else {
|
||||
p=1.0;
|
||||
if (tempC!=0) {
|
||||
if (sens1.present && sens3.present && controlMode==2) {
|
||||
t=sens1.t;
|
||||
if (sens2.present && 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 %) */
|
||||
if (int2<1) int2=1;
|
||||
if (tInt<int2*1000/per) tInt+=w; /* increase integral time until int2 sec. */
|
||||
if (tInt>w) {
|
||||
p=w/tInt;
|
||||
} else {
|
||||
p=1.0;
|
||||
}
|
||||
tShift=tShift*(1.0-p)+p*(cryo.temp-samp.temp);
|
||||
ERR_I(SetTemp(0));
|
||||
} else if (remoteMode==2 && sens1.present) {
|
||||
ERR_I(SetTemp(0));
|
||||
}
|
||||
tShift=tShift*(1.0-p)+p*(cryo.temp-samp.temp);
|
||||
ERR_I(SetTemp(0));
|
||||
}
|
||||
|
||||
ERR_P(LscCmd(ser, "KEYST?>key;DIOST?>cod2,out2;DOUT 3,30"));
|
||||
|
@ -187,7 +187,7 @@ c------------------------------------------------------------------------------
|
||||
subroutine TECS_WRITE_MSG(IOLUN) !!
|
||||
!! ================================
|
||||
!!
|
||||
!! write out error message of last error and stack info
|
||||
!! write out error message of last error without stack info
|
||||
!!
|
||||
implicit none
|
||||
|
||||
|
@ -70,13 +70,8 @@ subroutine tecs_plot(file)
|
||||
endif
|
||||
else
|
||||
if (.not. zoom) then
|
||||
if (window==0) then ! maximal
|
||||
x1=0
|
||||
x2=1e20
|
||||
else
|
||||
x2=(x1+x2+window)/2
|
||||
x1=x2-window
|
||||
endif
|
||||
x2=(x1+x2+window)/2
|
||||
x1=x2-window
|
||||
endif
|
||||
ntot=dlog_get(dmax, nset, tbase, x1-window*0.1, x2+window*0.1, undef, xd, yd)
|
||||
endif
|
||||
@ -278,6 +273,7 @@ subroutine tecs_plot(file)
|
||||
lastj=j+1
|
||||
elseif (xd(j)>x2 .or. yd(j,i)<ymin(rl) .or. yd(j,i)>ymax(rl)) then
|
||||
call pgpage
|
||||
window=x2-x1
|
||||
goto 1
|
||||
endif
|
||||
enddo
|
||||
|
34
tecsdriv.c
34
tecsdriv.c
@ -307,7 +307,7 @@
|
||||
pEVDriver pNew = NULL;
|
||||
pTecsDriv pMe = NULL;
|
||||
pSicsVariable pInst = NULL;
|
||||
char *pStart = NULL, *pBin=NULL, *pLog=NULL, *pPort=NULL;
|
||||
char *pPort=NULL;
|
||||
|
||||
pNew = CreateEVDriver(argc,argv);
|
||||
pMe = (pTecsDriv)malloc(sizeof(TecsDriv));
|
||||
@ -322,10 +322,7 @@
|
||||
/* initalise pTecsDriver */
|
||||
pMe->lastError = NULL;
|
||||
|
||||
/* get the start server option */
|
||||
pStart = IFindOption(pSICSOptions, "TecsStartCmd");
|
||||
if (pStart==NULL) return(NULL);
|
||||
str_copy(pMe->server, pStart);
|
||||
pMe->server[0]='\0';
|
||||
|
||||
/* get the port number for tecs */
|
||||
pMe->port=0;
|
||||
@ -334,34 +331,9 @@
|
||||
pMe->port=atoi(pPort);
|
||||
}
|
||||
if (pMe->port==0) {
|
||||
pPort="9753";
|
||||
pMe->port=atoi(pPort);
|
||||
pMe->port=9753;
|
||||
}
|
||||
str_append(pMe->server, " -p ");
|
||||
str_append(pMe->server, pPort);
|
||||
|
||||
/* get the instrument name */
|
||||
pInst = FindVariable(pServ->pSics,"instrument");
|
||||
if (pInst==NULL ||
|
||||
pInst->text==NULL ||
|
||||
strlen(pInst->text)>sizeof(pMe->server)-6) return NULL;
|
||||
str_append(pMe->server, " -n tecs_");
|
||||
str_append(pMe->server, pInst->text);
|
||||
|
||||
/* add binDir option if present */
|
||||
pBin = IFindOption(pSICSOptions, "TecsBinDir");
|
||||
if (pBin!=NULL) {
|
||||
str_append(pMe->server, " -b ");
|
||||
str_append(pMe->server, pBin);
|
||||
}
|
||||
/* add logDir option if present */
|
||||
pLog = IFindOption(pSICSOptions, "TecsLogDir");
|
||||
if (pLog!=NULL) {
|
||||
str_append(pMe->server, " -d ");
|
||||
str_append(pMe->server, pLog);
|
||||
}
|
||||
str_append(pMe->server, " &");
|
||||
|
||||
/* initialise function pointers */
|
||||
pNew->SetValue = TecsRun;
|
||||
pNew->GetValue = TecsGet;
|
||||
|
Reference in New Issue
Block a user