#include #include #include #include #include "errhdl.h" #include "logfile.h" #include "lsc.h" #include "util.h" #define MC LSC_MAX_CMDS #define MAX_PAR 16 #define MAX_ARG 9 /* when changing FBUF_LEN, change also the constant in the fscanf call in subroutine LscExeCmd */ #define FBUF_LEN 132 int LscEqPar(char *par, char *res) { char pbuf[SER_BUF_LEN], rbuf[SER_BUF_LEN]; char *plist[MAX_PAR], *rlist[MAX_PAR]; int i,n,i1,i2; float f1, f2; char ch1, ch2; strcpy(pbuf, par); strcpy(rbuf, res); n=MAX_PAR; str_split(pbuf, ',', plist, &n); str_split(rbuf, ',', rlist, &n); for (i=0; i1e-4+abs(f1)*5e-6) { logfileOut("%s#%s\n", plist[i], rlist[i]); return(0); } } } return(1); } int LscCmdChkC(SerChannel *ser, const char *cmds) { char buf[128]; assert(strlen(cmds)<128); strcpy(buf, cmds); return(LscCmdChk(ser, buf)); } int LscCmdChk(SerChannel *ser, char *cmds) { char *b, *o, *cn, *c, *d, *r, *res; char *clist[MC], *plist[MC], *rlist[MC], *olist[MC]; char obuf[SER_BUF_LEN], r1[SER_BUF_LEN]; int i,n,m,j,cnt,l; if (NULL!=strchr(cmds, '?')) ERR_COD(EINVAL); cn=cmds; o=&obuf[0]; m=MC; do { n=m; cn=str_split(cn, ';', clist, &n); for (i=0; id) { *d=' '; b=d; } else { *d=','; } plist[i]=d+1; l=strlen(c); if ((o-&obuf[0])+l+(d-c)+2>SER_BUF_LEN) ERR_COD(ENOBUFS); olist[i]=o; strcpy(o, c); o+=l; *o=';'; o++; strncpy(o, c, d-c); o[b-c]='?'; o+=d-c; if (b==d) o++; *o=';'; o++; }; o--; *o='\0'; cnt=0; do { cnt++; if (cnt>3) ERR_MSG("can not set parameter"); ERR_P(res=SerCmd(ser, obuf)); if (cnt>0) { if (0==strcmp(r1, res)) break; /* got two times the same result */ } strcpy(r1, res); j=n; r=str_split(res, ';', rlist, &n); if (r==NULL || n!=j) continue; for (i=0; i