TecsServer no longer restarted by SICS

This commit is contained in:
cvs
2000-06-07 06:37:13 +00:00
parent b7c9700c51
commit f979f410a4
9 changed files with 69 additions and 68 deletions

View File

@ -1,6 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <signal.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
@ -8,6 +9,11 @@
#include "coc_client.h" #include "coc_client.h"
#include "str_util.h" #include "str_util.h"
/* --- non ANSI signal --- */
#ifndef SIGPIPE
#define SIGPIPE 13
#endif
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
int CocConnect(CocConn *conn) { int CocConnect(CocConn *conn) {
@ -29,11 +35,14 @@ int CocConnect(CocConn *conn) {
int CocOpen(CocConn *conn) int CocOpen(CocConn *conn)
{ {
int i, try, tmo; int i, try, tmo, iret=-1;
ERR_I(i=CocConnect(conn)); ERR_I(i=CocConnect(conn));
if (i==0) return(0); 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); printf("Starting TecsServer ...\n\n%s\n", conn->startcmd);
ERR_I(system(conn->startcmd)); ERR_I(system(conn->startcmd));
@ -50,7 +59,7 @@ int CocOpen(CocConn *conn)
} }
} }
ERR_MSG("can not start TECS, too many retries"); 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) int CocTryCmd(CocConn *conn) {
{ if (conn->fd<0) { int iret=-1;
ERR_I(CocOpen(conn));
signal(SIGPIPE, SIG_IGN);
if (conn->fd<0) {
ERR_I(iret=CocOpen(conn));
iret=-1;
ERR_I(CocSendMagic(conn, conn->magic)); ERR_I(CocSendMagic(conn, conn->magic));
} }
ERR_SI(send(conn->fd, conn->cmdbuf->buf, conn->cmdbuf->wrpos, 0)); ERR_SI(send(conn->fd, conn->cmdbuf->buf, conn->cmdbuf->wrpos, 0));
ERR_I(CocRecv(conn->fd, conn->resbuf)); ERR_I(CocRecv(conn->fd, conn->resbuf));
signal(SIGPIPE, SIG_DFL);
return(0); 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; if (iret>=0) break;
close(conn->fd); close(conn->fd);
conn->fd=-1; conn->fd=-1;
if (ErrCode!=ECONNRESET && ErrCode!=EPIPE) goto OnError; if (iret==-1) goto OnError; /* severe error */
ErrShow("try again, error was"); ErrShort(ErrMessage);
ErrShort("try to reconnect");
} }
ERR_P(err=str_get_str(conn->resbuf, NULL)); ERR_P(err=str_get_str(conn->resbuf, NULL));
if (*err!='\0') { ErrMsg(err); ErrTxt(": (response from server)",0 ); return(-2); } if (*err!='\0') { ErrMsg(err); ErrTxt(": (response from server)",0 ); return(-2); }

View File

