- bug fix in coc_server.c

- bug fixes in tecs
- new system to determine host:port in six and tecs_client
This commit is contained in:
zolliker
2005-09-21 11:06:23 +00:00
parent 66d9d45dae
commit c7280ec25d
16 changed files with 328 additions and 309 deletions

View File

@ -103,6 +103,9 @@ int CocInitClient(CocConn *conn, char *host, int port, char *magic, int bufsize,
int CocSendMagic(CocConn *conn, char *magic) { int CocSendMagic(CocConn *conn, char *magic) {
char *err; char *err;
if (magic != conn->magic) {
str_copy(conn->magic, magic);
}
StrClear(&conn->resbuf); /* use return buffer for command in order to preserve command buffer */ StrClear(&conn->resbuf); /* use return buffer for command in order to preserve command buffer */
ERR_I(StrPut(&conn->resbuf, "", COC_MAGIC)); ERR_I(StrPut(&conn->resbuf, "", COC_MAGIC));
ERR_I(StrPut(&conn->resbuf, magic, COC_SEP)); ERR_I(StrPut(&conn->resbuf, magic, COC_SEP));

View File

@ -387,7 +387,7 @@ int CocPushThisHandler(CocVar *var, CocClient *cl, void *base, int mode) {
var->pending=1; var->pending=1;
} }
n=cl->npend; n=cl->npend;
if (n>=sizeof(cl->pend)) { if (n * sizeof(Pend) >= sizeof(cl->pend)) {
ERR_MSG("too many commands") ERR_MSG("too many commands")
} }
cl->pend[n].var=var; cl->pend[n].var=var;

View File

@ -11,9 +11,10 @@ linux=/afs/psi.ch/project/sinq/linux/stow/tecs/bin/ \
amor@amor:tecs/ focus@focus:tecs/ trics@trics:tecs/ \ amor@amor:tecs/ focus@focus:tecs/ trics@trics:tecs/ \
tasp@tasp:tecs/ dmc@dmc:tecs/ hrpt@hrpt:tecs/ \ tasp@tasp:tecs/ dmc@dmc:tecs/ hrpt@hrpt:tecs/ \
morpheus@morpheus:tecs/ sans@sans:tecs/ sans2@sans2:tecs/ \ morpheus@morpheus:tecs/ sans@sans:tecs/ sans2@sans2:tecs/ \
l_samenv@lnsl15:tecs/ \
type@darwin \ type@darwin \
macosx=/afs/psi.ch/project/sinq/mac_os/stow/tecs/bin/ \ macosx=/afs/psi.ch/project/sinq/mac_os/stow/tecs/bin/ \
admin@ldmprep1:bin/ admin@ldmprep2:bin/ \ prep1=admin@ldmprep1:bin/ prep2=admin@ldmprep2:bin/ \
) )
set dests="" set dests=""

View File

