- Adapted indenation to new agreed upon system

This commit is contained in:
koennecke
2009-02-13 09:01:24 +00:00
parent eb72d5c486
commit b3ac7dff3f
37 changed files with 11946 additions and 11757 deletions

View File

@@ -81,16 +81,18 @@
**==================================================================== **====================================================================
** StrMatch - compare two strings. ** StrMatch - compare two strings.
*/ */
int StrMatch ( int StrMatch(
/* ======== /* ========
*/ char *str_a, */ char *str_a,
char *str_b, char *str_b, int min_len)
int min_len) { {
int i = 0; int i = 0;
while ((tolower(str_a[i]) == tolower(str_b[i])) && (str_a[i] != '\0')) i++; while ((tolower(str_a[i]) == tolower(str_b[i])) && (str_a[i] != '\0'))
i++;
return ((str_a[i] == '\0') && (i >= min_len)); return ((str_a[i] == '\0') && (i >= min_len));
} }
/*-------------------------------------------------- End of StrMatch.C =======*/ /*-------------------------------------------------- End of StrMatch.C =======*/

View File

@@ -15,7 +15,7 @@
/* /*
** Structures needed by AsynSrv_Utility. ** Structures needed by AsynSrv_Utility.
*/ */
struct AsynSrv__info { struct AsynSrv__info {
int skt; /* The socket number of the connection */ int skt; /* The socket number of the connection */
char host[20]; /* The name of RS-232-C server */ char host[20]; /* The name of RS-232-C server */
int port; /* The TCP/IP port number of server */ int port; /* The TCP/IP port number of server */
@@ -34,9 +34,9 @@
int n_replies; /* # of last response returned to caller */ int n_replies; /* # of last response returned to caller */
void (*idleHandler) (int, int); /* MZ. handler called when waiting .. void (*idleHandler) (int, int); /* MZ. handler called when waiting ..
** .. on a response */ ** .. on a response */
}; };
struct AsynSrv_HostPortSkt { struct AsynSrv_HostPortSkt {
char host[30]; char host[30];
int port; int port;
int skt; int skt;
@@ -46,6 +46,6 @@
int rply_hdr_len; int rply_hdr_len;
int usage_cnt; int usage_cnt;
int status; int status;
}; };
/*------------------------------------------------ End of AsynSrv_DEF.H --*/ /*------------------------------------------------ End of AsynSrv_DEF.H --*/
#endif /* _asynsrv_def_ */ #endif /* _asynsrv_def_ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -69,28 +69,31 @@
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
** Global Variables ** Global Variables
*/ */
extern int C_gbl_status = 0; extern int C_gbl_status = 0;
extern struct dsc$descriptor_s C_name_desc = {0, extern struct dsc$descriptor_s C_name_desc = { 0,
DSC$K_DTYPE_T, DSC$K_DTYPE_T,
DSC$K_CLASS_S, DSC$K_CLASS_S,
0}; 0
};
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
** Old-style prototypes of routines which we are ** Old-style prototypes of routines which we are
** bridging to. ** bridging to.
*/ */
int log_arr_get (); int log_arr_get();
int log_int_get (); int log_int_get();
int log_flt_get (); int log_flt_get();
int log_str_get (); int log_str_get();
int str_edit (); int str_edit();
int tt_port_connect (); int tt_port_connect();
int tt_port_disconnect (); int tt_port_disconnect();
int tt_port_io (); int tt_port_io();
int tt_port_config (); int tt_port_config();
/* --------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------*/
int C_log_arr_get (char *name, int arr_size, int *value, int indx) { int C_log_arr_get(char *name, int arr_size, int *value, int indx)
{
/* ============= /* =============
** **
** This routine is useful for calling LOG_ARR_GET from a C program. ** This routine is useful for calling LOG_ARR_GET from a C program.
@@ -110,15 +113,17 @@
** C_name_desc - set up as a string descriptor for name. It can ** C_name_desc - set up as a string descriptor for name. It can
** be used to generate an error message if return status == 0. ** be used to generate an error message if return status == 0.
*/ */
C_name_desc.dsc$w_length = strlen (name); C_name_desc.dsc$w_length = strlen(name);
C_name_desc.dsc$a_pointer = name; C_name_desc.dsc$a_pointer = name;
C_gbl_status = log_arr_get (&C_name_desc, &arr_size, value, &indx); C_gbl_status = log_arr_get(&C_name_desc, &arr_size, value, &indx);
return (C_gbl_status & 1); return (C_gbl_status & 1);
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int C_log_int_get (char *name, long int *value, int indx) { int C_log_int_get(char *name, long int *value, int indx)
{
/* ============= /* =============
** **
** This routine is useful for calling LOG_INT_GET from a C program. ** This routine is useful for calling LOG_INT_GET from a C program.
@@ -136,15 +141,17 @@
** C_name_desc - set up as a string descriptor for name. It can ** C_name_desc - set up as a string descriptor for name. It can
** be used to generate an error message if return status == 0. ** be used to generate an error message if return status == 0.
*/ */
C_name_desc.dsc$w_length = strlen (name); C_name_desc.dsc$w_length = strlen(name);
C_name_desc.dsc$a_pointer = name; C_name_desc.dsc$a_pointer = name;
C_gbl_status = log_int_get (&C_name_desc, value, &indx); C_gbl_status = log_int_get(&C_name_desc, value, &indx);
return (C_gbl_status & 1); return (C_gbl_status & 1);
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int C_log_flt_get (char *name, float *value, int indx) { int C_log_flt_get(char *name, float *value, int indx)
{
/* ============= /* =============
** **
** This routine is useful for calling LOG_FLT_GET from a C program. ** This routine is useful for calling LOG_FLT_GET from a C program.
@@ -162,15 +169,17 @@
** C_name_desc - set up as a string descriptor for name. It can ** C_name_desc - set up as a string descriptor for name. It can
** be used to generate an error message if return status == 0. ** be used to generate an error message if return status == 0.
*/ */
C_name_desc.dsc$w_length = strlen (name); C_name_desc.dsc$w_length = strlen(name);
C_name_desc.dsc$a_pointer = name; C_name_desc.dsc$a_pointer = name;
C_gbl_status = log_flt_get (&C_name_desc, value, &indx); C_gbl_status = log_flt_get(&C_name_desc, value, &indx);
return (C_gbl_status & 1); return (C_gbl_status & 1);
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int C_log_str_get (char *name, char *value, int val_size, int indx) { int C_log_str_get(char *name, char *value, int val_size, int indx)
{
/* ============= /* =============
** **
** This routine is useful for calling LOG_STR_GET from a C program. ** This routine is useful for calling LOG_STR_GET from a C program.
@@ -190,29 +199,32 @@
** C_name_desc - set up as a string descriptor for name. It can ** C_name_desc - set up as a string descriptor for name. It can
** be used to generate an error message if return status == 0. ** be used to generate an error message if return status == 0.
*/ */
struct dsc$descriptor_s my_val_desc = {0, struct dsc$descriptor_s my_val_desc = { 0,
DSC$K_DTYPE_T, DSC$K_DTYPE_T,
DSC$K_CLASS_S, DSC$K_CLASS_S,
0}; 0
};
C_name_desc.dsc$w_length = strlen (name); C_name_desc.dsc$w_length = strlen(name);
C_name_desc.dsc$a_pointer = name; C_name_desc.dsc$a_pointer = name;
my_val_desc.dsc$w_length = val_size - 1; my_val_desc.dsc$w_length = val_size - 1;
my_val_desc.dsc$a_pointer = value; my_val_desc.dsc$a_pointer = value;
C_gbl_status = log_str_get (&C_name_desc, &my_val_desc, &indx); C_gbl_status = log_str_get(&C_name_desc, &my_val_desc, &indx);
value[val_size - 1] = 0; /* Zero-terminate the string */ value[val_size - 1] = 0; /* Zero-terminate the string */
if (C_gbl_status & 1) { /* If success, strip trailing spaces */ if (C_gbl_status & 1) { /* If success, strip trailing spaces */
while ((strlen (value) > 0) && (value[strlen (value) - 1] == ' ')) { while ((strlen(value) > 0) && (value[strlen(value) - 1] == ' ')) {
value[strlen (value) - 1] = 0; value[strlen(value) - 1] = 0;
} }
} }
return (C_gbl_status & 1); return (C_gbl_status & 1);
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int C_str_edit (char *out, char *in, char *ctrl, int *length) { int C_str_edit(char *out, char *in, char *ctrl, int *length)
{
/* ========== /* ==========
** **
** This routine is useful for calling STR_EDIT from a C program. ** This routine is useful for calling STR_EDIT from a C program.
@@ -235,39 +247,44 @@
** Global variables: ** Global variables:
** C_gbl_status - set to the VAX/VMS return status of STR_EDIT. ** C_gbl_status - set to the VAX/VMS return status of STR_EDIT.
*/ */
struct dsc$descriptor_s out_desc = {0, struct dsc$descriptor_s out_desc = { 0,
DSC$K_DTYPE_T, DSC$K_DTYPE_T,
DSC$K_CLASS_S, DSC$K_CLASS_S,
0}; 0
struct dsc$descriptor_s in_desc = {0, };
struct dsc$descriptor_s in_desc = { 0,
DSC$K_DTYPE_T, DSC$K_DTYPE_T,
DSC$K_CLASS_S, DSC$K_CLASS_S,
0}; 0
struct dsc$descriptor_s ctrl_desc = {0, };
struct dsc$descriptor_s ctrl_desc = { 0,
DSC$K_DTYPE_T, DSC$K_DTYPE_T,
DSC$K_CLASS_S, DSC$K_CLASS_S,
0}; 0
};
out_desc.dsc$w_length = *length - 1; out_desc.dsc$w_length = *length - 1;
out_desc.dsc$a_pointer = out; out_desc.dsc$a_pointer = out;
in_desc.dsc$w_length = strlen (in); in_desc.dsc$w_length = strlen(in);
in_desc.dsc$a_pointer = in; in_desc.dsc$a_pointer = in;
ctrl_desc.dsc$w_length = strlen (ctrl); ctrl_desc.dsc$w_length = strlen(ctrl);
ctrl_desc.dsc$a_pointer = ctrl; ctrl_desc.dsc$a_pointer = ctrl;
C_gbl_status = str_edit (&out_desc, &in_desc, &ctrl_desc, length); C_gbl_status = str_edit(&out_desc, &in_desc, &ctrl_desc, length);
if (*length >= 0) { /* zero-terminate the output string */ if (*length >= 0) { /* zero-terminate the output string */
out[*length] = '\0'; out[*length] = '\0';
}else { } else {
out[0] = '\0'; out[0] = '\0';
} }
return (C_gbl_status & 1); return (C_gbl_status & 1);
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int C_tt_port_connect (int *hndl, int *chan, char *lognam, char *pwd) { int C_tt_port_connect(int *hndl, int *chan, char *lognam, char *pwd)
{
/* ================= /* =================
** **
** This routine is useful for calling TT_PORT_CONNECT from a C program. ** This routine is useful for calling TT_PORT_CONNECT from a C program.
@@ -292,30 +309,33 @@
** Global variables: ** Global variables:
** C_gbl_status - set to the VAX/VMS return status of TT_PORT_CONNECT. ** C_gbl_status - set to the VAX/VMS return status of TT_PORT_CONNECT.
*/ */
struct dsc$descriptor_s lognam_desc = {0, struct dsc$descriptor_s lognam_desc = { 0,
DSC$K_DTYPE_T, DSC$K_DTYPE_T,
DSC$K_CLASS_S, DSC$K_CLASS_S,
0}; 0
struct dsc$descriptor_s pwd_desc = {0, };
struct dsc$descriptor_s pwd_desc = { 0,
DSC$K_DTYPE_T, DSC$K_DTYPE_T,
DSC$K_CLASS_S, DSC$K_CLASS_S,
0}; 0
lognam_desc.dsc$w_length = strlen (lognam); };
lognam_desc.dsc$w_length = strlen(lognam);
lognam_desc.dsc$a_pointer = lognam; lognam_desc.dsc$a_pointer = lognam;
if (pwd != NULL) { if (pwd != NULL) {
pwd_desc.dsc$w_length = strlen (pwd); pwd_desc.dsc$w_length = strlen(pwd);
pwd_desc.dsc$a_pointer = pwd; pwd_desc.dsc$a_pointer = pwd;
C_gbl_status = tt_port_connect ( C_gbl_status = tt_port_connect(hndl, chan, &lognam_desc, &pwd_desc);
hndl, chan, &lognam_desc, &pwd_desc); } else {
}else { C_gbl_status = tt_port_connect(hndl, chan, &lognam_desc, NULL);
C_gbl_status = tt_port_connect (hndl, chan, &lognam_desc, NULL);
} }
return (C_gbl_status & 1); return (C_gbl_status & 1);
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int C_tt_port_disconnect (int *hndl) { int C_tt_port_disconnect(int *hndl)
{
/* ==================== /* ====================
** **
** This routine is useful for calling TT_PORT_DISCONNECT from a C program. ** This routine is useful for calling TT_PORT_DISCONNECT from a C program.
@@ -331,20 +351,18 @@
** Global variables: ** Global variables:
** C_gbl_status - set to the VAX/VMS return status of TT_PORT_DISCONNECT. ** C_gbl_status - set to the VAX/VMS return status of TT_PORT_DISCONNECT.
*/ */
C_gbl_status = tt_port_disconnect (hndl); C_gbl_status = tt_port_disconnect(hndl);
return (C_gbl_status & 1); return (C_gbl_status & 1);
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int C_tt_port_io ( int C_tt_port_io(
/* ============ /* ============
*/ int *hndl, */ int *hndl,
char *rqst, char *rqst, char *term, char *answ, int *answ_len, /* Attention -- Read/Write argument!! */
char *term, int flush, int tmo)
char *answ, {
int *answ_len, /* Attention -- Read/Write argument!! */
int flush,
int tmo) {
/* /*
** This routine is useful for calling TT_PORT_IO from a C program. ** This routine is useful for calling TT_PORT_IO from a C program.
** Refer to the DELTAT.OLB description of TT_PORT_IO to clarify any ** Refer to the DELTAT.OLB description of TT_PORT_IO to clarify any
@@ -386,18 +404,21 @@
** Global variables: ** Global variables:
** C_gbl_status - set to the VAX/VMS return status of TT_PORT_IO. ** C_gbl_status - set to the VAX/VMS return status of TT_PORT_IO.
*/ */
struct dsc$descriptor_s rqst_desc = {0, struct dsc$descriptor_s rqst_desc = { 0,
DSC$K_DTYPE_T, DSC$K_DTYPE_T,
DSC$K_CLASS_S, DSC$K_CLASS_S,
0}; 0
struct dsc$descriptor_s term_desc = {0, };
struct dsc$descriptor_s term_desc = { 0,
DSC$K_DTYPE_T, DSC$K_DTYPE_T,
DSC$K_CLASS_S, DSC$K_CLASS_S,
0}; 0
struct dsc$descriptor_s answ_desc = {0, };
struct dsc$descriptor_s answ_desc = { 0,
DSC$K_DTYPE_T, DSC$K_DTYPE_T,
DSC$K_CLASS_S, DSC$K_CLASS_S,
0}; 0
};
char *my_rqst = NULL; char *my_rqst = NULL;
char *my_term = NULL; char *my_term = NULL;
char *my_answ = NULL; char *my_answ = NULL;
@@ -407,13 +428,15 @@
int my_tmo = 2; int my_tmo = 2;
my_tmo = tmo; my_tmo = tmo;
if (my_tmo < 0) my_tmo = 0; if (my_tmo < 0)
my_tmo = 0;
my_flush = flush; my_flush = flush;
if (my_flush != 0) my_flush = 1; if (my_flush != 0)
my_flush = 1;
if (answ != NULL) { if (answ != NULL) {
if (answ_len == 0) { if (answ_len == 0) {
printf ("C_tt_port_io -- argument error.\n"); printf("C_tt_port_io -- argument error.\n");
printf (" %s\n", printf(" %s\n",
"answ_len must be present if answ is present."); "answ_len must be present if answ is present.");
C_gbl_status = FALSE; C_gbl_status = FALSE;
return FALSE; return FALSE;
@@ -422,30 +445,32 @@
answ_desc.dsc$a_pointer = answ; answ_desc.dsc$a_pointer = answ;
} }
if (term != NULL) { if (term != NULL) {
term_desc.dsc$w_length = strlen (term); term_desc.dsc$w_length = strlen(term);
term_desc.dsc$a_pointer = term; term_desc.dsc$a_pointer = term;
} }
if (rqst != NULL) { if (rqst != NULL) {
rqst_desc.dsc$w_length = strlen (rqst); rqst_desc.dsc$w_length = strlen(rqst);
rqst_desc.dsc$a_pointer = rqst; rqst_desc.dsc$a_pointer = rqst;
} }
C_gbl_status = tt_port_io (hndl, &rqst_desc, &term_desc, C_gbl_status = tt_port_io(hndl, &rqst_desc, &term_desc,
&answ_desc, &my_answ_len, &my_flush, &my_tmo); &answ_desc, &my_answ_len, &my_flush, &my_tmo);
if (answ_desc.dsc$w_length > 0) { /* Process any input string */ if (answ_desc.dsc$w_length > 0) { /* Process any input string */
if (answ_desc.dsc$w_length > my_answ_len) { /* Room for terminator? */ if (answ_desc.dsc$w_length > my_answ_len) { /* Room for terminator? */
answ[my_answ_len+1] = answ[my_answ_len]; /* Yes, so move it. */ answ[my_answ_len + 1] = answ[my_answ_len]; /* Yes, so move it. */
} }
answ[my_answ_len] = '\0'; /* Put in null terminator */ answ[my_answ_len] = '\0'; /* Put in null terminator */
*answ_len = my_answ_len; /* Return value to caller */ *answ_len = my_answ_len; /* Return value to caller */
} }
return (C_gbl_status & 1); return (C_gbl_status & 1);
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int C_tt_port_config ( int C_tt_port_config(
/* ================ /* ================
*/ int *hndl, */ int *hndl,
int mask) { int mask)
{
/* /*
** This routine is useful for calling TT_PORT_CONFIG from a C program. ** This routine is useful for calling TT_PORT_CONFIG from a C program.
** Refer to the DELTAT.OLB description of TT_PORT_CONFIG to clarify any ** Refer to the DELTAT.OLB description of TT_PORT_CONFIG to clarify any
@@ -465,8 +490,9 @@
** Global variables: ** Global variables:
** C_gbl_status - set to the VAX/VMS return status of TT_PORT_CONFIG. ** C_gbl_status - set to the VAX/VMS return status of TT_PORT_CONFIG.
*/ */
C_gbl_status = tt_port_config (hndl, &mask); C_gbl_status = tt_port_config(hndl, &mask);
return (C_gbl_status & 1); return (C_gbl_status & 1);
} }
/*=========================================== End of C_INTERFACES.C ========*/ /*=========================================== End of C_INTERFACES.C ========*/

View File

@@ -26,9 +26,9 @@
*/ */
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
int DILLU_Open(pDILLU *pData, char *pHost, int iPort, int iChannel, int DILLU_Open(pDILLU * pData, char *pHost, int iPort, int iChannel,
int iMode, char *pTransFile) int iMode, char *pTransFile)
{ {
int iRet; int iRet;
char pCommand[80]; char pCommand[80];
char pReply[132]; char pReply[132];
@@ -37,29 +37,25 @@
FILE *fd = NULL; FILE *fd = NULL;
/* check translation file first */ /* check translation file first */
fd = fopen(pTransFile,"r"); fd = fopen(pTransFile, "r");
if(!fd) if (!fd) {
{
return DILLU__FILENOTFOUND; return DILLU__FILENOTFOUND;
} }
fgets(pReply, 131,fd); fgets(pReply, 131, fd);
if(strstr(pReply,"DILLUTION") == NULL) if (strstr(pReply, "DILLUTION") == NULL) {
{
fclose(fd); fclose(fd);
return DILLU__NODILLFILE; return DILLU__NODILLFILE;
} }
pTable = CreateTable(fd); pTable = CreateTable(fd);
fclose(fd); fclose(fd);
if(!pTable) if (!pTable) {
{
return DILLU__ERRORTABLE; return DILLU__ERRORTABLE;
} }
/* allocate a new data structure */ /* allocate a new data structure */
self = (pDILLU)malloc(sizeof(DILLU)); self = (pDILLU) malloc(sizeof(DILLU));
if(self == NULL) if (self == NULL) {
{
return DILLU__BADMALLOC; return DILLU__BADMALLOC;
} }
@@ -67,8 +63,7 @@
self->pTranstable = pTable; self->pTranstable = pTable;
iRet = SerialOpen(&self->pData, pHost, iPort, iChannel); iRet = SerialOpen(&self->pData, pHost, iPort, iChannel);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
@@ -76,14 +71,12 @@
prevent problems. prevent problems.
*/ */
iRet = SerialConfig(&self->pData, 100); iRet = SerialConfig(&self->pData, 100);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
self->iReadOnly = iMode; self->iReadOnly = iMode;
if(!self->iReadOnly) if (!self->iReadOnly) {
{
/* switch to remote operation */ /* switch to remote operation */
/* iRet = SerialWriteRead(&self->pData,"C1\r\n",pReply,131); /* iRet = SerialWriteRead(&self->pData,"C1\r\n",pReply,131);
if(iRet != 1) if(iRet != 1)
@@ -93,21 +86,22 @@
*/ */
} }
return 1; return 1;
} }
/* --------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------*/
void DILLU_Close(pDILLU *pData) void DILLU_Close(pDILLU * pData)
{ {
char pReply[132]; char pReply[132];
int iRet; int iRet;
pDILLU self; pDILLU self;
self = *pData; self = *pData;
if(!self) if (!self)
return; return;
/* switch to local operation */ /* switch to local operation */
iRet = SerialWriteRead(&self->pData,"C0\r\n",pReply,131); iRet = SerialWriteRead(&self->pData, "C0\r\n", pReply, 131);
/* ignore errors on this one, the thing may be down */ /* ignore errors on this one, the thing may be down */
/* close connection */ /* close connection */
@@ -116,10 +110,11 @@
/* free memory */ /* free memory */
free(self); free(self);
*pData = NULL; *pData = NULL;
} }
/* --------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------*/
int DILLU_Config(pDILLU *pData, int iTmo) int DILLU_Config(pDILLU * pData, int iTmo)
{ {
int iRet; int iRet;
char pReply[132]; char pReply[132];
char pCommand[10]; char pCommand[10];
@@ -128,33 +123,32 @@
self = *pData; self = *pData;
/* first timeout */ /* first timeout */
if(iTmo > 0) if (iTmo > 0) {
{
iRet = SerialConfig(&self->pData, iTmo); iRet = SerialConfig(&self->pData, iTmo);
if(iRet < 0) if (iRet < 0) {
{
return iRet; return iRet;
} }
} }
return 1; return 1;
} }
/* --------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------*/
int DILLU_Send(pDILLU *pData, char *pCommand, char *pReply, int iLen) int DILLU_Send(pDILLU * pData, char *pCommand, char *pReply, int iLen)
{ {
pDILLU self; pDILLU self;
self = *pData; self = *pData;
/* make sure, that there is a \r at the end of the command */ /* make sure, that there is a \r at the end of the command */
if(strchr(pCommand,(int)'\r') == NULL) if (strchr(pCommand, (int) '\r') == NULL) {
{ strcat(pCommand, "\r\n");
strcat(pCommand,"\r\n");
}
return SerialWriteRead(&self->pData,pCommand,pReply,iLen);
} }
return SerialWriteRead(&self->pData, pCommand, pReply, iLen);
}
/* --------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------*/
int DILLU_Read(pDILLU *pData, float *fVal) int DILLU_Read(pDILLU * pData, float *fVal)
{ {
char pCommand[10], pReply[132]; char pCommand[10], pReply[132];
int iRet; int iRet;
float fRead = -9999.; float fRead = -9999.;
@@ -165,69 +159,62 @@
/* send D command */ /* send D command */
sprintf(pCommand,"D\r\n"); sprintf(pCommand, "D\r\n");
iRet = SerialWriteRead(&self->pData,pCommand,pReply,131); iRet = SerialWriteRead(&self->pData, pCommand, pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
/* read ohms */ /* read ohms */
iRet = sscanf(pReply,"%f",&fOhm); iRet = sscanf(pReply, "%f", &fOhm);
if(iRet != 1) if (iRet != 1) {
{
return DILLU__BADREAD; return DILLU__BADREAD;
} }
if(fOhm > 9999890.) if (fOhm > 9999890.) {
{
return DILLU__SILLYANSWER; return DILLU__SILLYANSWER;
} }
/* convert to K */ /* convert to K */
iRet = InterpolateVal2(self->pTranstable,fOhm,&fRead); iRet = InterpolateVal2(self->pTranstable, fOhm, &fRead);
*fVal = fRead; *fVal = fRead;
return 1; return 1;
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
int DILLU_Set(pDILLU *pData, float fVal) int DILLU_Set(pDILLU * pData, float fVal)
{ {
char pCommand[50], pReply[132]; char pCommand[50], pReply[132];
int iRet, i,iRange, iExec; int iRet, i, iRange, iExec;
const float fPrecision = 0.0001; const float fPrecision = 0.0001;
float fSet, fRead, fOhms, tmax, fTemp; float fSet, fRead, fOhms, tmax, fTemp;
pDILLU self; pDILLU self;
self = *pData; self = *pData;
if(self->iReadOnly) if (self->iReadOnly) {
{
return DILLU__READONLY; return DILLU__READONLY;
} }
/* send D command to read current value*/ /* send D command to read current value */
sprintf(pCommand,"D\r\n"); sprintf(pCommand, "D\r\n");
iRet = SerialWriteRead(&self->pData,pCommand,pReply,131); iRet = SerialWriteRead(&self->pData, pCommand, pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
/* read ohms */ /* read ohms */
iRet = sscanf(pReply,"%f",&fRead); iRet = sscanf(pReply, "%f", &fRead);
if(iRet != 1) if (iRet != 1) {
{
return DILLU__BADREAD; return DILLU__BADREAD;
} }
if(fRead > 9999890.) if (fRead > 9999890.) {
{
return DILLU__SILLYANSWER; return DILLU__SILLYANSWER;
} }
/* convert new set value to ohms */ /* convert new set value to ohms */
iRet = InterpolateVal1(self->pTranstable,fVal,&fOhms); iRet = InterpolateVal1(self->pTranstable, fVal, &fOhms);
if(!iRet) if (!iRet) {
{
return DILLU__OUTOFRANGE; return DILLU__OUTOFRANGE;
} }
@@ -235,186 +222,160 @@
#ifdef debug #ifdef debug
printf("C1\n"); printf("C1\n");
#endif #endif
iRet = SerialWriteRead(&self->pData,"C1\r\n",pReply,131); iRet = SerialWriteRead(&self->pData, "C1\r\n", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
/* set heater power */ /* set heater power */
strcpy(pCommand,"G3\r"); strcpy(pCommand, "G3\r");
if(fOhms > 1125) if (fOhms > 1125) {
{ strcpy(pCommand, "G2\r");
strcpy(pCommand,"G2\r");
} }
if(fOhms > 4000) if (fOhms > 4000)
strcpy(pCommand,"G1\r"); strcpy(pCommand, "G1\r");
#ifdef debug #ifdef debug
printf("A9\n"); printf("A9\n");
#endif #endif
iRet = SerialWriteRead(&self->pData,"A9\r",pReply,131); iRet = SerialWriteRead(&self->pData, "A9\r", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
#ifdef debug #ifdef debug
printf("%s\n",pCommand); printf("%s\n", pCommand);
#endif #endif
iRet = SerialWriteRead(&self->pData,pCommand,pReply,131); iRet = SerialWriteRead(&self->pData, pCommand, pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
/* Integrator time constant */ /* Integrator time constant */
strcpy(pCommand,"G2\r"); strcpy(pCommand, "G2\r");
if(fOhms > 200) if (fOhms > 200)
strcpy(pCommand,"G1\r"); strcpy(pCommand, "G1\r");
if(fOhms > 2000) if (fOhms > 2000)
strcpy(pCommand,"G0\r"); strcpy(pCommand, "G0\r");
strcpy(pCommand,"G7\r"); strcpy(pCommand, "G7\r");
if(fOhms > 400.) if (fOhms > 400.) {
{ strcpy(pCommand, "G6\r");
strcpy(pCommand,"G6\r");
} }
#ifdef debug #ifdef debug
printf("A4\n"); printf("A4\n");
#endif #endif
iRet = SerialWriteRead(&self->pData,"A4\r",pReply,131); iRet = SerialWriteRead(&self->pData, "A4\r", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
#ifdef debug #ifdef debug
printf("%s\n",pCommand); printf("%s\n", pCommand);
#endif #endif
iRet = SerialWriteRead(&self->pData,pCommand,pReply,131); iRet = SerialWriteRead(&self->pData, pCommand, pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
/* derivator time constant */ /* derivator time constant */
if(fOhms > 1000.) if (fOhms > 1000.) {
{ strcpy(pCommand, "G1\r");
strcpy(pCommand,"G1\r"); } else {
} strcpy(pCommand, "G2\r");
else
{
strcpy(pCommand,"G2\r");
} }
#ifdef debug #ifdef debug
printf("A5\n"); printf("A5\n");
#endif #endif
iRet = SerialWriteRead(&self->pData,"A5\r",pReply,131); iRet = SerialWriteRead(&self->pData, "A5\r", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
#ifdef debug #ifdef debug
printf("%s\n",pCommand); printf("%s\n", pCommand);
iRet = 1; iRet = 1;
#endif #endif
iRet = SerialWriteRead(&self->pData,pCommand,pReply,131); iRet = SerialWriteRead(&self->pData, pCommand, pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
/* proportional gain */ /* proportional gain */
if(fOhms > 500.) if (fOhms > 500.) {
{ strcpy(pCommand, "G3\r");
strcpy(pCommand,"G3\r");
} }
if(fOhms > 1000) if (fOhms > 1000) {
{ strcpy(pCommand, "G2\r");
strcpy(pCommand,"G2\r");
} }
if(fOhms > 2000) if (fOhms > 2000) {
{ strcpy(pCommand, "G1\r");
strcpy(pCommand,"G1\r");
} }
#ifdef debug #ifdef debug
printf("A6\n"); printf("A6\n");
#endif #endif
iRet = SerialWriteRead(&self->pData,"A6\r",pReply,131); iRet = SerialWriteRead(&self->pData, "A6\r", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
#ifdef debug #ifdef debug
printf("%s\n",pCommand); printf("%s\n", pCommand);
#endif #endif
iRet = SerialWriteRead(&self->pData,pCommand,pReply,131); iRet = SerialWriteRead(&self->pData, pCommand, pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
/* range calculation a la Elsenhans */ /* range calculation a la Elsenhans */
iRange = 1; iRange = 1;
fTemp = fOhms*10000.; fTemp = fOhms * 10000.;
if( (fRead > 1.9) || (fOhms > 1.9) ) if ((fRead > 1.9) || (fOhms > 1.9)) {
{
iRange = 2; iRange = 2;
fTemp = fOhms*1000.; fTemp = fOhms * 1000.;
} }
if( (fRead > 19) || (fOhms > 19) ) if ((fRead > 19) || (fOhms > 19)) {
{
iRange = 3; iRange = 3;
fTemp = fOhms*100.; fTemp = fOhms * 100.;
} }
if( (fRead > 190) || (fOhms > 190) ) if ((fRead > 190) || (fOhms > 190)) {
{
iRange = 4; iRange = 4;
fTemp = fOhms*10.; fTemp = fOhms * 10.;
} }
if( (fRead > 750) || (fOhms > 750) ) if ((fRead > 750) || (fOhms > 750)) {
{
iRange = 5; iRange = 5;
fTemp = fOhms; fTemp = fOhms;
} }
if( (fRead > 19000) || (fOhms > 19000) ) if ((fRead > 19000) || (fOhms > 19000)) {
{
iRange = 6; iRange = 6;
fTemp = fOhms/10.; fTemp = fOhms / 10.;
} }
if( (fRead > 190000) || (fOhms > 190000) ) if ((fRead > 190000) || (fOhms > 190000)) {
{
iRange = 7; iRange = 7;
fTemp = fOhms/100.; fTemp = fOhms / 100.;
} }
sprintf(pCommand,"R%1.1d\r",iRange); sprintf(pCommand, "R%1.1d\r", iRange);
#ifdef debug #ifdef debug
printf("%s\n",pCommand); printf("%s\n", pCommand);
#endif #endif
iRet = SerialWriteRead(&self->pData,pCommand,pReply,131); iRet = SerialWriteRead(&self->pData, pCommand, pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
/* finally set temperature */ /* finally set temperature */
#ifdef debug #ifdef debug
printf("Set Val befor hex: %d\n",(int)fTemp); printf("Set Val befor hex: %d\n", (int) fTemp);
#endif #endif
sprintf(pCommand,"G%4.4X\r",(int)fTemp); sprintf(pCommand, "G%4.4X\r", (int) fTemp);
#ifdef debug #ifdef debug
printf("A3\n"); printf("A3\n");
#endif #endif
iRet = SerialWriteRead(&self->pData,"A3\r",pReply,131); iRet = SerialWriteRead(&self->pData, "A3\r", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
#ifdef debug #ifdef debug
printf("%s\n",pCommand); printf("%s\n", pCommand);
#endif #endif
iRet = SerialWriteRead(&self->pData,pCommand,pReply,131); iRet = SerialWriteRead(&self->pData, pCommand, pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
@@ -424,58 +385,57 @@
#ifdef debug #ifdef debug
printf("C1\n"); printf("C1\n");
#endif #endif
iRet = SerialWriteRead(&self->pData,"C0\r\n",pReply,131); iRet = SerialWriteRead(&self->pData, "C0\r\n", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
return 1; return 1;
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
void DILLU_Error2Text(pDILLU *pData,int iCode, char *pError, int iLen) void DILLU_Error2Text(pDILLU * pData, int iCode, char *pError, int iLen)
{ {
char pBueffel[512]; char pBueffel[512];
pDILLU self; pDILLU self;
self = *pData; self = *pData;
switch(iCode) switch (iCode) {
{
case DILLU__FILENOTFOUND: case DILLU__FILENOTFOUND:
strncpy(pError,"Translation Table file not found",iLen); strncpy(pError, "Translation Table file not found", iLen);
return; return;
break; break;
case DILLU__NODILLFILE: case DILLU__NODILLFILE:
strncpy(pError,"Translation Table file is not DILLU",iLen); strncpy(pError, "Translation Table file is not DILLU", iLen);
return; return;
break; break;
case DILLU__ERRORTABLE: case DILLU__ERRORTABLE:
strncpy(pError,"Translation Table could not be created",iLen); strncpy(pError, "Translation Table could not be created", iLen);
return; return;
break; break;
case DILLU__BADREAD: case DILLU__BADREAD:
strncpy(pError,"Message corrupted",iLen); strncpy(pError, "Message corrupted", iLen);
return; return;
break; break;
case DILLU__SILLYANSWER: case DILLU__SILLYANSWER:
strncpy(pError,"Message corrupted",iLen); strncpy(pError, "Message corrupted", iLen);
return; return;
break; break;
case DILLU__BADMALLOC: case DILLU__BADMALLOC:
strncpy(pError,"Out of memory in Open_DILLU",iLen); strncpy(pError, "Out of memory in Open_DILLU", iLen);
return; return;
break; break;
case DILLU__READONLY: case DILLU__READONLY:
strncpy(pError,"DILLU is read-only",iLen); strncpy(pError, "DILLU is read-only", iLen);
return; return;
break; break;
case DILLU__OUTOFRANGE: case DILLU__OUTOFRANGE:
strncpy(pError,"Requested value is out of range",iLen); strncpy(pError, "Requested value is out of range", iLen);
return; return;
break; break;
default: default:
SerialError(iCode,pError,iLen); SerialError(iCode, pError, iLen);
break; break;
} }
} }

View File

@@ -30,16 +30,16 @@
#define DILLU__BADMALLOC -717 #define DILLU__BADMALLOC -717
#define DILLU__NODILLUFOUND -711 #define DILLU__NODILLUFOUND -711
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
typedef struct __DILLU { typedef struct __DILLU {
void *pData; void *pData;
pSTable pTranstable; pSTable pTranstable;
int iReadOnly; int iReadOnly;
} DILLU; } DILLU;
typedef struct __DILLU *pDILLU; typedef struct __DILLU *pDILLU;
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
int DILLU_Open(pDILLU *pData,char *pHost, int iPort, int iChannel, int DILLU_Open(pDILLU * pData, char *pHost, int iPort, int iChannel,
int iMode, char *pTransFile); int iMode, char *pTransFile);
/***** creates an DILLU datastructure and opens a connection to the ITCL4 /***** creates an DILLU datastructure and opens a connection to the ITCL4
controller. Input Parameters are: controller. Input Parameters are:
@@ -55,14 +55,14 @@
*/ */
void DILLU_Close(pDILLU *pData); void DILLU_Close(pDILLU * pData);
/****** close a connection to an DILLU controller and frees its /****** close a connection to an DILLU controller and frees its
data structure. The only parameter is a pointer to the data data structure. The only parameter is a pointer to the data
structure for this controller. This pointer will be invalid after structure for this controller. This pointer will be invalid after
this call. this call.
*/ */
int DILLU_Config(pDILLU *pData, int iTmo); int DILLU_Config(pDILLU * pData, int iTmo);
/***** configure some aspects of a DILLU temperature controller. /***** configure some aspects of a DILLU temperature controller.
The parameter are: The parameter are:
- a pointer to the data structure for the controller as - a pointer to the data structure for the controller as
@@ -72,7 +72,7 @@
failure. failure.
*/ */
int DILLU_Send(pDILLU *pData, char *pCommand, char *pReply, int iLen); int DILLU_Send(pDILLU * pData, char *pCommand, char *pReply, int iLen);
/******* send a the command in pCommand to the DILLU controller. /******* send a the command in pCommand to the DILLU controller.
A possible reply is returned in the buffer pReply. A possible reply is returned in the buffer pReply.
Maximum iLen characters are copied to pReply. Maximum iLen characters are copied to pReply.
@@ -83,7 +83,7 @@
failure. failure.
*/ */
int DILLU_Read(pDILLU *pData, float *fVal); int DILLU_Read(pDILLU * pData, float *fVal);
/****** /******
Reads the current temperature at the controller Reads the current temperature at the controller
@@ -91,7 +91,7 @@
failure. failure.
*/ */
int DILLU_Set(pDILLU *pData, float fVal); int DILLU_Set(pDILLU * pData, float fVal);
/****** sets a new preset temperature in the DILL temperature /****** sets a new preset temperature in the DILL temperature
controller. Parameters are: controller. Parameters are:
- a pointer to a DILLU data structure as returned by Open_DILLU. - a pointer to a DILLU data structure as returned by Open_DILLU.
@@ -101,8 +101,6 @@
failure. failure.
*/ */
void DILLU_Error2Text(pDILLU *pData, int iCode, char *pError, int iLen); void DILLU_Error2Text(pDILLU * pData, int iCode, char *pError, int iLen);
#endif #endif

View File

@@ -17,23 +17,24 @@
#define MAX_MOT 12 #define MAX_MOT 12
enum EL734_Requests {FULL__STATUS, enum EL734_Requests { FULL__STATUS,
SHORT__STATUS}; SHORT__STATUS
};
/* /*
** Structure to which the EL734_Open handle points. ** Structure to which the EL734_Open handle points.
*/ */
struct EL734info { struct EL734info {
struct AsynSrv__info asyn_info; /* Contains skt, host, port & chan */ struct AsynSrv__info asyn_info; /* Contains skt, host, port & chan */
int motor; int motor;
int ored_msr, fp_cntr, fr_cntr; int ored_msr, fp_cntr, fr_cntr;
struct RS__MsgStruct to_host; struct RS__MsgStruct to_host;
struct RS__RespStruct from_host; struct RS__RespStruct from_host;
}; };
/* /*
** Structure holding everything that is known about a VME Motor Controller. ** Structure holding everything that is known about a VME Motor Controller.
** It is also the structure of replies from the Server. ** It is also the structure of replies from the Server.
*/ */
struct Motor_State { struct Motor_State {
int motor; /* Motor number */ int motor; /* Motor number */
int exists; /* True if Motor exists */ int exists; /* True if Motor exists */
int msr; /* MSR - Motor Status Register */ int msr; /* MSR - Motor Status Register */
@@ -46,7 +47,7 @@ enum EL734_Requests {FULL__STATUS,
int dec_pt; /* A - # of decimal places */ int dec_pt; /* A - # of decimal places */
int enc_factor[2]; /* FD - Encoder scaling factors (numer/denom) */ int enc_factor[2]; /* FD - Encoder scaling factors (numer/denom) */
int mot_factor[2]; /* FM - Motor scaling factors (numer/denom) */ int mot_factor[2]; /* FM - Motor scaling factors (numer/denom) */
char inertia_tol[16];/* D - Inertia tol'nce (sec) (Schleppfehler) */ char inertia_tol[16]; /* D - Inertia tol'nce (sec) (Schleppfehler) */
int ramp; /* E - Start/stop ramp (kHz/sec) */ int ramp; /* E - Start/stop ramp (kHz/sec) */
int loop_mode; /* F - Open loop/Closed loop (0/1) */ int loop_mode; /* F - Open loop/Closed loop (0/1) */
int slow_hz; /* G - Start/stop frequency (Mot-S/sec) */ int slow_hz; /* G - Start/stop frequency (Mot-S/sec) */
@@ -68,6 +69,6 @@ enum EL734_Requests {FULL__STATUS,
int ac_state; /* AC - Air-cushion state (0 = down) */ int ac_state; /* AC - Air-cushion state (0 = down) */
int out; /* SO - State of Output Signal */ int out; /* SO - State of Output Signal */
int in; /* RI - State of Input Signal */ int in; /* RI - State of Input Signal */
}; };
/*------------------------------------------------ End of EL734_DEF.H --*/ /*------------------------------------------------ End of EL734_DEF.H --*/
#endif /* _el734_def_ */ #endif /* _el734_def_ */

File diff suppressed because it is too large Load Diff

View File

@@ -24,20 +24,20 @@
#define False 0 #define False 0
#define True 1 #define True 1
typedef struct typedef struct {
{
float fUpper; /* upper limit */ float fUpper; /* upper limit */
float fLower; /* Lower Limit */ float fLower; /* Lower Limit */
int iFix; /* fixed, unfixed flag */ int iFix; /* fixed, unfixed flag */
float fSoftZero; /* SW-zero point */ float fSoftZero; /* SW-zero point */
float fSoftUpper; /* software upper boundary*/ float fSoftUpper; /* software upper boundary */
float fSoftLower; /* " lower " */ float fSoftLower; /* " lower " */
int iLowFlag, iUpFlag, iZeroFlag; /*activity flags */ int iLowFlag, iUpFlag, iZeroFlag; /*activity flags */
void *pData; /* EL734 open struct */ void *pData; /* EL734 open struct */
} EL734st; } EL734st;
EXTERN int EL734Action(ClientData pDat, Tcl_Interp *i, int a, char *argv[]); EXTERN int EL734Action(ClientData pDat, Tcl_Interp * i, int a,
static void EL734Error2Text(char *pBuffer, int errcode); char *argv[]);
static void EL734Error2Text(char *pBuffer, int errcode);
/*--------------------------------------------------------------------------- /*---------------------------------------------------------------------------
Tcl has a high niceness level. It deletes a command properly when Tcl has a high niceness level. It deletes a command properly when
@@ -46,10 +46,11 @@
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
EXTERN void EL734Murder(ClientData pData) EXTERN void EL734Murder(ClientData pData)
{ {
EL734st *pTa = (EL734st *)pData; EL734st *pTa = (EL734st *) pData;
EL734_Close(&(pTa->pData)); EL734_Close(&(pTa->pData));
free(pData); free(pData);
} }
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
EL734 is the main entry point for this stuff. It connects to a motor EL734 is the main entry point for this stuff. It connects to a motor
and, on success, creates a new command with the name of the motor. and, on success, creates a new command with the name of the motor.
@@ -57,7 +58,7 @@ EXTERN void EL734Murder(ClientData pData)
EL734 name host port channel index EL734 name host port channel index
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
int EL734(ClientData clientData, Tcl_Interp *interp, int EL734(ClientData clientData, Tcl_Interp * interp,
int argc, char *argv[]) int argc, char *argv[])
{ {
int iRet; int iRet;
@@ -67,151 +68,137 @@ int EL734(ClientData clientData, Tcl_Interp *interp,
char pBueffel[80]; char pBueffel[80];
/* check arguments */ /* check arguments */
if(argc < 6) if (argc < 6) {
{
Tcl_AppendResult(interp, Tcl_AppendResult(interp,
" Insufficient arguments: EL734 name host port channel index" " Insufficient arguments: EL734 name host port channel index",
, (char *) NULL); (char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/* convert arguments */ /* convert arguments */
iRet = Tcl_GetInt(interp,argv[3],&iPort); iRet = Tcl_GetInt(interp, argv[3], &iPort);
if(iRet == TCL_ERROR) if (iRet == TCL_ERROR) {
{ Tcl_AppendResult(interp, "Need integer value for port", (char *) NULL);
Tcl_AppendResult(interp,"Need integer value for port",
(char *)NULL);
return iRet; return iRet;
} }
iRet = Tcl_GetInt(interp,argv[4],&iChannel); iRet = Tcl_GetInt(interp, argv[4], &iChannel);
if(iRet == TCL_ERROR) if (iRet == TCL_ERROR) {
{ Tcl_AppendResult(interp, "Need integer value for channel",
Tcl_AppendResult(interp,"Need integer value for channel", (char *) NULL);
(char *)NULL);
return iRet; return iRet;
} }
iRet = Tcl_GetInt(interp,argv[5],&iMotor); iRet = Tcl_GetInt(interp, argv[5], &iMotor);
if(iRet == TCL_ERROR) if (iRet == TCL_ERROR) {
{ Tcl_AppendResult(interp, "Need integer value for motor",
Tcl_AppendResult(interp,"Need integer value for motor", (char *) NULL);
(char *)NULL);
return iRet; return iRet;
} }
/* make a new pointer, initialise EL734st */ /* make a new pointer, initialise EL734st */
pEL734 = (EL734st *)malloc(sizeof(EL734st)); pEL734 = (EL734st *) malloc(sizeof(EL734st));
if(pEL734 ==NULL) if (pEL734 == NULL) {
{ Tcl_AppendResult(interp, "No memory in EL734", NULL);
Tcl_AppendResult(interp,"No memory in EL734",NULL);
return TCL_ERROR; return TCL_ERROR;
} }
pEL734->iFix = False; pEL734->iFix = False;
pEL734->fSoftZero = INACTIVE+1; pEL734->fSoftZero = INACTIVE + 1;
pEL734->fSoftUpper = INACTIVE+1.; pEL734->fSoftUpper = INACTIVE + 1.;
pEL734->fSoftLower = -INACTIVE-1.; pEL734->fSoftLower = -INACTIVE - 1.;
pEL734->iZeroFlag = False; pEL734->iZeroFlag = False;
pEL734->iLowFlag = False; pEL734->iLowFlag = False;
pEL734->iUpFlag = False; pEL734->iUpFlag = False;
/* open the motor, finally */ /* open the motor, finally */
iRet = EL734_Open(&(pEL734->pData), argv[2],iPort,iChannel,iMotor,"STPMC EL734"); iRet =
if(iRet) /* success */ EL734_Open(&(pEL734->pData), argv[2], iPort, iChannel, iMotor,
{ "STPMC EL734");
if (iRet) { /* success */
/* figure out motor limits */ /* figure out motor limits */
EL734_GetLimits(&(pEL734->pData),&(pEL734->fLower), EL734_GetLimits(&(pEL734->pData), &(pEL734->fLower),
&(pEL734->fUpper)); &(pEL734->fUpper));
/* handle TCL, create new command: the motor */ /* handle TCL, create new command: the motor */
Tcl_CreateCommand(interp,strdup(argv[1]),EL734Action, Tcl_CreateCommand(interp, strdup(argv[1]), EL734Action,
(ClientData)pEL734,EL734Murder); (ClientData) pEL734, EL734Murder);
Tcl_AppendResult(interp,strdup(argv[1]),(char *)NULL); Tcl_AppendResult(interp, strdup(argv[1]), (char *) NULL);
return TCL_OK; return TCL_OK;
} } else {
else EL734_ErrInfo(&pErr, &iPort, &iChannel, &iMotor);
{ EL734Error2Text(pBueffel, iPort);
EL734_ErrInfo(&pErr,&iPort,&iChannel, &iMotor); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
EL734Error2Text(pBueffel,iPort);
Tcl_AppendResult(interp,pBueffel,(char *) NULL);
free(pEL734); free(pEL734);
return TCL_ERROR; return TCL_ERROR;
} }
} }
/*--------------------------------------------------------------------------- /*---------------------------------------------------------------------------
CheckPos checks a position and converts it to a real position. CheckPos checks a position and converts it to a real position.
Returns TCL_ERROR on mistake, TCL_OK else Returns TCL_ERROR on mistake, TCL_OK else
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
static int CheckPos(Tcl_Interp *interp, EL734st *pData, static int CheckPos(Tcl_Interp * interp, EL734st * pData,
float fRequested, float *fDrive) float fRequested, float *fDrive)
{ {
float fPos; float fPos;
char pBueffel[132]; char pBueffel[132];
/* fixed ? */ /* fixed ? */
if(pData->iFix) if (pData->iFix) {
{ Tcl_AppendResult(interp, "Motor fixed", NULL);
Tcl_AppendResult(interp,"Motor fixed",NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/* check against SW-boundaries */ /* check against SW-boundaries */
if(pData->iUpFlag) if (pData->iUpFlag) {
{ if (fRequested > pData->fSoftUpper) {
if(fRequested > pData->fSoftUpper)
{
sprintf(pBueffel, sprintf(pBueffel,
"Requested position: %f violates SW-boundary %f", "Requested position: %f violates SW-boundary %f",
fRequested, pData->fSoftUpper); fRequested, pData->fSoftUpper);
Tcl_AppendResult(interp,pBueffel,(char *) NULL); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
} }
if(pData->iLowFlag) if (pData->iLowFlag) {
{ if (fRequested < pData->fSoftLower) {
if(fRequested < pData->fSoftLower)
{
sprintf(pBueffel, sprintf(pBueffel,
"Requested position: %f violates SW-boundary %f", "Requested position: %f violates SW-boundary %f",
fRequested, pData->fSoftLower); fRequested, pData->fSoftLower);
Tcl_AppendResult(interp,pBueffel,(char *) NULL); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
} }
/* correct for zero point */ /* correct for zero point */
if(pData->iZeroFlag) if (pData->iZeroFlag) {
{
fPos = fRequested - pData->fSoftZero; fPos = fRequested - pData->fSoftZero;
} } else {
else
{
fPos = fRequested; fPos = fRequested;
} }
/* check HW-boundaries */ /* check HW-boundaries */
if( (fPos < pData->fLower) || (fPos > pData->fUpper) ) if ((fPos < pData->fLower) || (fPos > pData->fUpper)) {
{ sprintf(pBueffel, " %f outside limits %f %f",
sprintf(pBueffel," %f outside limits %f %f", fPos, pData->fLower, pData->fUpper);
fPos,pData->fLower, pData->fUpper); Tcl_AppendResult(interp, "Requested position: ",
Tcl_AppendResult(interp,"Requested position: ", pBueffel, (char *) NULL);
pBueffel,(char *)NULL);
return TCL_ERROR; return TCL_ERROR;
} }
*fDrive = fPos; *fDrive = fPos;
return TCL_OK; return TCL_OK;
} }
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
fucking standard library missing functionality!!!!!!!!!!!!!!!! fucking standard library missing functionality!!!!!!!!!!!!!!!!
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
static float absf(float x) static float absf(float x)
{ {
if(x < .0) if (x < .0)
return -x; return -x;
else else
return x; return x;
} }
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
@@ -230,10 +217,10 @@ int EL734(ClientData clientData, Tcl_Interp *interp,
motor upper val sets a software upper limit motor upper val sets a software upper limit
motor lower val sets a software lower limit motor lower val sets a software lower limit
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp, EXTERN int EL734Action(ClientData clientData, Tcl_Interp * interp,
int argc, char *argv[]) int argc, char *argv[])
{ {
EL734st *pData = (EL734st *)clientData; EL734st *pData = (EL734st *) clientData;
char pBueffel[80]; char pBueffel[80];
char *pErr = NULL; char *pErr = NULL;
int iRet, iMSR, iOMSR, iFPC, iFRC, iSS; int iRet, iMSR, iOMSR, iFPC, iFRC, iSS;
@@ -244,50 +231,43 @@ EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp,
/* check parameters */ /* check parameters */
if(argc < 2) if (argc < 2) {
{
Tcl_AppendResult(interp, Tcl_AppendResult(interp,
"Usage: motor and either dr, pos, hlim slim run zero up lo",(char *)NULL); "Usage: motor and either dr, pos, hlim slim run zero up lo",
(char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
if(pData == NULL) if (pData == NULL) {
{ Tcl_AppendResult(interp, "Motor data lost!!!!!!!!", (char *) NULL);
Tcl_AppendResult(interp,
"Motor data lost!!!!!!!!",(char *)NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/* check for HW-lim */ /* check for HW-lim */
if(strcmp(argv[1],"hlim") == 0) if (strcmp(argv[1], "hlim") == 0) {
{ sprintf(pBueffel, " %f %f", pData->fLower, pData->fUpper);
sprintf(pBueffel," %f %f",pData->fLower,pData->fUpper); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
Tcl_AppendResult(interp,pBueffel,(char *)NULL);
return TCL_OK; return TCL_OK;
} }
/* check for SW-lim */ /* check for SW-lim */
if(strcmp(argv[1],"slim") == 0) if (strcmp(argv[1], "slim") == 0) {
{ sprintf(pBueffel, " %f %f", pData->fSoftLower, pData->fSoftUpper);
sprintf(pBueffel," %f %f",pData->fSoftLower,pData->fSoftUpper); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
Tcl_AppendResult(interp,pBueffel,(char *)NULL);
return TCL_OK; return TCL_OK;
} }
/* fix & unfix */ /* fix & unfix */
if(strcmp(argv[1],"fix") == 0) if (strcmp(argv[1], "fix") == 0) {
{
pData->iFix = True; pData->iFix = True;
return TCL_OK; return TCL_OK;
} }
if(strcmp(argv[1],"unfix") == 0) if (strcmp(argv[1], "unfix") == 0) {
{
pData->iFix = False; pData->iFix = False;
return TCL_OK; return TCL_OK;
} }
/* reset */ /* reset */
if(strcmp(argv[1],"reset")== 0) if (strcmp(argv[1], "reset") == 0) {
{
pData->iFix = False; pData->iFix = False;
pData->iLowFlag = False; pData->iLowFlag = False;
pData->iUpFlag = False; pData->iUpFlag = False;
@@ -296,62 +276,46 @@ EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp,
} }
/* check for pos */ /* check for pos */
if(strcmp(argv[1],"pos") == 0) if (strcmp(argv[1], "pos") == 0) {
{
iRet = EL734_GetStatus(&(pData->pData), iRet = EL734_GetStatus(&(pData->pData),
&iMSR, &iMSR, &iOMSR, &iFPC, &iFRC, &iSS, &fPos);
&iOMSR, if (!iRet) {
&iFPC, EL734_ErrInfo(&pErr, &iMSR, &iOMSR, &iSS);
&iFRC, EL734Error2Text(pBueffel, iMSR);
&iSS, Tcl_AppendResult(interp, pBueffel, (char *) NULL);
&fPos);
if(!iRet)
{
EL734_ErrInfo(&pErr,&iMSR,&iOMSR, &iSS);
EL734Error2Text(pBueffel,iMSR);
Tcl_AppendResult(interp,pBueffel,(char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} } else {
else if (pData->iZeroFlag) {
{
if(pData->iZeroFlag)
{
fPos += pData->fSoftZero; fPos += pData->fSoftZero;
} }
sprintf(pBueffel," %f",fPos); sprintf(pBueffel, " %f", fPos);
Tcl_AppendResult(interp,pBueffel,NULL); Tcl_AppendResult(interp, pBueffel, NULL);
return TCL_OK; return TCL_OK;
} }
} }
/* zero point */ /* zero point */
if(strcmp(argv[1],"zero") == 0) if (strcmp(argv[1], "zero") == 0) {
{
/* check for zero already been defined */ /* check for zero already been defined */
if(pData->iZeroFlag) if (pData->iZeroFlag) {
{
Tcl_AppendResult(interp, Tcl_AppendResult(interp,
"Request to set new zero point rejected.", "Request to set new zero point rejected.",
" Use reset before new definition. ", " Use reset before new definition. ",
" I'll get confused otherwise ", " I'll get confused otherwise ", NULL);
NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/* get the new position */ /* get the new position */
if(argc < 3) if (argc < 3) {
{ Tcl_AppendResult(interp, "Usage: motor zero val", NULL);
Tcl_AppendResult(interp,
"Usage: motor zero val",NULL);
return TCL_ERROR; return TCL_ERROR;
} }
iRet = Tcl_GetDouble(interp,argv[2],&dPos); iRet = Tcl_GetDouble(interp, argv[2], &dPos);
fNpos = dPos; fNpos = dPos;
if(iRet == TCL_ERROR) if (iRet == TCL_ERROR) {
{ Tcl_AppendResult(interp, "Need float value for new zeropint",
Tcl_AppendResult(interp,"Need float value for new zeropint", (char *) NULL);
(char *)NULL);
return iRet; return iRet;
} }
pData->fSoftZero = -fNpos; pData->fSoftZero = -fNpos;
@@ -360,22 +324,18 @@ EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp,
} }
/* upper SW-limit */ /* upper SW-limit */
if(strcmp(argv[1],"up") == 0) if (strcmp(argv[1], "up") == 0) {
{
/* get the new position */ /* get the new position */
if(argc < 3) if (argc < 3) {
{ Tcl_AppendResult(interp, "Usage: motor up val", NULL);
Tcl_AppendResult(interp,
"Usage: motor up val",NULL);
return TCL_ERROR; return TCL_ERROR;
} }
iRet = Tcl_GetDouble(interp,argv[2],&dPos); iRet = Tcl_GetDouble(interp, argv[2], &dPos);
fNpos = dPos; fNpos = dPos;
if(iRet == TCL_ERROR) if (iRet == TCL_ERROR) {
{ Tcl_AppendResult(interp, "Need float value for new upper limit",
Tcl_AppendResult(interp,"Need float value for new upper limit", (char *) NULL);
(char *)NULL);
return iRet; return iRet;
} }
pData->fSoftUpper = fNpos; pData->fSoftUpper = fNpos;
@@ -384,22 +344,18 @@ EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp,
} }
/* lower SW-limit */ /* lower SW-limit */
if(strcmp(argv[1],"lo") == 0) if (strcmp(argv[1], "lo") == 0) {
{
/* get the new position */ /* get the new position */
if(argc < 3) if (argc < 3) {
{ Tcl_AppendResult(interp, "Usage: motor lo val", NULL);
Tcl_AppendResult(interp,
"Usage: motor lo val",NULL);
return TCL_ERROR; return TCL_ERROR;
} }
iRet = Tcl_GetDouble(interp,argv[2],&dPos); iRet = Tcl_GetDouble(interp, argv[2], &dPos);
fNpos = dPos; fNpos = dPos;
if(iRet == TCL_ERROR) if (iRet == TCL_ERROR) {
{ Tcl_AppendResult(interp, "Need float value for new lower limit",
Tcl_AppendResult(interp,"Need float value for new lower limit", (char *) NULL);
(char *)NULL);
return iRet; return iRet;
} }
pData->fSoftLower = fNpos; pData->fSoftLower = fNpos;
@@ -410,87 +366,73 @@ EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp,
/* this is most important: dr for Drive */ /* this is most important: dr for Drive */
if(strcmp(argv[1],"dr") == 0) if (strcmp(argv[1], "dr") == 0) {
{
/* get the new position */ /* get the new position */
if(argc < 3) if (argc < 3) {
{ Tcl_AppendResult(interp, "Usage: motor dr val", NULL);
Tcl_AppendResult(interp,
"Usage: motor dr val",NULL);
return TCL_ERROR; return TCL_ERROR;
} }
iRet = Tcl_GetDouble(interp,argv[2],&dPos); iRet = Tcl_GetDouble(interp, argv[2], &dPos);
fNpos = dPos; fNpos = dPos;
if(iRet == TCL_ERROR) if (iRet == TCL_ERROR) {
{ Tcl_AppendResult(interp, "Need value to drive to", (char *) NULL);
Tcl_AppendResult(interp,"Need value to drive to",
(char *)NULL);
return iRet; return iRet;
} }
/* check if compatible with limits */ /* check if compatible with limits */
if(CheckPos(interp,pData,fNpos,&fPos) == TCL_ERROR) if (CheckPos(interp, pData, fNpos, &fPos) == TCL_ERROR)
return TCL_ERROR; return TCL_ERROR;
/* finally move */ /* finally move */
iRet = EL734_MoveWait(&(pData->pData), fPos, &iOMSR, iRet = EL734_MoveWait(&(pData->pData), fPos, &iOMSR,
&iFPC, &iFRC,&fNpos); &iFPC, &iFRC, &fNpos);
/* 99.99999999999% of all code is error checking */ /* 99.99999999999% of all code is error checking */
if(!iRet) if (!iRet) {
{ EL734_ErrInfo(&pErr, &iMSR, &iOMSR, &iSS);
EL734_ErrInfo(&pErr,&iMSR,&iOMSR, &iSS); EL734Error2Text(pBueffel, iMSR);
EL734Error2Text(pBueffel,iMSR); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
Tcl_AppendResult(interp,pBueffel,(char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/* check if driving has been done */ /* check if driving has been done */
if(absf(fPos-fNpos) > MOTACURRACY) if (absf(fPos - fNpos) > MOTACURRACY) {
{
Tcl_AppendResult(interp, Tcl_AppendResult(interp,
" Motor error: inacurate driving!", " Motor error: inacurate driving!",
" Probably something serious is wrong ", " Probably something serious is wrong ",
" Check the fucking hardware ", " Check the fucking hardware ", NULL);
NULL);
return TCL_ERROR; return TCL_ERROR;
} }
return TCL_OK; return TCL_OK;
} }
/* this is most important: run for Driving without waiting */ /* this is most important: run for Driving without waiting */
if(strcmp(argv[1],"run") == 0) if (strcmp(argv[1], "run") == 0) {
{
/* get the new position */ /* get the new position */
if(argc < 3) if (argc < 3) {
{ Tcl_AppendResult(interp, "Usage: motor run val", NULL);
Tcl_AppendResult(interp,
"Usage: motor run val",NULL);
return TCL_ERROR; return TCL_ERROR;
} }
iRet = Tcl_GetDouble(interp,argv[2],&dPos); iRet = Tcl_GetDouble(interp, argv[2], &dPos);
fNpos = dPos; fNpos = dPos;
if(iRet == TCL_ERROR) if (iRet == TCL_ERROR) {
{ Tcl_AppendResult(interp, "Need value to run for", (char *) NULL);
Tcl_AppendResult(interp,"Need value to run for",
(char *)NULL);
return iRet; return iRet;
} }
/* check if compatible with limits */ /* check if compatible with limits */
if(CheckPos(interp,pData,fNpos,&fPos) == TCL_ERROR) if (CheckPos(interp, pData, fNpos, &fPos) == TCL_ERROR)
return TCL_ERROR; return TCL_ERROR;
/* finally move */ /* finally move */
iRet = EL734_MoveNoWait (&(pData->pData), fPos); iRet = EL734_MoveNoWait(&(pData->pData), fPos);
/* 99.99999999999% of all code is error checking */ /* 99.99999999999% of all code is error checking */
if(!iRet) if (!iRet) {
{ EL734_ErrInfo(&pErr, &iMSR, &iOMSR, &iSS);
EL734_ErrInfo(&pErr,&iMSR,&iOMSR, &iSS); EL734Error2Text(pBueffel, iMSR);
EL734Error2Text(pBueffel,iMSR); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
Tcl_AppendResult(interp,pBueffel,(char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
return TCL_OK; return TCL_OK;
@@ -503,31 +445,28 @@ EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp,
to yield a return value. Usage by normal motor users strictly to yield a return value. Usage by normal motor users strictly
discouraged. discouraged.
*/ */
if(strcmp(argv[1],"com") == 0) if (strcmp(argv[1], "com") == 0) {
{ strcpy(pBueffel, argv[2]);
strcpy(pBueffel,argv[2]); for (i = 3; i < argc; i++) {
for(i = 3; i < argc; i++) strcat(pBueffel, " ");
{ strcat(pBueffel, argv[i]);
strcat(pBueffel," ");
strcat(pBueffel,argv[i]);
} }
sprintf(pBueffel,"%s\r",pBueffel); sprintf(pBueffel, "%s\r", pBueffel);
iRet = EL734_SendCmnds(&(pData->pData),pBueffel,NULL); iRet = EL734_SendCmnds(&(pData->pData), pBueffel, NULL);
if(!iRet) if (!iRet) {
{ EL734_ErrInfo(&pErr, &iMSR, &iOMSR, &iSS);
EL734_ErrInfo(&pErr,&iMSR,&iOMSR, &iSS); EL734Error2Text(pBueffel, iMSR);
EL734Error2Text(pBueffel,iMSR); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
Tcl_AppendResult(interp,pBueffel,(char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/* fetch reply */ /* fetch reply */
pReply = (struct RS__RplyStruct *)EL734_GetReply( pReply =
&(pData->pData),NULL); (struct RS__RplyStruct *) EL734_GetReply(&(pData->pData), NULL);
while(pReply != NULL) while (pReply != NULL) {
{ Tcl_AppendElement(interp, pReply->rply);
Tcl_AppendElement(interp,pReply->rply); pReply =
pReply = (struct RS__RplyStruct *)EL734_GetReply( (struct RS__RplyStruct *) EL734_GetReply(&(pData->pData),
&(pData->pData),pReply); pReply);
} }
return TCL_OK; return TCL_OK;
} }
@@ -535,110 +474,110 @@ EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp,
/* if we end here an unknown command has been sent */ /* if we end here an unknown command has been sent */
Tcl_AppendResult(interp, Tcl_AppendResult(interp,
"Usage: motor and either dr, run,zero, pos, hlim" "Usage: motor and either dr, run,zero, pos, hlim"
"slim up low reset fix unfix",(char *)NULL); "slim up low reset fix unfix", (char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/*--------------------------------------------------------------------------- /*---------------------------------------------------------------------------
EL734Error2Text converts between an EL734 error code to text EL734Error2Text converts between an EL734 error code to text
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
void EL734Error2Text(char *pBuffer, int iErr) void EL734Error2Text(char *pBuffer, int iErr)
{ {
switch(iErr) switch (iErr) {
{
case -28: case -28:
strcpy(pBuffer,"EL734__BAD_ADR"); strcpy(pBuffer, "EL734__BAD_ADR");
break; break;
case -8: case -8:
strcpy(pBuffer,"EL734__BAD_BIND"); strcpy(pBuffer, "EL734__BAD_BIND");
break; break;
case -30: case -30:
strcpy(pBuffer,"EL734__BAD_BSY"); strcpy(pBuffer, "EL734__BAD_BSY");
break; break;
case -3: case -3:
strcpy(pBuffer,"EL734__BAD_CMD"); strcpy(pBuffer, "EL734__BAD_CMD");
break; break;
case -9: case -9:
strcpy(pBuffer,"EL734__BAD_CONNECT"); strcpy(pBuffer, "EL734__BAD_CONNECT");
break; break;
case -23: case -23:
strcpy(pBuffer,"EL734__BAD_FLUSH"); strcpy(pBuffer, "EL734__BAD_FLUSH");
break; break;
case -6: case -6:
strcpy(pBuffer,"EL734__BAD_HOST"); strcpy(pBuffer, "EL734__BAD_HOST");
break; break;
case -10: case -10:
strcpy(pBuffer,"EL734__BAD_ID"); strcpy(pBuffer, "EL734__BAD_ID");
break; break;
case -5: case -5:
strcpy(pBuffer,"EL734__BAD_ILLG"); strcpy(pBuffer, "EL734__BAD_ILLG");
break; break;
case -2: case -2:
strcpy(pBuffer,"EL734__BAD_LOC"); strcpy(pBuffer, "EL734__BAD_LOC");
break; break;
case -11: case -11:
strcpy(pBuffer,"EL734__BAD_MALLOC"); strcpy(pBuffer, "EL734__BAD_MALLOC");
break; break;
case -21: case -21:
strcpy(pBuffer,"EL734__BAD_NOT_BCD"); strcpy(pBuffer, "EL734__BAD_NOT_BCD");
break; break;
case -4: case -4:
strcpy(pBuffer,"EL734__BAD_OFL"); strcpy(pBuffer, "EL734__BAD_OFL");
break; break;
case -29: case -29:
strcpy(pBuffer,"EL734__BAD_PAR"); strcpy(pBuffer, "EL734__BAD_PAR");
break; break;
case -17: case -17:
strcpy(pBuffer,"EL734__BAD_RECV"); strcpy(pBuffer, "EL734__BAD_RECV");
break; break;
case -19: case -19:
strcpy(pBuffer,"EL734__BAD_RECV_NET"); strcpy(pBuffer, "EL734__BAD_RECV_NET");
break; break;
case -18: case -18:
strcpy(pBuffer,"EL734__BAD_RECV_PIPE"); strcpy(pBuffer, "EL734__BAD_RECV_PIPE");
break; break;
case -20: case -20:
strcpy(pBuffer,"EL734__BAD_RECV_UNKN"); strcpy(pBuffer, "EL734__BAD_RECV_UNKN");
break; break;
case -22: case -22:
strcpy(pBuffer,"EL734__BAD_RECVLEN"); strcpy(pBuffer, "EL734__BAD_RECVLEN");
break; break;
case -24: case -24:
strcpy(pBuffer,"EL734__BAD_RECV1"); strcpy(pBuffer, "EL734__BAD_RECV1");
break; break;
case -26: case -26:
strcpy(pBuffer,"EL734__BAD_RECV1_NET"); strcpy(pBuffer, "EL734__BAD_RECV1_NET");
break; break;
case -25: case -25:
strcpy(pBuffer,"EL734__BAD_RECV1_PIPE"); strcpy(pBuffer, "EL734__BAD_RECV1_PIPE");
break; break;
case -27: case -27:
strcpy(pBuffer,"EL734__BAD_RNG"); strcpy(pBuffer, "EL734__BAD_RNG");
break; break;
case -13: case -13:
strcpy(pBuffer,"EL734__BAD_SEND"); strcpy(pBuffer, "EL734__BAD_SEND");
break; break;
case -14: case -14:
strcpy(pBuffer,"EL734__BAD_SEND_PIPE"); strcpy(pBuffer, "EL734__BAD_SEND_PIPE");
break; break;
case -15: case -15:
strcpy(pBuffer,"EL734__BAD_SEND_NET"); strcpy(pBuffer, "EL734__BAD_SEND_NET");
break; break;
case -16: case -16:
strcpy(pBuffer,"EL734__BAD_SEND_UNKN"); strcpy(pBuffer, "EL734__BAD_SEND_UNKN");
break; break;
case -12: case -12:
strcpy(pBuffer,"EL734__BAD_SENDLEN"); strcpy(pBuffer, "EL734__BAD_SENDLEN");
break; break;
case -7: case -7:
strcpy(pBuffer,"EL734__BAD_SOCKET"); strcpy(pBuffer, "EL734__BAD_SOCKET");
break; break;
case -1: case -1:
strcpy(pBuffer,"EL734__BAD_TMO"); strcpy(pBuffer, "EL734__BAD_TMO");
break; break;
default: default:
strcpy(pBuffer,"Unknown EL734 error"); strcpy(pBuffer, "Unknown EL734 error");
break; break;
} }
} }

View File

@@ -29,7 +29,8 @@ enum EL737_States {
PTSP = 0x9, PTSP = 0x9,
PCSP = 0xA, PCSP = 0xA,
LRTSP = 0xD, LRTSP = 0xD,
LRCSP = 0xE}; LRCSP = 0xE
};
enum EL737_Consts { enum EL737_Consts {
VMECNT__PRESET_COUNT, VMECNT__PRESET_COUNT,
@@ -37,20 +38,21 @@ enum EL737_Consts {
VMECNT__FULL, VMECNT__FULL,
VMECNT__SHORT, VMECNT__SHORT,
VMECNT__INCR}; VMECNT__INCR
};
/* /*
** Structure to which the EL737_Open handle points. ** Structure to which the EL737_Open handle points.
*/ */
struct EL737info { struct EL737info {
struct AsynSrv__info asyn_info; /* Contains skt, host, port & chan */ struct AsynSrv__info asyn_info; /* Contains skt, host, port & chan */
int c5, c6, c7, c8; int c5, c6, c7, c8;
struct RS__MsgStruct to_host; struct RS__MsgStruct to_host;
struct RS__RespStruct from_host; struct RS__RespStruct from_host;
}; };
/* /*
** Structure holding everything that is known about a VME Neutron Counter. ** Structure holding everything that is known about a VME Neutron Counter.
*/ */
struct Counter_State { struct Counter_State {
int state; /* RS */ int state; /* RS */
char timer[16]; /* RT \ RA */ char timer[16]; /* RT \ RA */
int cntrs[8]; /* RC 1 ... RC 8 / */ int cntrs[8]; /* RC 1 ... RC 8 / */
@@ -62,6 +64,6 @@ enum EL737_Consts {
char threshes[8][16]; /* DL 1 ... DL 8 */ char threshes[8][16]; /* DL 1 ... DL 8 */
int mon_preset; /* MP */ int mon_preset; /* MP */
char timer_preset[16]; /* TP */ char timer_preset[16]; /* TP */
}; };
/*----------------------------------------------------- End of EL737_DEF.H --*/ /*----------------------------------------------------- End of EL737_DEF.H --*/
#endif /* _el737_def_ */ #endif /* _el737_def_ */

File diff suppressed because it is too large Load Diff

View File

@@ -23,13 +23,13 @@
#define True 1 #define True 1
#define False 0 #define False 0
typedef struct typedef struct {
{
void *pData; /* EL737 open struct */ void *pData; /* EL737 open struct */
} EL737st; } EL737st;
EXTERN int EL737Action(ClientData pDat, Tcl_Interp *i, int a, char *argv[]); EXTERN int EL737Action(ClientData pDat, Tcl_Interp * i, int a,
static void EL737Error2Text(char *pBuffer, int errcode); char *argv[]);
static void EL737Error2Text(char *pBuffer, int errcode);
/*--------------------------------------------------------------------------- /*---------------------------------------------------------------------------
Tcl has a high niceness level. It deletes a command properly when Tcl has a high niceness level. It deletes a command properly when
@@ -38,10 +38,11 @@
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
EXTERN void EL737Murder(ClientData pData) EXTERN void EL737Murder(ClientData pData)
{ {
EL737st *pTa = (EL737st *)pData; EL737st *pTa = (EL737st *) pData;
EL737_Close(&(pTa->pData)); EL737_Close(&(pTa->pData));
free(pData); free(pData);
} }
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
CterEL737 is the main entry point for this stuff. It connects to a counter CterEL737 is the main entry point for this stuff. It connects to a counter
and, on success, creates a new command with the name of the counter. and, on success, creates a new command with the name of the counter.
@@ -49,7 +50,7 @@ EXTERN void EL737Murder(ClientData pData)
EL737 name host port channel EL737 name host port channel
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
int CterEL737(ClientData clientData, Tcl_Interp *interp, int CterEL737(ClientData clientData, Tcl_Interp * interp,
int argc, char *argv[]) int argc, char *argv[])
{ {
int iRet; int iRet;
@@ -59,58 +60,51 @@ int CterEL737(ClientData clientData, Tcl_Interp *interp,
char pBueffel[80]; char pBueffel[80];
/* check arguments */ /* check arguments */
if(argc < 5) if (argc < 5) {
{
Tcl_AppendResult(interp, Tcl_AppendResult(interp,
" Insufficient arguments: CterEL737 name host port channel" " Insufficient arguments: CterEL737 name host port channel",
, (char *) NULL); (char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/* convert arguments */ /* convert arguments */
iRet = Tcl_GetInt(interp,argv[3],&iPort); iRet = Tcl_GetInt(interp, argv[3], &iPort);
if(iRet == TCL_ERROR) if (iRet == TCL_ERROR) {
{ Tcl_AppendResult(interp, "Need integer value for port", (char *) NULL);
Tcl_AppendResult(interp,"Need integer value for port",
(char *)NULL);
return iRet; return iRet;
} }
iRet = Tcl_GetInt(interp,argv[4],&iChannel); iRet = Tcl_GetInt(interp, argv[4], &iChannel);
if(iRet == TCL_ERROR) if (iRet == TCL_ERROR) {
{ Tcl_AppendResult(interp, "Need integer value for channel",
Tcl_AppendResult(interp,"Need integer value for channel", (char *) NULL);
(char *)NULL);
return iRet; return iRet;
} }
/* make a new pointer, initialise EL737st */ /* make a new pointer, initialise EL737st */
pEL737 = (EL737st *)malloc(sizeof(EL737st)); pEL737 = (EL737st *) malloc(sizeof(EL737st));
if(pEL737 ==NULL) if (pEL737 == NULL) {
{ Tcl_AppendResult(interp, "No memory in EL734", NULL);
Tcl_AppendResult(interp,"No memory in EL734",NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/* open the rotten Counter, finally */ /* open the rotten Counter, finally */
iRet = EL737_Open(&(pEL737->pData), argv[2],iPort,iChannel); iRet = EL737_Open(&(pEL737->pData), argv[2], iPort, iChannel);
if(iRet) /* success */ if (iRet) { /* success */
{
/* handle TCL, create new command: the Counter */ /* handle TCL, create new command: the Counter */
Tcl_CreateCommand(interp,strdup(argv[1]),EL737Action, Tcl_CreateCommand(interp, strdup(argv[1]), EL737Action,
(ClientData)pEL737,EL737Murder); (ClientData) pEL737, EL737Murder);
Tcl_AppendResult(interp,strdup(argv[1]),(char *)NULL); Tcl_AppendResult(interp, strdup(argv[1]), (char *) NULL);
return TCL_OK; return TCL_OK;
} } else {
else EL737_ErrInfo(&pErr, &iPort, &iChannel, &iMotor);
{ EL737Error2Text(pBueffel, iPort);
EL737_ErrInfo(&pErr,&iPort,&iChannel, &iMotor); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
EL737Error2Text(pBueffel,iPort);
Tcl_AppendResult(interp,pBueffel,(char *) NULL);
free(pEL737); free(pEL737);
return TCL_ERROR; return TCL_ERROR;
} }
} }
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
EL737 Action is the routine where commands send to the conter will EL737 Action is the routine where commands send to the conter will
@@ -130,10 +124,10 @@ int CterEL737(ClientData clientData, Tcl_Interp *interp,
{ counts monitor time } { counts monitor time }
counter Stop forces counter to stop counter Stop forces counter to stop
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
EXTERN int EL737Action(ClientData clientData, Tcl_Interp *interp, EXTERN int EL737Action(ClientData clientData, Tcl_Interp * interp,
int argc, char *argv[]) int argc, char *argv[])
{ {
EL737st *pData = (EL737st *)clientData; EL737st *pData = (EL737st *) clientData;
char pBueffel[132]; char pBueffel[132];
char pNumBuf[20]; char pNumBuf[20];
char *pErr = NULL; char *pErr = NULL;
@@ -144,257 +138,227 @@ EXTERN int EL737Action(ClientData clientData, Tcl_Interp *interp,
double dVal; double dVal;
/* obviously we need at least a keyword! */ /* obviously we need at least a keyword! */
if(argc < 2) if (argc < 2) {
{ Tcl_AppendResult(interp, "No keyword given", NULL);
Tcl_AppendResult(interp,"No keyword given",NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/* get values out */ /* get values out */
if(strcmp(argv[1],"value") == 0) if (strcmp(argv[1], "value") == 0) {
{ iRet = EL737_GetStatus(&(pData->pData), &iC1, &iC2, &iC3,
iRet = EL737_GetStatus(&(pData->pData),&iC1, &iC2, &iC3, &iC4, &fTime, &iRS);
&iC4,&fTime,&iRS); if (!iRet) {
if(!iRet) EL737_ErrInfo(&pErr, &iC1, &iC2, &iC3);
{ EL737Error2Text(pBueffel, iC1);
EL737_ErrInfo(&pErr,&iC1,&iC2, &iC3); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
EL737Error2Text(pBueffel,iC1);
Tcl_AppendResult(interp,pBueffel,(char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
sprintf(pNumBuf,"%d",iC2); sprintf(pNumBuf, "%d", iC2);
Tcl_AppendElement(interp,pNumBuf); Tcl_AppendElement(interp, pNumBuf);
sprintf(pNumBuf,"%d",iC1); sprintf(pNumBuf, "%d", iC1);
Tcl_AppendElement(interp,pNumBuf); Tcl_AppendElement(interp, pNumBuf);
sprintf(pNumBuf,"%f",fTime); sprintf(pNumBuf, "%f", fTime);
Tcl_AppendElement(interp,pNumBuf); Tcl_AppendElement(interp, pNumBuf);
return TCL_OK; return TCL_OK;
} }
/* isDone ? */ /* isDone ? */
if(strcmp(argv[1],"isDone") == 0) if (strcmp(argv[1], "isDone") == 0) {
{ iRet = EL737_GetStatus(&(pData->pData), &iC1, &iC2, &iC3,
iRet = EL737_GetStatus(&(pData->pData),&iC1, &iC2, &iC3, &iC4, &fTime, &iRS);
&iC4,&fTime,&iRS); if (!iRet) {
if(!iRet) EL737_ErrInfo(&pErr, &iC1, &iC2, &iC3);
{ EL737Error2Text(pBueffel, iC1);
EL737_ErrInfo(&pErr,&iC1,&iC2, &iC3); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
EL737Error2Text(pBueffel,iC1);
Tcl_AppendResult(interp,pBueffel,(char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
if(iRS == 0) /* done is true */ if (iRS == 0) { /* done is true */
{ sprintf(pNumBuf, "%d", True);
sprintf(pNumBuf,"%d",True); } else {
sprintf(pNumBuf, "%d", False);
} }
else Tcl_AppendResult(interp, pNumBuf, (char *) NULL);
{
sprintf(pNumBuf,"%d",False);
}
Tcl_AppendResult(interp,pNumBuf,(char *) NULL);
return TCL_OK; return TCL_OK;
} }
/* actual counting neutrons in two different modes */ /* actual counting neutrons in two different modes */
if(strcmp(argv[1],"wait") == 0) if (strcmp(argv[1], "wait") == 0) {
{
iFlag = 2; iFlag = 2;
} }
if(strcmp(argv[1],"start") == 0) if (strcmp(argv[1], "start") == 0) {
{
iFlag = 1; iFlag = 1;
} }
if(iFlag > 0) /* we need to count */ if (iFlag > 0) { /* we need to count */
{ if (argc < 4) { /* not enough arguments */
if(argc < 4) /* not enough arguments */ Tcl_AppendResult(interp, "Usage: ", argv[0], argv[1],
{ " timer or monitor val", NULL);
Tcl_AppendResult(interp,"Usage: ",argv[0],argv[1],
" timer or monitor val",NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/* timer or monitor preset ? */ /* timer or monitor preset ? */
if(strcmp(argv[2],"timer") == 0) if (strcmp(argv[2], "timer") == 0) {
{
iMode = 1; iMode = 1;
} } else if (strcmp(argv[2], "monitor") == 0) {
else if (strcmp(argv[2],"monitor") == 0)
{
iMode = 2; iMode = 2;
} } else {
else Tcl_AppendResult(interp, "Usage: ", argv[0], argv[1],
{ " timer or monitor val", NULL);
Tcl_AppendResult(interp,"Usage: ",argv[0],argv[1],
" timer or monitor val",NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/* get the preset value */ /* get the preset value */
iRet = Tcl_GetDouble(interp,argv[3],&dVal); iRet = Tcl_GetDouble(interp, argv[3], &dVal);
if(iRet == TCL_ERROR) if (iRet == TCL_ERROR) {
{
return TCL_ERROR; return TCL_ERROR;
} }
/* actual start collecting neutrons */ /* actual start collecting neutrons */
if(iMode == 1) if (iMode == 1) {
{ iRet = EL737_StartTime(&(pData->pData), (float) dVal, &iRS);
iRet = EL737_StartTime(&(pData->pData),(float)dVal, } else {
&iRS); iRet = EL737_StartCnt(&(pData->pData), (int) dVal, &iRS);
} }
else if (!iRet) {
{ EL737_ErrInfo(&pErr, &iC1, &iC2, &iC3);
iRet = EL737_StartCnt(&(pData->pData),(int)dVal, EL737Error2Text(pBueffel, iC1);
&iRS); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
}
if(!iRet)
{
EL737_ErrInfo(&pErr,&iC1,&iC2, &iC3);
EL737Error2Text(pBueffel,iC1);
Tcl_AppendResult(interp,pBueffel,(char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
} /* end of count startup code */ }
/* end of count startup code */
/* if apropriate: wait */ /* if apropriate: wait */
if(iFlag == 2) if (iFlag == 2) {
{ iRet = EL737_WaitIdle(&(pData->pData), &iC1, &iC2, &iC3, &iC4, &fTime);
iRet = EL737_WaitIdle(&(pData->pData),&iC1, &iC2, &iC3, if (!iRet) {
&iC4,&fTime); EL737_ErrInfo(&pErr, &iC1, &iC2, &iC3);
if(!iRet) EL737Error2Text(pBueffel, iC1);
{ Tcl_AppendResult(interp, pBueffel, (char *) NULL);
EL737_ErrInfo(&pErr,&iC1,&iC2, &iC3);
EL737Error2Text(pBueffel,iC1);
Tcl_AppendResult(interp,pBueffel,(char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
return TCL_OK; return TCL_OK;
} } else if (iFlag == 1) {
else if(iFlag == 1)
{
return TCL_OK; return TCL_OK;
} }
/* the stop command */ /* the stop command */
if(strcmp(argv[1],"stop") == 0) if (strcmp(argv[1], "stop") == 0) {
{ iRet = EL737_Stop(&(pData->pData), &iC1, &iC2, &iC3,
iRet = EL737_Stop(&(pData->pData),&iC1, &iC2, &iC3, &iC4, &fTime, &iRS);
&iC4,&fTime,&iRS); if (!iRet) {
if(!iRet) EL737_ErrInfo(&pErr, &iC1, &iC2, &iC3);
{ EL737Error2Text(pBueffel, iC1);
EL737_ErrInfo(&pErr,&iC1,&iC2, &iC3); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
EL737Error2Text(pBueffel,iC1);
Tcl_AppendResult(interp,pBueffel,(char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
return TCL_OK; return TCL_OK;
} }
Tcl_AppendResult(interp," obscure command: ",argv[1], Tcl_AppendResult(interp, " obscure command: ", argv[1],
" not understood by EL737 counter", NULL); " not understood by EL737 counter", NULL);
return TCL_ERROR; return TCL_ERROR;
} }
/*--------------------------------------------------------------------------- /*---------------------------------------------------------------------------
EL737Error2Text converts between an EL734 error code to text EL737Error2Text converts between an EL734 error code to text
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
void EL737Error2Text(char *pBuffer, int iErr) void EL737Error2Text(char *pBuffer, int iErr)
{ {
switch(iErr) switch (iErr) {
{
case -28: case -28:
strcpy(pBuffer,"EL737__BAD_ADR"); strcpy(pBuffer, "EL737__BAD_ADR");
break; break;
case -8: case -8:
strcpy(pBuffer,"EL737__BAD_OVFL"); strcpy(pBuffer, "EL737__BAD_OVFL");
break; break;
case -30: case -30:
strcpy(pBuffer,"EL737__BAD_BSY"); strcpy(pBuffer, "EL737__BAD_BSY");
break; break;
case -3: case -3:
strcpy(pBuffer,"EL737__BAD_SNTX"); strcpy(pBuffer, "EL737__BAD_SNTX");
break; break;
case -9: case -9:
strcpy(pBuffer,"EL737__BAD_CONNECT"); strcpy(pBuffer, "EL737__BAD_CONNECT");
break; break;
case -23: case -23:
strcpy(pBuffer,"EL737__BAD_FLUSH"); strcpy(pBuffer, "EL737__BAD_FLUSH");
break; break;
case -6: case -6:
strcpy(pBuffer,"EL734__BAD_DEV"); strcpy(pBuffer, "EL734__BAD_DEV");
break; break;
case -10: case -10:
strcpy(pBuffer,"EL737__BAD_ID"); strcpy(pBuffer, "EL737__BAD_ID");
break; break;
case -5: case -5:
strcpy(pBuffer,"EL737__BAD_ILLG"); strcpy(pBuffer, "EL737__BAD_ILLG");
break; break;
case -2: case -2:
strcpy(pBuffer,"EL737__BAD_LOC"); strcpy(pBuffer, "EL737__BAD_LOC");
break; break;
case -11: case -11:
strcpy(pBuffer,"EL737__BAD_MALLOC"); strcpy(pBuffer, "EL737__BAD_MALLOC");
break; break;
case -21: case -21:
strcpy(pBuffer,"EL737__BAD_NOT_BCD"); strcpy(pBuffer, "EL737__BAD_NOT_BCD");
break; break;
case -4: case -4:
strcpy(pBuffer,"EL737__BAD_OFL"); strcpy(pBuffer, "EL737__BAD_OFL");
break; break;
case -29: case -29:
strcpy(pBuffer,"EL737__BAD_PAR"); strcpy(pBuffer, "EL737__BAD_PAR");
break; break;
case -17: case -17:
strcpy(pBuffer,"EL737__BAD_RECV"); strcpy(pBuffer, "EL737__BAD_RECV");
break; break;
case -19: case -19:
strcpy(pBuffer,"EL737__BAD_RECV_NET"); strcpy(pBuffer, "EL737__BAD_RECV_NET");
break; break;
case -18: case -18:
strcpy(pBuffer,"EL737__BAD_RECV_PIPE"); strcpy(pBuffer, "EL737__BAD_RECV_PIPE");
break; break;
case -20: case -20:
strcpy(pBuffer,"EL737__BAD_RECV_UNKN"); strcpy(pBuffer, "EL737__BAD_RECV_UNKN");
break; break;
case -22: case -22:
strcpy(pBuffer,"EL737__BAD_RECVLEN"); strcpy(pBuffer, "EL737__BAD_RECVLEN");
break; break;
case -24: case -24:
strcpy(pBuffer,"EL737__BAD_RECV1"); strcpy(pBuffer, "EL737__BAD_RECV1");
break; break;
case -26: case -26:
strcpy(pBuffer,"EL737__BAD_RECV1_NET"); strcpy(pBuffer, "EL737__BAD_RECV1_NET");
break; break;
case -25: case -25:
strcpy(pBuffer,"EL737__BAD_RECV1_PIPE"); strcpy(pBuffer, "EL737__BAD_RECV1_PIPE");
break; break;
case -27: case -27:
strcpy(pBuffer,"EL737__BAD_RNG"); strcpy(pBuffer, "EL737__BAD_RNG");
break; break;
case -13: case -13:
strcpy(pBuffer,"EL737__BAD_SEND"); strcpy(pBuffer, "EL737__BAD_SEND");
break; break;
case -14: case -14:
strcpy(pBuffer,"EL737__BAD_SEND_PIPE"); strcpy(pBuffer, "EL737__BAD_SEND_PIPE");
break; break;
case -15: case -15:
strcpy(pBuffer,"EL737__BAD_SEND_NET"); strcpy(pBuffer, "EL737__BAD_SEND_NET");
break; break;
case -16: case -16:
strcpy(pBuffer,"EL737__BAD_SEND_UNKN"); strcpy(pBuffer, "EL737__BAD_SEND_UNKN");
break; break;
case -12: case -12:
strcpy(pBuffer,"EL737__BAD_SENDLEN"); strcpy(pBuffer, "EL737__BAD_SENDLEN");
break; break;
case -7: case -7:
strcpy(pBuffer,"EL737__BAD_SOCKET"); strcpy(pBuffer, "EL737__BAD_SOCKET");
break; break;
case -1: case -1:
strcpy(pBuffer,"EL737__BAD_TMO"); strcpy(pBuffer, "EL737__BAD_TMO");
break; break;
default: default:
strcpy(pBuffer,"Unknown EL737 error"); strcpy(pBuffer, "Unknown EL737 error");
break; break;
} }
} }

View File

@@ -21,11 +21,11 @@
/* /*
** Structure to which the EL755_Open handle points. ** Structure to which the EL755_Open handle points.
*/ */
struct EL755info { struct EL755info {
struct AsynSrv__info asyn_info; /* Contains skt, host, port & chan */ struct AsynSrv__info asyn_info; /* Contains skt, host, port & chan */
int index; int index;
struct RS__MsgStruct to_host; struct RS__MsgStruct to_host;
struct RS__RespStruct from_host; struct RS__RespStruct from_host;
}; };
/*------------------------------------------------ End of EL755_DEF.H --*/ /*------------------------------------------------ End of EL755_DEF.H --*/
#endif /* _el755_def_ */ #endif /* _el755_def_ */

View File

@@ -16,11 +16,13 @@
** routine if he wishes to log these errors in ** routine if he wishes to log these errors in
** some other way. ** some other way.
*/ */
void EL755_ErrorLog ( void EL755_ErrorLog(
/* ============== /* ==============
*/ char *routine_name, */ char *routine_name,
char *text) { char *text)
{
fprintf(stderr, "%s: %s\n", routine_name, text);
}
fprintf (stderr, "%s: %s\n", routine_name, text);
}
/*-------------------------------------------- End of EL755_ErrorLog.C =======*/ /*-------------------------------------------- End of EL755_ErrorLog.C =======*/

File diff suppressed because it is too large Load Diff

View File

@@ -3,103 +3,102 @@
EL734Error2Text converts between an EL734 error code to text EL734Error2Text converts between an EL734 error code to text
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
void EL734Error2Text(char *pBuffer, int iErr) void EL734Error2Text(char *pBuffer, int iErr)
{ {
switch(iErr) switch (iErr) {
{
case -28: case -28:
strcpy(pBuffer,"EL734__BAD_ADR"); strcpy(pBuffer, "EL734__BAD_ADR");
break; break;
case -8: case -8:
strcpy(pBuffer,"EL734__BAD_BIND"); strcpy(pBuffer, "EL734__BAD_BIND");
break; break;
case -30: case -30:
strcpy(pBuffer,"EL734__BAD_BSY"); strcpy(pBuffer, "EL734__BAD_BSY");
break; break;
case -3: case -3:
strcpy(pBuffer,"EL734__BAD_CMD"); strcpy(pBuffer, "EL734__BAD_CMD");
break; break;
case -9: case -9:
strcpy(pBuffer,"EL734__BAD_CONNECT"); strcpy(pBuffer, "EL734__BAD_CONNECT");
break; break;
case -23: case -23:
strcpy(pBuffer,"EL734__BAD_FLUSH"); strcpy(pBuffer, "EL734__BAD_FLUSH");
break; break;
case -6: case -6:
strcpy(pBuffer,"EL734__BAD_HOST"); strcpy(pBuffer, "EL734__BAD_HOST");
break; break;
case -10: case -10:
strcpy(pBuffer,"EL734__BAD_ID"); strcpy(pBuffer, "EL734__BAD_ID");
break; break;
case -5: case -5:
strcpy(pBuffer,"EL734__BAD_ILLG"); strcpy(pBuffer, "EL734__BAD_ILLG");
break; break;
case -2: case -2:
strcpy(pBuffer,"EL734__BAD_LOC"); strcpy(pBuffer, "EL734__BAD_LOC");
break; break;
case -11: case -11:
strcpy(pBuffer,"EL734__BAD_MALLOC"); strcpy(pBuffer, "EL734__BAD_MALLOC");
break; break;
case -21: case -21:
strcpy(pBuffer,"EL734__BAD_NOT_BCD"); strcpy(pBuffer, "EL734__BAD_NOT_BCD");
break; break;
case -4: case -4:
strcpy(pBuffer,"EL734__BAD_OFL"); strcpy(pBuffer, "EL734__BAD_OFL");
break; break;
case -29: case -29:
strcpy(pBuffer,"EL734__BAD_PAR"); strcpy(pBuffer, "EL734__BAD_PAR");
break; break;
case -17: case -17:
strcpy(pBuffer,"EL734__BAD_RECV"); strcpy(pBuffer, "EL734__BAD_RECV");
break; break;
case -19: case -19:
strcpy(pBuffer,"EL734__BAD_RECV_NET"); strcpy(pBuffer, "EL734__BAD_RECV_NET");
break; break;
case -18: case -18:
strcpy(pBuffer,"EL734__BAD_RECV_PIPE"); strcpy(pBuffer, "EL734__BAD_RECV_PIPE");
break; break;
case -20: case -20:
strcpy(pBuffer,"EL734__BAD_RECV_UNKN"); strcpy(pBuffer, "EL734__BAD_RECV_UNKN");
break; break;
case -22: case -22:
strcpy(pBuffer,"EL734__BAD_RECVLEN"); strcpy(pBuffer, "EL734__BAD_RECVLEN");
break; break;
case -24: case -24:
strcpy(pBuffer,"EL734__BAD_RECV1"); strcpy(pBuffer, "EL734__BAD_RECV1");
break; break;
case -26: case -26:
strcpy(pBuffer,"EL734__BAD_RECV1_NET"); strcpy(pBuffer, "EL734__BAD_RECV1_NET");
break; break;
case -25: case -25:
strcpy(pBuffer,"EL734__BAD_RECV1_PIPE"); strcpy(pBuffer, "EL734__BAD_RECV1_PIPE");
break; break;
case -27: case -27:
strcpy(pBuffer,"EL734__BAD_RNG"); strcpy(pBuffer, "EL734__BAD_RNG");
break; break;
case -13: case -13:
strcpy(pBuffer,"EL734__BAD_SEND"); strcpy(pBuffer, "EL734__BAD_SEND");
break; break;
case -14: case -14:
strcpy(pBuffer,"EL734__BAD_SEND_PIPE"); strcpy(pBuffer, "EL734__BAD_SEND_PIPE");
break; break;
case -15: case -15:
strcpy(pBuffer,"EL734__BAD_SEND_NET"); strcpy(pBuffer, "EL734__BAD_SEND_NET");
break; break;
case -16: case -16:
strcpy(pBuffer,"EL734__BAD_SEND_UNKN"); strcpy(pBuffer, "EL734__BAD_SEND_UNKN");
break; break;
case -12: case -12:
strcpy(pBuffer,"EL734__BAD_SENDLEN"); strcpy(pBuffer, "EL734__BAD_SENDLEN");
break; break;
case -7: case -7:
strcpy(pBuffer,"EL734__BAD_SOCKET"); strcpy(pBuffer, "EL734__BAD_SOCKET");
break; break;
case -1: case -1:
strcpy(pBuffer,"EL734__BAD_TMO"); strcpy(pBuffer, "EL734__BAD_TMO");
break; break;
default: default:
strcpy(pBuffer,"Unknown EL734 error"); strcpy(pBuffer, "Unknown EL734 error");
break; break;
} }
} }

View File

@@ -89,21 +89,23 @@
/* /*
** FailInet: Some network failure has occurred. ** FailInet: Some network failure has occurred.
*/ */
void FailInet (char *text) { void FailInet(char *text)
{
/* ======== /* ========
** Output the given text and exit the process. ** Output the given text and exit the process.
*/ */
int my_errno, my_vaxc_errno; int my_errno, my_vaxc_errno;
GetErrno (&my_errno, &my_vaxc_errno); GetErrno(&my_errno, &my_vaxc_errno);
printf ("### Internet Error ###\n"); printf("### Internet Error ###\n");
#ifdef __VMS #ifdef __VMS
printf (" ### errno = %d.\n", my_errno); printf(" ### errno = %d.\n", my_errno);
printf (" ### vaxc$errno = %d.\n", my_vaxc_errno); printf(" ### vaxc$errno = %d.\n", my_vaxc_errno);
#else #else
printf (" ### errno = %d.\n", my_errno); printf(" ### errno = %d.\n", my_errno);
#endif #endif
perror (text); perror(text);
exit (EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/*------------------------------------------------- End of FAILINET.C =======*/ /*------------------------------------------------- End of FAILINET.C =======*/

View File

@@ -82,7 +82,8 @@
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
** GetErrno: Make copies of errno and vaxc$errno for debug. ** GetErrno: Make copies of errno and vaxc$errno for debug.
*/ */
void GetErrno (int *his_errno, int *his_vaxc_errno) { void GetErrno(int *his_errno, int *his_vaxc_errno)
{
/* ======== /* ========
*/ */
*his_errno = errno; /* Make copy of errno */ *his_errno = errno; /* Make copy of errno */
@@ -92,5 +93,6 @@
*his_vaxc_errno = 1; *his_vaxc_errno = 1;
#endif #endif
return; return;
} }
/*------------------------------------------------- End of GETERRNO.C =======*/ /*------------------------------------------------- End of GETERRNO.C =======*/

View File

@@ -45,16 +45,16 @@
#include "itc4util.h" #include "itc4util.h"
/* -------------------------------------------------------------------------*/ /* -------------------------------------------------------------------------*/
int ITC4_Open(pITC4 *pData, char *pHost, int iPort, int iChannel, int iMode) int ITC4_Open(pITC4 * pData, char *pHost, int iPort, int iChannel,
{ int iMode)
{
int iRet; int iRet;
char pCommand[80]; char pCommand[80];
char pReply[132]; char pReply[132];
pITC4 self = NULL; pITC4 self = NULL;
self = (pITC4)malloc(sizeof(ITC4)); self = (pITC4) malloc(sizeof(ITC4));
if(self == NULL) if (self == NULL) {
{
return ITC4__BADMALLOC; return ITC4__BADMALLOC;
} }
*pData = self; *pData = self;
@@ -65,8 +65,7 @@
self->fMult = 10.; self->fMult = 10.;
iRet = SerialOpen(&self->pData, pHost, iPort, iChannel); iRet = SerialOpen(&self->pData, pHost, iPort, iChannel);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
@@ -74,8 +73,7 @@
prevent problems. prevent problems.
*/ */
iRet = SerialConfig(&self->pData, 100); iRet = SerialConfig(&self->pData, 100);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
@@ -86,79 +84,68 @@
an ITC4 if I do not get a proper response. an ITC4 if I do not get a proper response.
*/ */
self->i503 = 0; self->i503 = 0;
iRet = SerialWriteRead(&self->pData,"V\r\n",pReply,131); iRet = SerialWriteRead(&self->pData, "V\r\n", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
if(strstr(pReply,"ITC503") != NULL) if (strstr(pReply, "ITC503") != NULL) {
{
self->i503 = 1; self->i503 = 1;
} }
if(!self->iReadOnly) if (!self->iReadOnly) {
{
/* switch to remote and locked operation */ /* switch to remote and locked operation */
iRet = SerialWriteRead(&self->pData,"C3\r\n",pReply,131); iRet = SerialWriteRead(&self->pData, "C3\r\n", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
if(pReply[0] == '?') if (pReply[0] == '?') {
{ strcpy(self->pAns, pReply);
strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
/* set the control sensor, for this we need to switch A0 first, /* set the control sensor, for this we need to switch A0 first,
the do it and switch back the do it and switch back
*/ */
iRet = SerialWriteRead(&self->pData,"A0\r\n",pReply,131); iRet = SerialWriteRead(&self->pData, "A0\r\n", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
if(pReply[0] == '?') if (pReply[0] == '?') {
{ strcpy(self->pAns, pReply);
strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
sprintf(pCommand,"H%1.1d\r\n",self->iControl); sprintf(pCommand, "H%1.1d\r\n", self->iControl);
iRet = SerialWriteRead(&self->pData,pCommand,pReply,131); iRet = SerialWriteRead(&self->pData, pCommand, pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
if(pReply[0] == '?') if (pReply[0] == '?') {
{ strcpy(self->pAns, pReply);
strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
/* controls to automatic */ /* controls to automatic */
iRet = SerialWriteRead(&self->pData,"A3\r\n",pReply,131); iRet = SerialWriteRead(&self->pData, "A3\r\n", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
if(pReply[0] == '?') if (pReply[0] == '?') {
{ strcpy(self->pAns, pReply);
strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
/* reset timeout */ /* reset timeout */
iRet = SerialConfig(&self->pData, 10); iRet = SerialConfig(&self->pData, 10);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
} }
return 1; return 1;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
void ITC4_Close(pITC4 *pData) void ITC4_Close(pITC4 * pData)
{ {
char pReply[132]; char pReply[132];
int iRet; int iRet;
pITC4 self; pITC4 self;
@@ -166,7 +153,7 @@
self = *pData; self = *pData;
/* switch to local operation */ /* switch to local operation */
iRet = SerialWriteRead(&self->pData,"C0\r\n",pReply,131); iRet = SerialWriteRead(&self->pData, "C0\r\n", pReply, 131);
/* ignore errors on this one, the thing may be down */ /* ignore errors on this one, the thing may be down */
/* close connection */ /* close connection */
@@ -175,11 +162,12 @@
/* free memory */ /* free memory */
free(self); free(self);
*pData = NULL; *pData = NULL;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int ITC4_Config(pITC4 *pData, int iTmo, int iRead, int iControl, int ITC4_Config(pITC4 * pData, int iTmo, int iRead, int iControl,
float fDiv,float fMult) float fDiv, float fMult)
{ {
int iRet; int iRet;
char pReply[132]; char pReply[132];
char pCommand[10]; char pCommand[10];
@@ -188,60 +176,50 @@
self = *pData; self = *pData;
/* first timeout */ /* first timeout */
if(iTmo > 0) if (iTmo > 0) {
{
iRet = SerialConfig(&self->pData, iTmo); iRet = SerialConfig(&self->pData, iTmo);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
} }
/* Read Sensor */ /* Read Sensor */
if( (iRead > 0) && (iRead < 5) && (self->iRead != iRead) ) if ((iRead > 0) && (iRead < 5) && (self->iRead != iRead)) {
{
self->iRead = iRead; self->iRead = iRead;
} }
/* Control Sensor */ /* Control Sensor */
if( (iControl > 0) && (iControl < 5) ) if ((iControl > 0) && (iControl < 5)) {
{
/* set the control sensor, for this we need to switch A0 first, /* set the control sensor, for this we need to switch A0 first,
the do it and switch back the do it and switch back
*/ */
iRet = SerialWriteRead(&self->pData,"A0\r\n",pReply,131); iRet = SerialWriteRead(&self->pData, "A0\r\n", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
if(pReply[0] == '?') if (pReply[0] == '?') {
{ strcpy(self->pAns, pReply);
strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
/* set sensor */ /* set sensor */
sprintf(pCommand,"H%1.1d\r\n",iControl); sprintf(pCommand, "H%1.1d\r\n", iControl);
iRet = SerialWriteRead(&self->pData,pCommand,pReply,131); iRet = SerialWriteRead(&self->pData, pCommand, pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
if(pReply[0] == '?') if (pReply[0] == '?') {
{ strcpy(self->pAns, pReply);
strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
/* controls to automatic */ /* controls to automatic */
iRet = SerialWriteRead(&self->pData,"A3\r\n",pReply,131); iRet = SerialWriteRead(&self->pData, "A3\r\n", pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
if(pReply[0] == '?') if (pReply[0] == '?') {
{ strcpy(self->pAns, pReply);
strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
} }
@@ -249,24 +227,25 @@
self->fMult = fMult; self->fMult = fMult;
return 1; return 1;
} }
/* --------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------*/
int ITC4_Send(pITC4 *pData, char *pCommand, char *pReply, int iLen) int ITC4_Send(pITC4 * pData, char *pCommand, char *pReply, int iLen)
{ {
pITC4 self; pITC4 self;
self = *pData; self = *pData;
/* make sure, that there is a \r at the end of the command */ /* make sure, that there is a \r at the end of the command */
if(strchr(pCommand,(int)'\r') == NULL) if (strchr(pCommand, (int) '\r') == NULL) {
{ strcat(pCommand, "\r");
strcat(pCommand,"\r");
}
return SerialWriteRead(&self->pData,pCommand,pReply,iLen);
} }
return SerialWriteRead(&self->pData, pCommand, pReply, iLen);
}
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int ITC4_Read(pITC4 *pData, float *fVal) int ITC4_Read(pITC4 * pData, float *fVal)
{ {
char pCommand[10], pReply[132]; char pCommand[10], pReply[132];
int iRet; int iRet;
float fRead = -9999999.; float fRead = -9999999.;
@@ -276,43 +255,37 @@
/* format and send R command */ /* format and send R command */
sprintf(pCommand,"R%1.1d\r\n",self->iRead); sprintf(pCommand, "R%1.1d\r\n", self->iRead);
iRet = SerialWriteRead(&self->pData,pCommand,pReply,131); iRet = SerialWriteRead(&self->pData, pCommand, pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
if(pReply[0] == '?') if (pReply[0] == '?') {
{ strcpy(self->pAns, pReply);
strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
/* analyse reply */ /* analyse reply */
if(pReply[0] != 'R') if (pReply[0] != 'R') {
{ strcpy(self->pAns, pReply);
strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
iRet = sscanf(&pReply[1],"%f",&fRead); iRet = sscanf(&pReply[1], "%f", &fRead);
if(iRet != 1) if (iRet != 1) {
{
return ITC4__BADREAD; return ITC4__BADREAD;
} }
if(self->i503) if (self->i503) {
{
*fVal = fRead; *fVal = fRead;
} } else {
else *fVal = fRead / self->fDiv;
{
*fVal = fRead/self->fDiv;
} }
return 1; return 1;
} }
/* -------------------------------------------------------------------------*/ /* -------------------------------------------------------------------------*/
int ITC4_Set(pITC4 *pData, float fVal) int ITC4_Set(pITC4 * pData, float fVal)
{ {
char pCommand[10], pReply[132]; char pCommand[10], pReply[132];
int iRet, i, iRead; int iRet, i, iRead;
const float fPrecision = 0.0001; const float fPrecision = 0.0001;
@@ -322,38 +295,31 @@
self = *pData; self = *pData;
if(self->iReadOnly) if (self->iReadOnly) {
{
return ITC4__READONLY; return ITC4__READONLY;
} }
/* format command */ /* format command */
if(self->i503) if (self->i503) {
{ sprintf(pCommand, "T%-7.3f\r\n", fVal);
sprintf(pCommand,"T%-7.3f\r\n",fVal); } else {
}
else
{
fSet = fVal; fSet = fVal;
iSet = (int)(fSet*self->fMult); iSet = (int) (fSet * self->fMult);
sprintf(pCommand,"T%5.5d\r\n",iSet); sprintf(pCommand, "T%5.5d\r\n", iSet);
} }
/* try three times: send, read, test, if OK return, else /* try three times: send, read, test, if OK return, else
resend. This must be done because the ITC4 tends to loose resend. This must be done because the ITC4 tends to loose
characters characters
*/ */
for(i = 0; i < 3; i++) for (i = 0; i < 3; i++) {
{
/* send command */ /* send command */
iRet = SerialWriteRead(&self->pData,pCommand,pReply,131); iRet = SerialWriteRead(&self->pData, pCommand, pReply, 131);
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
if(pReply[0] == '?') if (pReply[0] == '?') {
{ strcpy(self->pAns, pReply);
strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
/* read the set value again */ /* read the set value again */
@@ -361,61 +327,58 @@
self->iRead = 0; /* make a R0 */ self->iRead = 0; /* make a R0 */
fDum = self->fDiv; fDum = self->fDiv;
self->fDiv = self->fMult; self->fDiv = self->fMult;
iRet = ITC4_Read(pData,&fRead); iRet = ITC4_Read(pData, &fRead);
self->iRead = iRead; self->iRead = iRead;
self->fDiv = fDum; self->fDiv = fDum;
if(iRet != 1) if (iRet != 1) {
{
return iRet; return iRet;
} }
/* check the value read back */ /* check the value read back */
if(self->i503) if (self->i503) {
{
fDelta = fRead - fVal; fDelta = fRead - fVal;
} } else {
else
{
fDelta = fRead - fSet; fDelta = fRead - fSet;
} }
if(fDelta < 0) if (fDelta < 0)
fDelta = -fDelta; fDelta = -fDelta;
if(fDelta < fPrecision) if (fDelta < fPrecision) {
{
/* Success, go home */ /* Success, go home */
return 1; return 1;
} }
} }
return ITC4__BADSET; return ITC4__BADSET;
} }
/* -------------------------------------------------------------------------*/ /* -------------------------------------------------------------------------*/
void ITC4_ErrorTxt(pITC4 *pData,int iCode, char *pError, int iLen) void ITC4_ErrorTxt(pITC4 * pData, int iCode, char *pError, int iLen)
{ {
char pBueffel[512]; char pBueffel[512];
pITC4 self; pITC4 self;
self = *pData; self = *pData;
switch(iCode) switch (iCode) {
{
case ITC4__BADCOM: case ITC4__BADCOM:
sprintf(pBueffel,"ITC4: Invalid command or offline, got %s", sprintf(pBueffel, "ITC4: Invalid command or offline, got %s",
self->pAns); self->pAns);
strncpy(pError,pBueffel,iLen); strncpy(pError, pBueffel, iLen);
break; break;
case ITC4__BADPAR: case ITC4__BADPAR:
strncpy(pError,"ITC4: Invalid parameter specified",iLen); strncpy(pError, "ITC4: Invalid parameter specified", iLen);
break; break;
case ITC4__BADMALLOC: case ITC4__BADMALLOC:
strncpy(pError,"ITC4: Error allocating memory in ITC4",iLen); strncpy(pError, "ITC4: Error allocating memory in ITC4", iLen);
break; break;
case ITC4__BADREAD: case ITC4__BADREAD:
strncpy(pError,"ITC4: Badly formatted answer",iLen); strncpy(pError, "ITC4: Badly formatted answer", iLen);
break; break;
case ITC4__BADSET: case ITC4__BADSET:
strncpy(pError,"ITC4: Failed three times to write new set value to ITC4",iLen); strncpy(pError,
"ITC4: Failed three times to write new set value to ITC4",
iLen);
break; break;
default: default:
SerialError(iCode, pError,iLen); SerialError(iCode, pError, iLen);
break; break;
} }
} }

View File

@@ -30,7 +30,7 @@
/* failed three times to set temperature */ /* failed three times to set temperature */
#define ITC4__READONLY -531 #define ITC4__READONLY -531
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
typedef struct __ITC4 { typedef struct __ITC4 {
int iRead; int iRead;
int iControl; int iControl;
void *pData; void *pData;
@@ -38,13 +38,14 @@
float fDiv; float fDiv;
float fMult; float fMult;
int iReadOnly; int iReadOnly;
int i503; /* flag for model 503, understanding float*/ int i503; /* flag for model 503, understanding float */
} ITC4; } ITC4;
typedef struct __ITC4 *pITC4; typedef struct __ITC4 *pITC4;
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
int ITC4_Open(pITC4 *pData,char *pHost, int iPort, int iChannel, int iMode); int ITC4_Open(pITC4 * pData, char *pHost, int iPort, int iChannel,
int iMode);
/***** creates an ITC4 datastructure and opens a connection to the ITCL4 /***** creates an ITC4 datastructure and opens a connection to the ITCL4
controller. Input Parameters are: controller. Input Parameters are:
the hostname the hostname
@@ -57,14 +58,14 @@
*/ */
void ITC4_Close(pITC4 *pData); void ITC4_Close(pITC4 * pData);
/****** close a connection to an ITC4controller and frees its /****** close a connection to an ITC4controller and frees its
data structure. The only parameter is a pointer to the data data structure. The only parameter is a pointer to the data
structure for this controller. This pointer will be invalid after structure for this controller. This pointer will be invalid after
this call. this call.
*/ */
int ITC4_Config(pITC4 *pData, int iTmo, int iRead, int ITC4_Config(pITC4 * pData, int iTmo, int iRead,
int iControl, float fDiv, float fMult); int iControl, float fDiv, float fMult);
/***** configure some aspects of a ITC4temperature controller. /***** configure some aspects of a ITC4temperature controller.
The parameter are: The parameter are:
@@ -81,7 +82,7 @@
failure. failure.
*/ */
int ITC4_Send(pITC4 *pData, char *pCommand, char *pReply, int iLen); int ITC4_Send(pITC4 * pData, char *pCommand, char *pReply, int iLen);
/******* send a the command in pCommand to the ITC4controller. /******* send a the command in pCommand to the ITC4controller.
A possible reply is returned in the buffer pReply. A possible reply is returned in the buffer pReply.
Maximum iLen characters are copied to pReply. Maximum iLen characters are copied to pReply.
@@ -92,7 +93,7 @@
failure. failure.
*/ */
int ITC4_Read(pITC4 *pData, float *fVal); int ITC4_Read(pITC4 * pData, float *fVal);
/******* reads the current actual temperature of the sensor /******* reads the current actual temperature of the sensor
configured by ConfigITC4for reading. The value is returned configured by ConfigITC4for reading. The value is returned
in fVal. The first parameter is a pointer to a ITCL4 in fVal. The first parameter is a pointer to a ITCL4
@@ -102,7 +103,7 @@
failure. failure.
*/ */
int ITC4_Set(pITC4 *pData, float fVal); int ITC4_Set(pITC4 * pData, float fVal);
/****** sets a new preset temperature in the ITC4temperature /****** sets a new preset temperature in the ITC4temperature
controller. Parameters are: controller. Parameters are:
- a pointer to a ITC4data structure as returned by OpenITCL4. - a pointer to a ITC4data structure as returned by OpenITCL4.
@@ -112,7 +113,7 @@
failure. failure.
*/ */
void ITC4_ErrorTxt(pITC4 *pData, int iCode, char *pError, int iLen); void ITC4_ErrorTxt(pITC4 * pData, int iCode, char *pError, int iLen);
/******* translates one of the negative error ITC4error codes /******* translates one of the negative error ITC4error codes
into text. Maximum iLen bytes will be copied to the into text. Maximum iLen bytes will be copied to the
buffer pError; buffer pError;
@@ -120,5 +121,3 @@
#endif #endif

View File

@@ -154,7 +154,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef FORTIFY #ifdef FORTIFY
#include <fortify.h> #include <fortify.h>
#endif #endif
#include <sinq_prototypes.h> #include <sinq_prototypes.h>
@@ -167,7 +167,8 @@
**-------------------------------------------------------------------------- **--------------------------------------------------------------------------
** MakeCharPrintable: makes a single character printable. ** MakeCharPrintable: makes a single character printable.
*/ */
int MakeCharPrintable (char *out, int out_size, char in) { int MakeCharPrintable(char *out, int out_size, char in)
{
/* ================= /* =================
** **
** Return value is number of chars put into *out. ** Return value is number of chars put into *out.
@@ -182,95 +183,141 @@
} }
switch (in) { switch (in) {
case '^': *pntr++ = '\\'; *pntr++ = '^'; break; case '^':
case '\\': *pntr++ = '\\'; *pntr++ = '\\'; break; *pntr++ = '\\';
case '\000': *pntr++ = '\\'; *pntr++ = '0'; break; *pntr++ = '^';
case '\007': *pntr++ = '\\'; *pntr++ = 'a'; break; break;
case '\010': *pntr++ = '\\'; *pntr++ = 'b'; break; case '\\':
case '\011': *pntr++ = '\\'; *pntr++ = 't'; break; *pntr++ = '\\';
case '\012': *pntr++ = '\\'; *pntr++ = 'n'; break; *pntr++ = '\\';
case '\013': *pntr++ = '\\'; *pntr++ = 'v'; break; break;
case '\014': *pntr++ = '\\'; *pntr++ = 'f'; break; case '\000':
case '\015': *pntr++ = '\\'; *pntr++ = 'r'; break; *pntr++ = '\\';
*pntr++ = '0';
break;
case '\007':
*pntr++ = '\\';
*pntr++ = 'a';
break;
case '\010':
*pntr++ = '\\';
*pntr++ = 'b';
break;
case '\011':
*pntr++ = '\\';
*pntr++ = 't';
break;
case '\012':
*pntr++ = '\\';
*pntr++ = 'n';
break;
case '\013':
*pntr++ = '\\';
*pntr++ = 'v';
break;
case '\014':
*pntr++ = '\\';
*pntr++ = 'f';
break;
case '\015':
*pntr++ = '\\';
*pntr++ = 'r';
break;
default: default:
if ((in < ' ') || (in > '~')) { if ((in < ' ') || (in > '~')) {
pntr += sprintf (pntr, "\\%3.3o", in); pntr += sprintf(pntr, "\\%3.3o", in);
}else { } else {
*pntr++ = in; *pntr++ = in;
} }
} }
out_size = (out_size > (pntr - buff)) ? (pntr - buff) : out_size; out_size = (out_size > (pntr - buff)) ? (pntr - buff) : out_size;
memcpy (out, buff, out_size); memcpy(out, buff, out_size);
return out_size; return out_size;
} }
/* /*
**-------------------------------------------------------------------------- **--------------------------------------------------------------------------
** MakeMemPrintable: alternative version of MakePrintable. ** MakeMemPrintable: alternative version of MakePrintable.
*/ */
char *MakeMemPrintable ( char *MakeMemPrintable(
/* ================ /* ================
*/ char *out, */ char *out,
int out_size, int out_size, char *in, int in_len)
char *in, {
int in_len) {
int i; int i;
char *pntr; char *pntr;
if (out_size <= 0) return out; if (out_size <= 0)
return out;
while ((out_size > 1) && (in_len > 0)) { while ((out_size > 1) && (in_len > 0)) {
i = MakeCharPrintable (out, (out_size - 1), *in); i = MakeCharPrintable(out, (out_size - 1), *in);
out += i; out_size -= i; out += i;
in++; in_len--; out_size -= i;
in++;
in_len--;
} }
*out = NIL; *out = NIL;
return out; return out;
} }
/* /*
**-------------------------------------------------------------------------- **--------------------------------------------------------------------------
** MakePrint: Make all characters in a buffer printable. ** MakePrint: Make all characters in a buffer printable.
*/ */
char *MakePrint (char *chr) { char *MakePrint(char *chr)
{
/* ========= /* =========
*/ */
int len, i; int len, i;
for (i = 0; chr[i] != NIL; i++) chr[i] &= 0x7F; for (i = 0; chr[i] != NIL; i++)
chr[i] &= 0x7F;
len = strlen (chr); len = strlen(chr);
if (len <= 0) return chr; if (len <= 0)
return chr;
if (chr[len-1] == '\r') chr[len-1] = NIL; if (chr[len - 1] == '\r')
if (chr[len-1] == '\n') chr[len-1] = NIL; chr[len - 1] = NIL;
if (chr[len - 1] == '\n')
chr[len - 1] = NIL;
for (i = 0; chr[i] != NIL; i++) { for (i = 0; chr[i] != NIL; i++) {
if (chr[i] < ' ') chr[i] = '.'; if (chr[i] < ' ')
if (chr[i] == 0x7F) chr[i] = '.'; chr[i] = '.';
if (chr[i] == 0x7F)
chr[i] = '.';
} }
return chr; return chr;
} }
/* /*
**-------------------------------------------------------------------------- **--------------------------------------------------------------------------
** MakePrintable: improved version of MakePrint. ** MakePrintable: improved version of MakePrint.
*/ */
char *MakePrintable ( char *MakePrintable(
/* ============= /* =============
*/ char *out, */ char *out,
int out_size, int out_size, char *in)
char *in) { {
int i; int i;
char *pntr; char *pntr;
if (out_size <= 0) return out; if (out_size <= 0)
return out;
while ((out_size > 1) && (*in != NIL)) { while ((out_size > 1) && (*in != NIL)) {
i = MakeCharPrintable (out, (out_size - 1), *in); i = MakeCharPrintable(out, (out_size - 1), *in);
in++; out += i; out_size -= i; in++;
out += i;
out_size -= i;
} }
*out = NIL; *out = NIL;
return out; return out;
} }
/*-------------------------------------------- End of MakePrint.C =======*/ /*-------------------------------------------- End of MakePrint.C =======*/

View File

@@ -76,7 +76,7 @@
** **
** An example of a command item might be: "0006RMT 1\r" ** An example of a command item might be: "0006RMT 1\r"
**--------------------------------------------------------------------------*/ **--------------------------------------------------------------------------*/
struct RS__MsgStruct { struct RS__MsgStruct {
char msg_size[4]; /* 4 ASCII decimal chars!! */ char msg_size[4]; /* 4 ASCII decimal chars!! */
char msg_id[4]; char msg_id[4];
char c_pcol_lvl[4]; /* Client protocol level */ char c_pcol_lvl[4]; /* Client protocol level */
@@ -85,19 +85,19 @@
char terms[4]; char terms[4];
char n_cmnds[4]; char n_cmnds[4];
char cmnds[356]; char cmnds[356];
}; };
/* /*
** The "cmnds" buffer in RS__MsgStruct is a concatenated ** The "cmnds" buffer in RS__MsgStruct is a concatenated
** list of the following structures. ** list of the following structures.
*/ */
struct RS__CmndStruct { struct RS__CmndStruct {
char cmnd_len[2]; char cmnd_len[2];
char cmnd[1]; char cmnd[1];
}; };
struct RS__CmndStruct_V01B { struct RS__CmndStruct_V01B {
char cmnd_len[4]; char cmnd_len[4];
char cmnd[1]; char cmnd[1];
}; };
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
** Structure of Reply from Server to Client - everything is sent in ASCII ** Structure of Reply from Server to Client - everything is sent in ASCII
** for LabView's benefit. ** for LabView's benefit.
@@ -150,7 +150,7 @@
** **
** An example of a reply item might be: "0009\r12.3456\0" ** An example of a reply item might be: "0009\r12.3456\0"
**--------------------------------------------------------------------------*/ **--------------------------------------------------------------------------*/
struct RS__RespStruct { struct RS__RespStruct {
char msg_size[4]; char msg_size[4];
char msg_id[4]; char msg_id[4];
char s_pcol_lvl[4]; /* Server protocol level */ char s_pcol_lvl[4]; /* Server protocol level */
@@ -159,12 +159,12 @@
char rplys[496]; char rplys[496];
char sub_status[12]; char sub_status[12];
} u; } u;
}; };
/* /*
** The "rplys" buffer in RS__RespStruct is a ** The "rplys" buffer in RS__RespStruct is a
** concatenated list of the following structures. ** concatenated list of the following structures.
*/ */
struct RS__RplyStruct { struct RS__RplyStruct {
char rply_len[2]; /* 2 ASCII decimal chars!! char rply_len[2]; /* 2 ASCII decimal chars!!
** The length includes the ** The length includes the
** terminator, term, and the ** terminator, term, and the
@@ -172,8 +172,8 @@
*/ */
char term; /* The terminating character */ char term; /* The terminating character */
char rply[1]; /* Zero terminated string */ char rply[1]; /* Zero terminated string */
}; };
struct RS__RplyStruct_V01B { struct RS__RplyStruct_V01B {
char rply_len[4]; /* 4 ASCII decimal chars!! char rply_len[4]; /* 4 ASCII decimal chars!!
** The length includes the ** The length includes the
** terminator, term, and the ** terminator, term, and the
@@ -181,6 +181,6 @@
*/ */
char term; /* The terminating character */ char term; /* The terminating character */
char rply[1]; /* Zero terminated string */ char rply[1]; /* Zero terminated string */
}; };
/*------------------------------------------------ End of RS232C_DEF.H --*/ /*------------------------------------------------ End of RS232C_DEF.H --*/
#endif /* _rs232c_def_ */ #endif /* _rs232c_def_ */

File diff suppressed because it is too large Load Diff

View File

@@ -22,25 +22,25 @@
#line 30 "velodorn.w" #line 30 "velodorn.w"
int SerialOpen(void **pData, char *pHost, int iPort, int iChannel); int SerialOpen(void **pData, char *pHost, int iPort, int iChannel);
int SerialForceOpen(void **pData, char *pHost, int iPort, int iChannel); int SerialForceOpen(void **pData, char *pHost, int iPort, int iChannel);
int SerialConfig(void **pData, int iTmo); int SerialConfig(void **pData, int iTmo);
int SerialGetTmo(void **pData); int SerialGetTmo(void **pData);
int SerialATerm(void **pData, char *pTerm); int SerialATerm(void **pData, char *pTerm);
int SerialAGetTerm(void **pData, char *pTerm, int iTermLen); int SerialAGetTerm(void **pData, char *pTerm, int iTermLen);
int SerialSendTerm(void **pData, char *pTerm); int SerialSendTerm(void **pData, char *pTerm);
int SerialGetSocket(void **pData); int SerialGetSocket(void **pData);
int SerialClose(void **pData); int SerialClose(void **pData);
int SerialForceClose(void **pData); int SerialForceClose(void **pData);
int SerialSend(void **pData, char *pCommand); int SerialSend(void **pData, char *pCommand);
int SerialReceive(void **pData, char *pBuffer, int iBufLen); int SerialReceive(void **pData, char *pBuffer, int iBufLen);
int SerialReceiveWithTerm(void **pData, char *pBuffer, int SerialReceiveWithTerm(void **pData, char *pBuffer,
int iBufLen,char *cTerm); int iBufLen, char *cTerm);
int SerialError(int iError, char *pError, int iErrLen); int SerialError(int iError, char *pError, int iErrLen);
int SerialWriteRead(void **pData, char *pCommand, int SerialWriteRead(void **pData, char *pCommand,
char *pBuffer, int iBufLen); char *pBuffer, int iBufLen);
int SerialNoReply(void **pData, char *pCommand); int SerialNoReply(void **pData, char *pCommand);
#line 175 "velodorn.w" #line 175 "velodorn.w"
@@ -48,8 +48,8 @@
#line 116 "velodorn.w" #line 116 "velodorn.w"
typedef int (*SerialSleep)(void *pData, int iTime); typedef int (*SerialSleep) (void *pData, int iTime);
void SetSerialSleep(void **pData, SerialSleep pFunc, void *pUserData); void SetSerialSleep(void **pData, SerialSleep pFunc, void *pUserData);
#line 177 "velodorn.w" #line 177 "velodorn.w"

View File

@@ -19,656 +19,242 @@
#include <el737_def.h> #include <el737_def.h>
#endif #endif
/* ---------------------------------------------------------------------*/ /* ---------------------------------------------------------------------*/
int AsynSrv_ChanClose ( int AsynSrv_ChanClose(struct AsynSrv__info *asyn_info);
struct AsynSrv__info *asyn_info); int AsynSrv_Close(struct AsynSrv__info *asyn_info, int force_flag);
int AsynSrv_Close ( int AsynSrv_Config(struct AsynSrv__info *asyn_info, ...);
struct AsynSrv__info *asyn_info, int AsynSrv_ConfigDflt(char *par_id, ...);
int force_flag); void AsynSrv_ErrInfo(char **entry_txt,
int AsynSrv_Config ( int *errcode, int *my_errno, int *vaxc_errno);
struct AsynSrv__info *asyn_info, int AsynSrv_Flush(struct AsynSrv__info *asyn_info);
...); int AsynSrv_GetLenTerm(struct AsynSrv__info *asyn_info,
int AsynSrv_ConfigDflt (
char *par_id,
...);
void AsynSrv_ErrInfo (
char **entry_txt,
int *errcode,
int *my_errno,
int *vaxc_errno);
int AsynSrv_Flush (
struct AsynSrv__info *asyn_info);
int AsynSrv_GetLenTerm (
struct AsynSrv__info *asyn_info,
struct RS__RespStruct *rcve_buff, struct RS__RespStruct *rcve_buff,
char *rply, char *rply, int *len, char *term);
int *len, char *AsynSrv_GetReply(struct AsynSrv__info *asyn_info,
char *term); struct RS__RespStruct *rcve_buff, char *last_rply);
char *AsynSrv_GetReply ( int AsynSrv_Open(struct AsynSrv__info *asyn_info);
struct AsynSrv__info *asyn_info, int AsynSrv_OpenNew(struct AsynSrv__info *asyn_info);
struct RS__RespStruct *rcve_buff, int AsynSrv_SendCmnds(struct AsynSrv__info *asyn_info,
char *last_rply);
int AsynSrv_Open (
struct AsynSrv__info *asyn_info);
int AsynSrv_OpenNew (
struct AsynSrv__info *asyn_info);
int AsynSrv_SendCmnds (
struct AsynSrv__info *asyn_info,
struct RS__MsgStruct *send_buff, struct RS__MsgStruct *send_buff,
struct RS__RespStruct *rcve_buff, struct RS__RespStruct *rcve_buff, ...);
...); int AsynSrv_SendCmndsBig(struct AsynSrv__info *asyn_info,
int AsynSrv_SendCmndsBig (
struct AsynSrv__info *asyn_info,
struct RS__MsgStruct *send_buff, struct RS__MsgStruct *send_buff,
int send_buff_size, int send_buff_size,
struct RS__RespStruct *rcve_buff, struct RS__RespStruct *rcve_buff,
int rcve_buff_size, int rcve_buff_size, ...);
...); int AsynSrv_Trace(struct AsynSrv__info *asyn_info, int state);
int AsynSrv_Trace ( int AsynSrv_Trace_Write(struct AsynSrv__info *asyn_info);
struct AsynSrv__info *asyn_info,
int state);
int AsynSrv_Trace_Write (
struct AsynSrv__info *asyn_info);
/* ---------------------------------------------------------------------*/ /* ---------------------------------------------------------------------*/
int C_log_arr_get ( int C_log_arr_get(char *name, int arr_size, int *value, int indx);
char *name, int C_log_flt_get(char *name, float *value, int indx);
int arr_size, int C_log_int_get(char *name, long int *value, int indx);
int *value, int C_log_str_get(char *name, char *value, int val_size, int indx);
int indx);
int C_log_flt_get (
char *name,
float *value,
int indx);
int C_log_int_get (
char *name,
long int *value,
int indx);
int C_log_str_get (
char *name,
char *value,
int val_size,
int indx);
/* ---------------------------------------------------------------------*/ /* ---------------------------------------------------------------------*/
int C_str_edit ( int C_str_edit(char *out, char *in, char *ctrl, int *length);
char *out,
char *in,
char *ctrl,
int *length);
/* ---------------------------------------------------------------------*/ /* ---------------------------------------------------------------------*/
int C_tt_port_config ( int C_tt_port_config(int *hndl, int mask);
int *hndl, int C_tt_port_connect(int *hndl, int *chan, char *lognam, char *pwd);
int mask); int C_tt_port_disconnect(int *hndl);
int C_tt_port_connect ( int C_tt_port_io(int *hndl,
int *hndl,
int *chan,
char *lognam,
char *pwd);
int C_tt_port_disconnect (
int *hndl);
int C_tt_port_io (
int *hndl,
char *rqst, char *rqst,
char *term, char *term,
char *answ, char *answ, int *answ_len, int flush, int tmo);
int *answ_len,
int flush,
int tmo);
/* ---------------------------------------------------------------------*/ /* ---------------------------------------------------------------------*/
int EL734_Close ( int EL734_Close(void **handle, int force_flag);
void **handle, int EL734_Config(void **handle, ...);
int force_flag); char *EL734_EncodeMSR(char *text,
int EL734_Config (
void **handle,
...);
char *EL734_EncodeMSR (
char *text,
int text_len, int text_len,
int msr, int msr, int ored_msr, int fp_cntr, int fr_cntr);
int ored_msr, char *EL734_EncodeSS(char *text, int text_len, int ss);
int fp_cntr, void EL734_ErrInfo(char **entry_txt,
int fr_cntr); int *errcode, int *my_errno, int *vaxc_errno);
char *EL734_EncodeSS ( int EL734_GetAirCush(void **handle, int *present, int *state);
char *text, int EL734_GetEncGearing(void **handle, int *nominator, int *denominator);
int text_len, int EL734_GetId(void **handle, char *id_txt, int id_len);
int ss); int EL734_GetLimits(void **handle, float *lo, float *hi);
void EL734_ErrInfo ( int EL734_GetMotorGearing(void **handle, int *nominator, int *denominator);
char **entry_txt, int EL734_GetNullPoint(void **handle, int *null_pt);
int *errcode, int EL734_GetPosition(void **handle, float *ist_posit);
int *my_errno, int EL734_GetPrecision(void **handle, int *n_dec);
int *vaxc_errno); int EL734_GetRefMode(void **handle, int *mode);
int EL734_GetAirCush ( int EL734_GetRefParam(void **handle, float *param);
void **handle, int EL734_GetSpeeds(void **handle, int *lo, int *hi, int *ramp);
int *present, int EL734_GetStatus(void **handle,
int *state);
int EL734_GetEncGearing (
void **handle,
int *nominator,
int *denominator);
int EL734_GetId (
void **handle,
char *id_txt,
int id_len);
int EL734_GetLimits (
void **handle,
float *lo,
float *hi);
int EL734_GetMotorGearing (
void **handle,
int *nominator,
int *denominator);
int EL734_GetNullPoint (
void **handle,
int *null_pt);
int EL734_GetPosition (
void **handle,
float *ist_posit);
int EL734_GetPrecision (
void **handle,
int *n_dec);
int EL734_GetRefMode (
void **handle,
int *mode);
int EL734_GetRefParam (
void **handle,
float *param);
int EL734_GetSpeeds (
void **handle,
int *lo,
int *hi,
int *ramp);
int EL734_GetStatus (
void **handle,
int *msr, int *msr,
int *ored_msr, int *ored_msr,
int *fp_cntr, int *fp_cntr, int *fr_cntr, int *ss, float *ist_posit);
int *fr_cntr, int EL734_GetZeroPoint(void **handle, float *zero_pt);
int *ss, int EL734_MoveNoWait(void **handle, float soll_posit);
float *ist_posit); int EL734_MoveWait(void **handle,
int EL734_GetZeroPoint (
void **handle,
float *zero_pt);
int EL734_MoveNoWait (
void **handle,
float soll_posit);
int EL734_MoveWait (
void **handle,
float soll_posit, float soll_posit,
int *ored_msr, int *ored_msr,
int *fp_cntr, int *fp_cntr, int *fr_cntr, float *ist_posit);
int *fr_cntr, int EL734_Open(void **handle,
float *ist_posit); char *host, int port, int chan, int motor, char *id);
int EL734_Open ( int EL734_PutOffline(void **handle);
void **handle, int EL734_PutOnline(void **handle, int echo);
char *host, int EL734_SendCmnd(void **handle, char *cmnd, char *rply, int rply_size);
int port, int EL734_SetAirCush(void **handle, int state);
int chan, int EL734_SetErrcode(struct EL734info *info_ptr,
int motor, char *response, char *cmnd);
char *id); int EL734_SetHighSpeed(void **handle, int hi);
int EL734_PutOffline ( int EL734_SetLowSpeed(void **handle, int lo);
void **handle); int EL734_SetRamp(void **handle, int ramp);
int EL734_PutOnline ( int EL734_Stop(void **handle);
void **handle, int EL734_WaitIdle(void **handle,
int echo);
int EL734_SendCmnd (
void **handle,
char *cmnd,
char *rply,
int rply_size);
int EL734_SetAirCush (
void **handle,
int state);
int EL734_SetErrcode (
struct EL734info *info_ptr,
char *response,
char *cmnd);
int EL734_SetHighSpeed (
void **handle,
int hi);
int EL734_SetLowSpeed (
void **handle,
int lo);
int EL734_SetRamp (
void **handle,
int ramp);
int EL734_Stop (
void **handle);
int EL734_WaitIdle (
void **handle,
int *ored_msr, int *ored_msr,
int *fp_cntr, int *fp_cntr, int *fr_cntr, float *ist_posit);
int *fr_cntr, void EL734_ZeroStatus(void **handle);
float *ist_posit);
void EL734_ZeroStatus (
void **handle);
/* ---------------------------------------------------------------------*/ /* ---------------------------------------------------------------------*/
int EL737_Close ( int EL737_Close(void **handle, int force_flag);
void **handle, int EL737_Config(void **handle, ...);
int force_flag); int EL737_Continue(void **handle, int *status);
int EL737_Config ( int EL737_EnableThresh(void **handle, int indx);
void **handle, void EL737_ErrInfo(char **entry_txt,
...); int *errcode, int *my_errno, int *vaxc_errno);
int EL737_Continue ( int EL737_GetMonIntegTime(void **handle, int indx, float *mon_integ_time);
void **handle, int EL737_GetRateIntegTime(void **handle, float *rate_integ_time);
int *status); void *EL737_GetReply(void **handle, void *last_rply);
int EL737_EnableThresh ( int EL737_GetStatus(void **handle,
void **handle,
int indx);
void EL737_ErrInfo (
char **entry_txt,
int *errcode,
int *my_errno,
int *vaxc_errno);
int EL737_GetMonIntegTime (
void **handle,
int indx,
float *mon_integ_time);
int EL737_GetRateIntegTime (
void **handle,
float *rate_integ_time);
void *EL737_GetReply (
void **handle,
void *last_rply);
int EL737_GetStatus (
void **handle,
int *c1, int *c1,
int *c2, int *c2, int *c3, int *c4, float *timer, int *rs);
int *c3, int EL737_GetStatusExtra(void **handle,
int *c4, int *c5, int *c6, int *c7, int *c8);
float *timer, int EL737_GetThresh(void **handle, int *indx, float *val);
int *rs); int EL737_Open(void **handle, char *host, int port, int chan);
int EL737_GetStatusExtra ( int EL737_Pause(void **handle, int *status);
void **handle, int EL737_SendCmnd(void **handle, char *cmnd, char *rply, int rply_size);
int *c5, int EL737_SetErrcode(struct EL737info *info_ptr,
int *c6, char *response, char *cmnd);
int *c7, int EL737_SetThresh(void **handle, int indx, float val);
int *c8); int EL737_StartCnt(void **handle, int preset_count, int *status);
int EL737_GetThresh ( int EL737_StartTime(void **handle, float preset_time, int *status);
void **handle, int EL737_Stop(void **handle,
int *indx,
float *val);
int EL737_Open (
void **handle,
char *host,
int port,
int chan);
int EL737_Pause (
void **handle,
int *status);
int EL737_SendCmnd (
void **handle,
char *cmnd,
char *rply,
int rply_size);
int EL737_SetErrcode (
struct EL737info *info_ptr,
char *response,
char *cmnd);
int EL737_SetThresh (
void **handle,
int indx,
float val);
int EL737_StartCnt (
void **handle,
int preset_count,
int *status);
int EL737_StartTime (
void **handle,
float preset_time,
int *status);
int EL737_Stop (
void **handle,
int *c1, int *c1,
int *c2, int *c2, int *c3, int *c4, float *timer, int *status);
int *c3, int EL737_StopFast(void **handle);
int *c4, int EL737_WaitIdle(void **handle,
float *timer, int *c1, int *c2, int *c3, int *c4, float *timer);
int *status);
int EL737_StopFast (
void **handle);
int EL737_WaitIdle (
void **handle,
int *c1,
int *c2,
int *c3,
int *c4,
float *timer);
/* ---------------------------------------------------------------------*/ /* ---------------------------------------------------------------------*/
int EL755_Close ( int EL755_Close(void **handle, int force_flag);
void **handle, int EL755_Config(void **handle, ...);
int force_flag); void EL755_ErrInfo(char **entry_txt,
int EL755_Config ( int *errcode, int *my_errno, int *vaxc_errno);
void **handle, int EL755_ErrorLog(char *routine_name, char *text);
...); int EL755_GetConstant(void **handle, float *value);
void EL755_ErrInfo ( int EL755_GetCurrents(void **handle, float *soll, float *ist);
char **entry_txt, int EL755_GetId(void **handle, char *id_txt, int id_len);
int *errcode, int EL755_GetLimit(void **handle, float *value);
int *my_errno, int EL755_GetRamp(void **handle, float *value);
int *vaxc_errno); int EL755_GetTimeConstant(void **handle, float *value);
int EL755_ErrorLog ( int EL755_GetVoltageRange(void **handle, float *value);
char *routine_name, int EL755_Open(void **handle, char *host, int port, int chan, int indx);
char *text); int EL755_PutOffline(void **handle);
int EL755_GetConstant ( int EL755_PutOnline(void **handle, int echo);
void **handle, int EL755_SendTillSameStr(void **handle,
float *value); char *cmnd, char *rply, int rply_len);
int EL755_GetCurrents ( int EL755_SendTillSameVal(void **handle, char *cmnd, float *val);
void **handle, int EL755_SendTillTwoVals(void **handle,
float *soll, char *cmnd, float *val0, float *val1);
float *ist); int EL755_SetConstant(void **handle, float value);
int EL755_GetId ( int EL755_SetCurrent(void **handle, float soll);
void **handle, int EL755_SetLimit(void **handle, float value);
char *id_txt, int EL755_SetRamp(void **handle, float value);
int id_len); int EL755_SetTimeConstant(void **handle, float value);
int EL755_GetLimit ( int EL755_SetVoltageRange(void **handle, float value);
void **handle,
float *value);
int EL755_GetRamp (
void **handle,
float *value);
int EL755_GetTimeConstant (
void **handle,
float *value);
int EL755_GetVoltageRange (
void **handle,
float *value);
int EL755_Open (
void **handle,
char *host,
int port,
int chan,
int indx);
int EL755_PutOffline (
void **handle);
int EL755_PutOnline (
void **handle,
int echo);
int EL755_SendTillSameStr (
void **handle,
char *cmnd,
char *rply,
int rply_len);
int EL755_SendTillSameVal (
void **handle,
char *cmnd,
float *val);
int EL755_SendTillTwoVals (
void **handle,
char *cmnd,
float *val0,
float *val1);
int EL755_SetConstant (
void **handle,
float value);
int EL755_SetCurrent (
void **handle,
float soll);
int EL755_SetLimit (
void **handle,
float value);
int EL755_SetRamp (
void **handle,
float value);
int EL755_SetTimeConstant (
void **handle,
float value);
int EL755_SetVoltageRange (
void **handle,
float value);
/* ---------------------------------------------------------------------*/ /* ---------------------------------------------------------------------*/
int Fluke_Close ( int Fluke_Close(void **handle, int force_flag);
void **handle, int Fluke_Config(void **handle, ...);
int force_flag); void Fluke_ErrInfo(char **entry_txt,
int Fluke_Config ( int *errcode, int *my_errno, int *vaxc_errno);
void **handle, int Fluke_ErrorLog(char *routine_name, char *text);
...); int Fluke_Open(void **handle, char *host, int port, int chan);
void Fluke_ErrInfo ( int Fluke_Read(void **handle, float *ist);
char **entry_txt, int Fluke_SendTillSame(void **handle,
int *errcode, char *cmnd, char *rply, int rply_len);
int *my_errno, int Fluke_SendTillSameVal(void **handle, char *cmnd, float *val);
int *vaxc_errno);
int Fluke_ErrorLog (
char *routine_name,
char *text);
int Fluke_Open (
void **handle,
char *host,
int port,
int chan);
int Fluke_Read (
void **handle,
float *ist);
int Fluke_SendTillSame (
void **handle,
char *cmnd,
char *rply,
int rply_len);
int Fluke_SendTillSameVal (
void **handle,
char *cmnd,
float *val);
/* ---------------------------------------------------------------------*/ /* ---------------------------------------------------------------------*/
int ITC_Close ( int ITC_Close(void **handle, int force_flag);
void **handle, int ITC_Config(void **handle, ...);
int force_flag); int ITC_Dump_RAM(void **handle,
int ITC_Config ( int buff_size, char *buff, int *dump_len, int *n_diffs);
void **handle, void ITC_ErrInfo(char **entry_txt,
...); int *errcode, int *my_errno, int *vaxc_errno);
int ITC_Dump_RAM ( int ITC_GetConfig(void **handle, ...);
void **handle, int ITC_Load_RAM(void **handle, int load_len, char *buff);
int buff_size, int ITC_Load_Table(void **handle, char *buff);
char *buff, int ITC_Open(void **handle, char *host, int port, int chan);
int *dump_len, int ITC_Read_ITC_Sensor(void **handle,
int *n_diffs); int sensor, float factor, float *value);
void ITC_ErrInfo ( int ITC_Read_LTC11_Sensor(void **handle, int sensor, float *value);
char **entry_txt, int ITC_Read_LTC11_SetPt(void **handle, float *value);
int *errcode, int ITC_ReadAuxTemp(void **handle, float *value);
int *my_errno, int ITC_ReadControlTemp(void **handle, float *value);
int *vaxc_errno); int ITC_ReadHeaterOp(void **handle, float *op_level, float *op_percent);
int ITC_GetConfig ( int ITC_ReadId(void **handle, char *id_txt, int id_txt_len, int *id_len);
void **handle, int ITC_ReadPID(void **handle, float *p, float *i, float *d);
...); int ITC_ReadSampleTemp(void **handle, float *s_temp);
int ITC_Load_RAM ( int ITC_ReadSetPoint(void **handle, float *sp_temp);
void **handle, int ITC_ReadStatus(void **handle,
int load_len,
char *buff);
int ITC_Load_Table (
void **handle,
char *buff);
int ITC_Open (
void **handle,
char *host,
int port,
int chan);
int ITC_Read_ITC_Sensor (
void **handle,
int sensor,
float factor,
float *value);
int ITC_Read_LTC11_Sensor (
void **handle,
int sensor,
float *value);
int ITC_Read_LTC11_SetPt (
void **handle,
float *value);
int ITC_ReadAuxTemp (
void **handle,
float *value);
int ITC_ReadControlTemp (
void **handle,
float *value);
int ITC_ReadHeaterOp (
void **handle,
float *op_level,
float *op_percent);
int ITC_ReadId (
void **handle,
char *id_txt,
int id_txt_len,
int *id_len);
int ITC_ReadPID (
void **handle,
float *p,
float *i,
float *d);
int ITC_ReadSampleTemp (
void **handle,
float *s_temp);
int ITC_ReadSetPoint (
void **handle,
float *sp_temp);
int ITC_ReadStatus (
void **handle,
char *status_txt, char *status_txt,
int status_txt_len, int status_txt_len,
int *status_len, int *status_len, int *auto_state, int *remote_state);
int *auto_state, int ITC_SendTillAckOk(void **handle,
int *remote_state); struct RS__MsgStruct *to_host,
int ITC_SendTillAckOk ( struct RS__RespStruct *from_host, char *cmnd);
void **handle, int ITC_SendTillSame(void **handle,
struct RS__MsgStruct *to_host, struct RS__MsgStruct *to_host,
struct RS__RespStruct *from_host, struct RS__RespStruct *from_host,
char *cmnd); char *cmnd, char *rply, int rply_len);
int ITC_SendTillSame ( int ITC_SendTillSameLen(void **handle,
void **handle,
struct RS__MsgStruct *to_host, struct RS__MsgStruct *to_host,
struct RS__RespStruct *from_host, struct RS__RespStruct *from_host,
char *cmnd, char *cmnd, char *rply, int rply_len);
char *rply, int ITC_SendTillSameLenAckOK(void **handle,
int rply_len);
int ITC_SendTillSameLen (
void **handle,
struct RS__MsgStruct *to_host, struct RS__MsgStruct *to_host,
struct RS__RespStruct *from_host, struct RS__RespStruct *from_host,
char *cmnd, char *cmnd, char *rply, int rply_len);
char *rply, int ITC_SetControlTemp(void **handle, float s_temp);
int rply_len); int ITC_SetHeatLevel(void **handle, float heat_percent);
int ITC_SendTillSameLenAckOK ( int ITC_ErrorLog(char *routine_name, char *text);
void **handle,
struct RS__MsgStruct *to_host,
struct RS__RespStruct *from_host,
char *cmnd,
char *rply,
int rply_len);
int ITC_SetControlTemp (
void **handle,
float s_temp);
int ITC_SetHeatLevel (
void **handle,
float heat_percent);
int ITC_ErrorLog (
char *routine_name,
char *text);
/* ---------------------------------------------------------------------*/ /* ---------------------------------------------------------------------*/
int SPS_Close ( int SPS_Close(void **handle, int force_flag);
void **handle, int SPS_Config(void **handle, ...);
int force_flag); void SPS_ErrInfo(char **entry_txt,
int SPS_Config ( int *errcode, int *my_errno, int *vaxc_errno);
void **handle, int SPS_ErrorLog(char *routine_name, char *text);
...); int SPS_GetStatus(void **handle,
void SPS_ErrInfo (
char **entry_txt,
int *errcode,
int *my_errno,
int *vaxc_errno);
int SPS_ErrorLog (
char *routine_name,
char *text);
int SPS_GetStatus (
void **handle,
unsigned char *status_vals, unsigned char *status_vals,
int n_status_vals, int n_status_vals, int *adc_vals, int n_adc_vals);
int *adc_vals, int SPS_Open(void **handle, char *host, int port, int chan);
int n_adc_vals); int SPS_SendTillSame(void **handle,
int SPS_Open (
void **handle,
char *host,
int port,
int chan);
int SPS_SendTillSame (
void **handle,
struct RS__MsgStruct *to_host, struct RS__MsgStruct *to_host,
struct RS__RespStruct *from_host, struct RS__RespStruct *from_host,
char *cmnd, char *cmnd, char *rply, int rply_len);
char *rply, int SPS_SendTillSameLen(void **handle,
int rply_len);
int SPS_SendTillSameLen (
void **handle,
struct RS__MsgStruct *to_host, struct RS__MsgStruct *to_host,
struct RS__RespStruct *from_host, struct RS__RespStruct *from_host,
char *cmnd, char *cmnd, char *rply, int rply_len);
char *rply,
int rply_len);
/* ---------------------------------------------------------------------*/ /* ---------------------------------------------------------------------*/
int VelSel_Close ( int VelSel_Close(void **handle, int force_flag);
void **handle, void VelSel_Config(void **handle, int msec_tmo, char *eot_str);
int force_flag); void VelSel_ErrInfo(char **entry_txt,
void VelSel_Config ( int *errcode, int *my_errno, int *vaxc_errno);
void **handle, void *VelSel_GetReply(void **handle, void *last_rply);
int msec_tmo, int VelSel_GetStatus(void **handle, char *status_str, int status_str_len);
char *eot_str); int VelSel_Open(void **handle, char *host, int port, int chan);
void VelSel_ErrInfo ( int VelSel_SendCmnd(void **handle, char *cmnd, char *rply, int rply_size);
char **entry_txt,
int *errcode,
int *my_errno,
int *vaxc_errno);
void *VelSel_GetReply (
void **handle,
void *last_rply);
int VelSel_GetStatus (
void **handle,
char *status_str,
int status_str_len);
int VelSel_Open (
void **handle,
char *host,
int port,
int chan);
int VelSel_SendCmnd (
void **handle,
char *cmnd,
char *rply,
int rply_size);
/* ---------------------------------------------------------------------*/ /* ---------------------------------------------------------------------*/
void FailInet ( void FailInet(char *text);
char *text); void GetErrno(int *his_errno, int *his_vaxc_errno);
void GetErrno ( int MakeCharPrintable(char *out, int out_size, char in);
int *his_errno, char *MakePrint(char *text);
int *his_vaxc_errno); char *MakePrintable(char *out, int out_size, char *in);
int MakeCharPrintable ( void *Map_to_ACS();
char *out, char *StrEdit(char *out, char *in, char *ctrl, int *ln);
int out_size, char *StrJoin(char *result, int result_size, char *str_a, char *str_b);
char in); int StrMatch(char *str_a, char *str_b, int min_len);
char *MakePrint ( int Get_TASMAD_Info(char *file_name, int *nItems, ...);
char *text); int Get_TASMAD_Info_Filename(char *file_name, char *buf, int *bufSize);
char *MakePrintable ( int Update_TASMAD_Info(char *file_name, int *nItems, ...);
char *out,
int out_size,
char *in);
void *Map_to_ACS ();
char *StrEdit (
char *out,
char *in,
char *ctrl,
int *ln);
char *StrJoin (
char *result,
int result_size,
char *str_a,
char *str_b);
int StrMatch (
char *str_a,
char *str_b,
int min_len);
int Get_TASMAD_Info (
char *file_name,
int *nItems,
...);
int Get_TASMAD_Info_Filename (
char *file_name,
char *buf,
int *bufSize);
int Update_TASMAD_Info (
char *file_name,
int *nItems,
...);
/*--------------------------------------------- End of SINQ_PROTOTYPES.H --*/ /*--------------------------------------------- End of SINQ_PROTOTYPES.H --*/
#endif /* _sinq_prototypes_loaded_ */ #endif /* _sinq_prototypes_loaded_ */

File diff suppressed because it is too large Load Diff

View File

@@ -14,7 +14,7 @@
#define SINQHMUTILITY #define SINQHMUTILITY
#include "sinqhm_def.h" #include "sinqhm_def.h"
typedef struct __SINQHM *pSINQHM; typedef struct __SINQHM *pSINQHM;
/*------------------------------ Error codes -----------------------------*/ /*------------------------------ Error codes -----------------------------*/
#line 341 "sinqhm.w" #line 341 "sinqhm.w"
@@ -46,60 +46,58 @@
#line 118 "sinqhm.w" #line 118 "sinqhm.w"
pSINQHM CreateSINQHM(char *pHMComputer, int iMasterPort); pSINQHM CreateSINQHM(char *pHMComputer, int iMasterPort);
pSINQHM CopySINQHM(pSINQHM self); pSINQHM CopySINQHM(pSINQHM self);
void DeleteSINQHM(pSINQHM self); void DeleteSINQHM(pSINQHM self);
void SINQHMSetPar(pSINQHM self, int iRank, int iLength, int iBinWidth); void SINQHMSetPar(pSINQHM self, int iRank, int iLength, int iBinWidth);
void SINQHMSetPSD(pSINQHM self, int xSize, int xOff, int xFac, void SINQHMSetPSD(pSINQHM self, int xSize, int xOff, int xFac,
int ySize, int yOff, int yFac); int ySize, int yOff, int yFac);
#line 142 "sinqhm.w" #line 142 "sinqhm.w"
int SINQHMError2Text(int iErr, char *pBuffer, int iBufLen); int SINQHMError2Text(int iErr, char *pBuffer, int iBufLen);
#line 155 "sinqhm.w" #line 155 "sinqhm.w"
int SINQHMConfigure(pSINQHM self, int iMode, int iRank, int iLength, int SINQHMConfigure(pSINQHM self, int iMode, int iRank, int iLength,
int iBinWidth, int iLowBin, int iCompress); int iBinWidth, int iLowBin, int iCompress);
int SINQHMConfigurePSD(pSINQHM self, int iMode, int SINQHMConfigurePSD(pSINQHM self, int iMode,
int xSize, int xOff, int xFac, int xSize, int xOff, int xFac,
int ySize, int yOff, int yFac, int ySize, int yOff, int yFac,
int iBinWidth, int iBinWidth, float *iEdges, int iEdgeLength);
float *iEdges, int iEdgeLength);
int SINQHMDeconfigure(pSINQHM self, int iHarsh); int SINQHMDeconfigure(pSINQHM self, int iHarsh);
int SINQHMGetStatus(pSINQHM self,int *iMode, int *iDaq, int SINQHMGetStatus(pSINQHM self, int *iMode, int *iDaq,
int *iRank, int *iBinWidth, int *iRank, int *iBinWidth,
int *iLength, int *iClients); int *iLength, int *iClients);
int SINQHMDebug(pSINQHM self, int iLevel); int SINQHMDebug(pSINQHM self, int iLevel);
int SINQHMKill(pSINQHM self); int SINQHMKill(pSINQHM self);
#line 261 "sinqhm.w" #line 261 "sinqhm.w"
int SINQHMOpenDAQ(pSINQHM self); int SINQHMOpenDAQ(pSINQHM self);
int SINQHMCloseDAQ(pSINQHM self); int SINQHMCloseDAQ(pSINQHM self);
int SINQHMStartDAQ(pSINQHM self); int SINQHMStartDAQ(pSINQHM self);
int SINQHMStopDAQ(pSINQHM self); int SINQHMStopDAQ(pSINQHM self);
int SINQHMInhibitDAQ(pSINQHM self); int SINQHMInhibitDAQ(pSINQHM self);
int SINQHMContinueDAQ(pSINQHM self); int SINQHMContinueDAQ(pSINQHM self);
int SINQHMWrite(pSINQHM self, int iNum, int iStart, int iEnd, int SINQHMWrite(pSINQHM self, int iNum, int iStart, int iEnd, void *pData);
void *pData); long SINQHMSize(pSINQHM self, int iNum, int iStart, int iEnd);
long SINQHMSize(pSINQHM self, int iNum, int iStart, int iEnd); int SINQHMRead(pSINQHM self, int iNum, int iStart, int iEnd,
int SINQHMRead(pSINQHM self, int iNum, int iStart, int iEnd,
void *pData, int iDataLen); void *pData, int iDataLen);
int SINQHMProject(pSINQHM self, int code, int xStart, int nx, int SINQHMProject(pSINQHM self, int code, int xStart, int nx,
int yStart, int ny, void *pData, int iDataLen); int yStart, int ny, void *pData, int iDataLen);
int SINQHMZero(pSINQHM self, int iNum, int iStart, int iEnd); int SINQHMZero(pSINQHM self, int iNum, int iStart, int iEnd);
#line 382 "sinqhm.w" #line 382 "sinqhm.w"
#line 232 "sinqhm.w" #line 232 "sinqhm.w"
int SINQHMDefineBank(pSINQHM self, int iBankNumber, int iStart, int iEnd, int SINQHMDefineBank(pSINQHM self, int iBankNumber, int iStart, int iEnd,
float *iEdges, int iEdgeLength); float *iEdges, int iEdgeLength);
#line 383 "sinqhm.w" #line 383 "sinqhm.w"

View File

@@ -261,7 +261,7 @@
**------------------------------------------------------------------------------ **------------------------------------------------------------------------------
** Define structure of a TOF histogram data item. ** Define structure of a TOF histogram data item.
*/ */
struct tof_histog { struct tof_histog {
int cntr_nmbr; /* Counter number */ int cntr_nmbr; /* Counter number */
uint lo_edge; /* Low edge of first bin (20-bit value) */ uint lo_edge; /* Low edge of first bin (20-bit value) */
uint hi_edge; /* Top edge of last bin (20-bit value) */ uint hi_edge; /* Top edge of last bin (20-bit value) */
@@ -279,12 +279,12 @@
usint *w_bin_data; /* .. pointer if it's 16-bit bins */ usint *w_bin_data; /* .. pointer if it's 16-bit bins */
uint *l_bin_data; /* .. pointer if it's 32-bit bins */ uint *l_bin_data; /* .. pointer if it's 32-bit bins */
} u; } u;
}; };
/* Define a TOF 'edge-info' structure. This structure is created /* Define a TOF 'edge-info' structure. This structure is created
** as a result of a TOF 'edge-array' in a SQHM__TOF config cmnd. ** as a result of a TOF 'edge-array' in a SQHM__TOF config cmnd.
*/ */
struct tof_edge_info { struct tof_edge_info {
uint n_bins; /* Number of bins in histogram */ uint n_bins; /* Number of bins in histogram */
uint flag; /* Flag bits defining type of histo */ uint flag; /* Flag bits defining type of histo */
uint bin_span; /* Time spanned by a histogram bin (20-bit uint bin_span; /* Time spanned by a histogram bin (20-bit
@@ -294,38 +294,40 @@
uint edges[2]; /* Array of edge data (20-bit values). There uint edges[2]; /* Array of edge data (20-bit values). There
** are actually (n_bins+1) items in the array ** are actually (n_bins+1) items in the array
** and give the bottom edges of the bin */ ** and give the bottom edges of the bin */
}; };
/* Define structure of a TOF 'edge-array' in SQHM__TOF config cmnd /* Define structure of a TOF 'edge-array' in SQHM__TOF config cmnd
*/ */
struct tof_edge_arr { struct tof_edge_arr {
uint n_bins; /* Number of bins in histogram */ uint n_bins; /* Number of bins in histogram */
uint flag; /* Flag (0/1) for fixed/variable bin size */ uint flag; /* Flag (0/1) for fixed/variable bin size */
uint *edges; /* Array of bottom edges (20-bit values) */ uint *edges; /* Array of bottom edges (20-bit values) */
}; };
/* Define structure of a TOF 'bank' in SQHM__TOF config command /* Define structure of a TOF 'bank' in SQHM__TOF config command
*/ */
struct tof_bank { struct tof_bank {
usint first; /* Number of first counter in bank */ usint first; /* Number of first counter in bank */
usint n_cntrs; /* Number of counters in bank */ usint n_cntrs; /* Number of counters in bank */
usint edge_indx; /* Index of edge array */ usint edge_indx; /* Index of edge array */
usint bytes_per_bin; /* Number of bytes per bin */ usint bytes_per_bin; /* Number of bytes per bin */
}; };
/* /*
**------------------------------------------------------------------------------ **------------------------------------------------------------------------------
** Define command structure. ** Define command structure.
*/ */
struct req_buff_struct { /* For messages to SinqHM */ struct req_buff_struct { /* For messages to SinqHM */
uint bigend; uint bigend;
uint cmnd; uint cmnd;
union { union {
char filler[56]; char filler[56];
struct {uint max_pkt, struct {
strt_mode;} cnct; uint max_pkt, strt_mode;
} cnct;
struct {uint mode; struct {
uint mode;
union { union {
struct { struct {
uint n_buffs; uint n_buffs;
@@ -363,48 +365,52 @@
} u; } u;
} cnfg; } cnfg;
struct {uint mask;} dbg; struct {
uint mask;
} dbg;
struct {uint sub_code;} decnfg; struct {
uint sub_code;
} decnfg;
struct {uint sub_cmnd;} daq; struct {
uint sub_cmnd;
} daq;
struct {uint sub_code, struct {
x_lo, uint sub_code, x_lo, nx, y_lo, ny, xdim, nhist;
nx, } project;
y_lo,
ny,
xdim,
nhist;} project;
struct {uint hist_no, struct {
first_bin, uint hist_no, first_bin, n_bins;
n_bins;} read; } read;
struct {uint hist_no;} select; struct {
uint hist_no;
} select;
struct {uint hist_no, struct {
first_bin, uint hist_no, first_bin, n_bins, bytes_per_bin;
n_bins, } write;
bytes_per_bin;} write;
struct {uint hist_no, struct {
first_bin, uint hist_no, first_bin, n_bins;
n_bins;} zero; } zero;
} u; } u;
}; };
/* /*
**------------------------------------------------------------------------------ **------------------------------------------------------------------------------
** Define status response structure. ** Define status response structure.
*/ */
struct rply_buff_struct { /* For messages from SinqHM */ struct rply_buff_struct { /* For messages from SinqHM */
uint bigend; uint bigend;
uint status; uint status;
uint sub_status; uint sub_status;
union { union {
char message[52]; char message[52];
struct {uint port; struct {
uint port;
uint pkt_size; uint pkt_size;
uint hm_mode; uint hm_mode;
uint n_hists; uint n_hists;
@@ -416,14 +422,18 @@
uint lo_cntr; uint lo_cntr;
uint lo_bin; uint lo_bin;
uint compress; uint compress;
uint up_time;} cnct; uint up_time;
} cnct;
struct {usint daq_now; struct {
usint daq_now;
usint daq_was; usint daq_was;
usint filler_mask; usint filler_mask;
usint server_mask;} daq; usint server_mask;
} daq;
struct {uint n_extra_bytes; struct {
uint n_extra_bytes;
uint up_time; uint up_time;
usint offset_vxWorks_ident; usint offset_vxWorks_ident;
usint offset_vxWorks_date; usint offset_vxWorks_date;
@@ -436,20 +446,26 @@
usint offset_sinqhm_filler_ident; usint offset_sinqhm_filler_ident;
usint offset_sinqhm_filler_date; usint offset_sinqhm_filler_date;
usint offset_sinqhm_routines_ident; usint offset_sinqhm_routines_ident;
usint offset_sinqhm_routines_date;} ident; usint offset_sinqhm_routines_date;
} ident;
struct {uint n_bins; struct {
uint bytes_per_bin;
uint cnts_lo;
uint cnts_hi;} project;
struct {uint first_bin;
uint n_bins; uint n_bins;
uint bytes_per_bin; uint bytes_per_bin;
uint cnts_lo; uint cnts_lo;
uint cnts_hi;} read; uint cnts_hi;
} project;
struct {uint cfg_state; struct {
uint first_bin;
uint n_bins;
uint bytes_per_bin;
uint cnts_lo;
uint cnts_hi;
} read;
struct {
uint cfg_state;
usint n_hists, curr_hist; usint n_hists, curr_hist;
uint num_bins; uint num_bins;
uint max_n_hists; uint max_n_hists;
@@ -464,20 +480,22 @@
uint both; uint both;
} dt_or_dts; } dt_or_dts;
uint num_bad_events; uint num_bad_events;
uint up_time;} status; uint up_time;
} status;
} u; } u;
}; };
/* /*
**------------------------------------------------------------------------------ **------------------------------------------------------------------------------
** Define structure of message to SinqHM-filler. ** Define structure of message to SinqHM-filler.
*/ */
struct msg_to_filler_struct { /* For messages to SinqHM-filler */ struct msg_to_filler_struct { /* For messages to SinqHM-filler */
union { union {
char message[32]; /* Ensure buffer is 32 bytes total */ char message[32]; /* Ensure buffer is 32 bytes total */
struct { struct {
uint cmnd; uint cmnd;
uint index; uint index;
usint new_mask;} uu; usint new_mask;
} uu;
} u; } u;
}; };
/*======================================================= End of SinqHM_def.h */ /*======================================================= End of SinqHM_def.h */

View File

@@ -163,12 +163,11 @@
** strncpy to be sure result is always ** strncpy to be sure result is always
** null terminated. ** null terminated.
*/ */
char *StrEdit ( char *StrEdit(
/* ======= /* =======
*/ char *out, */ char *out,
char *in, char *in, char *ctrl, int *ln)
char *ctrl, {
int *ln) {
int i, j, k, l, m, len, inxt, out_size; int i, j, k, l, m, len, inxt, out_size;
char my_ctrl[80]; char my_ctrl[80];
@@ -177,10 +176,15 @@
int do_uncomment, do_upcase; int do_uncomment, do_upcase;
out_size = *ln; out_size = *ln;
if (out_size < 1) {*ln = 0; return NULL;} /* Can't do anything!! */ if (out_size < 1) {
*ln = 0;
if (strlen (in) <= 0) { return NULL;
*out = NIL; *ln = 0; return out; /* Nothing to do!! */ }
/* Can't do anything!! */
if (strlen(in) <= 0) {
*out = NIL;
*ln = 0;
return out; /* Nothing to do!! */
} }
/* /*
** Scan ctrl looking to see what has to be done. Do this by first ** Scan ctrl looking to see what has to be done. Do this by first
@@ -188,38 +192,45 @@
** routine, convert to lowercase and split into tokens at any space, ** routine, convert to lowercase and split into tokens at any space,
** tab or comma. ** tab or comma.
*/ */
len = strlen (ctrl); len = strlen(ctrl);
if (len >= sizeof (my_ctrl)) { if (len >= sizeof(my_ctrl)) {
*out = NIL; *ln = 0; return NULL; *out = NIL;
*ln = 0;
return NULL;
} }
for (i = 0; i <= len; i++) my_ctrl[i] = tolower (ctrl[i]); for (i = 0; i <= len; i++)
my_ctrl[i] = tolower(ctrl[i]);
do_collapse = do_compress = do_lowercase = do_trim = do_uncomment = do_collapse = do_compress = do_lowercase = do_trim = do_uncomment =
do_upcase = False; do_upcase = False;
tok_nxt = strtok (my_ctrl, ", \t\f\v\n"); tok_nxt = strtok(my_ctrl, ", \t\f\v\n");
while (tok_nxt != NULL) { while (tok_nxt != NULL) {
if (strcmp (tok_nxt, "collapse") == 0) { if (strcmp(tok_nxt, "collapse") == 0) {
do_collapse = True; do_collapse = True;
}else if (strcmp (tok_nxt, "compress") == 0) { } else if (strcmp(tok_nxt, "compress") == 0) {
do_compress = True; do_compress = True;
}else if (strcmp (tok_nxt, "lowercase") == 0) { } else if (strcmp(tok_nxt, "lowercase") == 0) {
do_lowercase = True; do_lowercase = True;
}else if (strcmp (tok_nxt, "trim") == 0) { } else if (strcmp(tok_nxt, "trim") == 0) {
do_trim = True; do_trim = True;
}else if (strcmp (tok_nxt, "uncomment") == 0) { } else if (strcmp(tok_nxt, "uncomment") == 0) {
do_uncomment = True; do_uncomment = True;
}else if (strcmp (tok_nxt, "upcase") == 0) { } else if (strcmp(tok_nxt, "upcase") == 0) {
do_upcase = True; do_upcase = True;
}else { } else {
*out = NIL; *ln = 0; return NULL; /* Illegal ctrl verb */ *out = NIL;
*ln = 0;
return NULL; /* Illegal ctrl verb */
} }
tok_nxt = strtok (NULL, ", \t\f\v\n"); tok_nxt = strtok(NULL, ", \t\f\v\n");
} }
len = strlen (in) + 1; len = strlen(in) + 1;
my_in = malloc (len); /* Get some working space */ my_in = malloc(len); /* Get some working space */
if (my_in == NULL) { if (my_in == NULL) {
*out = NIL; *ln = 0; return NULL; *out = NIL;
*ln = 0;
return NULL;
} }
/* /*
** Copy "in" to the "my_in" working space, processing any '\' escape ** Copy "in" to the "my_in" working space, processing any '\' escape
@@ -234,24 +245,67 @@
if (*in == '\\') { /* Look for escape sequence */ if (*in == '\\') { /* Look for escape sequence */
in++; in++;
switch (*in) { switch (*in) {
case 'a': case 'A': *nxt++ = '\007'; in++; break; case 'a':
case 'b': case 'B': *nxt++ = '\010'; in++; break; case 'A':
case 'f': case 'F': *nxt++ = '\014'; in++; break; *nxt++ = '\007';
case 'n': case 'N': *nxt++ = '\012'; in++; break;
case 'r': case 'R': *nxt++ = '\015'; in++; break;
case 't': case 'T': *nxt++ = '\011'; in++; break;
case 'v': case 'V': *nxt++ = '\013'; in++; break;
case '\\': *nxt++ = '\\'; in++; break;
case '\'': *nxt++ = '\''; in++; break;
case '\"': *nxt++ = '\"'; in++; break;
case '\?': *nxt++ = '\?'; in++; break;
case 'x': case 'X':
in++; in++;
i = strspn (in, "0123456789abcdefABCDEF"); break;
case 'b':
case 'B':
*nxt++ = '\010';
in++;
break;
case 'f':
case 'F':
*nxt++ = '\014';
in++;
break;
case 'n':
case 'N':
*nxt++ = '\012';
in++;
break;
case 'r':
case 'R':
*nxt++ = '\015';
in++;
break;
case 't':
case 'T':
*nxt++ = '\011';
in++;
break;
case 'v':
case 'V':
*nxt++ = '\013';
in++;
break;
case '\\':
*nxt++ = '\\';
in++;
break;
case '\'':
*nxt++ = '\'';
in++;
break;
case '\"':
*nxt++ = '\"';
in++;
break;
case '\?':
*nxt++ = '\?';
in++;
break;
case 'x':
case 'X':
in++;
i = strspn(in, "0123456789abcdefABCDEF");
if (i > 0) { if (i > 0) {
*nxt++ = strtol (in, &in, 16); break; *nxt++ = strtol(in, &in, 16);
}else { break;
*nxt++ = '\\'; break; } else {
*nxt++ = '\\';
break;
} }
case '0': case '0':
case '1': case '1':
@@ -261,42 +315,49 @@
case '5': case '5':
case '6': case '6':
case '7': case '7':
i = strspn (in, "01234567"); i = strspn(in, "01234567");
if (i > 3) { if (i > 3) {
sscanf (in, "%3o", &j); sscanf(in, "%3o", &j);
*nxt++ = j; *nxt++ = j;
in += 3; in += 3;
break; break;
}else if (i > 0) { } else if (i > 0) {
sscanf (in, "%o", &j); sscanf(in, "%o", &j);
*nxt++ = j; *nxt++ = j;
in += i; in += i;
break; break;
}else { } else {
*nxt++ = '\\'; *nxt++ = '\\';
break; break;
} }
default: default:
*nxt++ = '\\'; /* Invalid esc sequ - just copy it */ *nxt++ = '\\'; /* Invalid esc sequ - just copy it */
} }
}else if (*in == '\"') { /* Look for non-escaped double quotes */ } else if (*in == '\"') { /* Look for non-escaped double quotes */
*nxt++ = QUOTE; *in++; /* Make it something unlikely */ *nxt++ = QUOTE;
}else { *in++; /* Make it something unlikely */
} else {
*nxt++ = *in++; *nxt++ = *in++;
} }
} }
*nxt = '\0'; *nxt = '\0';
my_out = malloc (len); /* Get some working space */ my_out = malloc(len); /* Get some working space */
if (my_out == NULL) { if (my_out == NULL) {
free (my_in); *out = NIL; *ln = 0; return NULL; free(my_in);
*out = NIL;
*ln = 0;
return NULL;
} }
*my_out = NIL; *my_out = NIL;
my_tmp = malloc (len); /* Get some working space */ my_tmp = malloc(len); /* Get some working space */
if (my_tmp == NULL) { if (my_tmp == NULL) {
free (my_out); free (my_in); free(my_out);
*out = NIL; *ln = 0; return NULL; free(my_in);
*out = NIL;
*ln = 0;
return NULL;
} }
*my_tmp = NIL; *my_tmp = NIL;
*out = NIL; *out = NIL;
@@ -304,12 +365,14 @@
** Ensure "in" has an even number of non-escaped quotes. Return if not. ** Ensure "in" has an even number of non-escaped quotes. Return if not.
*/ */
i = 0; i = 0;
for (j = 0; my_in[j] != NIL; j++) if (my_in[j] == QUOTE) i++; for (j = 0; my_in[j] != NIL; j++)
if (my_in[j] == QUOTE)
i++;
if ((i & 1) == 1) { if ((i & 1) == 1) {
free (my_tmp); free(my_tmp);
free (my_out); free(my_out);
free (my_in); free(my_in);
*ln = strlen (out); *ln = strlen(out);
return NULL; return NULL;
} }
/* /*
@@ -319,22 +382,22 @@
inxt = 0; inxt = 0;
while (my_in[inxt] != NIL) { while (my_in[inxt] != NIL) {
if (my_in[inxt] == QUOTE) { /* Is there a quoted string next? */ if (my_in[inxt] == QUOTE) { /* Is there a quoted string next? */
nxt = strchr (&my_in[inxt+1], QUOTE); /* Yes, find matching quote. */ nxt = strchr(&my_in[inxt + 1], QUOTE); /* Yes, find matching quote. */
j = nxt - &my_in[inxt+1]; j = nxt - &my_in[inxt + 1];
memcpy (my_tmp, &my_in[inxt+1], j); /* Make copy of it */ memcpy(my_tmp, &my_in[inxt + 1], j); /* Make copy of it */
my_tmp[j] = NIL; my_tmp[j] = NIL;
inxt = inxt + j + 2; inxt = inxt + j + 2;
}else { } else {
nxt = strchr (&my_in[inxt], QUOTE); /* Not a quoted string; .. nxt = strchr(&my_in[inxt], QUOTE); /* Not a quoted string; ..
** .. find next non-escaped .. ** .. find next non-escaped ..
** .. quote. ** .. quote.
*/ */
if (nxt != NULL) { if (nxt != NULL) {
j = nxt - my_in - inxt; j = nxt - my_in - inxt;
}else { } else {
j = strlen (&my_in[inxt]); j = strlen(&my_in[inxt]);
} }
memcpy (my_tmp, &my_in[inxt], j); /* Make copy for us to work on */ memcpy(my_tmp, &my_in[inxt], j); /* Make copy for us to work on */
my_tmp[j] = NIL; my_tmp[j] = NIL;
inxt = inxt + j; inxt = inxt + j;
/* /*
@@ -343,10 +406,14 @@
*/ */
if (do_collapse || do_compress) { if (do_collapse || do_compress) {
for (k = 0; my_tmp[k] != NIL; k++) { for (k = 0; my_tmp[k] != NIL; k++) {
if (my_tmp[k] == '\t') my_tmp[k] = ' '; if (my_tmp[k] == '\t')
if (my_tmp[k] == '\f') my_tmp[k] = ' '; my_tmp[k] = ' ';
if (my_tmp[k] == '\v') my_tmp[k] = ' '; if (my_tmp[k] == '\f')
if (my_tmp[k] == '\n') my_tmp[k] = ' '; my_tmp[k] = ' ';
if (my_tmp[k] == '\v')
my_tmp[k] = ' ';
if (my_tmp[k] == '\n')
my_tmp[k] = ' ';
} }
if (do_collapse) { if (do_collapse) {
l = 0; l = 0;
@@ -357,59 +424,63 @@
} }
} }
my_tmp[l] = NIL; my_tmp[l] = NIL;
}else if (do_compress) { } else if (do_compress) {
for (k = 0; my_tmp[k] != NIL; k++) { for (k = 0; my_tmp[k] != NIL; k++) {
if (my_tmp[k] == ' ') { if (my_tmp[k] == ' ') {
l = strspn (&my_tmp[k], " "); l = strspn(&my_tmp[k], " ");
if (l > 1) { if (l > 1) {
for (m = 0; my_tmp[k+l+m] != NIL; m++) { for (m = 0; my_tmp[k + l + m] != NIL; m++) {
my_tmp[k+m+1] = my_tmp[k+l+m]; my_tmp[k + m + 1] = my_tmp[k + l + m];
} }
my_tmp[k+m+1] = NIL; my_tmp[k + m + 1] = NIL;
} }
} }
} }
} }
} }
if (do_lowercase) { if (do_lowercase) {
for (k = 0; my_tmp[k] != NIL; k++) my_tmp[k] = _tolower (my_tmp[k]); for (k = 0; my_tmp[k] != NIL; k++)
my_tmp[k] = _tolower(my_tmp[k]);
} }
if (do_upcase) { if (do_upcase) {
for (k = 0; my_tmp[k] != NIL; k++) my_tmp[k] = _toupper (my_tmp[k]); for (k = 0; my_tmp[k] != NIL; k++)
my_tmp[k] = _toupper(my_tmp[k]);
} }
if (do_uncomment) { if (do_uncomment) {
nxt = strchr (my_tmp, '!'); nxt = strchr(my_tmp, '!');
if (nxt != NULL) { if (nxt != NULL) {
*nxt = NIL; /* Truncate the string at the "!" */ *nxt = NIL; /* Truncate the string at the "!" */
my_in[inxt] = NIL; /* Stop processing loop too */ my_in[inxt] = NIL; /* Stop processing loop too */
} }
} }
} }
StrJoin (out, out_size, my_out, my_tmp); StrJoin(out, out_size, my_out, my_tmp);
strcpy (my_out, out); strcpy(my_out, out);
} }
if (do_trim) { if (do_trim) {
i = strspn (my_out, " "); i = strspn(my_out, " ");
if (i == strlen (my_out)) { /* If all spaces, result is a null string */ if (i == strlen(my_out)) { /* If all spaces, result is a null string */
*out = NIL; *out = NIL;
}else { } else {
for (j = strlen (my_out); my_out[j-1] == ' '; j--); for (j = strlen(my_out); my_out[j - 1] == ' '; j--);
my_out[j] = NIL; my_out[j] = NIL;
} }
strcpy (out, &my_out[i]); strcpy(out, &my_out[i]);
} }
free (my_tmp); free(my_tmp);
free (my_out); free(my_out);
free (my_in); free(my_in);
*ln = strlen (out); *ln = strlen(out);
/* /*
** Undo any encoded escape characters. ** Undo any encoded escape characters.
*/ */
for (i = 0; out[i] != NIL; i++) { for (i = 0; out[i] != NIL; i++) {
if (out[i] == ~'\"') out[i] = '\"'; if (out[i] == ~'\"')
out[i] = '\"';
} }
return out; return out;
} }
/*-------------------------------------------------- End of StrEdit.C -------*/ /*-------------------------------------------------- End of StrEdit.C -------*/

View File

@@ -89,54 +89,57 @@
** strncpy to be sure result is always ** strncpy to be sure result is always
** null terminated. ** null terminated.
*/ */
char *StrJoin ( char *StrJoin(
/* ======= /* =======
*/ char *result, */ char *result,
int result_size, int result_size, char *str_a, char *str_b)
char *str_a, {
char *str_b) {
int i, size, size_a, size_b; int i, size, size_a, size_b;
size = result_size - 1; size = result_size - 1;
if (size < 0) return result; if (size < 0)
return result;
if (result == str_a) { /* Are the result and str_a the same? */ if (result == str_a) { /* Are the result and str_a the same? */
size_a = strlen (str_a); /* Yes */ size_a = strlen(str_a); /* Yes */
if (size_a > size) { /* Check sizes anyway. */ if (size_a > size) { /* Check sizes anyway. */
result[size] = NIL; /* Truncate str_a. No room for str_b! */ result[size] = NIL; /* Truncate str_a. No room for str_b! */
}else { } else {
size = size - strlen (result); /* And append str_b */ size = size - strlen(result); /* And append str_b */
if (size > 0) { if (size > 0) {
strncat (result, str_b, size); strncat(result, str_b, size);
} }
} }
}else if (result == str_b) { /* Are the result and str_b the same? */ } else if (result == str_b) { /* Are the result and str_b the same? */
size_a = strlen (str_a); /* Yes, this is a bit complicated! */ size_a = strlen(str_a); /* Yes, this is a bit complicated! */
size_b = strlen (str_b); size_b = strlen(str_b);
if (size_a >= size) { /* If str_a completely fills result, .. */ if (size_a >= size) { /* If str_a completely fills result, .. */
result[0] = NIL; /* .. then just copy in str_a */ result[0] = NIL; /* .. then just copy in str_a */
strncat (result, str_a, size); strncat(result, str_a, size);
}else { } else {
/* /*
** Otherwise, str_b must first be moved to ** Otherwise, str_b must first be moved to
** make room for str_a and then str_a must ** make room for str_a and then str_a must
** be put at the front of the result. ** be put at the front of the result.
*/ */
if ((size_a + size_b) > size) size_b = size - size_a; if ((size_a + size_b) > size)
result[size_a+size_b] = NIL; size_b = size - size_a;
for (i = (size_b-1); i >= 0; i--) { result[size_a + size_b] = NIL;
result[size_a+i] = str_b[i]; for (i = (size_b - 1); i >= 0; i--) {
result[size_a + i] = str_b[i];
} }
memcpy (result, str_a, size_a); memcpy(result, str_a, size_a);
} }
}else { /* Result is neither str_a nor str_b so .. */ } else { /* Result is neither str_a nor str_b so .. */
result[0] = NIL; /* .. str_a needs to be copied */ result[0] = NIL; /* .. str_a needs to be copied */
strncat (result, str_a, size); strncat(result, str_a, size);
size = size - strlen (result); /* And str_a appended */ size = size - strlen(result); /* And str_a appended */
if (size > 0) strncat (result, str_b, size); if (size > 0)
strncat(result, str_b, size);
} }
return result; return result;
} }
/*-------------------------------------------------- End of STRJOIN.C =======*/ /*-------------------------------------------------- End of STRJOIN.C =======*/

View File

@@ -12,14 +12,14 @@
#include "table.h" #include "table.h"
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
typedef struct __SicsTable { typedef struct __SicsTable {
float *fVal1; float *fVal1;
float *fVal2; float *fVal2;
int iLength; int iLength;
} STable; } STable;
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
pSTable CreateTable(FILE *fd) pSTable CreateTable(FILE * fd)
{ {
pSTable pNew = NULL; pSTable pNew = NULL;
long lStart, lEnd, lData, i; long lStart, lEnd, lData, i;
char *pBuffer = NULL, *pEnd = NULL, *pEndLine, *pPtr; char *pBuffer = NULL, *pEnd = NULL, *pEndLine, *pPtr;
@@ -30,147 +30,131 @@
/* find length of file, create a buffer and read it in */ /* find length of file, create a buffer and read it in */
lStart = ftell(fd); lStart = ftell(fd);
fseek(fd,0L,SEEK_END); fseek(fd, 0L, SEEK_END);
lEnd = ftell(fd); lEnd = ftell(fd);
lData = lEnd - lStart; lData = lEnd - lStart;
pBuffer = (char *)malloc(lData*sizeof(char)); pBuffer = (char *) malloc(lData * sizeof(char));
if(!pBuffer) if (!pBuffer) {
{
return NULL; return NULL;
} }
fseek(fd,lStart,SEEK_SET); fseek(fd, lStart, SEEK_SET);
fread(pBuffer,sizeof(char),lData,fd); fread(pBuffer, sizeof(char), lData, fd);
/* find number of lines */ /* find number of lines */
for(i = 0, iLength = 0; i < lData; i++) for (i = 0, iLength = 0; i < lData; i++) {
{ if (pBuffer[i] == '\n') {
if(pBuffer[i] == '\n')
{
iLength++; iLength++;
} }
} }
/* allocate the table structure */ /* allocate the table structure */
pNew = (pSTable)malloc(sizeof(STable)); pNew = (pSTable) malloc(sizeof(STable));
if(!pNew) if (!pNew) {
{
free(pBuffer); free(pBuffer);
return NULL; return NULL;
} }
pNew->iLength = iLength; pNew->iLength = iLength;
pNew->fVal1 = (float *)malloc(sizeof(float)*iLength); pNew->fVal1 = (float *) malloc(sizeof(float) * iLength);
pNew->fVal2 = (float *)malloc(sizeof(float)*iLength); pNew->fVal2 = (float *) malloc(sizeof(float) * iLength);
if( (!pNew->fVal1) || (!pNew->fVal2)) if ((!pNew->fVal1) || (!pNew->fVal2)) {
{
free(pBuffer); free(pBuffer);
free(pNew); free(pNew);
return NULL; return NULL;
} }
memset(pNew->fVal1,0,iLength*sizeof(float)); memset(pNew->fVal1, 0, iLength * sizeof(float));
memset(pNew->fVal2,0,iLength*sizeof(float)); memset(pNew->fVal2, 0, iLength * sizeof(float));
/* dodge through the file reading pairs until end */ /* dodge through the file reading pairs until end */
pPtr = pBuffer; pPtr = pBuffer;
pEnd = pBuffer + lData; pEnd = pBuffer + lData;
pEndLine = pBuffer; pEndLine = pBuffer;
i = 0; i = 0;
while(pEndLine < pEnd) while (pEndLine < pEnd) {
{ if (*pEndLine == '\n') {
if(*pEndLine == '\n')
{
*pEndLine = '\0'; *pEndLine = '\0';
iRet = sscanf(pPtr,"%f %f",&fVal1, &fVal2); iRet = sscanf(pPtr, "%f %f", &fVal1, &fVal2);
if(iRet == 2) if (iRet == 2) {
{
pNew->fVal1[i] = fVal1; pNew->fVal1[i] = fVal1;
pNew->fVal2[i] = fVal2; pNew->fVal2[i] = fVal2;
i++; i++;
} }
pEndLine++; pEndLine++;
pPtr = pEndLine; pPtr = pEndLine;
} } else {
else
{
pEndLine++; pEndLine++;
} }
} }
free(pBuffer); free(pBuffer);
return pNew; return pNew;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
void DeleteTable(pSTable self) void DeleteTable(pSTable self)
{ {
if(self->fVal1) if (self->fVal1) {
{
free(self->fVal1); free(self->fVal1);
} }
if(self->fVal2) if (self->fVal2) {
{
free(self->fVal2); free(self->fVal2);
} }
free(self); free(self);
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int InterpolateVal1(pSTable self, float fKey, float *fResult) int InterpolateVal1(pSTable self, float fKey, float *fResult)
{ {
float fFrac; float fFrac;
int i1,i; int i1, i;
assert(self); assert(self);
assert(self->fVal1); assert(self->fVal1);
assert(self->fVal2); assert(self->fVal2);
/* search the entry point */ /* search the entry point */
for(i = 0; i < self->iLength; i++) for (i = 0; i < self->iLength; i++) {
{ if (self->fVal1[i] >= fKey) {
if(self->fVal1[i] >= fKey)
{
i1 = i; i1 = i;
break; break;
} }
} }
if(i1 >= self->iLength) if (i1 >= self->iLength) {
{
return 0; return 0;
} }
/* interpolate */ /* interpolate */
fFrac = (fKey - self->fVal1[i1 -1]) fFrac = (fKey - self->fVal1[i1 - 1])
/ (self->fVal1[i1] - self->fVal1[i1 - 1]); / (self->fVal1[i1] - self->fVal1[i1 - 1]);
*fResult = self->fVal2[i1-1] *fResult = self->fVal2[i1 - 1]
+ fFrac*(self->fVal2[i1] - self->fVal2[i1 -1]); + fFrac * (self->fVal2[i1] - self->fVal2[i1 - 1]);
return 1; return 1;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int InterpolateVal2(pSTable self, float fKey, float *fResult) int InterpolateVal2(pSTable self, float fKey, float *fResult)
{ {
float fFrac; float fFrac;
int i1,i; int i1, i;
assert(self); assert(self);
assert(self->fVal1); assert(self->fVal1);
assert(self->fVal2); assert(self->fVal2);
/* search the entry point */ /* search the entry point */
for(i = 0; i < self->iLength; i++) for (i = 0; i < self->iLength; i++) {
{ if (self->fVal2[i] <= fKey) {
if(self->fVal2[i] <= fKey)
{
i1 = i; i1 = i;
break; break;
} }
} }
if(i1 >= self->iLength) if (i1 >= self->iLength) {
{
return 0; return 0;
} }
/* interpolate */ /* interpolate */
fFrac = (fKey - self->fVal2[i1 -1]) fFrac = (fKey - self->fVal2[i1 - 1])
/ (self->fVal2[i1] - self->fVal2[i1 - 1]); / (self->fVal2[i1] - self->fVal2[i1 - 1]);
*fResult = self->fVal1[i1-1] *fResult = self->fVal1[i1 - 1]
+ fFrac*(self->fVal1[i1] - self->fVal1[i1 -1]); + fFrac * (self->fVal1[i1] - self->fVal1[i1 - 1]);
return 1; return 1;
} }

View File

@@ -11,23 +11,23 @@
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#ifndef SICSTABLE #ifndef SICSTABLE
#define SICSTABLE #define SICSTABLE
typedef struct __SicsTable *pSTable; typedef struct __SicsTable *pSTable;
/*------------------------- live & death ----------------------------------*/ /*------------------------- live & death ----------------------------------*/
pSTable CreateTable(FILE *fd); pSTable CreateTable(FILE * fd);
/* /*
creates a new table from a given file. The file is meant to have creates a new table from a given file. The file is meant to have
been positioned to the first entry for the table in the file. been positioned to the first entry for the table in the file.
This leaves the caller free to examine a header, if any. This leaves the caller free to examine a header, if any.
*/ */
void DeleteTable(pSTable self); void DeleteTable(pSTable self);
/*------------------------- Interpolation --------------------------------*/ /*------------------------- Interpolation --------------------------------*/
int InterpolateVal1(pSTable pTable, float fKey, float *fResult); int InterpolateVal1(pSTable pTable, float fKey, float *fResult);
/* /*
Returns a result from the second column for a key from the Returns a result from the second column for a key from the
first column. first column.
*/ */
int InterpolateVal2(pSTable pTable, float fKey, float *fResult); int InterpolateVal2(pSTable pTable, float fKey, float *fResult);
/* /*
Returns a result from the first column for a key from the Returns a result from the first column for a key from the
second column. second column.

View File

@@ -9,7 +9,7 @@
#define OffsetOf(type, identifier) ((size_t)(&((type*) NULL)->identifier)) #define OffsetOf(type, identifier) ((size_t)(&((type*) NULL)->identifier))
#endif #endif
enum VelSel_Errors {VELSEL__BAD_TMO = -1, enum VelSel_Errors { VELSEL__BAD_TMO = -1,
VELSEL__BAD_CMD = -3, VELSEL__BAD_CMD = -3,
VELSEL__BAD_OFL = -4, VELSEL__BAD_OFL = -4,
VELSEL__BAD_ILLG = -5, VELSEL__BAD_ILLG = -5,
@@ -41,11 +41,12 @@ enum VelSel_Errors {VELSEL__BAD_TMO = -1,
VELSEL__BAD_STP = -33, VELSEL__BAD_STP = -33,
VELSEL__NOT_OPEN = -35, VELSEL__NOT_OPEN = -35,
VELSEL__BAD_ASYNSRV = -36, VELSEL__BAD_ASYNSRV = -36,
VELSEL__BAD_REPLY = -34}; VELSEL__BAD_REPLY = -34
};
/* /*
** Structure to which the VelSel_Open handle points. ** Structure to which the VelSel_Open handle points.
*/ */
struct VelSel_info { struct VelSel_info {
struct AsynSrv__info asyn_info; /* Contains skt, host, port & chan */ struct AsynSrv__info asyn_info; /* Contains skt, host, port & chan */
int tmo; int tmo;
char eot[4]; char eot[4];
@@ -53,6 +54,6 @@ enum VelSel_Errors {VELSEL__BAD_TMO = -1,
int n_replies, max_replies; int n_replies, max_replies;
struct RS__MsgStruct to_host; struct RS__MsgStruct to_host;
struct RS__RespStruct from_host; struct RS__RespStruct from_host;
}; };
/*------------------------------------------------ End of VelSel_DEF.H --*/ /*------------------------------------------------ End of VelSel_DEF.H --*/
#endif /* _velsel_def_ */ #endif /* _velsel_def_ */

View File

@@ -358,99 +358,106 @@
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
** Global Variables ** Global Variables
*/ */
static int VelSel_call_depth = 0; static int VelSel_call_depth = 0;
static char VelSel_routine[5][64]; static char VelSel_routine[5][64];
static int VelSel_errcode = 0; static int VelSel_errcode = 0;
static int VelSel_errno, VelSel_vaxc_errno; static int VelSel_errno, VelSel_vaxc_errno;
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** VelSel_Close: Close a connection to a Velocity Selector. ** VelSel_Close: Close a connection to a Velocity Selector.
*/ */
int VelSel_Close ( int VelSel_Close(
/* =========== /* ===========
*/ void **handle, */ void **handle,
int force_flag) { int force_flag)
{
struct VelSel_info *info_ptr; struct VelSel_info *info_ptr;
char buff[4]; char buff[4];
info_ptr = (struct VelSel_info *) *handle; info_ptr = (struct VelSel_info *) *handle;
if (info_ptr == NULL) return True; if (info_ptr == NULL)
return True;
if (info_ptr->asyn_info.skt != 0) { if (info_ptr->asyn_info.skt != 0) {
if (info_ptr->asyn_info.skt > 0) { if (info_ptr->asyn_info.skt > 0) {
AsynSrv_Close (*handle, force_flag); AsynSrv_Close(*handle, force_flag);
} }
} }
free (*handle); free(*handle);
*handle = NULL; *handle = NULL;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** VelSel_Config: Configure a connection to a Velocity Selector. ** VelSel_Config: Configure a connection to a Velocity Selector.
*/ */
void VelSel_Config ( void VelSel_Config(
/* ============ /* ============
*/ void **handle, */ void **handle,
int msec_tmo, int msec_tmo, char *eot_str)
char *eot_str) { {
int i; int i;
struct VelSel_info *info_ptr; struct VelSel_info *info_ptr;
info_ptr = (struct VelSel_info *) *handle; info_ptr = (struct VelSel_info *) *handle;
if (info_ptr == NULL) return; if (info_ptr == NULL)
return;
/*------------------------- /*-------------------------
** Set up the time-out ** Set up the time-out
*/ */
if (msec_tmo < 0) { if (msec_tmo < 0) {
info_ptr->tmo = -1; info_ptr->tmo = -1;
}else { } else {
info_ptr->tmo = (msec_tmo + 99)/100; /* Convert to deci-secs */ info_ptr->tmo = (msec_tmo + 99) / 100; /* Convert to deci-secs */
if (info_ptr->tmo > 9999) info_ptr->tmo = 9999; if (info_ptr->tmo > 9999)
info_ptr->tmo = 9999;
} }
/*--------------------------------- /*---------------------------------
** Set up the end-of-text string ** Set up the end-of-text string
*/ */
if (eot_str != NULL) { if (eot_str != NULL) {
for (i = 0; i < sizeof (info_ptr->eot); i++) info_ptr->eot[i] = '\0'; for (i = 0; i < sizeof(info_ptr->eot); i++)
info_ptr->eot[i] = '\0';
for (i = 0; i < sizeof (info_ptr->eot); i++) { for (i = 0; i < sizeof(info_ptr->eot); i++) {
if (eot_str[i] == '\0') break; if (eot_str[i] == '\0')
info_ptr->eot[i+1] = eot_str[i]; break;
info_ptr->eot[i + 1] = eot_str[i];
} }
info_ptr->eot[0] = '0' + i; info_ptr->eot[0] = '0' + i;
} }
return; return;
} }
/* /*
** ------------------------------------------------------------------------- ** -------------------------------------------------------------------------
** VelSel_ErrInfo: Return detailed status from last operation. ** VelSel_ErrInfo: Return detailed status from last operation.
*/ */
void VelSel_ErrInfo ( void VelSel_ErrInfo(
/* ============= /* =============
*/ char **entry_txt, */ char **entry_txt,
int *errcode, int *errcode, int *my_errno, int *vaxc_errno)
int *my_errno, {
int *vaxc_errno) {
int i; int i;
char buff[80]; char buff[80];
int asyn_errcode, asyn_errno, asyn_vaxerrno; int asyn_errcode, asyn_errno, asyn_vaxerrno;
char* asyn_errtxt; char *asyn_errtxt;
if (VelSel_call_depth <= 0) { if (VelSel_call_depth <= 0) {
strcpy (VelSel_routine[0], "VelSel_no_error_detected"); strcpy(VelSel_routine[0], "VelSel_no_error_detected");
*errcode = 0; *errcode = 0;
*my_errno = 0; *my_errno = 0;
*vaxc_errno = 0; *vaxc_errno = 0;
}else { } else {
if (VelSel_call_depth > 1) { /* Concatenate the names */ if (VelSel_call_depth > 1) { /* Concatenate the names */
for (i = 1; i < VelSel_call_depth; i++) { for (i = 1; i < VelSel_call_depth; i++) {
strcat (VelSel_routine[0], "/"); strcat(VelSel_routine[0], "/");
StrJoin (VelSel_routine[0], sizeof (VelSel_routine), StrJoin(VelSel_routine[0], sizeof(VelSel_routine),
VelSel_routine[0], VelSel_routine[i]); VelSel_routine[0], VelSel_routine[i]);
} }
} }
@@ -458,60 +465,127 @@
*my_errno = VelSel_errno; *my_errno = VelSel_errno;
*vaxc_errno = VelSel_vaxc_errno; *vaxc_errno = VelSel_vaxc_errno;
switch (VelSel_errcode) { switch (VelSel_errcode) {
case VELSEL__BAD_TMO: strcpy (buff, "/VELSEL__BAD_TMO"); break; case VELSEL__BAD_TMO:
case VELSEL__BAD_CMD: strcpy (buff, "/VELSEL__BAD_CMD"); break; strcpy(buff, "/VELSEL__BAD_TMO");
case VELSEL__BAD_OFL: strcpy (buff, "/VELSEL__BAD_OFL"); break; break;
case VELSEL__BAD_ILLG: strcpy (buff, "/VELSEL__BAD_ILLG"); break; case VELSEL__BAD_CMD:
case VELSEL__BAD_HOST: strcpy (buff, "/VELSEL__BAD_HOST"); break; strcpy(buff, "/VELSEL__BAD_CMD");
case VELSEL__BAD_SOCKET: strcpy (buff, "/VELSEL__BAD_SOCKET"); break; break;
case VELSEL__BAD_BIND: strcpy (buff, "/VELSEL__BAD_BIND"); break; case VELSEL__BAD_OFL:
case VELSEL__BAD_CONNECT: strcpy (buff, "/VELSEL__BAD_CONNECT"); break; strcpy(buff, "/VELSEL__BAD_OFL");
case VELSEL__BAD_DEV: strcpy (buff, "/VELSEL__BAD_DEV"); break; break;
case VELSEL__BAD_MALLOC: strcpy (buff, "/VELSEL__BAD_MALLOC"); break; case VELSEL__BAD_ILLG:
case VELSEL__BAD_SENDLEN: strcpy (buff, "/VELSEL__BAD_SENDLEN"); break; strcpy(buff, "/VELSEL__BAD_ILLG");
case VELSEL__BAD_SEND: strcpy (buff, "/VELSEL__BAD_SEND"); break; break;
case VELSEL__BAD_SEND_PIPE: strcpy (buff, "/VELSEL__BAD_SEND_PIPE"); break; case VELSEL__BAD_HOST:
case VELSEL__BAD_SEND_NET: strcpy (buff, "/VELSEL__BAD_SEND_NET"); break; strcpy(buff, "/VELSEL__BAD_HOST");
case VELSEL__BAD_SEND_UNKN: strcpy (buff, "/VELSEL__BAD_SEND_UNKN"); break; break;
case VELSEL__BAD_RECV: strcpy (buff, "/VELSEL__BAD_RECV"); break; case VELSEL__BAD_SOCKET:
case VELSEL__BAD_RECV_PIPE: strcpy (buff, "/VELSEL__BAD_RECV_PIPE"); break; strcpy(buff, "/VELSEL__BAD_SOCKET");
case VELSEL__BAD_RECV_NET: strcpy (buff, "/VELSEL__BAD_RECV_NET"); break; break;
case VELSEL__BAD_RECV_UNKN: strcpy (buff, "/VELSEL__BAD_RECV_UNKN"); break; case VELSEL__BAD_BIND:
case VELSEL__BAD_NOT_BCD: strcpy (buff, "/VELSEL__BAD_NOT_BCD"); break; strcpy(buff, "/VELSEL__BAD_BIND");
case VELSEL__BAD_RECVLEN: strcpy (buff, "/VELSEL__BAD_RECVLEN"); break; break;
case VELSEL__BAD_FLUSH: strcpy (buff, "/VELSEL__BAD_FLUSH"); break; case VELSEL__BAD_CONNECT:
case VELSEL__BAD_RECV1: strcpy (buff, "/VELSEL__BAD_RECV1"); break; strcpy(buff, "/VELSEL__BAD_CONNECT");
case VELSEL__BAD_RECV1_PIPE: strcpy (buff, "/VELSEL__BAD_RECV1_PIPE"); break; break;
case VELSEL__BAD_RECV1_NET: strcpy (buff, "/VELSEL__BAD_RECV1_NET"); break; case VELSEL__BAD_DEV:
case VELSEL__BAD_PAR: strcpy (buff, "/VELSEL__BAD_PAR"); break; strcpy(buff, "/VELSEL__BAD_DEV");
case VELSEL__BAD_BSY: strcpy (buff, "/VELSEL__BAD_BSY"); break; break;
case VELSEL__BAD_OPEN: strcpy (buff, "/VELSEL__BAD_OPEN"); break; case VELSEL__BAD_MALLOC:
case VELSEL__FORCED_CLOSED: strcpy (buff, "/VELSEL__FORCED_CLOSED"); break; strcpy(buff, "/VELSEL__BAD_MALLOC");
case VELSEL__BAD_STP: strcpy (buff, "/VELSEL__BAD_STP"); break; break;
case VELSEL__BAD_REPLY: strcpy (buff, "/VELSEL__BAD_REPLY"); break; case VELSEL__BAD_SENDLEN:
default: sprintf (buff, "/VELSEL__unknown_err_code: %d", VelSel_errcode); strcpy(buff, "/VELSEL__BAD_SENDLEN");
break;
case VELSEL__BAD_SEND:
strcpy(buff, "/VELSEL__BAD_SEND");
break;
case VELSEL__BAD_SEND_PIPE:
strcpy(buff, "/VELSEL__BAD_SEND_PIPE");
break;
case VELSEL__BAD_SEND_NET:
strcpy(buff, "/VELSEL__BAD_SEND_NET");
break;
case VELSEL__BAD_SEND_UNKN:
strcpy(buff, "/VELSEL__BAD_SEND_UNKN");
break;
case VELSEL__BAD_RECV:
strcpy(buff, "/VELSEL__BAD_RECV");
break;
case VELSEL__BAD_RECV_PIPE:
strcpy(buff, "/VELSEL__BAD_RECV_PIPE");
break;
case VELSEL__BAD_RECV_NET:
strcpy(buff, "/VELSEL__BAD_RECV_NET");
break;
case VELSEL__BAD_RECV_UNKN:
strcpy(buff, "/VELSEL__BAD_RECV_UNKN");
break;
case VELSEL__BAD_NOT_BCD:
strcpy(buff, "/VELSEL__BAD_NOT_BCD");
break;
case VELSEL__BAD_RECVLEN:
strcpy(buff, "/VELSEL__BAD_RECVLEN");
break;
case VELSEL__BAD_FLUSH:
strcpy(buff, "/VELSEL__BAD_FLUSH");
break;
case VELSEL__BAD_RECV1:
strcpy(buff, "/VELSEL__BAD_RECV1");
break;
case VELSEL__BAD_RECV1_PIPE:
strcpy(buff, "/VELSEL__BAD_RECV1_PIPE");
break;
case VELSEL__BAD_RECV1_NET:
strcpy(buff, "/VELSEL__BAD_RECV1_NET");
break;
case VELSEL__BAD_PAR:
strcpy(buff, "/VELSEL__BAD_PAR");
break;
case VELSEL__BAD_BSY:
strcpy(buff, "/VELSEL__BAD_BSY");
break;
case VELSEL__BAD_OPEN:
strcpy(buff, "/VELSEL__BAD_OPEN");
break;
case VELSEL__FORCED_CLOSED:
strcpy(buff, "/VELSEL__FORCED_CLOSED");
break;
case VELSEL__BAD_STP:
strcpy(buff, "/VELSEL__BAD_STP");
break;
case VELSEL__BAD_REPLY:
strcpy(buff, "/VELSEL__BAD_REPLY");
break;
default:
sprintf(buff, "/VELSEL__unknown_err_code: %d", VelSel_errcode);
} }
StrJoin (VelSel_routine[0], sizeof(VelSel_routine), VelSel_routine[0], buff); StrJoin(VelSel_routine[0], sizeof(VelSel_routine), VelSel_routine[0],
buff);
} }
AsynSrv_ErrInfo (&asyn_errtxt, &asyn_errcode, &asyn_errno, &asyn_vaxerrno); AsynSrv_ErrInfo(&asyn_errtxt, &asyn_errcode, &asyn_errno,
&asyn_vaxerrno);
if (asyn_errcode != 0) { if (asyn_errcode != 0) {
strcat (VelSel_routine[0], "/"); strcat(VelSel_routine[0], "/");
StrJoin (VelSel_routine[0], sizeof(VelSel_routine), StrJoin(VelSel_routine[0], sizeof(VelSel_routine),
VelSel_routine[0], asyn_errtxt); VelSel_routine[0], asyn_errtxt);
} }
*entry_txt = VelSel_routine[0]; *entry_txt = VelSel_routine[0];
VelSel_call_depth = 0; VelSel_call_depth = 0;
VelSel_errcode = 0; VelSel_errcode = 0;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** VelSel_GetReply - Get next reply from a reply buffer. ** VelSel_GetReply - Get next reply from a reply buffer.
*/ */
void *VelSel_GetReply ( void *VelSel_GetReply(
/* ============== /* ==============
*/ void **handle, /* Pointer to structure containing */ void **handle, /* Pointer to structure containing
** message to pull apart */ ** message to pull apart */
void *last_rply) { /* Starting point */ void *last_rply)
{ /* Starting point */
int rply_len; int rply_len;
struct RS__RplyStruct *ptr; struct RS__RplyStruct *ptr;
@@ -524,31 +598,34 @@
if (my_last_rply == NULL) { /* Start with first reply? */ if (my_last_rply == NULL) { /* Start with first reply? */
/* Yes */ /* Yes */
if (sscanf (my_info_ptr->from_host.n_rply, "%4d", if (sscanf(my_info_ptr->from_host.n_rply, "%4d",
&my_info_ptr->max_replies) != 1) my_info_ptr->max_replies = 0; &my_info_ptr->max_replies) != 1)
my_info_ptr->max_replies = 0;
if (my_info_ptr->max_replies > 0) if (my_info_ptr->max_replies > 0)
ptr = (struct RS__RplyStruct *) my_info_ptr->from_host.u.rplys; ptr = (struct RS__RplyStruct *) my_info_ptr->from_host.u.rplys;
my_info_ptr->n_replies = 1; my_info_ptr->n_replies = 1;
}else { } else {
my_info_ptr->n_replies++; my_info_ptr->n_replies++;
if (my_info_ptr->n_replies <= my_info_ptr->max_replies) { if (my_info_ptr->n_replies <= my_info_ptr->max_replies) {
if (sscanf (my_last_rply->rply_len, "%2d", &rply_len) == 1) { if (sscanf(my_last_rply->rply_len, "%2d", &rply_len) == 1) {
ptr = ptr =
(struct RS__RplyStruct *) ((char *) my_last_rply + rply_len + 2); (struct RS__RplyStruct *) ((char *) my_last_rply + rply_len +
2);
} }
} }
} }
return (void *) ptr; return (void *) ptr;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** VelSel_GetStatus: Get "???" response from Vel Selector ** VelSel_GetStatus: Get "???" response from Vel Selector
*/ */
int VelSel_GetStatus ( int VelSel_GetStatus(
/* =============== /* ===============
*/ void **handle, */ void **handle,
char *status_str, char *status_str, int status_str_len)
int status_str_len) { {
int status; int status;
struct VelSel_info *info_ptr; struct VelSel_info *info_ptr;
@@ -561,7 +638,7 @@
** Pre-set the routine name (in case of error) ** Pre-set the routine name (in case of error)
*/ */
if (VelSel_errcode == 0 && VelSel_call_depth < 5) { if (VelSel_errcode == 0 && VelSel_call_depth < 5) {
strcpy (VelSel_routine[VelSel_call_depth], "VelSel_GetStatus"); strcpy(VelSel_routine[VelSel_call_depth], "VelSel_GetStatus");
VelSel_call_depth++; VelSel_call_depth++;
} }
/*---------------------------------------------- /*----------------------------------------------
@@ -573,8 +650,8 @@
return False; return False;
} }
if (info_ptr->asyn_info.skt <= 0) { if (info_ptr->asyn_info.skt <= 0) {
memset (info_ptr->from_host.msg_size, memset(info_ptr->from_host.msg_size,
'0', sizeof (info_ptr->from_host.msg_size)); '0', sizeof(info_ptr->from_host.msg_size));
if ((VelSel_errcode == 0) && (info_ptr->asyn_info.skt < 0)) { if ((VelSel_errcode == 0) && (info_ptr->asyn_info.skt < 0)) {
VelSel_errcode = VELSEL__FORCED_CLOSED; VelSel_errcode = VELSEL__FORCED_CLOSED;
} }
@@ -583,28 +660,29 @@
/*---------------------------------------------- /*----------------------------------------------
** Send "???" command to Velocity Selector ** Send "???" command to Velocity Selector
*/ */
status = VelSel_SendCmnds (handle, "???", NULL); status = VelSel_SendCmnds(handle, "???", NULL);
if (!status) { if (!status) {
/* Error in VelSel_SendCmnds */ /* Error in VelSel_SendCmnds */
return False; return False;
}else { } else {
rply_ptr0 = VelSel_GetReply (handle, NULL); rply_ptr0 = VelSel_GetReply(handle, NULL);
if (rply_ptr0 == NULL) rply_ptr0 = (struct RS__RplyStruct *) "06\rNULL"; if (rply_ptr0 == NULL)
StrJoin (status_str, status_str_len, rply_ptr0->rply, ""); rply_ptr0 = (struct RS__RplyStruct *) "06\rNULL";
StrJoin(status_str, status_str_len, rply_ptr0->rply, "");
} }
VelSel_call_depth--; VelSel_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** VelSel_Open: Open a connection to a Velocity Selector. ** VelSel_Open: Open a connection to a Velocity Selector.
*/ */
int VelSel_Open ( int VelSel_Open(
/* ========== /* ==========
*/ void **handle, */ void **handle,
char *host, char *host, int port, int chan)
int port, {
int chan) {
int status; int status;
struct VelSel_info *my_handle; struct VelSel_info *my_handle;
@@ -618,7 +696,7 @@
** routine name (in case of error). ** routine name (in case of error).
*/ */
VelSel_errcode = VelSel_errno = VelSel_vaxc_errno = 0; VelSel_errcode = VelSel_errno = VelSel_vaxc_errno = 0;
strcpy (VelSel_routine[0], "VelSel_Open"); strcpy(VelSel_routine[0], "VelSel_Open");
VelSel_call_depth = 1; VelSel_call_depth = 1;
/*-------------------------------------------------------- /*--------------------------------------------------------
** Assume trouble ** Assume trouble
@@ -627,7 +705,7 @@
/*-------------------------------------------------------- /*--------------------------------------------------------
** Reserve space for the data we need to store. ** Reserve space for the data we need to store.
*/ */
my_handle = (struct VelSel_info *) malloc (sizeof (*my_handle)); my_handle = (struct VelSel_info *) malloc(sizeof(*my_handle));
if (my_handle == NULL) { if (my_handle == NULL) {
VelSel_errcode = VELSEL__BAD_MALLOC; /* malloc failed!! */ VelSel_errcode = VELSEL__BAD_MALLOC; /* malloc failed!! */
return False; return False;
@@ -635,17 +713,17 @@
/*-------------------------------------------------------- /*--------------------------------------------------------
** Set up the connection ** Set up the connection
*/ */
StrJoin (my_handle->asyn_info.host, sizeof (my_handle->asyn_info.host), StrJoin(my_handle->asyn_info.host, sizeof(my_handle->asyn_info.host),
host, ""); host, "");
my_handle->asyn_info.port = port; my_handle->asyn_info.port = port;
my_handle->asyn_info.chan = chan; my_handle->asyn_info.chan = chan;
status = AsynSrv_Open (&my_handle->asyn_info); status = AsynSrv_Open(&my_handle->asyn_info);
if (!status) { if (!status) {
VelSel_errcode = VELSEL__BAD_SOCKET; VelSel_errcode = VELSEL__BAD_SOCKET;
GetErrno (&VelSel_errno, &VelSel_vaxc_errno); /* Save errno info */ GetErrno(&VelSel_errno, &VelSel_vaxc_errno); /* Save errno info */
fprintf (stderr, "\nVelSel_Open/AsynSrv_Open: " fprintf(stderr, "\nVelSel_Open/AsynSrv_Open: "
"Failed to make connection.\n"); "Failed to make connection.\n");
free (my_handle); free(my_handle);
return False; return False;
} }
@@ -653,7 +731,7 @@
** there should be no reason for the REM ** there should be no reason for the REM
** command to take very long ** command to take very long
*/ */
strcpy (my_handle->eot, "1\n\0\0"); strcpy(my_handle->eot, "1\n\0\0");
my_handle->msg_id = 0; my_handle->msg_id = 0;
/* /*
** Now ensure the VelSel is on-line. The first "REM" command can ** Now ensure the VelSel is on-line. The first "REM" command can
@@ -662,28 +740,29 @@
** command is ignored for this reason (but the VelSel_SendCmnds ** command is ignored for this reason (but the VelSel_SendCmnds
** status must be OK otherwise it indicates a network problem). ** status must be OK otherwise it indicates a network problem).
*/ */
status = VelSel_SendCmnds ((void *) &my_handle, "REM", NULL); status = VelSel_SendCmnds((void *) &my_handle, "REM", NULL);
if (status) { if (status) {
status = VelSel_SendCmnds ((void *) &my_handle, "REM", NULL); status = VelSel_SendCmnds((void *) &my_handle, "REM", NULL);
} }
if (!status) { if (!status) {
/* Some error occurred in VelSel_SendCmnds - Errcode will /* Some error occurred in VelSel_SendCmnds - Errcode will
** have been set up there. ** have been set up there.
*/ */
AsynSrv_Close (&my_handle->asyn_info, False); AsynSrv_Close(&my_handle->asyn_info, False);
free (my_handle); free(my_handle);
return False; return False;
} }
/* /*
** Check the responses carefully. ** Check the responses carefully.
*/ */
rply_ptr0 = VelSel_GetReply ((void *) &my_handle, NULL); rply_ptr0 = VelSel_GetReply((void *) &my_handle, NULL);
if (rply_ptr0 == NULL) rply_ptr0 = (struct RS__RplyStruct *) "06\rNULL"; if (rply_ptr0 == NULL)
rply_ptr0 = (struct RS__RplyStruct *) "06\rNULL";
if (rply_ptr0->rply[0] == '?') { if (rply_ptr0->rply[0] == '?') {
VelSel_errcode = VELSEL__BAD_DEV; /* Error response - not a VelSel? */ VelSel_errcode = VELSEL__BAD_DEV; /* Error response - not a VelSel? */
AsynSrv_Close (&my_handle->asyn_info, False); AsynSrv_Close(&my_handle->asyn_info, False);
free (my_handle); free(my_handle);
return False; return False;
} }
/* /*
@@ -694,15 +773,17 @@
*handle = my_handle; *handle = my_handle;
VelSel_call_depth--; VelSel_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** VelSel_SendCmnds - Send commands to RS232C server. ** VelSel_SendCmnds - Send commands to RS232C server.
*/ */
int VelSel_SendCmnds ( int VelSel_SendCmnds(
/* ================ /* ================
*/ void **handle, */ void **handle,
...) { /* Now we have list of commands - ...)
{ /* Now we have list of commands -
** char *txt = pntr to cmnd strng ** char *txt = pntr to cmnd strng
** Terminate list with *txt = NULL. ** Terminate list with *txt = NULL.
*/ */
@@ -719,7 +800,7 @@
** Pre-set the routine name (in case of error) ** Pre-set the routine name (in case of error)
*/ */
if (VelSel_errcode == 0 && VelSel_call_depth < 5) { if (VelSel_errcode == 0 && VelSel_call_depth < 5) {
strcpy (VelSel_routine[VelSel_call_depth], "VelSel_SendCmnds"); strcpy(VelSel_routine[VelSel_call_depth], "VelSel_SendCmnds");
VelSel_call_depth++; VelSel_call_depth++;
} }
/*---------------------------------------------- /*----------------------------------------------
@@ -732,8 +813,8 @@
return False; return False;
} }
if (info_ptr->asyn_info.skt <= 0) { if (info_ptr->asyn_info.skt <= 0) {
memset (info_ptr->from_host.msg_size, memset(info_ptr->from_host.msg_size,
'0', sizeof (info_ptr->from_host.msg_size)); '0', sizeof(info_ptr->from_host.msg_size));
if ((VelSel_errcode == 0) && (info_ptr->asyn_info.skt < 0)) { if ((VelSel_errcode == 0) && (info_ptr->asyn_info.skt < 0)) {
VelSel_errcode = VELSEL__FORCED_CLOSED; VelSel_errcode = VELSEL__FORCED_CLOSED;
} }
@@ -745,177 +826,182 @@
info_ptr->n_replies = info_ptr->max_replies = 0; info_ptr->n_replies = info_ptr->max_replies = 0;
info_ptr->msg_id++; /* Set up an incrementing message id */ info_ptr->msg_id++; /* Set up an incrementing message id */
if (info_ptr->msg_id > 9999) info_ptr->msg_id = 1; if (info_ptr->msg_id > 9999)
sprintf (info_ptr->to_host.msg_id, "%04.4d", info_ptr->msg_id); info_ptr->msg_id = 1;
sprintf(info_ptr->to_host.msg_id, "%04.4d", info_ptr->msg_id);
memcpy (info_ptr->to_host.c_pcol_lvl, RS__PROTOCOL_ID, memcpy(info_ptr->to_host.c_pcol_lvl, RS__PROTOCOL_ID,
sizeof (info_ptr->to_host.c_pcol_lvl)); sizeof(info_ptr->to_host.c_pcol_lvl));
sprintf (info_ptr->to_host.serial_port, "%04.4d", info_ptr->asyn_info.chan); sprintf(info_ptr->to_host.serial_port, "%04.4d",
sprintf (info_ptr->to_host.tmo, "%04.4d", info_ptr->tmo); info_ptr->asyn_info.chan);
sprintf(info_ptr->to_host.tmo, "%04.4d", info_ptr->tmo);
memcpy (info_ptr->to_host.terms, info_ptr->eot, memcpy(info_ptr->to_host.terms, info_ptr->eot,
sizeof (info_ptr->to_host.terms)); sizeof(info_ptr->to_host.terms));
memcpy (info_ptr->to_host.n_cmnds, "0000", memcpy(info_ptr->to_host.n_cmnds, "0000",
sizeof (info_ptr->to_host.n_cmnds)); sizeof(info_ptr->to_host.n_cmnds));
va_start (ap, handle); /* Set up var arg machinery */ va_start(ap, handle); /* Set up var arg machinery */
txt_ptr = va_arg (ap, char *); /* Get pntr to next cmnd string */ txt_ptr = va_arg(ap, char *); /* Get pntr to next cmnd string */
ncmnds = 0; ncmnds = 0;
cmnd_lst_ptr = &info_ptr->to_host.cmnds[0]; cmnd_lst_ptr = &info_ptr->to_host.cmnds[0];
bytes_left = sizeof (info_ptr->to_host) - bytes_left = sizeof(info_ptr->to_host) -
OffsetOf (struct RS__MsgStruct, cmnds[0]); OffsetOf(struct RS__MsgStruct, cmnds[0]);
while (txt_ptr != NULL) { while (txt_ptr != NULL) {
size = 2 + strlen (txt_ptr); size = 2 + strlen(txt_ptr);
if (size > bytes_left) { if (size > bytes_left) {
VelSel_errcode = VELSEL__BAD_SENDLEN; /* Too much to send */ VelSel_errcode = VELSEL__BAD_SENDLEN; /* Too much to send */
fprintf (stderr, "\nVelSel_SendCmnds/send: too much to send" fprintf(stderr, "\nVelSel_SendCmnds/send: too much to send"
" - request ignored.\n"); " - request ignored.\n");
memset (info_ptr->from_host.msg_size, memset(info_ptr->from_host.msg_size,
'0', sizeof (info_ptr->from_host.msg_size)); '0', sizeof(info_ptr->from_host.msg_size));
return False; return False;
}else { } else {
strcpy (cmnd_lst_ptr+2, txt_ptr); strcpy(cmnd_lst_ptr + 2, txt_ptr);
c_len = strlen (txt_ptr); c_len = strlen(txt_ptr);
sprintf (text, "%02.2d", c_len); sprintf(text, "%02.2d", c_len);
memcpy (cmnd_lst_ptr, text, 2); memcpy(cmnd_lst_ptr, text, 2);
cmnd_lst_ptr = cmnd_lst_ptr + c_len + 2; cmnd_lst_ptr = cmnd_lst_ptr + c_len + 2;
ncmnds++; ncmnds++;
bytes_left = bytes_left - size; bytes_left = bytes_left - size;
txt_ptr = va_arg (ap, char *); txt_ptr = va_arg(ap, char *);
} }
} }
sprintf (text, "%04.4d", ncmnds); sprintf(text, "%04.4d", ncmnds);
memcpy (info_ptr->to_host.n_cmnds, memcpy(info_ptr->to_host.n_cmnds,
text, sizeof (info_ptr->to_host.n_cmnds)); text, sizeof(info_ptr->to_host.n_cmnds));
size = cmnd_lst_ptr - info_ptr->to_host.msg_id; size = cmnd_lst_ptr - info_ptr->to_host.msg_id;
size = (size + 3) & (~3); /* Round up to multiple of 4 */ size = (size + 3) & (~3); /* Round up to multiple of 4 */
sprintf (text, "%04.4d", size); sprintf(text, "%04.4d", size);
memcpy (info_ptr->to_host.msg_size, text, 4); memcpy(info_ptr->to_host.msg_size, text, 4);
status = send (info_ptr->asyn_info.skt, status = send(info_ptr->asyn_info.skt,
(char *) &info_ptr->to_host, size+4, 0); (char *) &info_ptr->to_host, size + 4, 0);
if (status != (size+4)) { if (status != (size + 4)) {
GetErrno (&VelSel_errno, &VelSel_vaxc_errno); GetErrno(&VelSel_errno, &VelSel_vaxc_errno);
if (status == 0) { if (status == 0) {
VelSel_errcode = VELSEL__BAD_SEND; /* Server exited (probably) */ VelSel_errcode = VELSEL__BAD_SEND; /* Server exited (probably) */
fprintf (stderr, "\nVelSel_SendCmnds/send: probable network problem"); fprintf(stderr, "\nVelSel_SendCmnds/send: probable network problem");
}else if (status == -1) { } else if (status == -1) {
if (VelSel_errno == EPIPE) { if (VelSel_errno == EPIPE) {
VelSel_errcode = VELSEL__BAD_SEND_PIPE; /* Server exited (probably) */ VelSel_errcode = VELSEL__BAD_SEND_PIPE; /* Server exited (probably) */
fprintf (stderr, "\nVelSel_SendCmnds/send: broken network pipe"); fprintf(stderr, "\nVelSel_SendCmnds/send: broken network pipe");
}else { } else {
VelSel_errcode = VELSEL__BAD_SEND_NET; /* It's some other net problem */ VelSel_errcode = VELSEL__BAD_SEND_NET; /* It's some other net problem */
perror ("VelSel_SendCmnds/send"); perror("VelSel_SendCmnds/send");
} }
}else { } else {
VelSel_errcode = VELSEL__BAD_SEND_UNKN; /* TCP/IP problems */ VelSel_errcode = VELSEL__BAD_SEND_UNKN; /* TCP/IP problems */
fprintf (stderr, "\nVelSel_SendCmnds/send: probable TCP/IP problem"); fprintf(stderr, "\nVelSel_SendCmnds/send: probable TCP/IP problem");
} }
VelSel_Close (handle, True); /* Force close TCP/IP connection */ VelSel_Close(handle, True); /* Force close TCP/IP connection */
fprintf (stderr, " - link to server force-closed.\n"); fprintf(stderr, " - link to server force-closed.\n");
return False; return False;
} }
size = sizeof (info_ptr->from_host.msg_size); size = sizeof(info_ptr->from_host.msg_size);
status = recv (info_ptr->asyn_info.skt, status = recv(info_ptr->asyn_info.skt,
info_ptr->from_host.msg_size, size, 0); info_ptr->from_host.msg_size, size, 0);
if (status != size) { if (status != size) {
GetErrno (&VelSel_errno, &VelSel_vaxc_errno); GetErrno(&VelSel_errno, &VelSel_vaxc_errno);
if (status == 0) { if (status == 0) {
VelSel_errcode = VELSEL__BAD_RECV; /* Server exited (probably) */ VelSel_errcode = VELSEL__BAD_RECV; /* Server exited (probably) */
fprintf (stderr, "\nVelSel_SendCmnds/recv: probable network problem"); fprintf(stderr, "\nVelSel_SendCmnds/recv: probable network problem");
}else if (status == -1) { } else if (status == -1) {
if (VelSel_errno == EPIPE) { if (VelSel_errno == EPIPE) {
VelSel_errcode = VELSEL__BAD_RECV_PIPE; /* Server exited (probably) */ VelSel_errcode = VELSEL__BAD_RECV_PIPE; /* Server exited (probably) */
fprintf (stderr, "\nVelSel_SendCmnds/recv: broken network pipe"); fprintf(stderr, "\nVelSel_SendCmnds/recv: broken network pipe");
}else { } else {
VelSel_errcode = VELSEL__BAD_RECV_NET; /* It's some other net problem */ VelSel_errcode = VELSEL__BAD_RECV_NET; /* It's some other net problem */
perror ("VelSel_SendCmnds/recv"); perror("VelSel_SendCmnds/recv");
} }
}else { } else {
VelSel_errcode = VELSEL__BAD_RECV_UNKN; /* TCP/IP problems */ VelSel_errcode = VELSEL__BAD_RECV_UNKN; /* TCP/IP problems */
fprintf (stderr, "\nVelSel_SendCmnds/recv: probable TCP/IP problem"); fprintf(stderr, "\nVelSel_SendCmnds/recv: probable TCP/IP problem");
} }
VelSel_Close (handle, True); /* Force close TCP/IP connection */ VelSel_Close(handle, True); /* Force close TCP/IP connection */
fprintf (stderr, " - link to server force-closed.\n"); fprintf(stderr, " - link to server force-closed.\n");
return False; return False;
} }
if (sscanf (info_ptr->from_host.msg_size, "%4d", &bytes_to_come) != 1) { if (sscanf(info_ptr->from_host.msg_size, "%4d", &bytes_to_come) != 1) {
VelSel_errcode = VELSEL__BAD_NOT_BCD; /* Header not an ASCII BCD integer */ VelSel_errcode = VELSEL__BAD_NOT_BCD; /* Header not an ASCII BCD integer */
VelSel_Close (handle, True); /* Force close TCP/IP connection */ VelSel_Close(handle, True); /* Force close TCP/IP connection */
fprintf (stderr, "\nVelSel_SendCmnds/recv: non-BCD byte count" fprintf(stderr, "\nVelSel_SendCmnds/recv: non-BCD byte count"
" - link to server force-closed.\n"); " - link to server force-closed.\n");
return False; return False;
} }
max_size = sizeof (info_ptr->from_host) - max_size = sizeof(info_ptr->from_host) -
sizeof (info_ptr->from_host.msg_size); sizeof(info_ptr->from_host.msg_size);
if (bytes_to_come > max_size) { if (bytes_to_come > max_size) {
VelSel_errcode = VELSEL__BAD_RECVLEN; VelSel_errcode = VELSEL__BAD_RECVLEN;
fprintf (stderr, "\nVelSel_SendCmnds/recv: pending message length too big" fprintf(stderr,
"\nVelSel_SendCmnds/recv: pending message length too big"
" - flushing ...\n"); " - flushing ...\n");
nxt_byte_ptr = &info_ptr->from_host.msg_size[size]; nxt_byte_ptr = &info_ptr->from_host.msg_size[size];
while (bytes_to_come > 0) { /* Flush out the incoming message */ while (bytes_to_come > 0) { /* Flush out the incoming message */
bytes_left = bytes_to_come; bytes_left = bytes_to_come;
if (bytes_left > max_size) bytes_left = max_size; if (bytes_left > max_size)
status = recv (info_ptr->asyn_info.skt, nxt_byte_ptr, bytes_left, 0); bytes_left = max_size;
status = recv(info_ptr->asyn_info.skt, nxt_byte_ptr, bytes_left, 0);
if (status <= 0) { if (status <= 0) {
VelSel_errcode = VELSEL__BAD_FLUSH; /* TCP/IP problem whilst flushing */ VelSel_errcode = VELSEL__BAD_FLUSH; /* TCP/IP problem whilst flushing */
GetErrno (&VelSel_errno, &VelSel_vaxc_errno); GetErrno(&VelSel_errno, &VelSel_vaxc_errno);
VelSel_Close (handle, True); /* Force close TCP/IP connection */ VelSel_Close(handle, True); /* Force close TCP/IP connection */
fprintf (stderr, "\nVelSel_SendCmnds/recv: network problem during" fprintf(stderr, "\nVelSel_SendCmnds/recv: network problem during"
" flush.\nLink to server force-closed.\n"); " flush.\nLink to server force-closed.\n");
return False; return False;
} }
bytes_to_come = bytes_to_come - status; bytes_to_come = bytes_to_come - status;
} }
fprintf (stderr, "\n flushed OK.\n"); fprintf(stderr, "\n flushed OK.\n");
memset (info_ptr->from_host.msg_size, memset(info_ptr->from_host.msg_size,
'0', sizeof (info_ptr->from_host.msg_size)); '0', sizeof(info_ptr->from_host.msg_size));
return False; return False;
}else { } else {
nxt_byte_ptr = &info_ptr->from_host.msg_size[size]; nxt_byte_ptr = &info_ptr->from_host.msg_size[size];
bytes_left = bytes_to_come; bytes_left = bytes_to_come;
while (bytes_left > 0) { /* Read the rest of the response */ while (bytes_left > 0) { /* Read the rest of the response */
status = recv (info_ptr->asyn_info.skt, nxt_byte_ptr, bytes_left, 0); status = recv(info_ptr->asyn_info.skt, nxt_byte_ptr, bytes_left, 0);
if (status <= 0) { if (status <= 0) {
GetErrno (&VelSel_errno, &VelSel_vaxc_errno); GetErrno(&VelSel_errno, &VelSel_vaxc_errno);
if (status == 0) { if (status == 0) {
VelSel_errcode = VELSEL__BAD_RECV1; /* Server exited (probably) */ VelSel_errcode = VELSEL__BAD_RECV1; /* Server exited (probably) */
fprintf (stderr, "\nVelSel_SendCmnds/recv/1: probable network " fprintf(stderr, "\nVelSel_SendCmnds/recv/1: probable network "
"problem"); "problem");
}else { } else {
if (VelSel_errno == EPIPE) { if (VelSel_errno == EPIPE) {
VelSel_errcode = VELSEL__BAD_RECV1_PIPE; /* Server exited (probably) */ VelSel_errcode = VELSEL__BAD_RECV1_PIPE; /* Server exited (probably) */
fprintf (stderr, "\nVelSel_SendCmnds/recv/1: broken network pipe"); fprintf(stderr,
}else { "\nVelSel_SendCmnds/recv/1: broken network pipe");
} else {
VelSel_errcode = VELSEL__BAD_RECV1_NET; /* It's some other net fault */ VelSel_errcode = VELSEL__BAD_RECV1_NET; /* It's some other net fault */
perror ("VelSel_SendCmnds/recv/1"); perror("VelSel_SendCmnds/recv/1");
} }
} }
VelSel_Close (handle, True); /* Force close TCP/IP connection */ VelSel_Close(handle, True); /* Force close TCP/IP connection */
fprintf (stderr, " - link to server force-closed.\n"); fprintf(stderr, " - link to server force-closed.\n");
return False; return False;
} }
bytes_left = bytes_left - status; bytes_left = bytes_left - status;
nxt_byte_ptr = nxt_byte_ptr + status; nxt_byte_ptr = nxt_byte_ptr + status;
} }
if ((sscanf (info_ptr->from_host.n_rply, "%4d", if ((sscanf(info_ptr->from_host.n_rply, "%4d",
&info_ptr->max_replies) != 1) || &info_ptr->max_replies) != 1) ||
(info_ptr->max_replies < 0)) { (info_ptr->max_replies < 0)) {
VelSel_errcode = VELSEL__BAD_REPLY; /* Reply is bad */ VelSel_errcode = VELSEL__BAD_REPLY; /* Reply is bad */
if (VelSel_call_depth < 5) { /* Add reply to routine stack */ if (VelSel_call_depth < 5) { /* Add reply to routine stack */
bytes_to_come = bytes_to_come + 4; bytes_to_come = bytes_to_come + 4;
if (bytes_to_come >= sizeof (VelSel_routine[0])) if (bytes_to_come >= sizeof(VelSel_routine[0]))
bytes_to_come = sizeof (VelSel_routine[0]) - 1; bytes_to_come = sizeof(VelSel_routine[0]) - 1;
for (i=0; i<bytes_to_come; i++) { for (i = 0; i < bytes_to_come; i++) {
if (info_ptr->from_host.msg_size[i] == '\0') if (info_ptr->from_host.msg_size[i] == '\0')
info_ptr->from_host.msg_size[i] = '.'; info_ptr->from_host.msg_size[i] = '.';
} }
info_ptr->from_host.msg_size[bytes_to_come] = '\0'; info_ptr->from_host.msg_size[bytes_to_come] = '\0';
strcpy (VelSel_routine[VelSel_call_depth], strcpy(VelSel_routine[VelSel_call_depth],
info_ptr->from_host.msg_size); info_ptr->from_host.msg_size);
VelSel_call_depth++; VelSel_call_depth++;
} }
@@ -924,5 +1010,6 @@
} }
VelSel_call_depth--; VelSel_call_depth--;
return True; return True;
} }
/*-------------------------------------------- End of VelSel_Utility.C =======*/ /*-------------------------------------------- End of VelSel_Utility.C =======*/