@ -76,6 +76,12 @@ void logfileOpen(int first) {
fil=fopen(filnam, "a"); fil=fopen(filnam, "a");
} }
#endif #endif
if (fil==NULL) {
printf("Can not open %s\n", filnam);
fil=stdout;
str_copy(filnam, "<stdout>");
return;
}
ErrSetOutFile(fil); ErrSetOutFile(fil);
if (first) { if (first) {
fprintf(fil, "%04d-%02d-%02d opened logfile\n" fprintf(fil, "%04d-%02d-%02d opened logfile\n"

View File

@ -69,12 +69,12 @@ void ErrShow(char *text)
outrtn(outarg, ""); outrtn(outarg, "");
} }
void ErrShort(void) { void ErrShort(char *msg) {
if (outrtn==NULL) { if (outrtn==NULL) {
outrtn=ErrOutFil; outrtn=ErrOutFil;
outarg=stdout; outarg=stdout;
} }
outrtn(outarg, ErrMessage); outrtn(outarg, msg);
} }
void ErrSetOutRtn(void (*rtn)(), void *arg) { 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) { void err_set_outrtn_(void (*rtn)(), void *arg) {
ErrSetOutRtn(rtn, arg); ErrSetOutRtn(rtn, arg);
} }
void err_short_(void) { void err_short_(void) {
ErrShort(); ErrShort(ErrMessage);
} }

View File

@ -74,9 +74,8 @@ void ErrTxt(char *text, int systemError);
void ErrMsg(char *msg); void ErrMsg(char *msg);
void ErrCod(int code); void ErrCod(int code);
void ErrShow(char *text); /* write out error message with stack info */ 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 ERR_EXIT(char *text);
void ErrLog(char *text);
void ErrSetOutRtn(void (*rtn)(), void *arg); void ErrSetOutRtn(void (*rtn)(), void *arg);
void ErrSetOutFile(FILE *file); void ErrSetOutFile(FILE *file);

View File

@ -70,7 +70,7 @@ int str_npad(char *dest, const char *src, int ldest) {
dest[i]=' '; dest[i]=' ';
} }
} }
return; return(lsrc);
} }
char *str_nsplit(char *dst, const char *src, char sep, int dstlen) { char *str_nsplit(char *dst, const char *src, char sep, int dstlen) {

View File

@ -591,6 +591,9 @@ int ReadTemp(void) {
if (stat==0) logfileOut(LOG_MAIN, "reading o.k. %s\n", sensor->ch); if (stat==0) logfileOut(LOG_MAIN, "reading o.k. %s\n", sensor->ch);
} }
if (stat==0) { 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 */ 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->t1 < sensor->min || sensor->min==0.0) sensor->min = sensor->t1;
if (sensor->t2 > sensor->max) sensor->max = sensor->t2; if (sensor->t2 > sensor->max) sensor->max = sensor->t2;
@ -621,6 +624,7 @@ int SetTemp(int switchOn) {
char *ch; char *ch;
float scale; float scale;
if (tempC>tLimit) tempC=tLimit;
if (switchOn) { if (switchOn) {
ERR_I(ReadTemp()); ERR_I(ReadTemp());
LogMinMax(1); LogMinMax(1);
@ -651,6 +655,7 @@ int SetTemp(int switchOn) {
tShift=-maxShift; tShift=-maxShift;
} }
tempH=(tempC+tShift)/scale; tempH=(tempC+tShift)/scale;
if (tempH>tLimit) tempH=tLimit;
if (tempC==0) { if (tempC==0) {
ERR_P(LscCmd(ser, "CSET 1:[chan],1,1,0;RANGE:0;SETP 1: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 */ } else if (remoteMode==1) { /* in local mode: do not switch on heater */
@ -810,7 +815,8 @@ int PeriodicTask(void) {
logTime=(putTim/logPeriod+1)*logPeriod; logTime=(putTim/logPeriod+1)*logPeriod;
if (tim>mmTime) LogMinMax(0); if (tim>mmTime) LogMinMax(0);
} }
if (sens1.present && sens3.present && controlMode==2 && tempC!=0) { if (tempC!=0) {
if (sens1.present && sens3.present && controlMode==2) {
t=sens1.t; t=sens1.t;
if (sens2.present && tempC<(tLow+tHigh)/2) t=sens2.t; if (sens2.present && tempC<(tLow+tHigh)/2) t=sens2.t;
d=(tempH-t)/t-1.0; /* relative difference */ d=(tempH-t)/t-1.0; /* relative difference */
@ -825,6 +831,9 @@ int PeriodicTask(void) {
} }
tShift=tShift*(1.0-p)+p*(cryo.temp-samp.temp); tShift=tShift*(1.0-p)+p*(cryo.temp-samp.temp);
ERR_I(SetTemp(0)); ERR_I(SetTemp(0));
} else if (remoteMode==2 && sens1.present) {
ERR_I(SetTemp(0));
}
} }
ERR_P(LscCmd(ser, "KEYST?>key;DIOST?>cod2,out2;DOUT 3,30")); ERR_P(LscCmd(ser, "KEYST?>key;DIOST?>cod2,out2;DOUT 3,30"));

View File

@ -187,7 +187,7 @@ c------------------------------------------------------------------------------
subroutine TECS_WRITE_MSG(IOLUN) !! 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 implicit none

View File

@ -70,14 +70,9 @@ subroutine tecs_plot(file)
endif endif
else else
if (.not. zoom) then if (.not. zoom) then
if (window==0) then ! maximal
x1=0
x2=1e20
else
x2=(x1+x2+window)/2 x2=(x1+x2+window)/2
x1=x2-window x1=x2-window
endif endif
endif
ntot=dlog_get(dmax, nset, tbase, x1-window*0.1, x2+window*0.1, undef, xd, yd) ntot=dlog_get(dmax, nset, tbase, x1-window*0.1, x2+window*0.1, undef, xd, yd)
endif endif
if (ntot<0) then if (ntot<0) then
@ -278,6 +273,7 @@ subroutine tecs_plot(file)
lastj=j+1 lastj=j+1
elseif (xd(j)>x2 .or. yd(j,i)<ymin(rl) .or. yd(j,i)>ymax(rl)) then elseif (xd(j)>x2 .or. yd(j,i)<ymin(rl) .or. yd(j,i)>ymax(rl)) then
call pgpage call pgpage
window=x2-x1
goto 1 goto 1
endif endif
enddo enddo

View File

@ -307,7 +307,7 @@
pEVDriver pNew = NULL; pEVDriver pNew = NULL;
pTecsDriv pMe = NULL; pTecsDriv pMe = NULL;
pSicsVariable pInst = NULL; pSicsVariable pInst = NULL;
char *pStart = NULL, *pBin=NULL, *pLog=NULL, *pPort=NULL; char *pPort=NULL;
pNew = CreateEVDriver(argc,argv); pNew = CreateEVDriver(argc,argv);
pMe = (pTecsDriv)malloc(sizeof(TecsDriv)); pMe = (pTecsDriv)malloc(sizeof(TecsDriv));
@ -322,10 +322,7 @@
/* initalise pTecsDriver */ /* initalise pTecsDriver */
pMe->lastError = NULL; pMe->lastError = NULL;
/* get the start server option */ pMe->server[0]='\0';
pStart = IFindOption(pSICSOptions, "TecsStartCmd");
if (pStart==NULL) return(NULL);
str_copy(pMe->server, pStart);
/* get the port number for tecs */ /* get the port number for tecs */
pMe->port=0; pMe->port=0;
@ -334,33 +331,8 @@
pMe->port=atoi(pPort); pMe->port=atoi(pPort);
} }
if (pMe->port==0) { if (pMe->port==0) {
pPort="9753"; pMe->port=9753;
pMe->port=atoi(pPort);
} }
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 */ /* initialise function pointers */
pNew->SetValue = TecsRun; pNew->SetValue = TecsRun;