@ -1,97 +1,146 @@
#include <time.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "myc_str.h" #include "instr_hosts.h"
#include "myc_fortran.h"
typedef struct { char *instr; char *host; int port; char *user; int cod; } Instrument; static char *getItem(char *line, char *name, char *value, int value_len) {
static Instrument list[]={ char find[32];
{ "DMC", "pc4629.psi.ch", 9753, "dmc" , 1}, char *found, *sp, *result;
{ "MORPHEUS", "pc4120.psi.ch", 9753, "morpheus" , 1}, int l;
{ "SANS", "pc4122.psi.ch", 9753, "sans" , 1},
{ "SANS2", "sans2.psi.ch", 9753, "sans2" , 1}, snprintf(find, sizeof find, "%s=%s", name, value);
{ "HRPT", "pc4630.psi.ch", 9753, "hrpt" , 1}, found = strstr(line, find);
{ "TRICS", "trics.psi.ch", 9753, "trics" , 1}, if (found && *value != '\0' && found[strlen(find)] > ' ') {
{ "AMOR", "amor.psi.ch", 9753, "amor" , 1}, /* when value is given, it must be complete */
{ "FOCUS", "focus.psi.ch", 9753, "focus" , 1}, found = NULL;
{ "TASP", "pc4478.psi.ch", 9753, "tasp", 1},
{ "RITA", "pc4345.psi.ch", 9753, NULL , 0},
{ "PREP", "lns1se.psi.ch", 9753, "admin" , 0},
{ "AREA", "lns1se.psi.ch", 9751, "admin" , 0},
{ "PREP1", "lnsl15.psi.ch", 9753, "l_samenv", 0},
{ "PREP2", "lnsl15.psi.ch", 9754, "l_samenv", 0},
{ "PREP3", "lnsl15.psi.ch", 9755, "l_samenv", 0},
{ "PREP4", "lnsl15.psi.ch", 9756, "l_samenv", 0},
{ "TEST", "lnsa15.psi.ch", 9755, "lnslib", 2}
};
int InstrHost(char *input, char *instr, char *host, char *user, char *pcod
, int instr_len, int host_len, int user_len, int pcod_len) {
char buf[256], *lnscode;
int i, j;
struct tm tim;
time_t t;
j=-1;
str_upcase(buf, input);
for (i = 0; i < sizeof(list) / sizeof(list[0]); i++) {
if (0==strcmp(buf, list[i].instr)) {
j=i;
}
} }
if (j<0) { if (found) {
str_lowcase(buf, input); found += strlen(name)+1;
for (i = 0; i < sizeof(list) / sizeof(list[0]); i++) { if (value_len == 0) {
if (list[i].host==strstr(list[i].host, buf)) { result = found;
if (j>=0) return 0;
j=i;
}
}
}
if (j<0) return 0;
str_ncpy(instr,list[j].instr, instr_len);
str_ncpy(host, list[j].host, host_len);
if (list[j].user != NULL) {
str_ncpy(user, list[j].user, user_len);
if (list[j].cod == 1) {
str_ncpy(pcod, instr, pcod_len);
str_ncat(pcod, "LNS", pcod_len);
} else if (list[j].cod == 2) {
time(&t);
tim=*localtime(&t);
lnscode=getenv("LNSCODE");
if (lnscode == NULL) {
sprintf(pcod, "%02dlns%d", tim.tm_year % 100, tim.tm_mon/6+1);
} else if (strlen(lnscode)==3) {
sprintf(pcod, "%c%clns%c", lnscode[0], lnscode[1], lnscode[2]);
} else {
sprintf(pcod, "%02dlns%s", tim.tm_year % 100, lnscode);
}
} else { } else {
str_ncpy(pcod, " ", pcod_len); sp = strchr(found, ' ');
if (sp && sp < found + value_len) {
l = sp - found;
} else {
l = strlen(found);
}
if (l < value_len) {
strncpy(value, found, l);
value[l] = '\0';
result = value;
} else {
value[0] = '\0';
result = NULL;
}
}
} else {
if (value_len > 0) {
*value = '\0';
}
result = NULL;
}
return result;
}
int InstrHost(char *service, char *input, char *instr, int instr_len,
char *host, int host_len, int *port) {
int i;
FILE *fil, *lfil;
char *hostlist;
char localhostlist[512];
char line[512], lline[512], hostport[64];
char *found, *colon, *crit;
int dirty, home, finished;
home = 0;
hostlist = getenv("InstrumentHostList");
if (!hostlist) {
hostlist="/afs/psi.ch/project/sinq/common/lib/sea/hostlist";
}
fil = fopen(hostlist, "r");
snprintf(localhostlist, sizeof localhostlist, "%s/.six/hostlist", getenv("HOME"));
lfil = fopen(localhostlist, "r");
dirty = 0;
if (fil) {
if (!lfil) dirty = 1;
} else {
if (!lfil) return 0;
fil = lfil;
lfil = NULL;
}
*port = 0;
if (input == NULL || input[0] <= ' ') {
crit = "host";
input = getenv("HOST");
} else {
crit="instr";
}
finished = 0;
while (NULL != fgets(line, sizeof line, fil)) {
if (!dirty && lfil
&& (fgets(lline, sizeof lline, lfil) == NULL
|| strcmp(line, lline) != 0)) {
dirty = 1;
}
if (!finished && getItem(line, crit, input, 0) != NULL) {
hostport[0]='\0';
found = getItem(line, service, hostport, sizeof hostport);
if (found) {
instr[0] = '\0';
getItem(line, "instr", instr, instr_len);
colon = strchr(hostport, ':');
if (colon) {
i = atoi(colon+1);
if (i > 0) {
*colon='\0';
snprintf(host, host_len, "%s", hostport);
finished = 1;
*port = i;
if (getItem(line, "host", getenv("HOST"), 0) != NULL) {
home = 1;
}
}
}
}
} }
} }
return list[j].port; if (fil) fclose(fil);
if (lfil) fclose(lfil);
if (dirty) {
fil = fopen(hostlist, "r");
if (fil) {
lfil = fopen(localhostlist, "w");
if (lfil) {
while( EOF != (i = getc(fil)) ) { /* copy file to local file */
putc(i, lfil);
}
fclose(lfil);
}
fclose(fil);
}
}
return home;
} }
#ifdef F_CHAR #ifdef MYC_FORTRAN
/* compile only when fortran c interface stuff is defined */ /* compile only when fortran c interface stuff is defined */
int F_FUN(instr_host)(F_CHAR(input), F_CHAR(instr), F_CHAR(host), F_CHAR(user), F_CHAR(pcod) #include "myc_fortran.h"
, int input_len, int instr_len, int host_len, int user_len, int pcod_len) {
char buf[256], in[256], ho[256], us[256], pc[256]; int F_FUN(instr_host)(F_CHAR(service), F_CHAR(input), F_CHAR(instr), F_CHAR(host), int *port
, int service_len, int input_len, int instr_len, int host_len) {
char buf[256], in[256], ho[256], sv[256];
int iRet; int iRet;
STR_TO_C(sv, service);
STR_TO_C(buf, input); STR_TO_C(buf, input);
iRet=InstrHost(buf, in, ho, us, pc, sizeof(in), sizeof(ho), sizeof(us), sizeof(pc)); iRet=InstrHost(sv, buf, in, sizeof(in), ho, sizeof(ho), port);
if (iRet>0) { if (*port>0) {
STR_TO_F(instr, in); STR_TO_F(instr, in);
STR_TO_F(host, ho); STR_TO_F(host, ho);
STR_TO_F(user, us);
STR_TO_F(pcod, pc);
} }
return iRet; return iRet;
} }

View File

@ -1,11 +1,15 @@
#ifndef _INSTR_HOSTS_H_ #ifndef _INSTR_HOSTS_H_
#define _INSTR_HOSTS_H_ #define _INSTR_HOSTS_H_
int InstrHost(char *input, char *instr, char *host, char *user, char *pcod int InstrHost(char *service, char *input, char *instr, int instr_len,
, int instr_len, int host_len, int user_len, int pcod_len); char *host, int host_len, int *port);
/* service (in) is a service name (tecs, sics, sea)
/* input may be a host of instrument name input (in) may be a host or instrument name
output is: instrument name, host name, user name and pcod (the code needed to enter...) instr (out) is the instrument name
host (out) is the host name
port (out) is the port name
the return value is 1, called from a computer related to the instrument,
0 else
*/ */
#endif /* _INSTR_HOSTS_H_ */ #endif /* _INSTR_HOSTS_H_ */

View File

