*** empty log message ***
This commit is contained in:
130
tecs/tecc.c
Normal file
130
tecs/tecc.c
Normal file
@@ -0,0 +1,130 @@
|
||||
#include "errhdl.h"
|
||||
#include "client.h"
|
||||
#include "tecc.h"
|
||||
|
||||
char command[80], response[80], device[80];
|
||||
float tempX, tempP, tempC;
|
||||
|
||||
pTecsClient TeccInit(char *server) {
|
||||
CocConn *conn;
|
||||
char buf[80];
|
||||
|
||||
ERR_SP(conn=(CocConn *)malloc(sizeof(*conn)));
|
||||
#ifdef __VMS
|
||||
sprintf(buf, "@start_tecs %s", server);
|
||||
#else
|
||||
sprintf(buf, "start_tecs %s", server);
|
||||
#endif
|
||||
CocInitClient(conn, "", "#rwacs", 0, buf);
|
||||
CocDefFlt(tempX, CocRD);
|
||||
CocDefFlt(tempP, CocRD);
|
||||
CocDefFlt(tempC, CocWR);
|
||||
CocDefStr(device, CocWR);
|
||||
CocDefStr(command, CocWR);
|
||||
CocDefStr(response, CocWR);
|
||||
return((pTecsClient)conn);
|
||||
OnError: return(NULL);
|
||||
}
|
||||
|
||||
int TeccSetDev(pTecsClient conn, char *dev) {
|
||||
str_copy(device, dev);
|
||||
ERR_I(CocCmd((CocConn *)conn, "[device]"));
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
char *TeccGetDev(pTecsClient conn) {
|
||||
ERR_I(CocCmd((CocConn *)conn, "device"));
|
||||
return(device);
|
||||
OnError: return(NULL);
|
||||
}
|
||||
|
||||
int TeccGet(pTecsClient conn, float *temp) {
|
||||
ERR_I(CocCmd((CocConn *)conn, "tempP"));
|
||||
*temp=tempP;
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int TeccGet3(pTecsClient conn, float temp[3]) {
|
||||
ERR_I(CocCmd((CocConn *)conn, "tempC,tempX,tempP"));
|
||||
temp[0]=tempC;
|
||||
temp[1]=tempX;
|
||||
temp[2]=tempP;
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int TeccSet(pTecsClient conn, float temp) {
|
||||
tempC=temp;
|
||||
ERR_I(CocCmd((CocConn *)conn, "[tempC]"));
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int TeccSend(pTecsClient conn, char *cmd, char *reply, int replyLen) {
|
||||
command[0]='\0';
|
||||
while (0!=strcmp(command, cmd)) {
|
||||
str_copy(command, cmd);
|
||||
strcpy(response,"<none>");
|
||||
ERR_I(CocCmd((CocConn *)conn, "[command,response]"));
|
||||
while (0==strcmp(response,"<none>") && 0==strcmp(command, cmd)) {
|
||||
util_delay(250);
|
||||
ERR_I(CocCmd((CocConn *)conn, "command,response"));
|
||||
}
|
||||
}
|
||||
str_ncpy(reply, response, replyLen);
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
void TeccClose(pTecsClient conn) {
|
||||
CocCloseClient((CocConn *)conn);
|
||||
free(conn);
|
||||
}
|
||||
|
||||
#ifdef __VMS
|
||||
|
||||
int TeccSetDevVms(pTecsClient conn, char **dev) {
|
||||
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((CocConn *)conn, "[device]"));
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int TeccGetDevVms(pTecsClient conn, char **dev) {
|
||||
int l, ld;
|
||||
|
||||
ERR_I(CocCmd((CocConn *)conn, "device"));
|
||||
ld=strlen(device);
|
||||
l=*(short *)dev;
|
||||
if (ld>=l) ld=l;
|
||||
strncpy(dev[1], device, ld);
|
||||
return(ld);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int TeccSendVms(pTecsClient conn, char **cmd, char **reply) {
|
||||
int l, lr;
|
||||
char cbuf[80], rbuf[80];
|
||||
|
||||
l=*(short *)cmd;
|
||||
if (l>=sizeof(cbuf)) l=sizeof(cbuf)-1;
|
||||
strncpy(cbuf, cmd[1], l);
|
||||
while (l>0 && cbuf[l-1]==' ') l--; /* trim */
|
||||
cbuf[l]='\0';
|
||||
TeccSend(conn, cbuf, rbuf, sizeof(rbuf));
|
||||
lr=strlen(rbuf);
|
||||
l=*(short *)reply;
|
||||
if (lr>=l) lr=l;
|
||||
strncpy(reply[1], rbuf, lr);
|
||||
return(lr);
|
||||
OnError: return(-1);
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user