7.4.00
This commit is contained in:
104
tecs/tecs_cli.c
104
tecs/tecs_cli.c
@@ -1,12 +1,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fortify.h>
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user