hi!
This commit is contained in:
@ -101,9 +101,70 @@ int CocTryCmd(CocConn *conn)
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
int CocCmd(CocConn *conn, const char *rwList)
|
||||
{ int iret, cnt, setmode, i;
|
||||
int CocCmdWithRetry(CocConn *conn) {
|
||||
int cnt, iret;
|
||||
char *err;
|
||||
|
||||
cnt=3;
|
||||
while (1) {
|
||||
cnt--;
|
||||
if (cnt<=0) {
|
||||
ERR_I(CocTryCmd(conn));
|
||||
break;
|
||||
}
|
||||
iret=CocTryCmd(conn);
|
||||
if (iret>=0) break;
|
||||
close(conn->fd);
|
||||
conn->fd=-1;
|
||||
if (ErrCode!=ECONNRESET && ErrCode!=EPIPE) goto OnError;
|
||||
ErrWrite("try again, error was");
|
||||
}
|
||||
ERR_P(err=str_get_str(conn->resbuf, NULL));
|
||||
if (*err!='\0') { ErrMsg(err); ErrTxt(": (response from server)",0 ); goto OnError; }
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
int CocSet(CocConn *conn, const char *name, const char *value) {
|
||||
|
||||
assert(conn!=NULL);
|
||||
str_put_start(conn->cmdbuf);
|
||||
ERR_I(str_put_str(conn->cmdbuf, "["));
|
||||
ERR_I(str_put_str(conn->cmdbuf, name));
|
||||
ERR_I(str_put_str(conn->cmdbuf, value));
|
||||
ERR_I(str_put_str(conn->cmdbuf, "]"));
|
||||
|
||||
ERR_I(CocCmdWithRetry(conn));
|
||||
|
||||
ERR_I(str_get_end(conn->resbuf));
|
||||
return(0);
|
||||
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
int CocGetN(CocConn *conn, const char *name, char *value, int reslen) {
|
||||
|
||||
assert(conn!=NULL);
|
||||
str_put_start(conn->cmdbuf);
|
||||
ERR_I(str_put_str(conn->cmdbuf, name));
|
||||
|
||||
ERR_I(CocCmdWithRetry(conn));
|
||||
|
||||
ERR_P(str_nget_str(conn->resbuf, value, reslen));
|
||||
ERR_I(str_get_end(conn->resbuf));
|
||||
return(0);
|
||||
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
int CocCmd(CocConn *conn, const char *rwList)
|
||||
{ int setmode, i;
|
||||
const char *t, *s;
|
||||
char nam[32];
|
||||
CocVar *var;
|
||||
@ -137,22 +198,7 @@ int CocCmd(CocConn *conn, const char *rwList)
|
||||
s=t+1;
|
||||
} while (*t!='\0');
|
||||
|
||||
cnt=3;
|
||||
while (1) {
|
||||
cnt--;
|
||||
if (cnt<=0) {
|
||||
ERR_I(CocTryCmd(conn));
|
||||
break;
|
||||
}
|
||||
iret=CocTryCmd(conn);
|
||||
if (iret>=0) break;
|
||||
close(conn->fd);
|
||||
conn->fd=-1;
|
||||
if (ErrCode!=ECONNRESET && ErrCode!=EPIPE) goto OnError;
|
||||
ErrWrite("try again, error was");
|
||||
}
|
||||
ERR_P(err=str_get_str(conn->resbuf, NULL));
|
||||
if (*err!='\0') { ErrMsg(err); ErrTxt(": (response from server)",0 ); goto OnError; }
|
||||
ERR_I(CocCmdWithRetry(conn));
|
||||
|
||||
/* read values */
|
||||
s=rwList;
|
||||
|
@ -16,6 +16,9 @@ typedef struct {
|
||||
int CocInitClient(CocConn *conn, char *host, int port, char *magic, int bufsize, char *startcmd);
|
||||
int CocSendMagic(CocConn *conn, char *magic);
|
||||
int CocCmd(CocConn *conn, const char *rwList);
|
||||
int CocSet(CocConn *conn, const char *name, const char *value);
|
||||
int CocGetN(CocConn *conn, const char *name, char *value, int reslen);
|
||||
#define CocGet(C,N,V) CocGetN(C,N,V,sizeof(V))
|
||||
void CocCloseClient(CocConn *conn);
|
||||
|
||||
#endif /* _COC_CLIENT_H_ */
|
||||
|
@ -135,7 +135,9 @@ int CocHandle1Request(int tmo_msec, int fd) {
|
||||
cl->res[0]='\0';
|
||||
} else {
|
||||
i=CocGetVar(serverVarList, buf, varname, 1);
|
||||
if (i<0) { err=ErrMessage; break; }
|
||||
if (i<0) {
|
||||
err=ErrMessage; break;
|
||||
}
|
||||
}
|
||||
modified=1;
|
||||
} else {
|
||||
@ -144,7 +146,9 @@ int CocHandle1Request(int tmo_msec, int fd) {
|
||||
cl->res[0]='\0';
|
||||
} else {
|
||||
i=CocPutVar(serverVarList, bufo, varname, 0);
|
||||
if (i<0) { err=ErrMessage; break; }
|
||||
if (i<0) {
|
||||
err=ErrMessage; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (buf->rdpos>=buf->wrpos) {
|
||||
|
@ -238,7 +238,7 @@ void CocFreeVarList(CocVar **varList) {
|
||||
p=v;
|
||||
v=p->next;
|
||||
p->next=NULL;
|
||||
printf("my_free %s\n", p->name);
|
||||
/* printf("my_free %s\n", p->name); */
|
||||
my_free(p);
|
||||
}
|
||||
*varList=NULL;
|
||||
|
@ -89,23 +89,26 @@ void ErrSetOutFile(FILE *arg) {
|
||||
outarg=arg;
|
||||
}
|
||||
|
||||
void ERR_EXIT(char *text) {
|
||||
ErrWrite(text); exit(1);
|
||||
}
|
||||
|
||||
void ErrShowFtn_(char *text, int length) {
|
||||
char buf[256];
|
||||
|
||||
if (length>=256) length=255;
|
||||
strncpy(buf, text, length);
|
||||
buf[length]='\0';
|
||||
ErrWrite(buf);
|
||||
}
|
||||
|
||||
#ifdef __VMS
|
||||
|
||||
typedef struct { short size, dummy; char *text; } Desc;
|
||||
|
||||
void ErrShowVms(Desc *desc) {
|
||||
char buf[256];
|
||||
int l;
|
||||
|
||||
l=desc->size;
|
||||
if (l>=256) l=255;
|
||||
strncpy(buf, desc->text, l);
|
||||
buf[l]='\0';
|
||||
ErrWrite(buf);
|
||||
void ErrShowFtn(Desc *desc) {
|
||||
ErrShowFtn_(desc->text, desc->size);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void ERR_EXIT(char *text) {
|
||||
ErrWrite(text); exit(1);
|
||||
}
|
||||
|
79
tecs/tecs.c
79
tecs/tecs.c
@ -31,6 +31,7 @@ typedef struct {
|
||||
int nSens; /* number of sensors */
|
||||
int codChanged; /* code has changed */
|
||||
int codDefined; /* code is not yet confirmed */
|
||||
float scale; /* scale for extreme ranges */
|
||||
char ch1[2], ch2[2]; /* channels for high/low T */
|
||||
char device[16]; /* device name */
|
||||
char tname[16];
|
||||
@ -127,12 +128,12 @@ int instCurve(char *nam, char *channel) {
|
||||
FILE *fil;
|
||||
int retstat;
|
||||
|
||||
str_copy(chan, channel);
|
||||
logfileOut(LOG_MAIN, "install curve %s\n", nam);
|
||||
|
||||
fil=NULL;
|
||||
crv=NULL;
|
||||
|
||||
str_copy(chan, channel);
|
||||
logfileOut(LOG_MAIN, "install curve %s\n", nam);
|
||||
|
||||
/* read curve file */
|
||||
str_copy(nbuf, binDir);
|
||||
str_append(nbuf, nam);
|
||||
@ -209,6 +210,7 @@ int instCurve(char *nam, char *channel) {
|
||||
retstat=-1; /* an error could be fixed */
|
||||
ERR_P(LscCmd(ser, "INTYPE [chan]:[intype];INCRV [chan]:[num];DISPFLD [fld],[chan],1;DISPLAY:[maxfld]"));
|
||||
logfileOut(LOG_MAIN, "curve %d on channel %s selected\n", num, chan);
|
||||
Progress(100);
|
||||
|
||||
} else { /* header does not match -> download */
|
||||
|
||||
@ -394,21 +396,22 @@ int loadCache() {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
float WeightedAverage(int n, float t1, float t2) {
|
||||
float WeightedAverage(int n, float tH, float tL) {
|
||||
float p,q;
|
||||
if (n==0) {
|
||||
return(0.0);
|
||||
} else if (n<2) {
|
||||
return(t1);
|
||||
return(tH);
|
||||
} else {
|
||||
if (t2<tLow) {
|
||||
return(t2);
|
||||
} else if (t1<tHigh) {
|
||||
p=tHigh-t1;
|
||||
q=t2-tLow;
|
||||
return((t1*p*p+t2*q*q)/(p*p+q*q));
|
||||
if (tL<tLow) {
|
||||
return(tL);
|
||||
} else if (tH<tHigh) {
|
||||
p=tHigh-tH;
|
||||
q=tL-tLow;
|
||||
if (p==0.0 && q==0.0) { p=1; q=1; } /* should not be the case */
|
||||
return((tL*p*p+tH*q*q)/(p*p+q*q));
|
||||
} else {
|
||||
return(t1);
|
||||
return(tH);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -480,8 +483,8 @@ int ReadTemp() {
|
||||
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);
|
||||
cryo.temp=WeightedAverage(cryo.nSens, cryo.t1, cryo.t2)*cryo.scale;
|
||||
samp.temp=WeightedAverage(samp.nSens, samp.t1, samp.t2)*samp.scale;
|
||||
if (samp.temp==0.0) samp.temp=cryo.temp;
|
||||
if (!deviceFlag
|
||||
&& !samp.dirty && samp.codDefined && !samp.codChanged
|
||||
@ -515,8 +518,8 @@ int PeriodicTask() {
|
||||
if (k!=serialNo) {
|
||||
if (!configuring) {
|
||||
str_copy(status, "controller connected");
|
||||
configuring=1;
|
||||
}
|
||||
configuring++;
|
||||
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 */
|
||||
@ -581,6 +584,7 @@ int PeriodicTask() {
|
||||
} else {
|
||||
if (testpoint->codChanged) {
|
||||
testpoint->codChanged=0;
|
||||
Progress(1);
|
||||
if (testpoint->code1==0) {
|
||||
logfileOut(LOG_MAIN, "%s unplugged\n", testpoint->tname);
|
||||
} else {
|
||||
@ -651,7 +655,9 @@ int inputSettings(Testpoint *this) {
|
||||
int Settings() {
|
||||
int i, j, k;
|
||||
float pa, pr, pw, dif;
|
||||
char nbuf[256], buf[256], *cfg, *p;
|
||||
|
||||
cfg=NULL;
|
||||
if (cryo.dirty && cryo.codDefined || samp.dirty && samp.codDefined) {
|
||||
|
||||
for (i=0; i<2; i++) {
|
||||
@ -703,6 +709,21 @@ int Settings() {
|
||||
}
|
||||
mode=2;
|
||||
|
||||
str_copy(nbuf, binDir);
|
||||
str_append(nbuf, cryo.device);
|
||||
str_append(nbuf, ".cfg");
|
||||
cfg=str_read_file(nbuf);
|
||||
if (cfg!=NULL) {
|
||||
logfileOut(LOG_MAIN, "%s opened\n", nbuf);
|
||||
p=str_split(buf, cfg, '\n');
|
||||
sscanf(buf, "%f%f", &cryo.scale, &samp.scale);
|
||||
while (p!=NULL) {
|
||||
p=str_split(buf, p, '\n');
|
||||
ERR_P(LscCmd(ser, buf));
|
||||
}
|
||||
my_free(cfg);
|
||||
}
|
||||
|
||||
if (saveTime!=0 && tim>saveTime) {
|
||||
ERR_P(LscCmd(ser, "CRVSAV;BUSY?>busy"));
|
||||
while (!busy) {
|
||||
@ -711,9 +732,12 @@ int Settings() {
|
||||
}
|
||||
saveTime=0;
|
||||
}
|
||||
ERR_I(ReadTemp());
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
OnError:
|
||||
if (cfg!=NULL) my_free(cfg);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
int ExecuteRequest() {
|
||||
@ -816,7 +840,7 @@ int mainBody(void)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{ int logIt=0;
|
||||
int i, iret, use_stdout=0;
|
||||
int i, iret, cntError, use_stdout=0;
|
||||
char *host;
|
||||
char buf[256], opt;
|
||||
int port, msecTmo;
|
||||
@ -828,7 +852,9 @@ int main(int argc, char *argv[])
|
||||
str_copy(samp.ch1,"C");
|
||||
str_copy(samp.ch2,"D");
|
||||
cryo.codChanged=1;
|
||||
cryo.scale=1.0;
|
||||
samp.codChanged=1;
|
||||
samp.scale=1.0;
|
||||
|
||||
logMask=LOG_MAIN+LOG_INFO;
|
||||
binDir="bin/";
|
||||
@ -948,18 +974,25 @@ int main(int argc, char *argv[])
|
||||
str_copy(buf, logDir);
|
||||
str_append(buf, serverId);
|
||||
str_append(buf, ".dlog");
|
||||
iret=DlogOpen(&dset, buf, 1);
|
||||
if (iret<0) {
|
||||
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));
|
||||
logfileOut(LOG_INFO, "open data log file: %s\n", buf);
|
||||
ERR_I(iret=DlogOpenWrt(&dset, buf, tim0.time, 2, 7*24*60*60/logPeriod, logPeriod, 0.0));
|
||||
if (iret==0) {
|
||||
logfileOut(LOG_INFO, "created\n");
|
||||
} else {
|
||||
logfileOut(LOG_INFO, "opened data log file: %s\n", buf);
|
||||
logfileOut(LOG_INFO, "opened\n");
|
||||
}
|
||||
logfileWrite(logMask);
|
||||
per=period;
|
||||
cntError=0;
|
||||
while (!quit) {
|
||||
iret=mainBody();
|
||||
if (iret<0) logfileShowErr("error in TecsServer");
|
||||
if (iret<0) {
|
||||
cntError++;
|
||||
if (cntError>10) ERR_MSG("too many errors - quit");
|
||||
logfileShowErr("error in TecsServer/mainBody");
|
||||
} else {
|
||||
if (cntError>0) cntError--;
|
||||
}
|
||||
}
|
||||
ERR_MSG("got quit command");
|
||||
OnError:
|
||||
|
131
tecs/tecs_cli.c
131
tecs/tecs_cli.c
@ -4,7 +4,7 @@
|
||||
#include "str_util.h"
|
||||
#include "tecs_cli.h"
|
||||
|
||||
static char device[80], command[80], buffer[132];
|
||||
static char device[80], command[80];
|
||||
static int quit, readTemp, configuring;
|
||||
static float tempX, tempP, tempC;
|
||||
|
||||
@ -17,7 +17,6 @@ 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);
|
||||
@ -27,19 +26,6 @@ pTecsClient TeccInit(char *startcmd, int port) {
|
||||
OnError: return(NULL);
|
||||
}
|
||||
|
||||
int TeccSetDev(pTecsClient conn, char *dev) {
|
||||
str_copy(device, dev);
|
||||
ERR_I(CocCmd(conn, "[device]"));
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
char *TeccGetDev(pTecsClient conn) {
|
||||
ERR_I(CocCmd(conn, "device"));
|
||||
return(device);
|
||||
OnError: return(NULL);
|
||||
}
|
||||
|
||||
int TeccGet3(pTecsClient conn, float *tC, float *tX, float *tP) {
|
||||
readTemp=1;
|
||||
ERR_I(CocCmd(conn, "tempC,tempX,tempP,[readTemp],configuring"));
|
||||
@ -62,11 +48,11 @@ int TeccWait(pTecsClient conn) {
|
||||
last=0;
|
||||
cnt=0;
|
||||
do {
|
||||
CocDelay(100);
|
||||
CocDelay(250);
|
||||
ERR_I(CocCmd(conn, "configuring"));
|
||||
if (configuring==last || configuring>1000) {
|
||||
cnt++;
|
||||
if (cnt>50) ERR_MSG("configuring timeout");
|
||||
if (cnt>20) ERR_MSG("configuring timeout");
|
||||
} else {
|
||||
cnt=0;
|
||||
last=configuring;
|
||||
@ -83,26 +69,6 @@ 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;
|
||||
@ -139,64 +105,75 @@ void TeccClose(pTecsClient conn) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __VMS
|
||||
int TeccSetParFtn_(pTecsClient conn, char *name, char *par, int namelen, int parlen) {
|
||||
char nbuf[64], pbuf[256];
|
||||
|
||||
typedef struct { short size, dummy; char *text; } Desc;
|
||||
if (namelen>=sizeof(nbuf)) namelen=sizeof(nbuf)-1;
|
||||
strncpy(nbuf, name, namelen);
|
||||
while (namelen>0 && nbuf[namelen-1]==' ') namelen--; /* trim */
|
||||
nbuf[namelen]='\0';
|
||||
|
||||
int TeccSetParVms(pTecsClient conn, Desc *name, Desc *par) {
|
||||
char nbuf[80];
|
||||
int l;
|
||||
if (parlen>=sizeof(pbuf)) parlen=sizeof(pbuf)-1;
|
||||
strncpy(pbuf, par, parlen);
|
||||
while (parlen>0 && pbuf[parlen-1]==' ') parlen--; /* trim */
|
||||
pbuf[parlen]='\0';
|
||||
|
||||
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));
|
||||
ERR_I(CocSet(conn, nbuf, pbuf));
|
||||
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int TeccGetParVms(pTecsClient conn, Desc *name, Desc *par) {
|
||||
int l, ld;
|
||||
char nbuf[64];
|
||||
int TeccGetParFtn_(pTecsClient conn, char *name, char *par, int namelen, int parlen) {
|
||||
int l;
|
||||
char nbuf[64], pbuf[256];
|
||||
|
||||
l=par->size;
|
||||
if (l>=sizeof(nbuf)) l=sizeof(nbuf)-1;
|
||||
strncpy(nbuf, par->text, l);
|
||||
while (l>0 && nbuf[l-1]==' ') l--; /* trim */
|
||||
if (namelen>=sizeof(nbuf)) namelen=sizeof(nbuf)-1;
|
||||
strncpy(nbuf, name, namelen);
|
||||
while (namelen>0 && nbuf[namelen-1]==' ') namelen--; /* trim */
|
||||
nbuf[namelen]='\0';
|
||||
|
||||
CocDefVar(nbuf, buffer, sizeof(buffer), &CocWR);
|
||||
ERR_I(CocCmd(conn, nbuf));
|
||||
ERR_I(CocGet(conn, nbuf, pbuf));
|
||||
|
||||
ld=strlen(buffer);
|
||||
l=par->size;
|
||||
if (ld>=l) ld=l;
|
||||
strncpy(par->text, buffer, ld);
|
||||
return(ld);
|
||||
l=strlen(pbuf);
|
||||
if (l>parlen) l=parlen;
|
||||
strncpy(par, pbuf, l);
|
||||
return(l);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int TeccSendVms(pTecsClient conn, Desc *cmd, Desc *reply) {
|
||||
int l, lr;
|
||||
int TeccSendFtn_(pTecsClient conn, char *cmd, char *reply, int cmdlen, int replylen) {
|
||||
int l;
|
||||
char cbuf[80], rbuf[80];
|
||||
|
||||
l=cmd->size;
|
||||
if (l>=sizeof(cbuf)) l=sizeof(cbuf)-1;
|
||||
strncpy(cbuf, cmd->text, l);
|
||||
while (l>0 && cbuf[l-1]==' ') l--; /* trim */
|
||||
cbuf[l]='\0';
|
||||
if (cmdlen>=sizeof(cbuf)) cmdlen=sizeof(cbuf)-1;
|
||||
strncpy(cbuf, cmd, cmdlen);
|
||||
while (cmdlen>0 && cbuf[cmdlen-1]==' ') cmdlen--; /* trim */
|
||||
cbuf[cmdlen]='\0';
|
||||
|
||||
ERR_I(TeccSend(conn, cbuf, rbuf, sizeof(rbuf)));
|
||||
lr=strlen(rbuf);
|
||||
l=reply->size;
|
||||
if (lr>=l) lr=l;
|
||||
strncpy(reply->text, rbuf, lr);
|
||||
return(lr);
|
||||
|
||||
l=strlen(rbuf);
|
||||
if (l>replylen) l=replylen;
|
||||
strncpy(reply, rbuf, l);
|
||||
return(l);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
#ifdef __VMS
|
||||
|
||||
typedef struct { short size, dummy; char *text; } Desc;
|
||||
|
||||
int TeccSetParFtn(pTecsClient conn, Desc *name, Desc *par) {
|
||||
return(TeccSetParFtn_(conn, name->text, par->text, name->size, par->size));
|
||||
}
|
||||
|
||||
int TeccGetParFtn(pTecsClient conn, Desc *name, Desc *par) {
|
||||
return(TeccGetParFtn_(conn, name->text, par->text, name->size, par->size));
|
||||
}
|
||||
|
||||
int TeccSendFtn(pTecsClient conn, Desc *cmd, Desc *reply) {
|
||||
return(TeccSendFtn_(conn, cmd->text, reply->text, cmd->size, reply->size));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -23,14 +23,6 @@ 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
|
||||
------------------------------------------------------------------------*/
|
||||
|
@ -45,7 +45,7 @@ int DlogRead(DlogSet *dset, int idx, void *data) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
int DlogOpen(DlogSet *dset, char *name, int write) {
|
||||
int DlogOpenOld(DlogSet *dset, char *name, int write) {
|
||||
int i, p, np, fd, flags;
|
||||
time_t tim;
|
||||
struct tm *timp;
|
||||
@ -79,11 +79,22 @@ int DlogOpen(DlogSet *dset, char *name, int write) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
int DlogCreate(DlogSet *dset, char *name, time_t start, int nset, int nlen, int period, float undef) {
|
||||
int fd, i, j, p;
|
||||
int DlogOpen(DlogSet *dset, char *name) {
|
||||
return(DlogOpenOld(dset, name, 0));
|
||||
}
|
||||
|
||||
int DlogOpenWrt(DlogSet *dset, char *name, time_t start, int nset, int nlen, int period, float undef) {
|
||||
int fd, i, j, p, iret;
|
||||
va_list ap;
|
||||
float f[DLOG_MAX_SET];
|
||||
|
||||
iret=DlogOpenOld(dset, name, 1);
|
||||
if (iret>=0 && dset->nset==nset
|
||||
&& dset->nlen==nlen
|
||||
&& dset->last+nlen*period>start
|
||||
&& dset->undef == undef) {
|
||||
return(1); /* take old file only if it matches */
|
||||
}
|
||||
fd=0;
|
||||
if (nset>DLOG_MAX_SET) ERR_MSG("nset too large");
|
||||
dset->nset=nset;
|
||||
@ -208,7 +219,7 @@ int dlog_get_(char *name, int *nset, int *nmax, double *starttime, float x[], fl
|
||||
int ntot;
|
||||
/* for compaq unix */
|
||||
str_trim(buf, name, namlen);
|
||||
ERR_I(DlogOpen(&dset, buf, 0));
|
||||
ERR_I(DlogOpen(&dset, buf));
|
||||
ERR_I(ntot=DlogGetMany(&dset, *nset, *nmax, starttime, x, y, index));
|
||||
DlogClose(&dset);
|
||||
return(ntot);
|
||||
@ -228,7 +239,7 @@ int DlogUpd(DlogSet *dset) {
|
||||
dset->pos=sizeof(int);
|
||||
#ifdef __VMS
|
||||
close(dset->fd);
|
||||
DlogOpen(dset, dset->name, 1);
|
||||
ERR_I(DlogOpenOld(dset, dset->name, 1));
|
||||
#endif
|
||||
return(0);
|
||||
OnError:
|
||||
|
@ -14,11 +14,11 @@ typedef struct {
|
||||
} DlogSet;
|
||||
|
||||
|
||||
int DlogOpen(DlogSet *dset, char *name, int write);
|
||||
int DlogOpen(DlogSet *dset, char *name);
|
||||
/* open existing dlog set */
|
||||
|
||||
int DlogCreate(DlogSet *dset, char *name, time_t start, int nset, int nlen, int period, float undef);
|
||||
/* create new dlog file */
|
||||
int DlogOpenWrt(DlogSet *dset, char *name, time_t start, int nset, int nlen, int period, float undef);
|
||||
/* create or append to new dlog file */
|
||||
|
||||
int DlogPut(DlogSet *dset, time_t time, int nset, float val[]);
|
||||
/* put values to dlog set */
|
||||
|
33
tecsdriv.c
33
tecsdriv.c
@ -69,24 +69,22 @@
|
||||
typedef struct {
|
||||
void *pData;
|
||||
char *lastError;
|
||||
time_t lastGet;
|
||||
int iLastError, port;
|
||||
char server[256];
|
||||
} TecsDriv, *pTecsDriv;
|
||||
|
||||
|
||||
static time_t lastGet=0;
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
int TecsWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
pEVControl self = NULL;
|
||||
char pBueffel[256];
|
||||
char pBueffel[256], result[256];
|
||||
int iRet;
|
||||
pEVDriver pD;
|
||||
pTecsDriv pMe;
|
||||
char *result;
|
||||
double fNum;
|
||||
float fVal;
|
||||
|
||||
@ -111,7 +109,7 @@
|
||||
pD=self->pDriv; assert(pD);
|
||||
pMe=pD->pPrivate; assert(pMe);
|
||||
if(argc > 2) { /* set case */
|
||||
iRet=TeccSetPar(pMe->pData,argv[1],argv[2]);
|
||||
iRet=CocSet(pMe->pData,argv[1],argv[2]);
|
||||
if (iRet<0) {
|
||||
sprintf(pBueffel,"ERROR: %s",ErrMessage);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
@ -119,8 +117,8 @@
|
||||
}
|
||||
return 1;
|
||||
} else { /* get case */
|
||||
result=TeccGetPar(pMe->pData,argv[1]);
|
||||
if (result==NULL) {
|
||||
iRet=CocGet(pMe->pData,argv[1],result);
|
||||
if (iRet<0) {
|
||||
sprintf(pBueffel,"ERROR: %s",ErrMessage);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
@ -138,40 +136,45 @@
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
static int TecsGet(pEVDriver self, float *fPos)
|
||||
{
|
||||
pTecsDriv pMe = NULL;
|
||||
int iRet;
|
||||
time_t now;
|
||||
static int configuring;
|
||||
|
||||
assert(self);
|
||||
pMe = (pTecsDriv)self->pPrivate;
|
||||
assert(pMe);
|
||||
|
||||
time(&now);
|
||||
if (now!=lastGet) { /* TecsGet was not yet called within this second */
|
||||
lastGet=now;
|
||||
if (now!=pMe->lastGet) { /* TecsGet was not yet called within this second */
|
||||
pMe->lastGet=now;
|
||||
} else {
|
||||
CocDelay(200); /* wait 0.2 sec. (seems that SICS has nothing else to do then reading temperatures) */
|
||||
}
|
||||
|
||||
/* get temperature */
|
||||
iRet = TeccGet(pMe->pData, fPos);
|
||||
if (iRet > 1) {
|
||||
if (pMe->iLastError==2) {
|
||||
iRet=TeccWait(pMe->pData);
|
||||
if (iRet > 0) {
|
||||
if (configuring) {
|
||||
iRet = TeccWait(pMe->pData);
|
||||
iRet = TeccGet(pMe->pData, fPos);
|
||||
} else {
|
||||
pMe->lastError = "configuring controller";
|
||||
pMe->lastError = ": controller busy (configuring)";
|
||||
pMe->iLastError=2; /* fixable */
|
||||
configuring=1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
configuring=0;
|
||||
if(iRet < 0) {
|
||||
pMe->lastError = ErrMessage;
|
||||
pMe->iLastError=1; /* severe */
|
||||
return 0;
|
||||
}
|
||||
pMe->lastError=0;
|
||||
pMe->iLastError=0;
|
||||
return 1;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@ -219,7 +222,7 @@
|
||||
assert(self);
|
||||
pMe = (pTecsDriv )self->pPrivate;
|
||||
assert(pMe);
|
||||
if (pMe->iLastError=1) { /* for Tecs, iLastError means severity level */
|
||||
if (pMe->iLastError==1) { /* for Tecs, iLastError means severity level */
|
||||
return(DEVFAULT); /* 1: severe */
|
||||
} else {
|
||||
return(DEVREDO); /* 2: try again, good luck! */
|
||||
|
Reference in New Issue
Block a user