7.4.00
This commit is contained in:
@ -1,6 +1,5 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fortify.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <fortify.h>
|
|
||||||
#include "coc_logfile.h"
|
#include "coc_logfile.h"
|
||||||
#include "err_handling.h"
|
#include "err_handling.h"
|
||||||
#include "str_util.h"
|
#include "str_util.h"
|
||||||
@ -25,17 +24,19 @@
|
|||||||
static FILE *fil=NULL;
|
static FILE *fil=NULL;
|
||||||
static char lnam[256]="", filnam[256]="";
|
static char lnam[256]="", filnam[256]="";
|
||||||
static char ebuf[20000]="";
|
static char ebuf[20000]="";
|
||||||
|
static char *statusBuf=NULL;
|
||||||
|
static int statusSize;
|
||||||
static char *eptr=&ebuf[0];
|
static char *eptr=&ebuf[0];
|
||||||
static int lastStamp=0;
|
static int lastStamp=0;
|
||||||
static int notDated=0;
|
static int notDated=0;
|
||||||
static int logMask=0;
|
static int logMask=0;
|
||||||
static int wrtMask=0;
|
static int wrtMask=0;
|
||||||
|
static int newLine=1;
|
||||||
int ftime (struct timeb *__timeptr); /* for some reason not defined in timeb.h with flag -std1 */
|
|
||||||
|
|
||||||
static int logfileStd;
|
static int logfileStd;
|
||||||
static int dirty, writeAll;
|
static int dirty, writeAll;
|
||||||
|
|
||||||
|
int ftime (struct timeb *__timeptr); /* for some reason not defined in timeb.h with flag -std1 */
|
||||||
|
|
||||||
void logfileOpen(int first) {
|
void logfileOpen(int first) {
|
||||||
struct tm *tim;
|
struct tm *tim;
|
||||||
struct timeb btim;
|
struct timeb btim;
|
||||||
@ -74,6 +75,12 @@ void logfileOpen(int first) {
|
|||||||
fil=fopen(filnam, "a");
|
fil=fopen(filnam, "a");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
ErrSetOutFile(fil);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logfileStatusBuffer(char *buffer, int bufsize) {
|
||||||
|
statusBuf=buffer;
|
||||||
|
statusSize=bufsize-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void logfileInit(char *path, int nodate, int use_stdout, int write_all) {
|
void logfileInit(char *path, int nodate, int use_stdout, int write_all) {
|
||||||
@ -87,10 +94,26 @@ void logfileInit(char *path, int nodate, int use_stdout, int write_all) {
|
|||||||
|
|
||||||
void logfileOut(int mask, const char *fmt, ...)
|
void logfileOut(int mask, const char *fmt, ...)
|
||||||
{ va_list ap;
|
{ va_list ap;
|
||||||
|
char buf[256], *p;
|
||||||
|
|
||||||
assert(mask>0 && mask<32);
|
assert(mask>0 && mask<32);
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|
||||||
|
if (mask & LOG_MAIN && statusBuf!=NULL) {
|
||||||
|
if (newLine) {
|
||||||
|
statusBuf[0]='\0';
|
||||||
|
newLine=0;
|
||||||
|
}
|
||||||
|
buf[statusSize]='\0';
|
||||||
|
vsprintf(buf, fmt, ap);
|
||||||
|
assert(buf[statusSize]=='\0'); /* check for overflow */
|
||||||
|
str_ncat(statusBuf, buf, statusSize);
|
||||||
|
p=strchr(statusBuf, '\n');
|
||||||
|
if (p!=NULL) {
|
||||||
|
newLine=1;
|
||||||
|
*p='\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
if (writeAll) {
|
if (writeAll) {
|
||||||
#ifdef __VMS
|
#ifdef __VMS
|
||||||
if (fil==NULL) logfileOpen(0);
|
if (fil==NULL) logfileOpen(0);
|
||||||
@ -203,7 +226,7 @@ void logfileClose()
|
|||||||
#ifdef __VMS
|
#ifdef __VMS
|
||||||
if (fil==NULL) logfileOpen(0);
|
if (fil==NULL) logfileOpen(0);
|
||||||
#endif
|
#endif
|
||||||
logfileWrite0(LOG_MAIN+LOG_WARN);
|
logfileWrite0(LOG_MAIN+LOG_INFO);
|
||||||
lastStamp-=1;
|
lastStamp-=1;
|
||||||
logfileStamp();
|
logfileStamp();
|
||||||
if (fil!=NULL) { fclose(fil); fil=NULL; }
|
if (fil!=NULL) { fclose(fil); fil=NULL; }
|
||||||
|
@ -6,9 +6,11 @@
|
|||||||
#define LOG_ALL 31
|
#define LOG_ALL 31
|
||||||
#define LOG_SER 8
|
#define LOG_SER 8
|
||||||
#define LOG_NET 4
|
#define LOG_NET 4
|
||||||
#define LOG_WARN 2
|
#define LOG_INFO 2
|
||||||
#define LOG_MAIN 1
|
#define LOG_MAIN 1
|
||||||
|
#define logfileStatusBuf(B) logfileStatusBuffer(B,sizeof(B))
|
||||||
|
|
||||||
|
void logfileStatusBuffer(char *buffer, int bufsize);
|
||||||
void logfileInit(char *path, int nodate, int use_stdout, int write_all);
|
void logfileInit(char *path, int nodate, int use_stdout, int write_all);
|
||||||
void logfileOut(int mask, const char *fmt, ...);
|
void logfileOut(int mask, const char *fmt, ...);
|
||||||
void logfileOutBuf(int mask, Str_Buf *buf);
|
void logfileOutBuf(int mask, Str_Buf *buf);
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
#include "coc_logfile.h"
|
#include "coc_logfile.h"
|
||||||
#include "coc_server.h"
|
#include "coc_server.h"
|
||||||
#include "str_util.h"
|
#include "str_util.h"
|
||||||
#include <fortify.h>
|
|
||||||
|
|
||||||
static Str_Buf *buf, *bufo;
|
static Str_Buf *buf, *bufo;
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ int CocInitServer(int bufsize, int port) {
|
|||||||
ERR_SI(setsockopt(mainFd,SOL_SOCKET,SO_REUSEADDR,&i,sizeof(int))); /* allow quick port reuse */
|
ERR_SI(setsockopt(mainFd,SOL_SOCKET,SO_REUSEADDR,&i,sizeof(int))); /* allow quick port reuse */
|
||||||
ERR_I(CocCreateSockAdr(&sadr, NULL, port));
|
ERR_I(CocCreateSockAdr(&sadr, NULL, port));
|
||||||
ERR_SI(bind(mainFd, (struct sockaddr *)&sadr, sizeof(sadr)));
|
ERR_SI(bind(mainFd, (struct sockaddr *)&sadr, sizeof(sadr)));
|
||||||
logfileOut(LOG_MAIN, "created server on port %d\n", port);
|
logfileOut(LOG_INFO, "created server on port %d\n", port);
|
||||||
ERR_SI(listen(mainFd, 8));
|
ERR_SI(listen(mainFd, 8));
|
||||||
FD_ZERO(&mask);
|
FD_ZERO(&mask);
|
||||||
FD_SET(mainFd, &mask);
|
FD_SET(mainFd, &mask);
|
||||||
@ -86,9 +85,9 @@ int CocHandle1Request(int tmo_msec, int fd) {
|
|||||||
cList->next=cl;
|
cList->next=cl;
|
||||||
h=gethostbyaddr(&cadr.sin_addr, 4, AF_INET);
|
h=gethostbyaddr(&cadr.sin_addr, 4, AF_INET);
|
||||||
if (h==NULL) {
|
if (h==NULL) {
|
||||||
logfileOut(LOG_MAIN, "(%d) open from %s\n", newfd, "local");
|
logfileOut(LOG_INFO, "(%d) open from %s\n", newfd, "local");
|
||||||
} else {
|
} else {
|
||||||
logfileOut(LOG_MAIN, "(%d) open from %s\n", newfd, h->h_name);
|
logfileOut(LOG_INFO, "(%d) open from %s\n", newfd, h->h_name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cl0=cList; cl=cl0->next;
|
cl0=cList; cl=cl0->next;
|
||||||
@ -96,7 +95,7 @@ int CocHandle1Request(int tmo_msec, int fd) {
|
|||||||
if (FD_ISSET(cl->fd, &rmask)) {
|
if (FD_ISSET(cl->fd, &rmask)) {
|
||||||
buf->wrpos=recv(cl->fd, buf->buf, buf->dsize, 0);
|
buf->wrpos=recv(cl->fd, buf->buf, buf->dsize, 0);
|
||||||
if (buf->wrpos<=0) {
|
if (buf->wrpos<=0) {
|
||||||
logfileOut(LOG_MAIN, "(%d) disconnected\n",cl->fd);
|
logfileOut(LOG_INFO, "(%d) disconnected\n",cl->fd);
|
||||||
close(cl->fd);
|
close(cl->fd);
|
||||||
FD_CLR(cl->fd, &mask);
|
FD_CLR(cl->fd, &mask);
|
||||||
cl0->next=cl->next;
|
cl0->next=cl->next;
|
||||||
@ -113,10 +112,10 @@ int CocHandle1Request(int tmo_msec, int fd) {
|
|||||||
logfileOut(LOG_NET, "(%d) ", cl->fd);
|
logfileOut(LOG_NET, "(%d) ", cl->fd);
|
||||||
if (varname[0]=='#') { /* access code */
|
if (varname[0]=='#') { /* access code */
|
||||||
if (0==strcmp(varname,"#rdacc")) {
|
if (0==strcmp(varname,"#rdacc")) {
|
||||||
logfileOut(LOG_MAIN, "set read mode\n");
|
logfileOut(LOG_INFO, "set read mode\n");
|
||||||
cl->mode=1;
|
cl->mode=1;
|
||||||
} else if (0==strcmp(varname,"#rwacs")) {
|
} else if (0==strcmp(varname,"#rwacs")) {
|
||||||
logfileOut(LOG_MAIN, "set write mode\n");
|
logfileOut(LOG_INFO, "set write mode\n");
|
||||||
cl->mode=2;
|
cl->mode=2;
|
||||||
} else {
|
} else {
|
||||||
err="bad access code";
|
err="bad access code";
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <fortify.h>
|
|
||||||
#include "err_handling.h"
|
#include "err_handling.h"
|
||||||
#include "str_util.h"
|
#include "str_util.h"
|
||||||
#include "coc_util.h"
|
#include "coc_util.h"
|
||||||
@ -155,6 +154,7 @@ CocVar *CocDefVar(const char *name, void *var, int type, int *flag) {
|
|||||||
p->var=var;
|
p->var=var;
|
||||||
p->type=type;
|
p->type=type;
|
||||||
p->flag=flag;
|
p->flag=flag;
|
||||||
|
/* printf("define %s %d\n", name, (int)var); */
|
||||||
return(p);
|
return(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,6 +180,7 @@ int CocGetVar(CocVar *varList, Str_Buf *buf, const char *name, int secure) {
|
|||||||
if (secure) { /* we are the server */
|
if (secure) { /* we are the server */
|
||||||
if (var->flag==&CocRD) ERR_MSG("variable is read only");
|
if (var->flag==&CocRD) ERR_MSG("variable is read only");
|
||||||
}
|
}
|
||||||
|
/* printf("get %s %d\n", name, (int)adr); */
|
||||||
if (var->type==-1) {
|
if (var->type==-1) {
|
||||||
ERR_I(str_get_int(buf, (int *)adr));
|
ERR_I(str_get_int(buf, (int *)adr));
|
||||||
} else if (var->type==-2) {
|
} else if (var->type==-2) {
|
||||||
@ -208,9 +209,10 @@ int CocPutVar(CocVar *varList, Str_Buf *buf, const char *name, int secure) {
|
|||||||
} else {
|
} else {
|
||||||
adr=(char *)adr + (int)var->var;
|
adr=(char *)adr + (int)var->var;
|
||||||
}
|
}
|
||||||
if (secure) { /* we are the client */
|
if (secure) { /* check acces */
|
||||||
if (var->flag==&CocRD) ERR_MSG("variable is read only");
|
if (var->flag==&CocRD) ERR_MSG("variable is read only");
|
||||||
}
|
}
|
||||||
|
/* printf("put %s %d\n", name, (int)adr); */
|
||||||
if (var->type==-1) {
|
if (var->type==-1) {
|
||||||
ERR_I(str_put_int(buf, *(int *)adr));
|
ERR_I(str_put_int(buf, *(int *)adr));
|
||||||
} else if (var->type==-2) {
|
} else if (var->type==-2) {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <fortify.h>
|
|
||||||
#include "err_handling.h"
|
#include "err_handling.h"
|
||||||
|
|
||||||
#define SLEN 64
|
#define SLEN 64
|
||||||
@ -73,11 +72,16 @@ void ErrSetOutRtn(void (*rtn)(), void *arg) {
|
|||||||
outarg=arg;
|
outarg=arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ErrSetOutFile(FILE *arg) {
|
||||||
|
outrtn=ErrOutFil;
|
||||||
|
outarg=arg;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __VMS
|
#ifdef __VMS
|
||||||
|
|
||||||
typedef struct { short size, dummy; char *text; } Desc;
|
typedef struct { short size, dummy; char *text; } Desc;
|
||||||
|
|
||||||
void ErrShowVms(Desc *desc, void (*outrtn)(), void *arg) {
|
void ErrShowVms(Desc *desc) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef _ERR_HANDLING_H_
|
#ifndef _ERR_HANDLING_H_
|
||||||
#define _ERR_HANDLING_H_
|
#define _ERR_HANDLING_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <sys/errno.h>
|
#include <sys/errno.h>
|
||||||
|
|
||||||
/* ErrHDL Error handling utilities
|
/* ErrHDL Error handling utilities
|
||||||
@ -76,6 +77,8 @@ void ErrCod(int code);
|
|||||||
void ErrWrite(char *text);
|
void ErrWrite(char *text);
|
||||||
void ERR_EXIT(char *text);
|
void ERR_EXIT(char *text);
|
||||||
void ErrLog(char *text);
|
void ErrLog(char *text);
|
||||||
|
void ErrSetOutRtn(void (*rtn)(), void *arg);
|
||||||
|
void ErrSetOutFile(FILE *file);
|
||||||
|
|
||||||
extern int ErrCode;
|
extern int ErrCode;
|
||||||
extern char *ErrMessage;
|
extern char *ErrMessage;
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <fortify.h>
|
|
||||||
#include "err_handling.h"
|
#include "err_handling.h"
|
||||||
#include "str_util.h"
|
#include "str_util.h"
|
||||||
#include "str_buf.h"
|
#include "str_buf.h"
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <fortify.h>
|
|
||||||
#include "err_handling.h"
|
#include "err_handling.h"
|
||||||
#include "str_util.h"
|
#include "str_util.h"
|
||||||
|
|
||||||
|
248
tecs/tecs.c
248
tecs/tecs.c
@ -5,7 +5,6 @@
|
|||||||
#include <sys/timeb.h>
|
#include <sys/timeb.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <fortify.h>
|
|
||||||
#include "err_handling.h"
|
#include "err_handling.h"
|
||||||
#include "coc_server.h"
|
#include "coc_server.h"
|
||||||
#include "coc_logfile.h"
|
#include "coc_logfile.h"
|
||||||
@ -13,8 +12,9 @@
|
|||||||
#include "tecs_lsc.h"
|
#include "tecs_lsc.h"
|
||||||
#include "tecs_dlog.h"
|
#include "tecs_dlog.h"
|
||||||
|
|
||||||
#define TABLE_FILE "lsc.tab"
|
#define TABLE_FILE "lsci.tab"
|
||||||
#define NO_CODE 999
|
#define NO_CODE 999
|
||||||
|
#define Progress(I) if (configuring) { configuring+=I; }
|
||||||
|
|
||||||
static SerChannel *ser=NULL;
|
static SerChannel *ser=NULL;
|
||||||
static char *serverId=NULL;
|
static char *serverId=NULL;
|
||||||
@ -33,13 +33,14 @@ typedef struct {
|
|||||||
int codDefined; /* code is not yet confirmed */
|
int codDefined; /* code is not yet confirmed */
|
||||||
char ch1[2], ch2[2]; /* channels for high/low T */
|
char ch1[2], ch2[2]; /* channels for high/low T */
|
||||||
char device[16]; /* device name */
|
char device[16]; /* device name */
|
||||||
} Part;
|
char tname[16];
|
||||||
|
} Testpoint;
|
||||||
|
|
||||||
Part /* C standard guarantees initialization to zero */
|
Testpoint /* C standard guarantees initialization to zero */
|
||||||
cryo, /* data for main sensors (on heat exchanger, or the only sensors) */
|
cryo, /* data for main sensors (on heat exchanger, or the only sensors) */
|
||||||
samp, /* data for extra sensors of sample stick */
|
samp, /* data for extra sensors of sample stick */
|
||||||
*parts[2]={&cryo, &samp},
|
*testpoints[2]={&cryo, &samp},
|
||||||
*part=&cryo;
|
*testpoint=&cryo;
|
||||||
|
|
||||||
static float
|
static float
|
||||||
tempC, /* set T */
|
tempC, /* set T */
|
||||||
@ -68,7 +69,9 @@ static int
|
|||||||
fld, /* field number */
|
fld, /* field number */
|
||||||
key, /* key status */
|
key, /* key status */
|
||||||
serialNo,
|
serialNo,
|
||||||
resist,
|
configuring=1,
|
||||||
|
resist, /* heater resistance */
|
||||||
|
readTemp, /* client requested readTemp */
|
||||||
cod1, cod2, out1, out2, /* codes read from digital input/output */
|
cod1, cod2, out1, out2, /* codes read from digital input/output */
|
||||||
iRange, iAmp, /* max. range and max. current code */
|
iRange, iAmp, /* max. range and max. current code */
|
||||||
per; /* effective period */
|
per; /* effective period */
|
||||||
@ -81,12 +84,12 @@ static time_t
|
|||||||
static int decod[8]={21,20,17,16,5,4,1,0}; /* for code conversion */
|
static int decod[8]={21,20,17,16,5,4,1,0}; /* for code conversion */
|
||||||
|
|
||||||
static char
|
static char
|
||||||
|
status[132], /* status buffer */
|
||||||
device[32], /* concatenated device names */
|
device[32], /* concatenated device names */
|
||||||
buf1[256], buf2[256], buf3[256], buf4[256], /* buffers for temporary use */
|
buf1[256], buf2[256], buf3[256], buf4[256], /* buffers for temporary use */
|
||||||
head[64], /* curve header */
|
head[64], /* curve header */
|
||||||
intype[64], /* input configuration */
|
intype[64], /* input configuration */
|
||||||
chan[2], /* actual channel */
|
chan[2]; /* actual channel */
|
||||||
xxxx;
|
|
||||||
|
|
||||||
static char
|
static char
|
||||||
*table=NULL, /* environment devices table */
|
*table=NULL, /* environment devices table */
|
||||||
@ -216,6 +219,7 @@ int instCurve(char *nam, char *channel) {
|
|||||||
logfileOut(LOG_MAIN, "download curve %d\n", num);
|
logfileOut(LOG_MAIN, "download curve %d\n", num);
|
||||||
/* select sensor type first to display sensor units */
|
/* select sensor type first to display sensor units */
|
||||||
ERR_P(LscCmd(ser, "INTYPE [chan]:[intype];DISPFLD [fld],[chan],3;DISPLAY:[maxfld]"));
|
ERR_P(LscCmd(ser, "INTYPE [chan]:[intype];DISPFLD [fld],[chan],3;DISPLAY:[maxfld]"));
|
||||||
|
Progress(1);
|
||||||
|
|
||||||
n=3;
|
n=3;
|
||||||
do {
|
do {
|
||||||
@ -227,11 +231,15 @@ int instCurve(char *nam, char *channel) {
|
|||||||
if (i!=0) ERR_MSG("can not delete curve");
|
if (i!=0) ERR_MSG("can not delete curve");
|
||||||
|
|
||||||
sprintf(lbuf, "CRVPT %d", num);
|
sprintf(lbuf, "CRVPT %d", num);
|
||||||
|
i=0;
|
||||||
do { /* download curve */
|
do { /* download curve */
|
||||||
t=str_split(nbuf, points, '\n');
|
t=str_split(nbuf, points, '\n');
|
||||||
if (nbuf[0]!='\0') {
|
if (nbuf[0]!='\0') {
|
||||||
ERR_I(str_substitute(buf, nbuf, "#0", lbuf));
|
ERR_I(str_substitute(buf, nbuf, "#0", lbuf));
|
||||||
ERR_P(LscCmd(ser, buf));
|
ERR_P(LscCmd(ser, buf));
|
||||||
|
i++;
|
||||||
|
if (i%10==0) sprintf(status, "downloading curve at line %d", i);
|
||||||
|
Progress(1);
|
||||||
}
|
}
|
||||||
points=t;
|
points=t;
|
||||||
} while (t!=NULL);
|
} while (t!=NULL);
|
||||||
@ -239,6 +247,7 @@ int instCurve(char *nam, char *channel) {
|
|||||||
/* write header, select curve */
|
/* write header, select curve */
|
||||||
str_upcase(head, chead);
|
str_upcase(head, chead);
|
||||||
ERR_P(LscCmd(ser, "CRVHDR [num]:[head];INCRV [chan]:[num];DISPFLD [fld],[chan],1"));
|
ERR_P(LscCmd(ser, "CRVHDR [num]:[head];INCRV [chan]:[num];DISPFLD [fld],[chan],1"));
|
||||||
|
Progress(1);
|
||||||
logfileOut(LOG_MAIN, "curve selected on channel %s\n", chan);
|
logfileOut(LOG_MAIN, "curve selected on channel %s\n", chan);
|
||||||
saveTime=tim+30;
|
saveTime=tim+30;
|
||||||
}
|
}
|
||||||
@ -288,11 +297,11 @@ int configInput() {
|
|||||||
char *ext;
|
char *ext;
|
||||||
|
|
||||||
retstat=-2; /* errors in following section are severe */
|
retstat=-2; /* errors in following section are severe */
|
||||||
if (part->manual) {
|
if (testpoint->manual) {
|
||||||
sprintf(buf, ".%s.", part->device);
|
sprintf(buf, "'%s'", testpoint->device);
|
||||||
} else {
|
} else {
|
||||||
sprintf(buf, "%+d ", part->code);
|
sprintf(buf, "%+d ", testpoint->code);
|
||||||
if (part->code==0) return(0);
|
if (testpoint->code==0) return(0);
|
||||||
}
|
}
|
||||||
if (table!=NULL && tim>tableTime+60) { free(table); table=NULL; }; /* clear old table */
|
if (table!=NULL && tim>tableTime+60) { free(table); table=NULL; }; /* clear old table */
|
||||||
if (table==NULL) { /* read table */
|
if (table==NULL) { /* read table */
|
||||||
@ -305,38 +314,38 @@ int configInput() {
|
|||||||
t=strstr(table, buf);
|
t=strstr(table, buf);
|
||||||
if (t==NULL) ERR_MSG("device not found");
|
if (t==NULL) ERR_MSG("device not found");
|
||||||
i=sscanf(t, "%79[^\n!]", buf); /* read line */
|
i=sscanf(t, "%79[^\n!]", buf); /* read line */
|
||||||
t=strchr(buf, '.');
|
t=strchr(buf, '\'');
|
||||||
if (t==NULL) ERR_MSG("missing '.' in table file");
|
if (t==NULL) ERR_MSG("missing ' in table file");
|
||||||
t++;
|
t++;
|
||||||
n=1;
|
n=1;
|
||||||
if (part==&samp) {
|
if (testpoint==&samp) {
|
||||||
samp.nSens=0;
|
samp.nSens=0;
|
||||||
i=sscanf(t, "%12s%d%d", nam, &nn, &n);
|
i=sscanf(t, "%12s%d%d", nam, &nn, &n);
|
||||||
if (i<1) ERR_MSG("missing sensor name");
|
if (i<1) ERR_MSG("missing sensor name");
|
||||||
ext="s";
|
ext=".s";
|
||||||
} else {
|
} else {
|
||||||
cryo.nSens=0;
|
cryo.nSens=0;
|
||||||
tLow=0; tHigh=0;
|
tLow=0; tHigh=0;
|
||||||
controlMode=0;
|
controlMode=0;
|
||||||
i=sscanf(t, "%12s%d%d%d%f%d%f%f%f", nam, &n, &nn, &controlMode, &tLimit, &resist, &power, &tLow, &tHigh);
|
i=sscanf(t, "%12s%d%d%d%f%d%f%f%f", nam, &n, &nn, &controlMode, &tLimit, &resist, &power, &tLow, &tHigh);
|
||||||
if (i<7) ERR_MSG("missing some sensor parameters");
|
if (i<7) ERR_MSG("missing some sensor parameters");
|
||||||
ext="x";
|
ext=".x";
|
||||||
}
|
}
|
||||||
if (n<0 || n>2) ERR_MSG("illegal value for nsensor");
|
if (n<0 || n>2) ERR_MSG("illegal value for nsensor");
|
||||||
if (n==0) return(0);
|
if (n==0) return(0);
|
||||||
if (!part->manual) { /* set device name */
|
nam[strlen(nam)-1]='\0'; /* strip off quote */
|
||||||
str_copy(part->device, nam);
|
if (!testpoint->manual) { /* set device name */
|
||||||
part->device[strlen(part->device)-1]='\0'; /* strip off '.' */
|
str_copy(testpoint->device, nam);
|
||||||
concatDevice();
|
concatDevice();
|
||||||
}
|
}
|
||||||
str_append(nam, ext);
|
str_append(nam, ext);
|
||||||
|
|
||||||
ERR_I(retstat=instCurve(nam, part->ch1));
|
ERR_I(retstat=instCurve(nam, testpoint->ch1));
|
||||||
if (n==2) {
|
if (n==2) {
|
||||||
str_append(nam, "l");
|
str_append(nam, "l");
|
||||||
ERR_I(retstat=instCurve(nam, part->ch2));
|
ERR_I(retstat=instCurve(nam, testpoint->ch2));
|
||||||
}
|
}
|
||||||
part->nSens=n;
|
testpoint->nSens=n;
|
||||||
return(0);
|
return(0);
|
||||||
OnError: return(retstat);
|
OnError: return(retstat);
|
||||||
}
|
}
|
||||||
@ -363,6 +372,7 @@ int loadCache() {
|
|||||||
bufi[3]=buf4;
|
bufi[3]=buf4;
|
||||||
for (i=60; i>21; i-=4) {
|
for (i=60; i>21; i-=4) {
|
||||||
sprintf(buf, "CRVHDR?%d>buf1;CRVHDR?%d>buf2;CRVHDR?%d>buf3;CRVHDR?%d>buf4", i, i-1, i-2, i-3);
|
sprintf(buf, "CRVHDR?%d>buf1;CRVHDR?%d>buf2;CRVHDR?%d>buf3;CRVHDR?%d>buf4", i, i-1, i-2, i-3);
|
||||||
|
Progress(1);
|
||||||
ERR_P(LscCmd(ser, buf));
|
ERR_P(LscCmd(ser, buf));
|
||||||
k=0;
|
k=0;
|
||||||
for (j=i; j>i-4; j--) {
|
for (j=i; j>i-4; j--) {
|
||||||
@ -434,6 +444,57 @@ int SetTemp(int switchOn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ReadTemp() {
|
int ReadTemp() {
|
||||||
|
char buf[256];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
readTemp=0;
|
||||||
|
buf[0]='\0';
|
||||||
|
|
||||||
|
if (cryo.nSens>0) {
|
||||||
|
str_append(buf, "KRDG?[cryo.ch1]>cryo.t1;");
|
||||||
|
if (cryo.nSens>1) {
|
||||||
|
str_append(buf, "KRDG?[cryo.ch2]>cryo.t2;");
|
||||||
|
} else {
|
||||||
|
cryo.t2=0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cryo.t1=0;
|
||||||
|
cryo.t2=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (samp.nSens>0) {
|
||||||
|
str_append(buf, "KRDG?[samp.ch1]>samp.t1;");
|
||||||
|
if (samp.nSens>1) {
|
||||||
|
str_append(buf, "KRDG?[samp.ch2]>samp.t2;");
|
||||||
|
} else {
|
||||||
|
samp.t2=0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
samp.t1=0;
|
||||||
|
samp.t2=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
i=strlen(buf);
|
||||||
|
if (i>0) {
|
||||||
|
buf[i-1]='\0'; /* strip off ';' */
|
||||||
|
ERR_P(LscCmd(ser, buf));
|
||||||
|
}
|
||||||
|
cryo.temp=WeightedAverage(cryo.nSens, cryo.t1, cryo.t2);
|
||||||
|
samp.temp=WeightedAverage(samp.nSens, samp.t1, samp.t2);
|
||||||
|
if (samp.temp==0.0) samp.temp=cryo.temp;
|
||||||
|
if (!deviceFlag
|
||||||
|
&& !samp.dirty && samp.codDefined && !samp.codChanged
|
||||||
|
&& !cryo.dirty && cryo.codDefined && !cryo.codChanged) {
|
||||||
|
configuring=0;
|
||||||
|
} else if (configuring==0) {
|
||||||
|
str_copy(status, "configuring");
|
||||||
|
configuring=1;
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
OnError: return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int PeriodicTask() {
|
||||||
char buf[256], lbuf[16];
|
char buf[256], lbuf[16];
|
||||||
char *res;
|
char *res;
|
||||||
int i, k;
|
int i, k;
|
||||||
@ -451,8 +512,12 @@ int ReadTemp() {
|
|||||||
ERR_P(LscCmd(ser, "*IDN?>buf1,buf2,serialNo,"));
|
ERR_P(LscCmd(ser, "*IDN?>buf1,buf2,serialNo,"));
|
||||||
if (0!=strcmp(buf1, "LSCI") || 0!=strcmp(buf2, "MODEL340") || serialNo==0) return(0);
|
if (0!=strcmp(buf1, "LSCI") || 0!=strcmp(buf2, "MODEL340") || serialNo==0) return(0);
|
||||||
if (k!=serialNo) {
|
if (k!=serialNo) {
|
||||||
if (cryo.manual || cryo.code!=0) cryo.dirty=1;
|
if (!configuring) {
|
||||||
if (samp.manual || samp.code!=0) samp.dirty=1;
|
str_copy(status, "controller connected");
|
||||||
|
configuring=1;
|
||||||
|
}
|
||||||
|
if (cryo.manual || cryo.code!=0) { cryo.dirty=1; }
|
||||||
|
if (samp.manual || samp.code!=0) { samp.dirty=1; }
|
||||||
ERR_P(LscCmd(ser, "RANGE:0")); /* switch off heater */
|
ERR_P(LscCmd(ser, "RANGE:0")); /* switch off heater */
|
||||||
/* reload curve cache: */
|
/* reload curve cache: */
|
||||||
if (cache!=NULL) free(cache);
|
if (cache!=NULL) free(cache);
|
||||||
@ -471,12 +536,8 @@ int ReadTemp() {
|
|||||||
noResp=0;
|
noResp=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ERR_P(LscCmd(ser,
|
ERR_I(ReadTemp());
|
||||||
"KRDG?[cryo.ch1]>cryo.t1;KRDG?[cryo.ch2]>cryo.t2;KRDG?[samp.ch1]>samp.t1;KRDG?[samp.ch2]>samp.t2"));
|
|
||||||
|
|
||||||
cryo.temp=WeightedAverage(cryo.nSens, cryo.t1, cryo.t2);
|
|
||||||
samp.temp=WeightedAverage(samp.nSens, samp.t1, samp.t2);
|
|
||||||
if (samp.temp==0.0) samp.temp=cryo.temp;
|
|
||||||
if (cryo.dirty==0 && samp.dirty==0 && noResp==0 && tim>logTime) {
|
if (cryo.dirty==0 && samp.dirty==0 && noResp==0 && tim>logTime) {
|
||||||
t2[0]=cryo.temp;
|
t2[0]=cryo.temp;
|
||||||
t2[1]=samp.temp;
|
t2[1]=samp.temp;
|
||||||
@ -512,24 +573,25 @@ int ReadTemp() {
|
|||||||
cryo.code1=3*decod[cod2 % 8] ^ 2*decod[cod1 % 8]; /* ^ is exclusive OR */
|
cryo.code1=3*decod[cod2 % 8] ^ 2*decod[cod1 % 8]; /* ^ is exclusive OR */
|
||||||
samp.code1=-(3*decod[cod2 / 8] ^ 2*decod[cod1 / 8]);
|
samp.code1=-(3*decod[cod2 / 8] ^ 2*decod[cod1 / 8]);
|
||||||
for (i=0; i<2; i++) {
|
for (i=0; i<2; i++) {
|
||||||
part=parts[i];
|
testpoint=testpoints[i];
|
||||||
if (part->code1!=part->code) {
|
if (testpoint->code1!=testpoint->code) {
|
||||||
part->code=part->code1;
|
testpoint->code=testpoint->code1;
|
||||||
part->codChanged=1;
|
testpoint->codChanged=1;
|
||||||
} else {
|
} else {
|
||||||
if (part->codChanged) {
|
if (testpoint->codChanged) {
|
||||||
part->codChanged=0;
|
testpoint->codChanged=0;
|
||||||
if (part->code1==0) {
|
if (testpoint->code1==0) {
|
||||||
logfileOut(LOG_MAIN, "unplugged X\n");
|
logfileOut(LOG_MAIN, "%s unplugged\n", testpoint->tname);
|
||||||
} else {
|
} else {
|
||||||
logfileOut(LOG_MAIN, "plugged (%d)\n", part->code1);
|
logfileOut(LOG_MAIN, "plugged %d on %s\n", testpoint->code1, testpoint->tname);
|
||||||
}
|
}
|
||||||
if (part->codDefined) {
|
if (testpoint->codDefined) {
|
||||||
part->manual=0;
|
testpoint->manual=0;
|
||||||
}
|
}
|
||||||
part->dirty=1;
|
testpoint->dirty=1;
|
||||||
|
if (!configuring) configuring=1;
|
||||||
}
|
}
|
||||||
part->codDefined=1;
|
testpoint->codDefined=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -550,31 +612,34 @@ int ReadTemp() {
|
|||||||
OnError: return(-1);
|
OnError: return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int inputSettings(Part *this) {
|
int inputSettings(Testpoint *this) {
|
||||||
|
|
||||||
part=this;
|
testpoint=this;
|
||||||
if (part->dirty && samp.codDefined) {
|
if (testpoint->dirty && samp.codDefined) {
|
||||||
if (busy==0 || cryo.dirty>=0 && part->dirty>=0) { /* do not enter when busy and cryo.dirty/P indicates error on last time */
|
if (busy==0 || cryo.dirty>=0 && testpoint->dirty>=0) { /* do not enter when busy and cryo.dirty/P indicates error on last time */
|
||||||
logfileOut(LOG_MAIN ,"configure inputs for ");
|
if (testpoint->manual) {
|
||||||
if (part->manual) {
|
logfileOut(LOG_MAIN ,"configure %s inputs for %s\n", testpoint->tname, testpoint->device);
|
||||||
logfileOut(LOG_MAIN ,"%s\n", part->device);
|
|
||||||
} else {
|
} else {
|
||||||
logfileOut(LOG_MAIN ,"%+d\n", part->code);
|
if (testpoint->code==0) {
|
||||||
|
logfileOut(LOG_MAIN ,"reset %s inputs\n", testpoint->tname);
|
||||||
|
} else {
|
||||||
|
logfileOut(LOG_MAIN ,"configure %s inputs for code %+d\n", testpoint->tname, testpoint->code);
|
||||||
}
|
}
|
||||||
if (part->dirty>0) part->try=0;
|
}
|
||||||
part->nSens=0;
|
if (testpoint->dirty>0) testpoint->try=0;
|
||||||
if (!part->manual) { part->device[0]='\0'; concatDevice(); }
|
testpoint->nSens=0;
|
||||||
part->dirty=configInput();
|
if (!testpoint->manual) { testpoint->device[0]='\0'; concatDevice(); }
|
||||||
if (part->dirty<0) {
|
testpoint->dirty=configInput();
|
||||||
part->try++;
|
if (testpoint->dirty<0) {
|
||||||
if (part->dirty!=-1 || part->try>3) {
|
testpoint->try++;
|
||||||
logfileShowErr("fatal error P");
|
if (testpoint->dirty!=-1 || testpoint->try>3) {
|
||||||
part->dirty=0; part->device[0]='\0'; concatDevice();
|
logfileShowErr("fatal error");
|
||||||
|
testpoint->dirty=0; testpoint->device[0]='\0'; concatDevice();
|
||||||
} else {
|
} else {
|
||||||
logfileShowErr("try again P");
|
logfileShowErr("try again");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ERR_P(LscCmd(ser, "ALARM [part.ch1]:[part.nSens],1,[tLimit],0,0,1;ALARM [part.ch2]:0;RELAY 1:1;BEEP:0"));
|
ERR_P(LscCmd(ser, "ALARM [testpoint.ch1]:[testpoint.nSens],1,[tLimit],0,0,1;ALARM [testpoint.ch2]:0;RELAY 1:1;BEEP:0"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -589,9 +654,9 @@ int Settings() {
|
|||||||
if (cryo.dirty && cryo.codDefined || samp.dirty && samp.codDefined) {
|
if (cryo.dirty && cryo.codDefined || samp.dirty && samp.codDefined) {
|
||||||
|
|
||||||
for (i=0; i<2; i++) {
|
for (i=0; i<2; i++) {
|
||||||
part=parts[i];
|
testpoint=testpoints[i];
|
||||||
if (part->dirty) {
|
if (testpoint->dirty) {
|
||||||
ERR_P(LscCmd(ser, "DISPFLD 2,[part.ch1],1;DISPFLD 4,[part.ch2],1"));
|
ERR_P(LscCmd(ser, "DISPFLD 2,[testpoint.ch1],1;DISPFLD 4,[testpoint.ch2],1"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inputSettings(&cryo);
|
inputSettings(&cryo);
|
||||||
@ -618,7 +683,7 @@ int Settings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
power=pw;
|
power=pw;
|
||||||
logfileOut(LOG_MAIN, "power %f\n", power, iAmp, iRange);
|
logfileOut(LOG_INFO, "power %f\n", power, iAmp, iRange);
|
||||||
ERR_P(LscCmd(ser, "CLIMIT 1:[tLimit],0,0,[iAmp],[iRange]"));
|
ERR_P(LscCmd(ser, "CLIMIT 1:[tLimit],0,0,[iAmp],[iRange]"));
|
||||||
tempC=0.001; tShift=0;
|
tempC=0.001; tShift=0;
|
||||||
ERR_I(SetTemp(1));
|
ERR_I(SetTemp(1));
|
||||||
@ -654,6 +719,7 @@ int ExecuteRequest() {
|
|||||||
char *t, *res;
|
char *t, *res;
|
||||||
struct CocClient *client;
|
struct CocClient *client;
|
||||||
|
|
||||||
|
if (readTemp) ReadTemp();
|
||||||
if (tim>auto_remote_time || setFlag) ERR_I(Settings());
|
if (tim>auto_remote_time || setFlag) ERR_I(Settings());
|
||||||
if (setFlag) {
|
if (setFlag) {
|
||||||
if (cryo.nSens>0) {
|
if (cryo.nSens>0) {
|
||||||
@ -674,6 +740,10 @@ int ExecuteRequest() {
|
|||||||
client->cmd[0]='\0';
|
client->cmd[0]='\0';
|
||||||
}
|
}
|
||||||
if (deviceFlag) {
|
if (deviceFlag) {
|
||||||
|
if (!configuring) {
|
||||||
|
str_copy(status, "configuring");
|
||||||
|
configuring=1;
|
||||||
|
}
|
||||||
t=strchr(device, '/');
|
t=strchr(device, '/');
|
||||||
if (t==NULL) {
|
if (t==NULL) {
|
||||||
if (0==strcmp(device, "0")) {
|
if (0==strcmp(device, "0")) {
|
||||||
@ -710,8 +780,7 @@ int mainBody(void)
|
|||||||
int i, iret, tdif;
|
int i, iret, tdif;
|
||||||
struct timeb tim1;
|
struct timeb tim1;
|
||||||
|
|
||||||
/* read & control temp */
|
ERR_I(PeriodicTask());
|
||||||
ERR_I(ReadTemp());
|
|
||||||
if (tim>=auto_remote_time) ERR_I(Settings());
|
if (tim>=auto_remote_time) ERR_I(Settings());
|
||||||
logfileWrite(logMask);
|
logfileWrite(logMask);
|
||||||
|
|
||||||
@ -731,7 +800,7 @@ int mainBody(void)
|
|||||||
tim0.time+=i / 1000;
|
tim0.time+=i / 1000;
|
||||||
tim0.millitm=i % 1000;
|
tim0.millitm=i % 1000;
|
||||||
if (tdif>1) {
|
if (tdif>1) {
|
||||||
logfileOut(LOG_MAIN ,"%d cycles lost\n", tdif-1);
|
logfileOut(LOG_INFO ,"%d cycles lost\n", tdif-1);
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
OnError:
|
OnError:
|
||||||
@ -751,21 +820,23 @@ int main(int argc, char *argv[])
|
|||||||
char buf[256], opt;
|
char buf[256], opt;
|
||||||
int port, msecTmo;
|
int port, msecTmo;
|
||||||
|
|
||||||
|
str_copy(cryo.tname,"main");
|
||||||
str_copy(cryo.ch1,"A");
|
str_copy(cryo.ch1,"A");
|
||||||
str_copy(cryo.ch2,"B");
|
str_copy(cryo.ch2,"B");
|
||||||
|
str_copy(samp.tname,"sample stick");
|
||||||
str_copy(samp.ch1,"C");
|
str_copy(samp.ch1,"C");
|
||||||
str_copy(samp.ch2,"D");
|
str_copy(samp.ch2,"D");
|
||||||
cryo.codChanged=1;
|
cryo.codChanged=1;
|
||||||
samp.codChanged=1;
|
samp.codChanged=1;
|
||||||
|
|
||||||
logMask=LOG_MAIN+LOG_WARN;
|
logMask=LOG_MAIN+LOG_INFO;
|
||||||
binDir="bin/";
|
binDir="bin/";
|
||||||
logDir="log/";
|
logDir="log/";
|
||||||
serverId="tecs";
|
serverId="tecs";
|
||||||
host="lnsp26";
|
host="lnsp26";
|
||||||
port=0;
|
port=0;
|
||||||
msecTmo=0;
|
msecTmo=0;
|
||||||
logfileOut(LOG_MAIN ,"%s ", argv[0]);
|
logfileOut(LOG_INFO ,"%s ", argv[0]);
|
||||||
for (i=1;i<argc;i++) {
|
for (i=1;i<argc;i++) {
|
||||||
if (argv[i]!=NULL) {
|
if (argv[i]!=NULL) {
|
||||||
if (argv[i][0]=='-') {
|
if (argv[i][0]=='-') {
|
||||||
@ -799,10 +870,10 @@ int main(int argc, char *argv[])
|
|||||||
i++;
|
i++;
|
||||||
port=atoi(argv[i]);
|
port=atoi(argv[i]);
|
||||||
} else {
|
} else {
|
||||||
logfileOut(LOG_MAIN ,"?");
|
logfileOut(LOG_INFO ,"?");
|
||||||
}
|
}
|
||||||
if (opt!=' ') logfileOut(LOG_MAIN ,"-%c ", opt);
|
if (opt!=' ') logfileOut(LOG_INFO ,"-%c ", opt);
|
||||||
logfileOut(LOG_MAIN ,"%s ", argv[i]);
|
logfileOut(LOG_INFO ,"%s ", argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (port==0) port=9753;
|
if (port==0) port=9753;
|
||||||
@ -811,22 +882,24 @@ int main(int argc, char *argv[])
|
|||||||
str_copy(buf, logDir);
|
str_copy(buf, logDir);
|
||||||
str_append(buf, serverId);
|
str_append(buf, serverId);
|
||||||
|
|
||||||
|
str_copy(status, "starting up");
|
||||||
|
logfileStatusBuf(status);
|
||||||
logfileInit(buf, logIt, use_stdout, logIt);
|
logfileInit(buf, logIt, use_stdout, logIt);
|
||||||
logfileOut(LOG_MAIN ,"\n");
|
logfileOut(LOG_INFO ,"\n");
|
||||||
logfileWrite(logMask);
|
logfileWrite(logMask);
|
||||||
|
|
||||||
ERR_I(CocInitServer(1024, port));
|
ERR_I(CocInitServer(1024, port));
|
||||||
|
|
||||||
CocDefStruct(cryo, Part);
|
CocDefStruct(cryo, Testpoint);
|
||||||
CocDefStruct(samp, Part);
|
CocDefStruct(samp, Testpoint);
|
||||||
CocDefPtr(part, Part);
|
CocDefPtr(testpoint, Testpoint);
|
||||||
|
|
||||||
CocFltFld(Part, temp, CocRD);
|
CocFltFld(Testpoint, temp, CocRD);
|
||||||
CocFltFld(Part, t1, CocRD);
|
CocFltFld(Testpoint, t1, CocRD);
|
||||||
CocFltFld(Part, t2, CocRD);
|
CocFltFld(Testpoint, t2, CocRD);
|
||||||
|
|
||||||
CocStrFld(Part, ch1, CocRD);
|
CocStrFld(Testpoint, ch1, CocRD);
|
||||||
CocStrFld(Part, ch2, CocRD);
|
CocStrFld(Testpoint, ch2, CocRD);
|
||||||
|
|
||||||
CocDefFlt(htr, CocRD);
|
CocDefFlt(htr, CocRD);
|
||||||
CocDefFlt(tempC, setFlag);
|
CocDefFlt(tempC, setFlag);
|
||||||
@ -845,6 +918,7 @@ int main(int argc, char *argv[])
|
|||||||
CocDefStr(head, CocRD);
|
CocDefStr(head, CocRD);
|
||||||
CocDefStr(chan, CocRD);
|
CocDefStr(chan, CocRD);
|
||||||
CocDefStr(intype, CocRD);
|
CocDefStr(intype, CocRD);
|
||||||
|
CocDefStr(status, CocRD);
|
||||||
|
|
||||||
CocDefInt(cod1, CocRD);
|
CocDefInt(cod1, CocRD);
|
||||||
CocDefInt(cod2, CocRD);
|
CocDefInt(cod2, CocRD);
|
||||||
@ -859,9 +933,11 @@ int main(int argc, char *argv[])
|
|||||||
CocDefInt(iRange, CocRD);
|
CocDefInt(iRange, CocRD);
|
||||||
CocDefInt(mode, CocRD);
|
CocDefInt(mode, CocRD);
|
||||||
|
|
||||||
|
CocDefInt(readTemp, CocWR);
|
||||||
CocDefInt(controlMode, CocWR);
|
CocDefInt(controlMode, CocWR);
|
||||||
CocDefInt(busy, CocRD);
|
CocDefInt(busy, CocRD);
|
||||||
CocDefInt(serialNo, CocRD);
|
CocDefInt(serialNo, CocRD);
|
||||||
|
CocDefInt(configuring, CocRD);
|
||||||
CocDefInt(quit, CocWR);
|
CocDefInt(quit, CocWR);
|
||||||
|
|
||||||
ERR_P(ser=SerOpen(host, msecTmo, idleHdl));
|
ERR_P(ser=SerOpen(host, msecTmo, idleHdl));
|
||||||
@ -873,10 +949,10 @@ int main(int argc, char *argv[])
|
|||||||
str_append(buf, ".dlog");
|
str_append(buf, ".dlog");
|
||||||
iret=DlogOpen(&dset, buf, 1);
|
iret=DlogOpen(&dset, buf, 1);
|
||||||
if (iret<0) {
|
if (iret<0) {
|
||||||
logfileOut(LOG_MAIN, "create data log file: %s\n", buf);
|
logfileOut(LOG_INFO, "create data log file: %s\n", buf);
|
||||||
ERR_I(DlogCreate(&dset, buf, tim0.time, 2, 7*24*60*60/logPeriod, logPeriod, 0.0));
|
ERR_I(DlogCreate(&dset, buf, tim0.time, 2, 7*24*60*60/logPeriod, logPeriod, 0.0));
|
||||||
} else {
|
} else {
|
||||||
logfileOut(LOG_MAIN, "opened data log file: %s\n", buf);
|
logfileOut(LOG_INFO, "opened data log file: %s\n", buf);
|
||||||
}
|
}
|
||||||
logfileWrite(logMask);
|
logfileWrite(logMask);
|
||||||
per=period;
|
per=period;
|
||||||
|
104
tecs/tecs_cli.c
104
tecs/tecs_cli.c
@ -1,12 +1,11 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fortify.h>
|
|
||||||
#include "err_handling.h"
|
#include "err_handling.h"
|
||||||
#include "str_util.h"
|
#include "str_util.h"
|
||||||
#include "tecs_cli.h"
|
#include "tecs_cli.h"
|
||||||
|
|
||||||
static char device[80], command[80];
|
static char device[80], command[80], buffer[132];
|
||||||
static int quit;
|
static int quit, readTemp, configuring;
|
||||||
static float tempX, tempP, tempC;
|
static float tempX, tempP, tempC;
|
||||||
|
|
||||||
pTecsClient TeccInit(char *startcmd, int port) {
|
pTecsClient TeccInit(char *startcmd, int port) {
|
||||||
@ -18,7 +17,10 @@ pTecsClient TeccInit(char *startcmd, int port) {
|
|||||||
CocDefFlt(tempP, CocRD);
|
CocDefFlt(tempP, CocRD);
|
||||||
CocDefFlt(tempX, CocRD);
|
CocDefFlt(tempX, CocRD);
|
||||||
CocDefStr(device, CocWR);
|
CocDefStr(device, CocWR);
|
||||||
|
CocDefStr(buffer, CocWR);
|
||||||
|
CocDefInt(configuring, CocRD);
|
||||||
CocDefInt(quit, CocWR);
|
CocDefInt(quit, CocWR);
|
||||||
|
CocDefInt(readTemp, CocWR);
|
||||||
CocDefCmd(command);
|
CocDefCmd(command);
|
||||||
|
|
||||||
return((pTecsClient)conn);
|
return((pTecsClient)conn);
|
||||||
@ -39,17 +41,37 @@ char *TeccGetDev(pTecsClient conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int TeccGet3(pTecsClient conn, float *tC, float *tX, float *tP) {
|
int TeccGet3(pTecsClient conn, float *tC, float *tX, float *tP) {
|
||||||
ERR_I(CocCmd(conn, "tempC,tempX,tempP"));
|
readTemp=1;
|
||||||
|
ERR_I(CocCmd(conn, "tempC,tempX,tempP,[readTemp],configuring"));
|
||||||
*tC=tempC;
|
*tC=tempC;
|
||||||
*tX=tempX;
|
*tX=tempX;
|
||||||
*tP=tempP;
|
*tP=tempP;
|
||||||
return(0);
|
return(configuring);
|
||||||
OnError: return(-1);
|
OnError: return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TeccGet(pTecsClient conn, float *temp) {
|
int TeccGet(pTecsClient conn, float *temp) {
|
||||||
ERR_I(CocCmd(conn, "tempP"));
|
ERR_I(CocCmd(conn, "tempP,[readTemp],configuring"));
|
||||||
*temp=tempP;
|
*temp=tempP;
|
||||||
|
return(configuring);
|
||||||
|
OnError: return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int TeccWait(pTecsClient conn) {
|
||||||
|
int last, cnt;
|
||||||
|
last=0;
|
||||||
|
cnt=0;
|
||||||
|
do {
|
||||||
|
CocDelay(100);
|
||||||
|
ERR_I(CocCmd(conn, "configuring"));
|
||||||
|
if (configuring==last || configuring>1000) {
|
||||||
|
cnt++;
|
||||||
|
if (cnt>50) ERR_MSG("configuring timeout");
|
||||||
|
} else {
|
||||||
|
cnt=0;
|
||||||
|
last=configuring;
|
||||||
|
}
|
||||||
|
} while (configuring>0);
|
||||||
return(0);
|
return(0);
|
||||||
OnError: return(-1);
|
OnError: return(-1);
|
||||||
}
|
}
|
||||||
@ -61,6 +83,26 @@ int TeccSet(pTecsClient conn, float temp) {
|
|||||||
OnError: return(-1);
|
OnError: return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *TeccGetPar(pTecsClient conn, const char *name) {
|
||||||
|
CocDefVar(name, buffer, sizeof(buffer), &CocWR);
|
||||||
|
ERR_I(CocCmd(conn, name));
|
||||||
|
return(buffer);
|
||||||
|
OnError: return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int TeccSetPar(pTecsClient conn, const char *name, const char *value) {
|
||||||
|
char nbuf[80];
|
||||||
|
|
||||||
|
str_copy(buffer, value);
|
||||||
|
CocDefVar(name, buffer, sizeof(buffer), &CocWR);
|
||||||
|
str_copy(nbuf, "[");
|
||||||
|
str_append(nbuf, name);
|
||||||
|
str_append(nbuf, "]");
|
||||||
|
ERR_I(CocCmd(conn, nbuf));
|
||||||
|
return(0);
|
||||||
|
OnError: return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
int TeccSend(pTecsClient conn, char *cmd, char *reply, int replyLen) {
|
int TeccSend(pTecsClient conn, char *cmd, char *reply, int replyLen) {
|
||||||
char *res;
|
char *res;
|
||||||
int cnt;
|
int cnt;
|
||||||
@ -99,46 +141,62 @@ void TeccClose(pTecsClient conn) {
|
|||||||
|
|
||||||
#ifdef __VMS
|
#ifdef __VMS
|
||||||
|
|
||||||
int TeccSetDevVms(pTecsClient conn, char **dev) {
|
typedef struct { short size, dummy; char *text; } Desc;
|
||||||
|
|
||||||
|
int TeccSetParVms(pTecsClient conn, Desc *name, Desc *par) {
|
||||||
|
char nbuf[80];
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
l=*(short *)dev;
|
l=par->size;
|
||||||
if (l>=sizeof(device)) l=sizeof(device)-1;
|
if (l>=sizeof(nbuf)) l=sizeof(nbuf)-3;
|
||||||
strncpy(device, dev[1], l);
|
strcpy(nbuf, "[");
|
||||||
while (l>0 && device[l-1]==' ') l--; /* trim */
|
strncat(nbuf, par->text, l);
|
||||||
device[l]='\0';
|
while (l>0 && nbuf[l-1]==' ') l--; /* trim */
|
||||||
ERR_I(CocCmd(conn, "[device]"));
|
strcat(nbuf, "]");
|
||||||
|
|
||||||
|
CocDefVar(nbuf, buffer, sizeof(buffer), &CocWR);
|
||||||
|
ERR_I(CocCmd(conn, nbuf));
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
OnError: return(-1);
|
OnError: return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TeccGetDevVms(pTecsClient conn, char **dev) {
|
int TeccGetParVms(pTecsClient conn, Desc *name, Desc *par) {
|
||||||
int l, ld;
|
int l, ld;
|
||||||
|
char nbuf[64];
|
||||||
|
|
||||||
ERR_I(CocCmd(conn, "device"));
|
l=par->size;
|
||||||
ld=strlen(device);
|
if (l>=sizeof(nbuf)) l=sizeof(nbuf)-1;
|
||||||
l=*(short *)dev;
|
strncpy(nbuf, par->text, l);
|
||||||
|
while (l>0 && nbuf[l-1]==' ') l--; /* trim */
|
||||||
|
|
||||||
|
CocDefVar(nbuf, buffer, sizeof(buffer), &CocWR);
|
||||||
|
ERR_I(CocCmd(conn, nbuf));
|
||||||
|
|
||||||
|
ld=strlen(buffer);
|
||||||
|
l=par->size;
|
||||||
if (ld>=l) ld=l;
|
if (ld>=l) ld=l;
|
||||||
strncpy(dev[1], device, ld);
|
strncpy(par->text, buffer, ld);
|
||||||
return(ld);
|
return(ld);
|
||||||
OnError: return(-1);
|
OnError: return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TeccSendVms(pTecsClient conn, char **cmd, char **reply) {
|
int TeccSendVms(pTecsClient conn, Desc *cmd, Desc *reply) {
|
||||||
int l, lr;
|
int l, lr;
|
||||||
char cbuf[80], rbuf[80];
|
char cbuf[80], rbuf[80];
|
||||||
|
|
||||||
l=*(short *)cmd;
|
l=cmd->size;
|
||||||
if (l>=sizeof(cbuf)) l=sizeof(cbuf)-1;
|
if (l>=sizeof(cbuf)) l=sizeof(cbuf)-1;
|
||||||
strncpy(cbuf, cmd[1], l);
|
strncpy(cbuf, cmd->text, l);
|
||||||
while (l>0 && cbuf[l-1]==' ') l--; /* trim */
|
while (l>0 && cbuf[l-1]==' ') l--; /* trim */
|
||||||
cbuf[l]='\0';
|
cbuf[l]='\0';
|
||||||
ERR_I(TeccSend(conn, cbuf, rbuf, sizeof(rbuf)));
|
ERR_I(TeccSend(conn, cbuf, rbuf, sizeof(rbuf)));
|
||||||
lr=strlen(rbuf);
|
lr=strlen(rbuf);
|
||||||
l=*(short *)reply;
|
l=reply->size;
|
||||||
if (lr>=l) lr=l;
|
if (lr>=l) lr=l;
|
||||||
strncpy(reply[1], rbuf, lr);
|
strncpy(reply->text, rbuf, lr);
|
||||||
return(lr);
|
return(lr);
|
||||||
OnError: return(-1);
|
OnError: return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,14 +15,6 @@ pTecsClient TeccInit(char *server, int port);
|
|||||||
/* init tecs client (connect to server)
|
/* init tecs client (connect to server)
|
||||||
------------------------------------------------------------------------*/
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
int TeccSetDev(pTecsClient conn, char *dev);
|
|
||||||
/* set device type
|
|
||||||
------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
char *TeccGetDev(pTecsClient conn);
|
|
||||||
/* get device type
|
|
||||||
------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
int TeccGet(pTecsClient conn, float *temp);
|
int TeccGet(pTecsClient conn, float *temp);
|
||||||
/* set temperature
|
/* set temperature
|
||||||
------------------------------------------------------------------------*/
|
------------------------------------------------------------------------*/
|
||||||
@ -31,6 +23,18 @@ int TeccSet(pTecsClient conn, float temp);
|
|||||||
/* get temperature
|
/* get temperature
|
||||||
------------------------------------------------------------------------*/
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
char *TeccGetPar(pTecsClient conn, const char *name);
|
||||||
|
/* get any parameter from tecs
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int TeccSetPar(pTecsClient conn, const char *name, const char *value);
|
||||||
|
/* set any parameter of tecs
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int TeccWait(pTecsClient conn);
|
||||||
|
/* wait until the controller is configured
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
int TeccSend(pTecsClient conn, char *cmd, char *reply, int replyLen);
|
int TeccSend(pTecsClient conn, char *cmd, char *reply, int replyLen);
|
||||||
/* send a command transparently to the controller
|
/* send a command transparently to the controller
|
||||||
replyLen is the maximal length of reply
|
replyLen is the maximal length of reply
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <fortify.h>
|
|
||||||
#include "err_handling.h"
|
#include "err_handling.h"
|
||||||
#include "str_util.h"
|
#include "str_util.h"
|
||||||
#include "tecs_dlog.h"
|
#include "tecs_dlog.h"
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <fortify.h>
|
|
||||||
#include "err_handling.h"
|
#include "err_handling.h"
|
||||||
#include "coc_logfile.h"
|
#include "coc_logfile.h"
|
||||||
#include "coc_util.h"
|
#include "coc_util.h"
|
||||||
@ -32,7 +31,7 @@ int LscEqPar(char *par, char *res) {
|
|||||||
i1=sscanf(pbuf, "%f", &f1);
|
i1=sscanf(pbuf, "%f", &f1);
|
||||||
i2=sscanf(rbuf, "%f", &f2);
|
i2=sscanf(rbuf, "%f", &f2);
|
||||||
if (i1!=1 || i2!=1 || abs(f1-f2)>1e-4+abs(f1)*5e-6) {
|
if (i1!=1 || i2!=1 || abs(f1-f2)>1e-4+abs(f1)*5e-6) {
|
||||||
logfileOut(LOG_WARN, "%s#%s\n", pbuf, rbuf);
|
logfileOut(LOG_INFO, "%s#%s\n", pbuf, rbuf);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,7 +70,7 @@ char *LscCmd(SerChannel *ser, const char *cmds) {
|
|||||||
ERR_I(str_put_str(&sbuf, seg));
|
ERR_I(str_put_str(&sbuf, seg));
|
||||||
while (p!=NULL) { /* substitute variables */
|
while (p!=NULL) { /* substitute variables */
|
||||||
p=str_split(varname, p, ']');
|
p=str_split(varname, p, ']');
|
||||||
if (p==NULL) ERR_MSG("missing '\'");
|
if (p==NULL) ERR_MSG("missing ']'");
|
||||||
ERR_I(CocPutVar(serverVarList, &sbuf, varname, 0));
|
ERR_I(CocPutVar(serverVarList, &sbuf, varname, 0));
|
||||||
p=str_split(seg, p, '[');
|
p=str_split(seg, p, '[');
|
||||||
ERR_I(str_put_str(&sbuf, seg));
|
ERR_I(str_put_str(&sbuf, seg));
|
||||||
@ -116,7 +115,7 @@ char *LscCmd(SerChannel *ser, const char *cmds) {
|
|||||||
buf[sbuf.wrpos-1]='\0'; /* strip off trailing ";" */
|
buf[sbuf.wrpos-1]='\0'; /* strip off trailing ";" */
|
||||||
}
|
}
|
||||||
ERR_P(res=SerCmd(ser, buf));
|
ERR_P(res=SerCmd(ser, buf));
|
||||||
if (0==strcmp("?TMO", res)) ERR_MSG("timeout");
|
if (0==strncmp("?TMO", res, 4)) ERR_MSG("timeout");
|
||||||
/*
|
/*
|
||||||
list[0..nres-1] contains a now:
|
list[0..nres-1] contains a now:
|
||||||
for a command with return request:
|
for a command with return request:
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fortify.h>
|
|
||||||
#include "rs232c_def.h"
|
#include "rs232c_def.h"
|
||||||
#include "asynsrv_def.h"
|
#include "asynsrv_def.h"
|
||||||
#include "sinq_prototypes.h"
|
#include "sinq_prototypes.h"
|
||||||
|
Reference in New Issue
Block a user