From a59f15d5f026e0bc918d83e1a19a858856e62d8a Mon Sep 17 00:00:00 2001 From: cvs Date: Mon, 12 Aug 2002 09:07:51 +0000 Subject: [PATCH] added tecs_c.c (for linux) --- tecs/tecs_c.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tecs/tecs_c.c diff --git a/tecs/tecs_c.c b/tecs/tecs_c.c new file mode 100644 index 00000000..484aa76a --- /dev/null +++ b/tecs/tecs_c.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include "myc_err.h" +#include "myc_str.h" +#include "myc_time.h" +#include "myc_mem.h" +#include "tecs_cli.h" +#include "tecs_c.h" + +static pTecsClient conn=NULL; +static char response[COC_RES_LEN]; +static char *rwCode="rwacs"; +static char *rdCode="rdacs"; + +char *TecsCmd(char *cmd) { + char nbuf[64], *p, pbuf[4]; + int iret=-1, l; + + p=strchr(cmd, ' '); + if (p==NULL) { + str_copy(nbuf, cmd); + } else { + l=p-cmd; + if (l>=sizeof(nbuf)) l=sizeof(nbuf)-1; + strncpy(nbuf, cmd, l+1); + nbuf[l]='\0'; + while (*p>'\0' && *p<=' ') p++; + if (*p=='\0') p=NULL; + } + if (p==NULL) { + CocReset(conn); + ERR_I(CocGetStr(conn, nbuf, pbuf, sizeof(pbuf))); + ERR_I(CocDoIt(conn, response, sizeof(response))); + } else { + CocReset(conn); + ERR_I(CocPutStr(conn, nbuf, p)); + ERR_I(CocDoIt(conn, response, sizeof(response))); + } + return response; + OnError: return ErrMessage; +} + +char *TecsGet3(float *tset, float *texch, float *tsamp) { + ERR_I(TeccGet3(conn, tset, texch, tsamp)); + return NULL; + OnError: return ErrMessage; +} + +char *TecsSet(float temp) { + ERR_I(TeccSet(conn, temp)); + return NULL; + OnError: return ErrMessage; +} + +char *TecsInit(char *host, int port) { + if (port==0) port=9753; + if (conn!=NULL) TeccClose(conn); + NEW(conn, CocConn); + if (host==NULL || *host=='\0') { + ERR_I(CocInitClient(conn, "", port, rwCode, 0, "")); + } else { + ERR_I(CocInitClient(conn, host, port, rdCode, 0, "")); + } + return NULL; + OnError: + FREE(conn); + return ErrMessage; +} + +int TecsIsOpen(void) { + return(conn!=NULL); +} + +void TecsClose(void) { + if (conn!=NULL) { + TeccClose(conn); + conn=NULL; + } +} +