diff --git a/tecs/coc_client.c b/tecs/coc_client.c index 545a6db4..a52b0c68 100644 --- a/tecs/coc_client.c +++ b/tecs/coc_client.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include diff --git a/tecs/coc_logfile.c b/tecs/coc_logfile.c index cfe24ca0..802fcfd4 100644 --- a/tecs/coc_logfile.c +++ b/tecs/coc_logfile.c @@ -17,7 +17,6 @@ #include #include #include -#include #include "coc_logfile.h" #include "err_handling.h" #include "str_util.h" @@ -25,17 +24,19 @@ static FILE *fil=NULL; static char lnam[256]="", filnam[256]=""; static char ebuf[20000]=""; +static char *statusBuf=NULL; +static int statusSize; static char *eptr=&ebuf[0]; static int lastStamp=0; static int notDated=0; static int logMask=0; static int wrtMask=0; - -int ftime (struct timeb *__timeptr); /* for some reason not defined in timeb.h with flag -std1 */ - +static int newLine=1; static int logfileStd; static int dirty, writeAll; +int ftime (struct timeb *__timeptr); /* for some reason not defined in timeb.h with flag -std1 */ + void logfileOpen(int first) { struct tm *tim; struct timeb btim; @@ -74,6 +75,12 @@ void logfileOpen(int first) { fil=fopen(filnam, "a"); } #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) { @@ -87,10 +94,26 @@ void logfileInit(char *path, int nodate, int use_stdout, int write_all) { void logfileOut(int mask, const char *fmt, ...) { va_list ap; + char buf[256], *p; assert(mask>0 && mask<32); 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) { #ifdef __VMS if (fil==NULL) logfileOpen(0); @@ -203,7 +226,7 @@ void logfileClose() #ifdef __VMS if (fil==NULL) logfileOpen(0); #endif - logfileWrite0(LOG_MAIN+LOG_WARN); + logfileWrite0(LOG_MAIN+LOG_INFO); lastStamp-=1; logfileStamp(); if (fil!=NULL) { fclose(fil); fil=NULL; } diff --git a/tecs/coc_logfile.h b/tecs/coc_logfile.h index fdf9791a..a1c92ea1 100644 --- a/tecs/coc_logfile.h +++ b/tecs/coc_logfile.h @@ -6,9 +6,11 @@ #define LOG_ALL 31 #define LOG_SER 8 #define LOG_NET 4 -#define LOG_WARN 2 +#define LOG_INFO 2 #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 logfileOut(int mask, const char *fmt, ...); void logfileOutBuf(int mask, Str_Buf *buf); diff --git a/tecs/coc_server.c b/tecs/coc_server.c index b5e31078..9c8c2578 100644 --- a/tecs/coc_server.c +++ b/tecs/coc_server.c @@ -19,7 +19,6 @@ #include "coc_logfile.h" #include "coc_server.h" #include "str_util.h" -#include 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_I(CocCreateSockAdr(&sadr, NULL, port)); 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)); FD_ZERO(&mask); FD_SET(mainFd, &mask); @@ -86,9 +85,9 @@ int CocHandle1Request(int tmo_msec, int fd) { cList->next=cl; h=gethostbyaddr(&cadr.sin_addr, 4, AF_INET); if (h==NULL) { - logfileOut(LOG_MAIN, "(%d) open from %s\n", newfd, "local"); + logfileOut(LOG_INFO, "(%d) open from %s\n", newfd, "local"); } 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 { cl0=cList; cl=cl0->next; @@ -96,7 +95,7 @@ int CocHandle1Request(int tmo_msec, int fd) { if (FD_ISSET(cl->fd, &rmask)) { buf->wrpos=recv(cl->fd, buf->buf, buf->dsize, 0); if (buf->wrpos<=0) { - logfileOut(LOG_MAIN, "(%d) disconnected\n",cl->fd); + logfileOut(LOG_INFO, "(%d) disconnected\n",cl->fd); close(cl->fd); FD_CLR(cl->fd, &mask); cl0->next=cl->next; @@ -113,10 +112,10 @@ int CocHandle1Request(int tmo_msec, int fd) { logfileOut(LOG_NET, "(%d) ", cl->fd); if (varname[0]=='#') { /* access code */ if (0==strcmp(varname,"#rdacc")) { - logfileOut(LOG_MAIN, "set read mode\n"); + logfileOut(LOG_INFO, "set read mode\n"); cl->mode=1; } else if (0==strcmp(varname,"#rwacs")) { - logfileOut(LOG_MAIN, "set write mode\n"); + logfileOut(LOG_INFO, "set write mode\n"); cl->mode=2; } else { err="bad access code"; diff --git a/tecs/coc_util.c b/tecs/coc_util.c index 216ba72c..efce5ded 100644 --- a/tecs/coc_util.c +++ b/tecs/coc_util.c @@ -7,7 +7,6 @@ #include #include #include -#include #include "err_handling.h" #include "str_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->type=type; p->flag=flag; +/* printf("define %s %d\n", name, (int)var); */ 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 (var->flag==&CocRD) ERR_MSG("variable is read only"); } + /* printf("get %s %d\n", name, (int)adr); */ if (var->type==-1) { ERR_I(str_get_int(buf, (int *)adr)); } else if (var->type==-2) { @@ -208,9 +209,10 @@ int CocPutVar(CocVar *varList, Str_Buf *buf, const char *name, int secure) { } else { 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"); } + /* printf("put %s %d\n", name, (int)adr); */ if (var->type==-1) { ERR_I(str_put_int(buf, *(int *)adr)); } else if (var->type==-2) { diff --git a/tecs/err_handling.c b/tecs/err_handling.c index eafb75e2..e7d06669 100644 --- a/tecs/err_handling.c +++ b/tecs/err_handling.c @@ -1,8 +1,7 @@ #include #include #include -#include -#include + #include "err_handling.h" #define SLEN 64 @@ -73,11 +72,16 @@ void ErrSetOutRtn(void (*rtn)(), void *arg) { outarg=arg; } +void ErrSetOutFile(FILE *arg) { + outrtn=ErrOutFil; + outarg=arg; +} + #ifdef __VMS typedef struct { short size, dummy; char *text; } Desc; -void ErrShowVms(Desc *desc, void (*outrtn)(), void *arg) { +void ErrShowVms(Desc *desc) { char buf[256]; int l; diff --git a/tecs/err_handling.h b/tecs/err_handling.h index 75303362..88110dee 100644 --- a/tecs/err_handling.h +++ b/tecs/err_handling.h @@ -1,6 +1,7 @@ #ifndef _ERR_HANDLING_H_ #define _ERR_HANDLING_H_ +#include #include /* ErrHDL Error handling utilities @@ -76,6 +77,8 @@ void ErrCod(int code); void ErrWrite(char *text); void ERR_EXIT(char *text); void ErrLog(char *text); +void ErrSetOutRtn(void (*rtn)(), void *arg); +void ErrSetOutFile(FILE *file); extern int ErrCode; extern char *ErrMessage; diff --git a/tecs/str_buf.c b/tecs/str_buf.c index 5c6ae052..aa135d9b 100644 --- a/tecs/str_buf.c +++ b/tecs/str_buf.c @@ -4,7 +4,6 @@ #include #include #include -#include #include "err_handling.h" #include "str_util.h" #include "str_buf.h" diff --git a/tecs/str_util.c b/tecs/str_util.c index c8f8614a..9d4346ce 100644 --- a/tecs/str_util.c +++ b/tecs/str_util.c @@ -7,7 +7,6 @@ #include #include #include -#include #include "err_handling.h" #include "str_util.h" diff --git a/tecs/tecs.c b/tecs/tecs.c index 07af6d2d..219832fa 100644 --- a/tecs/tecs.c +++ b/tecs/tecs.c @@ -5,7 +5,6 @@ #include #include #include -#include #include "err_handling.h" #include "coc_server.h" #include "coc_logfile.h" @@ -13,8 +12,9 @@ #include "tecs_lsc.h" #include "tecs_dlog.h" -#define TABLE_FILE "lsc.tab" +#define TABLE_FILE "lsci.tab" #define NO_CODE 999 +#define Progress(I) if (configuring) { configuring+=I; } static SerChannel *ser=NULL; static char *serverId=NULL; @@ -33,13 +33,14 @@ typedef struct { int codDefined; /* code is not yet confirmed */ char ch1[2], ch2[2]; /* channels for high/low T */ 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) */ samp, /* data for extra sensors of sample stick */ - *parts[2]={&cryo, &samp}, - *part=&cryo; + *testpoints[2]={&cryo, &samp}, + *testpoint=&cryo; static float tempC, /* set T */ @@ -68,7 +69,9 @@ static int fld, /* field number */ key, /* key status */ serialNo, - resist, + configuring=1, + resist, /* heater resistance */ + readTemp, /* client requested readTemp */ cod1, cod2, out1, out2, /* codes read from digital input/output */ iRange, iAmp, /* max. range and max. current code */ 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 char + status[132], /* status buffer */ device[32], /* concatenated device names */ buf1[256], buf2[256], buf3[256], buf4[256], /* buffers for temporary use */ head[64], /* curve header */ intype[64], /* input configuration */ - chan[2], /* actual channel */ - xxxx; + chan[2]; /* actual channel */ static char *table=NULL, /* environment devices table */ @@ -216,6 +219,7 @@ int instCurve(char *nam, char *channel) { logfileOut(LOG_MAIN, "download curve %d\n", num); /* select sensor type first to display sensor units */ ERR_P(LscCmd(ser, "INTYPE [chan]:[intype];DISPFLD [fld],[chan],3;DISPLAY:[maxfld]")); + Progress(1); n=3; do { @@ -227,11 +231,15 @@ int instCurve(char *nam, char *channel) { if (i!=0) ERR_MSG("can not delete curve"); sprintf(lbuf, "CRVPT %d", num); + i=0; do { /* download curve */ t=str_split(nbuf, points, '\n'); if (nbuf[0]!='\0') { ERR_I(str_substitute(buf, nbuf, "#0", lbuf)); ERR_P(LscCmd(ser, buf)); + i++; + if (i%10==0) sprintf(status, "downloading curve at line %d", i); + Progress(1); } points=t; } while (t!=NULL); @@ -239,6 +247,7 @@ int instCurve(char *nam, char *channel) { /* write header, select curve */ str_upcase(head, chead); 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); saveTime=tim+30; } @@ -288,11 +297,11 @@ int configInput() { char *ext; retstat=-2; /* errors in following section are severe */ - if (part->manual) { - sprintf(buf, ".%s.", part->device); + if (testpoint->manual) { + sprintf(buf, "'%s'", testpoint->device); } else { - sprintf(buf, "%+d ", part->code); - if (part->code==0) return(0); + sprintf(buf, "%+d ", testpoint->code); + if (testpoint->code==0) return(0); } if (table!=NULL && tim>tableTime+60) { free(table); table=NULL; }; /* clear old table */ if (table==NULL) { /* read table */ @@ -305,38 +314,38 @@ int configInput() { t=strstr(table, buf); if (t==NULL) ERR_MSG("device not found"); i=sscanf(t, "%79[^\n!]", buf); /* read line */ - t=strchr(buf, '.'); - if (t==NULL) ERR_MSG("missing '.' in table file"); + t=strchr(buf, '\''); + if (t==NULL) ERR_MSG("missing ' in table file"); t++; n=1; - if (part==&samp) { + if (testpoint==&samp) { samp.nSens=0; i=sscanf(t, "%12s%d%d", nam, &nn, &n); if (i<1) ERR_MSG("missing sensor name"); - ext="s"; + ext=".s"; } else { cryo.nSens=0; tLow=0; tHigh=0; controlMode=0; 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"); - ext="x"; + ext=".x"; } if (n<0 || n>2) ERR_MSG("illegal value for nsensor"); if (n==0) return(0); - if (!part->manual) { /* set device name */ - str_copy(part->device, nam); - part->device[strlen(part->device)-1]='\0'; /* strip off '.' */ + nam[strlen(nam)-1]='\0'; /* strip off quote */ + if (!testpoint->manual) { /* set device name */ + str_copy(testpoint->device, nam); concatDevice(); } str_append(nam, ext); - ERR_I(retstat=instCurve(nam, part->ch1)); + ERR_I(retstat=instCurve(nam, testpoint->ch1)); if (n==2) { 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); OnError: return(retstat); } @@ -363,6 +372,7 @@ int loadCache() { bufi[3]=buf4; 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); + Progress(1); ERR_P(LscCmd(ser, buf)); k=0; for (j=i; j>i-4; j--) { @@ -434,6 +444,57 @@ int SetTemp(int switchOn) { } 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 *res; int i, k; @@ -451,8 +512,12 @@ int ReadTemp() { ERR_P(LscCmd(ser, "*IDN?>buf1,buf2,serialNo,")); if (0!=strcmp(buf1, "LSCI") || 0!=strcmp(buf2, "MODEL340") || serialNo==0) return(0); if (k!=serialNo) { - if (cryo.manual || cryo.code!=0) cryo.dirty=1; - if (samp.manual || samp.code!=0) samp.dirty=1; + if (!configuring) { + 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 */ /* reload curve cache: */ if (cache!=NULL) free(cache); @@ -471,12 +536,8 @@ int ReadTemp() { noResp=0; } - ERR_P(LscCmd(ser, - "KRDG?[cryo.ch1]>cryo.t1;KRDG?[cryo.ch2]>cryo.t2;KRDG?[samp.ch1]>samp.t1;KRDG?[samp.ch2]>samp.t2")); + ERR_I(ReadTemp()); - 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) { t2[0]=cryo.temp; t2[1]=samp.temp; @@ -512,24 +573,25 @@ int ReadTemp() { cryo.code1=3*decod[cod2 % 8] ^ 2*decod[cod1 % 8]; /* ^ is exclusive OR */ samp.code1=-(3*decod[cod2 / 8] ^ 2*decod[cod1 / 8]); for (i=0; i<2; i++) { - part=parts[i]; - if (part->code1!=part->code) { - part->code=part->code1; - part->codChanged=1; + testpoint=testpoints[i]; + if (testpoint->code1!=testpoint->code) { + testpoint->code=testpoint->code1; + testpoint->codChanged=1; } else { - if (part->codChanged) { - part->codChanged=0; - if (part->code1==0) { - logfileOut(LOG_MAIN, "unplugged X\n"); + if (testpoint->codChanged) { + testpoint->codChanged=0; + if (testpoint->code1==0) { + logfileOut(LOG_MAIN, "%s unplugged\n", testpoint->tname); } else { - logfileOut(LOG_MAIN, "plugged (%d)\n", part->code1); + logfileOut(LOG_MAIN, "plugged %d on %s\n", testpoint->code1, testpoint->tname); } - if (part->codDefined) { - part->manual=0; + if (testpoint->codDefined) { + 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); } -int inputSettings(Part *this) { +int inputSettings(Testpoint *this) { - part=this; - if (part->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 */ - logfileOut(LOG_MAIN ,"configure inputs for "); - if (part->manual) { - logfileOut(LOG_MAIN ,"%s\n", part->device); + testpoint=this; + if (testpoint->dirty && samp.codDefined) { + if (busy==0 || cryo.dirty>=0 && testpoint->dirty>=0) { /* do not enter when busy and cryo.dirty/P indicates error on last time */ + if (testpoint->manual) { + logfileOut(LOG_MAIN ,"configure %s inputs for %s\n", testpoint->tname, testpoint->device); } else { - logfileOut(LOG_MAIN ,"%+d\n", part->code); - } - if (part->dirty>0) part->try=0; - part->nSens=0; - if (!part->manual) { part->device[0]='\0'; concatDevice(); } - part->dirty=configInput(); - if (part->dirty<0) { - part->try++; - if (part->dirty!=-1 || part->try>3) { - logfileShowErr("fatal error P"); - part->dirty=0; part->device[0]='\0'; concatDevice(); + if (testpoint->code==0) { + logfileOut(LOG_MAIN ,"reset %s inputs\n", testpoint->tname); } else { - logfileShowErr("try again P"); + logfileOut(LOG_MAIN ,"configure %s inputs for code %+d\n", testpoint->tname, testpoint->code); + } + } + if (testpoint->dirty>0) testpoint->try=0; + testpoint->nSens=0; + if (!testpoint->manual) { testpoint->device[0]='\0'; concatDevice(); } + testpoint->dirty=configInput(); + if (testpoint->dirty<0) { + testpoint->try++; + if (testpoint->dirty!=-1 || testpoint->try>3) { + logfileShowErr("fatal error"); + testpoint->dirty=0; testpoint->device[0]='\0'; concatDevice(); + } else { + logfileShowErr("try again"); } } 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) { for (i=0; i<2; i++) { - part=parts[i]; - if (part->dirty) { - ERR_P(LscCmd(ser, "DISPFLD 2,[part.ch1],1;DISPFLD 4,[part.ch2],1")); + testpoint=testpoints[i]; + if (testpoint->dirty) { + ERR_P(LscCmd(ser, "DISPFLD 2,[testpoint.ch1],1;DISPFLD 4,[testpoint.ch2],1")); } } inputSettings(&cryo); @@ -618,7 +683,7 @@ int Settings() { } } 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]")); tempC=0.001; tShift=0; ERR_I(SetTemp(1)); @@ -654,6 +719,7 @@ int ExecuteRequest() { char *t, *res; struct CocClient *client; + if (readTemp) ReadTemp(); if (tim>auto_remote_time || setFlag) ERR_I(Settings()); if (setFlag) { if (cryo.nSens>0) { @@ -674,6 +740,10 @@ int ExecuteRequest() { client->cmd[0]='\0'; } if (deviceFlag) { + if (!configuring) { + str_copy(status, "configuring"); + configuring=1; + } t=strchr(device, '/'); if (t==NULL) { if (0==strcmp(device, "0")) { @@ -710,8 +780,7 @@ int mainBody(void) int i, iret, tdif; struct timeb tim1; - /* read & control temp */ - ERR_I(ReadTemp()); + ERR_I(PeriodicTask()); if (tim>=auto_remote_time) ERR_I(Settings()); logfileWrite(logMask); @@ -731,7 +800,7 @@ int mainBody(void) tim0.time+=i / 1000; tim0.millitm=i % 1000; if (tdif>1) { - logfileOut(LOG_MAIN ,"%d cycles lost\n", tdif-1); + logfileOut(LOG_INFO ,"%d cycles lost\n", tdif-1); } return(0); OnError: @@ -751,21 +820,23 @@ int main(int argc, char *argv[]) char buf[256], opt; int port, msecTmo; + str_copy(cryo.tname,"main"); str_copy(cryo.ch1,"A"); str_copy(cryo.ch2,"B"); + str_copy(samp.tname,"sample stick"); str_copy(samp.ch1,"C"); str_copy(samp.ch2,"D"); cryo.codChanged=1; samp.codChanged=1; - logMask=LOG_MAIN+LOG_WARN; + logMask=LOG_MAIN+LOG_INFO; binDir="bin/"; logDir="log/"; serverId="tecs"; host="lnsp26"; port=0; msecTmo=0; - logfileOut(LOG_MAIN ,"%s ", argv[0]); + logfileOut(LOG_INFO ,"%s ", argv[0]); for (i=1;i #include -#include #include "err_handling.h" #include "str_util.h" #include "tecs_cli.h" -static char device[80], command[80]; -static int quit; +static char device[80], command[80], buffer[132]; +static int quit, readTemp, configuring; static float tempX, tempP, tempC; pTecsClient TeccInit(char *startcmd, int port) { @@ -18,7 +17,10 @@ pTecsClient TeccInit(char *startcmd, int port) { CocDefFlt(tempP, CocRD); CocDefFlt(tempX, CocRD); CocDefStr(device, CocWR); + CocDefStr(buffer, CocWR); + CocDefInt(configuring, CocRD); CocDefInt(quit, CocWR); + CocDefInt(readTemp, CocWR); CocDefCmd(command); return((pTecsClient)conn); @@ -39,17 +41,37 @@ char *TeccGetDev(pTecsClient conn) { } 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; *tX=tempX; *tP=tempP; - return(0); + return(configuring); OnError: return(-1); } int TeccGet(pTecsClient conn, float *temp) { - ERR_I(CocCmd(conn, "tempP")); + ERR_I(CocCmd(conn, "tempP,[readTemp],configuring")); *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); OnError: return(-1); } @@ -61,6 +83,26 @@ int TeccSet(pTecsClient conn, float temp) { 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) { char *res; int cnt; @@ -99,46 +141,62 @@ void TeccClose(pTecsClient conn) { #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; - l=*(short *)dev; - if (l>=sizeof(device)) l=sizeof(device)-1; - strncpy(device, dev[1], l); - while (l>0 && device[l-1]==' ') l--; /* trim */ - device[l]='\0'; - ERR_I(CocCmd(conn, "[device]")); + l=par->size; + if (l>=sizeof(nbuf)) l=sizeof(nbuf)-3; + strcpy(nbuf, "["); + strncat(nbuf, par->text, l); + while (l>0 && nbuf[l-1]==' ') l--; /* trim */ + strcat(nbuf, "]"); + + CocDefVar(nbuf, buffer, sizeof(buffer), &CocWR); + ERR_I(CocCmd(conn, nbuf)); + return(0); OnError: return(-1); } -int TeccGetDevVms(pTecsClient conn, char **dev) { +int TeccGetParVms(pTecsClient conn, Desc *name, Desc *par) { int l, ld; + char nbuf[64]; - ERR_I(CocCmd(conn, "device")); - ld=strlen(device); - l=*(short *)dev; + l=par->size; + if (l>=sizeof(nbuf)) l=sizeof(nbuf)-1; + 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; - strncpy(dev[1], device, ld); + strncpy(par->text, buffer, ld); return(ld); OnError: return(-1); } -int TeccSendVms(pTecsClient conn, char **cmd, char **reply) { +int TeccSendVms(pTecsClient conn, Desc *cmd, Desc *reply) { int l, lr; char cbuf[80], rbuf[80]; - l=*(short *)cmd; + l=cmd->size; 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 */ cbuf[l]='\0'; ERR_I(TeccSend(conn, cbuf, rbuf, sizeof(rbuf))); lr=strlen(rbuf); - l=*(short *)reply; + l=reply->size; if (lr>=l) lr=l; - strncpy(reply[1], rbuf, lr); + strncpy(reply->text, rbuf, lr); return(lr); OnError: return(-1); } + #endif diff --git a/tecs/tecs_cli.h b/tecs/tecs_cli.h index 3ae8072d..9008a0e8 100644 --- a/tecs/tecs_cli.h +++ b/tecs/tecs_cli.h @@ -15,14 +15,6 @@ pTecsClient TeccInit(char *server, int port); /* 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); /* set temperature ------------------------------------------------------------------------*/ @@ -31,6 +23,18 @@ int TeccSet(pTecsClient conn, float temp); /* 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); /* send a command transparently to the controller replyLen is the maximal length of reply diff --git a/tecs/tecs_dlog.c b/tecs/tecs_dlog.c index df72ec09..ddca50cf 100644 --- a/tecs/tecs_dlog.c +++ b/tecs/tecs_dlog.c @@ -7,7 +7,6 @@ #include #include #include -#include #include "err_handling.h" #include "str_util.h" #include "tecs_dlog.h" diff --git a/tecs/tecs_lsc.c b/tecs/tecs_lsc.c index f2ce8d95..8e18a8f1 100644 --- a/tecs/tecs_lsc.c +++ b/tecs/tecs_lsc.c @@ -3,7 +3,6 @@ #include #include #include -#include #include "err_handling.h" #include "coc_logfile.h" #include "coc_util.h" @@ -32,7 +31,7 @@ int LscEqPar(char *par, char *res) { i1=sscanf(pbuf, "%f", &f1); i2=sscanf(rbuf, "%f", &f2); 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); } } @@ -71,7 +70,7 @@ char *LscCmd(SerChannel *ser, const char *cmds) { ERR_I(str_put_str(&sbuf, seg)); while (p!=NULL) { /* substitute variables */ p=str_split(varname, p, ']'); - if (p==NULL) ERR_MSG("missing '\'"); + if (p==NULL) ERR_MSG("missing ']'"); ERR_I(CocPutVar(serverVarList, &sbuf, varname, 0)); p=str_split(seg, p, '['); 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 ";" */ } 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: for a command with return request: diff --git a/tecs/tecs_serial.c b/tecs/tecs_serial.c index 9ed02006..6b0049b6 100644 --- a/tecs/tecs_serial.c +++ b/tecs/tecs_serial.c @@ -1,7 +1,6 @@ #include #include -#include #include "rs232c_def.h" #include "asynsrv_def.h" #include "sinq_prototypes.h"