@ -51,6 +51,9 @@ lsc331: lsc331.o coc_server.o tecs_lsc.o tecs_serial.o coc_logfile.o \
TecsClient: $(TECLI_OBJ) $(FORTIFYOBJ) pg_plus/libpgplus.a TecsClient: $(TECLI_OBJ) $(FORTIFYOBJ) pg_plus/libpgplus.a
$(FC) -o $@ $Q $(PGLIB) $(RDLIB) $(FC) -o $@ $Q $(PGLIB) $(RDLIB)
instr_hosts.o: instr_hosts.c
$(CC) $(CFLAGS) -DMYC_FORTRAN -c $Q
$(HARDSUPLIB): $(HARDSUPLIB):
cd ../hardsup; make $(MFLAGS) libhlib.a cd ../hardsup; make $(MFLAGS) libhlib.a
@ -68,7 +71,7 @@ tecs_serial.o: tecs_serial.c
keep_running: keep_running.c keep_running: keep_running.c
$(CC) $(CFLAGS) -o $@ $Q $(FORTIFYOBJ) $(CC) $(CFLAGS) -o $@ $Q $(FORTIFYOBJ)
six: six.c term.o sys_select.o libtecsl.a six: six.c term.o sys_select.o libtecsl.a instr_hosts.o
$(CC) $(CFLAGS) -o $@ $Q $(FORTIFYOBJ) $(CC) $(CFLAGS) -o $@ $Q $(FORTIFYOBJ)
rexstart: rstart.c myc_str.o myc_err.o instr_hosts.o rexstart: rstart.c myc_str.o myc_err.o instr_hosts.o

View File

@ -9,7 +9,7 @@ include macosx_def
CC = gcc CC = gcc
FC = g77 FC = g77
CFLAGS = -DLINUX -g $(DFORTIFY) CFLAGS = -DLINUX -I.. -I../.. -g $(DFORTIFY)
FFLAGS = -Wimplicit -g FFLAGS = -Wimplicit -g
ARFLAGS = cr ARFLAGS = cr

View File

@ -1,6 +1,7 @@
#ifndef _SYS_UTIL_H_ #ifndef _SYS_UTIL_H_
#define _SYS_UTIL_H_ #define _SYS_UTIL_H_
#include "myc_str.h"
/* /*
fortran interface stuff fortran interface stuff

View File

@ -1,4 +1,4 @@
/* a simple commandline client for SICS and sea /* a simple commandline client for sics and sea
Markus Zolliker Markus Zolliker
Mar. 2003 first version Mar. 2003 first version
@ -13,20 +13,21 @@
#include <netdb.h> #include <netdb.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include "term.h" #include "term.h"
#include "coc_util.h" #include "coc_util.h"
#include "myc_err.h" #include "myc_err.h"
#include "myc_str.h" #include "myc_str.h"
#include "instr_hosts.h"
typedef enum { NORMAL, SPY, CLIENT, NMODE } Mode; typedef enum { NORMAL, SPY, CLIENT, NMODE } Mode;
#define MAXMSG 256 #define MAXMSG 256
static char *clcname="six", *servername="SICS"; static char *clcname="six", *servername="sics";
static int clclen=3; static int clclen=3;
static char *host; static char host[128];
static char instr[32]; static char instr[32];
static char savedHost[128];
static int sock[2]; /* main socket and spy socket */ static int sock[2]; /* main socket and spy socket */
static int level=0; /* undefined level */ static int level=0; /* undefined level */
static int deflevel=0; static int deflevel=0;
@ -98,8 +99,8 @@ void Usage(int cmds_only) {
" -a or a ask always for username/password, forget passwords\n" " -a or a ask always for username/password, forget passwords\n"
" -c or c use background color instead of # and |\n" " -c or c use background color instead of # and |\n"
" -s or s simulation mode (on some instruments)\n" " -s or s simulation mode (on some instruments)\n"
" \"host\" connect to a server on a different host\n" " <host> connect to a server on a different host\n"
" -p \"port\" connect to a server on a different port\n" " -p <port> connect to a server on a different port\n"
" -n do only a minimal login (no check of instrument)\n" " -n do only a minimal login (no check of instrument)\n"
" no option login with default privilege\n" " no option login with default privilege\n"
); );
@ -346,8 +347,7 @@ int setrights(int gotolevel) {
int savepw; int savepw;
if (pw == NULL) pw=pswd; if (pw == NULL) pw=pswd;
str_copy(prefhead, "."); str_copy(prefhead, clcname);
str_append(prefhead, clcname);
str_append(prefhead, "."); str_append(prefhead, ".");
str_append(prefhead, instr); str_append(prefhead, instr);
@ -405,6 +405,7 @@ int setrights(int gotolevel) {
sprintf(buf, "config rights %s %s", us, pw); sprintf(buf, "config rights %s %s", us, pw);
ERR_I(sendCmd(sock[0], buf)); ERR_I(sendCmd(sock[0], buf));
ERR_P(p=readWrite(12000,0,"Acknowledged")); ERR_P(p=readWrite(12000,0,"Acknowledged"));
PutC(".");
if (*p=='\0') { if (*p=='\0') {
if (0==strcmp(us, user1)) { if (0==strcmp(us, user1)) {
user1[0]='\0'; user1[0]='\0';
@ -420,6 +421,7 @@ int setrights(int gotolevel) {
} }
} }
if (ask) { if (ask) {
PutC("\r");
PutC(servername); PutC(servername);
PutC(" username"); PutC(" username");
if (us[0]!='\0') { if (us[0]!='\0') {
@ -472,6 +474,7 @@ int setrights(int gotolevel) {
level=3; level=3;
ERR_I(sendCmd(sock[0], "config list")); ERR_I(sendCmd(sock[0], "config list"));
ERR_P(p=readWrite(12000,1,"UserRights = ")); ERR_P(p=readWrite(12000,1,"UserRights = "));
PutC(".");
if (*p!='\0') { if (*p!='\0') {
level=*p-'0'; level=*p-'0';
} }
@ -512,34 +515,16 @@ int setrights(int gotolevel) {
} }
int SavePrefs(void) { int SavePrefs(void) {
struct hostent *ent;
char prefhead[128], name[128]; char prefhead[128], name[128];
FILE *fil; FILE *fil;
int iret;
char *p;
ERR_SI(gethostname(name, sizeof name)); /* get ip name of this host */ ERR_SI(gethostname(name, sizeof name)); /* get ip name of this host */
str_copy(prefhead, "."); str_copy(prefhead, clcname);
str_append(prefhead, clcname);
str_append(prefhead, "_"); str_append(prefhead, "_");
str_append(prefhead, sim); str_append(prefhead, sim);
str_append(prefhead, name); str_append(prefhead, name);
ERR_SP(ent = gethostbyname(name)); /* get my ip name */
snprintf(name, sizeof name, "%s", ent->h_name);
ERR_SP(fil=term_open_pref(0, prefhead, "w")); ERR_SP(fil=term_open_pref(0, prefhead, "w"));
p = getenv("Instrument");
if (p != NULL) {
ent = gethostbyname(p); /* get ip name of "Instrument" translation */
if (ent !=NULL && strcmp(ent->h_name, name) == 0) { /* we are on an instrument computer */
ent = gethostbyname(instr); /* get host name of server */
iret = (ent != NULL && strcmp(ent->h_name, name) != 0);
strcpy(savedHost, "localhost");
}
}
fprintf(fil, "host %s\n", savedHost);
fprintf(fil, "port %d\n", port);
fprintf(fil, "keys\n"); fprintf(fil, "keys\n");
term_save_keys(fil, PutC); term_save_keys(fil, PutC);
fclose(fil); fclose(fil);
@ -548,46 +533,22 @@ int SavePrefs(void) {
} }
int LoadPrefs(void) { int LoadPrefs(void) {
struct hostent *ent;
char prefhead[128], name[128], line[128]; char prefhead[128], name[128], line[128];
FILE *fil; FILE *fil;
ERR_SI(gethostname(name, sizeof name)); /* get ip name of this host */ ERR_SI(gethostname(name, sizeof name)); /* get ip name of this host */
str_copy(prefhead, "."); str_copy(prefhead, clcname);
str_append(prefhead, clcname);
str_append(prefhead, "_"); str_append(prefhead, "_");
str_append(prefhead, sim); str_append(prefhead, sim);
str_append(prefhead, name); str_append(prefhead, name);
fil=term_open_pref(0, prefhead, "r"); fil=term_open_pref(0, prefhead, "r");
if (fil) { if (fil) {
savedHost[0]='\0';
while (term_fgets(line, sizeof(line), fil)) { while (term_fgets(line, sizeof(line), fil)) {
if (0 == strncmp(line, "host ", 5)) { if (0 == strcmp(line, "keys")) {
snprintf(savedHost, sizeof savedHost, "%s", line+5);
} else if (0 == strncmp(line, "port ", 5)) {
if (port < 0) {
port = atoi(line+5);
}
} else if (0 == strcmp(line, "keys")) {
term_load_keys(fil, PutC); term_load_keys(fil, PutC);
} }
} }
fclose(fil); fclose(fil);
if (host == NULL && savedHost[0] != '\0') {
host = savedHost;
}
}
if (host == NULL) {
strcpy(savedHost, "localhost");
host = savedHost;
} else { /* standardize host name */
ent = gethostbyname(host);
if (ent) {
snprintf(savedHost, sizeof savedHost, "%s", ent->h_name);
host = savedHost;
} else {
savedHost[0]='\0'; /* do not save an unconfirmed host */
}
} }
return 0; return 0;
OnError: return -1; OnError: return -1;
@ -617,21 +578,23 @@ int main (int argc, char *argv[]) {
int iret, pos; int iret, pos;
fd_set mask; fd_set mask;
int i, j, gotolevel, sicslogin; int i, j, gotolevel, sicslogin;
int home;
int savehist = 0; int savehist = 0;
char buf[128], lbuf[16]; char buf[128], lbuf[16];
char stdPrompt[128]="", prompt[256]=""; char stdPrompt[128]="", prompt[256]="";
char *p; char *p;
char *bar; char *bar;
char *pnam[4]={"0", "MANAGER", "user", "spy"}; char *pnam[4]={"0", "MANAGER", "user", "spy"};
char hostArg[128]; char *hostArg;
char *subcmd; char *subcmd;
atexit(term_off); atexit(term_off);
port=-1; port=-1;
home=0;
sicslogin=1; sicslogin=1;
deflevel=0; deflevel=0;
gotolevel=0; gotolevel=0;
host=NULL; hostArg=NULL;
sock[1]=0; /* do not yet connect 2nd connection */ sock[1]=0; /* do not yet connect 2nd connection */
for (i=1; i<argc; i++) { for (i=1; i<argc; i++) {
if (0==strcmp(argv[i], "-s") || 0==strcmp(argv[i], "s")) { if (0==strcmp(argv[i], "-s") || 0==strcmp(argv[i], "s")) {
@ -672,7 +635,7 @@ int main (int argc, char *argv[]) {
PutC("missing host"); PutC("missing host");
UsageNote(); return 0; UsageNote(); return 0;
} }
host = argv[i]; hostArg = argv[i];
} else if (0==strcmp(argv[i], "-p")) { } else if (0==strcmp(argv[i], "-p")) {
i++; i++;
if (i>=argc) { if (i>=argc) {
@ -694,47 +657,55 @@ int main (int argc, char *argv[]) {
PutC("unknown option: "); PutC("unknown option: ");
PutC(argv[i]); PutC(argv[i]);
UsageNote(); return 0; UsageNote(); return 0;
} else if (argv[i][1] == '\0' && isdigit(argv[i][0])) {
port = atoi(argv[i]);
} else { } else {
host = argv[i]; hostArg = argv[i];
} }
} }
} }
if (host) { home = InstrHost(servername, hostArg, instr, sizeof instr
ent = gethostbyname(host); , host, sizeof host, &port);
if (!ent) { ent = gethostbyname(host);
PutC("unknown host: "); if (!ent) {
PutC(host); PutC("unknown host: ");
PutC("\n"); PutC(host);
return 0; PutC("\n");
} return 0;
snprintf(hostArg, sizeof hostArg, "%s", ent->h_name);
host = hostArg;
} }
snprintf(host, sizeof host, "%s", ent->h_name);
LoadPrefs(); LoadPrefs();
PutC( "---------------------------------------------------\n"); PutC( "---------------------------------------------------\n");
if (strcmp(clcname, "six") == 0) { if (strcmp(clcname, "six") == 0) {
PutC("six, a fast SICS commandline client (doc: six help)\n"); PutC("six, a fast sics commandline client (doc: six help)\n");
if (port == -1) { if (port == -1) {
if (*sim == '\0') { if (*sim == '\0') {
port = 2911; port = 2911;
} else { } else {
port = 2927; port = 2927;
} }
} home = 1;
}
} else { } else {
PutC("seacmd, a sea commandline client (doc: seacmd help)\n"); PutC("seacmd, a sea commandline client (doc: seacmd help)\n");
if (port == -1) { if (port == -1) {
port = 22911; port = 8641;
} else if (port > 0 && port < 9) {
port += 8640;
} }
home = 1;
} }
PutC( "---------------------------------------------------\n"); PutC( "---------------------------------------------------\n");
PutC(".");
ERR_I(sock[0]=Connect()); ERR_I(sock[0]=Connect());
PutC(".");
if (sock[0] == 0) return 0; if (sock[0] == 0) return 0;
if (sicslogin) { if (sicslogin) {
ERR_I(sendCmd(sock[0], "Instrument")); ERR_I(sendCmd(sock[0], "Instrument"));
ERR_P(p=readWrite(12000,0,"Instrument = ")); ERR_P(p=readWrite(12000,0,"Instrument = "));
PutC(".");
str_copy(instr, p); str_copy(instr, p);
if (*instr=='\0') { if (*instr=='\0') {
PutC("can not detect instrument\n"); PutC("can not detect instrument\n");
@ -746,7 +717,12 @@ int main (int argc, char *argv[]) {
if (0==strcmp(instr,"SANS-II")) { if (0==strcmp(instr,"SANS-II")) {
str_copy(instr, "SANS2"); str_copy(instr, "SANS2");
} }
if (!home) {
deflevel = 3;
gotolevel = 3;
}
ERR_I(i=setrights(gotolevel)); ERR_I(i=setrights(gotolevel));
PutC(".");
PutC("\rlogged in to "); PutC(servername); PutC(" as "); PutC("\rlogged in to "); PutC(servername); PutC(" as ");
PutC(pnam[level]); PutC(pnam[level]);
PutC(" on "); PutC(" on ");
@ -852,34 +828,19 @@ int main (int argc, char *argv[]) {
PrintCmd(buf, CLIENT); PrintCmd(buf, CLIENT);
PutC("defaults for next calls to "); PutC("defaults for next calls to ");
PutC(clcname); PutC(":\n"); PutC(clcname); PutC(":\n");
ERR_I(i=SavePrefs()); ERR_I(SavePrefs());
if (level == 0) { if (level == 0) {
gotolevel = 3; gotolevel = 3;
} else { } else {
gotolevel = level; gotolevel = level;
} }
PutC(" connect to "); deflevel = gotolevel;
if (i == 1) { ERR_I(setrights(gotolevel));
PutC(getenv("Instrument")); PutC(" login as ");
PutC(" (on "); PutC(us);
PutC(savedHost); PutC(" with ");
PutC(", this default can not be changed)\n"); PutC(pnam[level]);
} else { PutC(" privilege\n");
deflevel = gotolevel;
ERR_I(setrights(gotolevel));
PutC(instr);
PutC(" (");
PutC(savedHost);
if (port != 2911 && port !=2927) {
snprintf(buf, sizeof buf, ":%d", port);
PutC(buf);
}
PutC(")\n login as ");
PutC(us);
PutC(" with ");
PutC(pnam[level]);
PutC(" privilege\n");
}
buf[0]='\0'; buf[0]='\0';
} else { } else {
PrintCmd(buf, CLIENT); PrintCmd(buf, CLIENT);

View File

@ -19,5 +19,6 @@
enddo enddo
if (l .gt. 0) then if (l .gt. 0) then
if (str(1:l) .eq. ' ') l=0 if (str(1:l) .eq. ' ') l=0
if (str(l:l) .eq. ' ') l=l-1
endif endif
end end

View File

@ -18,6 +18,9 @@ void F_FUN(sys_rd_line)(F_CHAR(cmd), int *retlen, F_CHAR(prompt) F_CLEN(cmd) F_C
STR_TO_C(p0, prompt); STR_TO_C(p0, prompt);
str_copy(p, "\n"); str_copy(p, "\n");
str_append(p, p0); str_append(p, p0);
if (strlen(p0) < F_LEN(prompt)) {
str_append(p, " ");
}
if (last_line == NULL) { last_line =malloc(1); last_line[0] = '\0';}; if (last_line == NULL) { last_line =malloc(1); last_line[0] = '\0';};
line_read = readline(p); line_read = readline(p);

View File

@ -1928,63 +1928,59 @@ int PeriodicTask(void) {
ERR_I(ReadHeater(1)); ERR_I(ReadHeater(1));
if (relay || loop !=1) { if (alarmListSize!=0) {
if (alarmListSize!=0) { buf[0]='\0';
buf[0]='\0'; for (k=0;k<alarmListSize;k++) {
str_append(buf,";ALARMST?");
str_append(buf, alarmList[k]);
}
ERR_P(alms=LscCmd(ser, buf+1)); /* send without leading semicolon */
if (0!=strcmp(alarmStatus, alms)) {
str_copy(alarmStatus, alms);
alarmChannels[0]='\0';
for (k=0;k<alarmListSize;k++) { for (k=0;k<alarmListSize;k++) {
str_append(buf,";ALARMST?"); if (alms[k*4] != '0') {
str_append(buf, alarmList[k]); str_append(alarmChannels, alarmList[k]);
} str_append(alarmChannels, " ");
ERR_P(alms=LscCmd(ser, buf+1)); /* send without leading semicolon */ if (NULL==strstr(alarmHistory, alarmList[k])) { /* if not yet in history */
if (0!=strcmp(alarmStatus, alms)) { str_append(alarmHistory, alarmList[k]); /* add to history */
str_copy(alarmStatus, alms);
alarmChannels[0]='\0';
for (k=0;k<alarmListSize;k++) {
if (alms[k*4] != '0' || alms[k*4+2] != '0') {
str_append(alarmChannels, alarmList[k]);
str_append(alarmChannels, " ");
if (NULL==strstr(alarmHistory, alarmList[k])) { /* if not yet in history */
str_append(alarmHistory, alarmList[k]); /* add to history */
}
} }
} }
if (alarmChannels[0]=='\0') { }
if (lockAlarm) { if (alarmChannels[0]=='\0') {
logfileOut(LOG_MAIN, "No more active alarms, latching alarms: %s!\n", alarmHistory); if (lockAlarm) {
} else { logfileOut(LOG_MAIN, "No more active alarms, latching alarms: %s!\n", alarmHistory);
alarmHistory[0]='\0';
alarmChannels[0]='\0';
logfileOut(LOG_MAIN, "No more active alarms\n");
ERR_P(LscCmd(ser, "ALMRST"));
relay=0;
}
} else { } else {
logfileOut(LOG_MAIN, "Alarm on channel %s\n", alarmChannels); alarmHistory[0]='\0';
if (!relay0 && set!=0) { alarmChannels[0]='\0';
lockAlarm=1; logfileOut(LOG_MAIN, "No more active alarms\n");
logfileOut(LOG_MAIN, "Switch off heater\n"); ERR_P(LscCmd(ser, "ALMRST"));
jRange=0; relay=0;
if (loop==1) { /* turn on high relay manually, switch off heater and reset alarms */
ERR_P(LscCmd(ser, "RELAY 1:2,1;RANGE:0;ALMRST"));
} else {
ERR_P(LscCmd(ser, "RELAY 1:2,1;ANALOG 2:0,0;ALMRST"));
relay=1;
}
} else {
ERR_P(LscCmd(ser, "ALMRST"));
}
} }
} else { } else {
ERR_P(LscCmd(ser, "ALMRST")); logfileOut(LOG_MAIN, "Alarm on channel %s\n", alarmChannels);
if (!relay0 && set!=0) {
lockAlarm=1;
logfileOut(LOG_MAIN, "Switch off heater\n");
jRange=0;
if (loop==1) { /* turn on high relay manually, switch off heater and reset alarms */
ERR_P(LscCmd(ser, "RELAY 1:2,1;RANGE:0;ALMRST"));
} else {
ERR_P(LscCmd(ser, "RELAY 1:2,1;ANALOG 2:0,0;ALMRST"));
relay=1;
}
} else {
ERR_P(LscCmd(ser, "ALMRST"));
}
} }
} else if (loop == 1) { } else {
if (!relay0) logfileOut(LOG_MAIN, "Relay is on!\n"); ERR_P(LscCmd(ser, "ALMRST"));
alarmStatus[0]='\0';
} }
} else if (loop == 1) { } else if (loop == 1) {
alarmChannels[0]='\0'; if (!relay0) logfileOut(LOG_MAIN, "Relay is on!\n");
alarmStatus[0]='\0'; alarmStatus[0]='\0';
} }
relay0=relay; relay0=relay;
ERR_I(ReadTemp()); ERR_I(ReadTemp());
@ -2331,17 +2327,35 @@ int SetPower(float setpower) {
OnError: return -1; OnError: return -1;
} }
int AlarmReset(void) {
if (relay) {
ERR_P(LscCmd(ser, "RELAY 1:2,1"));
if (alarmHistory[0]=='\0') {
str_copy(alarmHistory, "X");
}
} else {
alarmHistory[0]='\0';
alarmStatus[0]='\0';
ERR_P(LscCmd(ser, "ALMRST;RELAY 1:1"));
logfileOut(LOG_MAIN, "reset alarms\n");
relay0=0;
lockAlarm=0;
}
OnError: return -1;
}
int SetHdl(int mode, void *base, int fd) { int SetHdl(int mode, void *base, int fd) {
if (mode==COC_WR) { if (mode==COC_WR) {
if (remoteMode!=2) { if (remoteMode!=2) {
ERR_MSG("controller is in local mode, enter 'remote' first"); ERR_MSG("controller is in local mode, enter 'remote' first");
} else if (relay && set!=0) { }
if (relay && set!=0) {
if (alarmChannels[0]!='\0') { if (alarmChannels[0]!='\0') {
ERR_MSG("alarm is active, set prohibited"); ERR_MSG("alarm is active, set prohibited");
} else { } else {
ERR_MSG("alarm was active, enter 'reset' first"); ERR_MSG("alarm was active, enter 'reset' first");
} }
} else if (set<0) { } else if (set<=0) {
set=0; set=0;
} else if (set>tLimit) { } else if (set>tLimit) {
set=0; set=0;
@ -2743,20 +2757,8 @@ int RelayHdl(int mode, void *base, int fd) {
if (alarmChannels[0]!='\0') ERR_MSG("alarm is still active"); if (alarmChannels[0]!='\0') ERR_MSG("alarm is still active");
return COC_DWR; return COC_DWR;
} else if (mode==COC_DWR) { } else if (mode==COC_DWR) {
if (relay) { ERR_I(AlarmReset());
ERR_P(LscCmd(ser, "RELAY 1:2,1")); set = 0;
if (alarmHistory[0]=='\0') {
str_copy(alarmHistory, "X");
}
} else {
alarmHistory[0]='\0';
alarmStatus[0]='\0';
ERR_P(LscCmd(ser, "ALMRST;RELAY 1:1"));
logfileOut(LOG_MAIN, "reset alarms\n");
relay0=0;
lockAlarm=0;
set=0;
}
} }
return 0; return 0;
OnError: return -1; OnError: return -1;
@ -3079,10 +3081,7 @@ int main(int argc, char *argv[]) {
str_append(buf, "/"); str_append(buf, "/");
ERR_I(str_append(buf, logDir)); ERR_I(str_append(buf, logDir));
} }
ERR_I(str_append(buf, serverId)); ERR_I(str_append(buf, "tecs"));
if (strcmp(serverId, "tecs") != 0) {
ERR_I(str_append(buf, "/tecs"));
}
logfile=logfileInit(buf, logIt, use_stdout, logIt && use_stdout); logfile=logfileInit(buf, logIt, use_stdout, logIt && use_stdout);
if (loggerDir[0] != '\0') { if (loggerDir[0] != '\0') {
@ -3093,11 +3092,6 @@ int main(int argc, char *argv[]) {
str_append(buf, "/"); str_append(buf, "/");
ERR_I(str_append(buf, loggerDir)); ERR_I(str_append(buf, loggerDir));
} }
if (strcmp(serverId, "tecs") != 0) {
ERR_I(str_append(buf, serverId));
mkdir(buf, S_IRWXU+S_IRGRP+S_IXGRP+S_IROTH+S_IXOTH);
/* do not check return value */
}
str_copy(loggerDir, buf); str_copy(loggerDir, buf);
LoggerSetDir(loggerDir); LoggerSetDir(loggerDir);
} }

View File

@ -10,30 +10,16 @@
#include "tecs_cli.h" #include "tecs_cli.h"
#include "tecs_data.h" #include "tecs_data.h"
int gethostname(char *name, int namelen);
static char response[COC_RES_LEN]; static char response[COC_RES_LEN];
static char *rwCode="rwacs"; static char *rwCode="rwacs";
static char *rdCode="rdacs"; static char *rdCode="rdacs";
pTecsClient TeccStart(char *startcmd, char *host, int port) { pTecsClient TeccStart(char *startcmd, char *host, int port) {
CocConn *conn; CocConn *conn;
char *code, *cmd, thishost[64], *th;
int iret; int iret;
NEW(conn, CocConn); NEW(conn, CocConn);
code=rwCode; ERR_I(iret=CocInitClient(conn, host, port, rdCode, 0, startcmd));
cmd=startcmd;
if (host[0]!='\0') {
gethostname(thishost, sizeof(thishost));
th=getenv(thishost);
if (th==NULL) th=thishost;
if (0!=strcmp(th, host) && host!=strstr(host, th)) {
code=rdCode;
cmd="";
}
}
ERR_I(iret=CocInitClient(conn, host, port, code, 0, cmd));
if (iret==1) ErrShort("TECS_INIT: can not connect to TecsServer"); if (iret==1) ErrShort("TECS_INIT: can not connect to TecsServer");
return((pTecsClient)conn); return((pTecsClient)conn);
OnError: OnError:
@ -43,17 +29,13 @@ pTecsClient TeccStart(char *startcmd, char *host, int port) {
pTecsClient TeccInit(char *startcmd, int port) { pTecsClient TeccInit(char *startcmd, int port) {
CocConn *conn=NULL; CocConn *conn=NULL;
char *code, host[64];
int iret; int iret;
NEW(conn, CocConn); NEW(conn, CocConn);
code=rwCode;
if (startcmd[0]=='#') { if (startcmd[0]=='#') {
gethostname(host, sizeof(host)); ERR_I(iret=CocInitClient(conn, startcmd+1, port, rdCode, 0, ""));
if (0!=strcmp(startcmd+1, host)) code=rdCode;
ERR_I(iret=CocInitClient(conn, startcmd+1, port, code, 0, ""));
} else { } else {
ERR_I(iret=CocInitClient(conn, "", port, code, 0, startcmd)); ERR_I(iret=CocInitClient(conn, "", port, rdCode, 0, startcmd));
} }
if (iret==1) ErrShort("TECS_INIT: can not connect to TecsServer"); if (iret==1) ErrShort("TECS_INIT: can not connect to TecsServer");
return((pTecsClient)conn); return((pTecsClient)conn);

View File

@ -8,8 +8,8 @@
parameter (maxfiles=10) parameter (maxfiles=10)
integer nfiles/0/, mfiles/0/, idx, luns(0:maxfiles-1) integer nfiles/0/, mfiles/0/, idx, luns(0:maxfiles-1)
character cmdpar*128 character cmdpar*128
character prompt*32/'tecs>'/ character prompt*32/'tecs[] '/
integer promptlen/6/ integer promptlen/7/
logical oneCommand logical oneCommand
character logarg*4/'25'/ character logarg*4/'25'/
character defcmd*8/'status'/ character defcmd*8/'status'/
@ -27,29 +27,20 @@
call sys_get_cmdpar(line, l) call sys_get_cmdpar(line, l)
if (l .eq. 0) then
call sys_getenv('TECS_DEFAULT', line)
call str_trim(line, line, l)
if (line(1:l) .ne. ' ') then
rwacs=1
else
l = 0
endif
endif
if (l .ne. 0) then if (l .ne. 0) then
if (line(1:l) .eq. 'off' .or. line(1:l) .eq. 'OFF') then
iret=tecs_start(' ', ' ', 9753)
if (iret .lt. 0) goto 91
iret=tecs_quit_server(0)
if (iret .lt. 0) goto 91
goto 99
endif
oneCommand=.true. oneCommand=.true.
port=instr_host(line, inst, host, user, pcod) if (l .eq. 1 .and.
1 line(1:1) .gt. '0' .and. line(1:1) .le. '9') then
port=9750+(ichar(line(1:1))-ichar('0'))
inst=line
host=' '
oneCommand=.false.
else
rwacs=instr_host('tecs', line, inst, host, port)
endif
else else
call sys_getenv('HOST', line) ! call sys_getenv('HOST', line)
port=instr_host(line, inst, host, user, pcod) rwacs=instr_host('tecs', line, inst, host, port)
oneCommand=.false. oneCommand=.false.
endif endif
@ -64,7 +55,7 @@
endif endif
iret=tecs_start(start, host, port) iret=tecs_start(start, host, port)
oneCommand=.false. oneCommand=.false.
prompt='tecs/'//inst(1:i)//'> ' prompt='tecs['//inst(1:i)//'] '
promptlen=i+7 promptlen=i+7
else else
iret=tecs_start(start, ' ', 9753) iret=tecs_start(start, ' ', 9753)

View File

@ -19,16 +19,16 @@ typedef struct {
int reset; int reset;
} Summary; } Summary;
typedef struct _Run { typedef struct Run {
struct _Run *next; struct Run *next;
int size, step; int size, step;
int startTime, endTime; int startTime, endTime;
float data[RUN_SIZE]; float data[RUN_SIZE];
} Run; } Run;
typedef struct _Set { typedef struct Set {
DataSet set; DataSet set;
struct _Set *next; struct Set *next;
int nRuns; int nRuns;
int step, lifetime; int step, lifetime;
int start, end; int start, end;
@ -113,7 +113,7 @@ Set *FindSet(Base *base, char *name) {
Set *CreateSet(Base *base, char *name, float *var, int step, int lifetime, int start) { Set *CreateSet(Base *base, char *name, float *var, int step, int lifetime, int start) {
Set *s; Set *s;
char *nam; char *nam;
s = FindSet(base, name); s = FindSet(base, name);
if (s != NULL) ERR_MSG("dataset exists"); if (s != NULL) ERR_MSG("dataset exists");
NEW(s, Set); NEW(s, Set);
@ -127,7 +127,7 @@ Set *CreateSet(Base *base, char *name, float *var, int step, int lifetime, int s
s->start = start; s->start = start;
s->step = step; s->step = step;
s->var = var; s->var = var;
s->log = LoggerMake(name, step, 0); s->log = NULL;
ResetSum(&s->sum); ResetSum(&s->sum);
return s; return s;
OnError: OnError:
@ -268,9 +268,11 @@ int DataPut(DataSet *set, int time, float value) {
return Put((Set *)set, time, value); return Put((Set *)set, time, value);
} }
int DataPutAll(DataBase *base, int time) { int DataPutAll(DataBase *base, int mytime) {
Set *s; Set *s;
char value[32]; char value[32];
char tname[32];
static time_t lastOpen = 0;
if (base == NULL) { if (base == NULL) {
s=database.head; s=database.head;
@ -279,14 +281,22 @@ int DataPutAll(DataBase *base, int time) {
} }
while (s!=NULL) { while (s!=NULL) {
if (s->var!=NULL) { if (s->var!=NULL) {
ERR_I(Put(s, time, *s->var)); ERR_I(Put(s, mytime, *s->var));
if (s->log == NULL && *s->var != DATA_UNDEF && time(NULL) > lastOpen + 300) {
/* try to make logger if not yet tried in the last 5 min. */
snprintf(tname, sizeof tname, "tt.%s", s->set.name);
s->log = LoggerMake(tname, s->step, 0);
if (s->log == NULL) {
lastOpen = time(NULL);
}
}
if (s->log != NULL) { if (s->log != NULL) {
if (*s->var == DATA_UNDEF) { if (*s->var == DATA_UNDEF) {
value[0]='\0'; value[0]='\0';
} else { } else {
snprintf(value, sizeof value, "%.5g", *s->var); snprintf(value, sizeof value, "%.5g", *s->var);
} }
LoggerWrite(s->log, mycUnixTime(time), s->step, value); LoggerWrite(s->log, mycUnixTime(mytime), s->step, value);
} }
} }
s=s->next; s=s->next;

View File

@ -5,6 +5,8 @@
#include <sys/time.h> #include <sys/time.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "term.h" #include "term.h"
#include "myc_mem.h" #include "myc_mem.h"
#include "myc_str.h" #include "myc_str.h"
@ -184,9 +186,10 @@ static int hist_pos=0; /* position when scrolling through the history */
static int hist_end=0; /* end of history. Always history[hist_end]==NULL */ static int hist_end=0; /* end of history. Always history[hist_end]==NULL */
FILE *term_open_pref(int temp, char *head, char *mode) { FILE *term_open_pref(int temp, char *head, char *mode) {
char buf[PATH_MAX+1], wd[PATH_MAX]; char buf[PATH_MAX+1], old[PATH_MAX+1], wd[PATH_MAX];
char *usr, *home, *p; char *usr, *home, *p;
int l; int l;
FILE *fil;
usr = getenv("USER"); usr = getenv("USER");
if (temp && usr==NULL) return NULL; if (temp && usr==NULL) return NULL;
@ -209,28 +212,41 @@ FILE *term_open_pref(int temp, char *head, char *mode) {
} }
} else { } else {
home = buf; home = buf;
} }
} else { } else {
home=getenv("HOME"); home=getenv("HOME");
if (!home) return NULL; if (!home) return NULL;
} }
if (temp) { if (temp) {
/* usr is now the username, or lnsg_<subdirectory> */ /* old file name */
str_copy(buf, "/tmp/"); str_copy(old, "/tmp/");
str_append(old, head);
str_append(old, ".");
str_append(old, usr);
/* new file name */
str_copy(buf, "/tmp/six/");
mkdir(buf, S_IRWXU+S_IRGRP+S_IXGRP+S_IROTH+S_IXOTH);
str_append(buf, head); str_append(buf, head);
str_append(buf, "."); str_append(buf, ".");
str_append(buf, usr); str_append(buf, usr); /* usr is the username, or lnsg_<subdirectory> */
} else { } else {
/* old file name */
str_copy(old, home);
str_append(old, "/.");
str_append(old, head);
/* new file name */
str_copy(buf, home); str_copy(buf, home);
str_append(buf, "/"); str_append(buf, "/.six/");
mkdir(buf, S_IRWXU+S_IRGRP+S_IXGRP+S_IROTH+S_IXOTH);
str_append(buf, head); str_append(buf, head);
} }
rename(old, buf); /* if old file exists, rename it to new */
if (*mode == 'd') { if (*mode == 'd') {
unlink(buf); unlink(buf);
return NULL; return NULL;
} else { } else {
return fopen(buf, mode); fil = fopen(buf, mode);
return fil;
} }
} }
@ -285,7 +301,7 @@ void term_read_hist(char *id) {
char buf[1024], *lin; char buf[1024], *lin;
str_copy(filehead, id); str_copy(filehead, id);
str_append(filehead, "_hist."); str_append(filehead, "_hist");
fil=term_open_pref(1, filehead, "r"); fil=term_open_pref(1, filehead, "r");
if (fil==NULL) return; if (fil==NULL) return;
hist_end=0; hist_end=0;