- 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

@ -84,13 +84,15 @@
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

@ -390,6 +390,7 @@
static int AsynSrv_connect_tmo = 5; /* Time-out on "connect" */ static int AsynSrv_connect_tmo = 5; /* Time-out on "connect" */
static int AsynSrv_msec_tmo = 10000; /* Time-out for responses */ static int AsynSrv_msec_tmo = 10000; /* Time-out for responses */
static char AsynSrv_eot[] = { '1', '\r', '\0', '\0' }; /* Terminators */ static char AsynSrv_eot[] = { '1', '\r', '\0', '\0' }; /* Terminators */
/* /*
** The following is the list of open connections (= number of ** The following is the list of open connections (= number of
** active sockets). ** active sockets).
@ -408,15 +409,18 @@
int AsynSrv_Close( int AsynSrv_Close(
/* ============= /* =============
*/ struct AsynSrv__info *asyn_info, */ struct AsynSrv__info *asyn_info,
int force_flag) { int force_flag)
{
int i, j, k, my_skt; int i, j, k, my_skt;
char buff[4]; char buff[4];
/*----------------------------------------------- /*-----------------------------------------------
*/ */
if (asyn_info == NULL) return True; /* Just return if nothing to do! */ if (asyn_info == NULL)
return True; /* Just return if nothing to do! */
my_skt = asyn_info->skt; my_skt = asyn_info->skt;
if (my_skt <= 0) return True; /* Just return if nothing to do! */ if (my_skt <= 0)
return True; /* Just return if nothing to do! */
/*----------------------------------------------- /*-----------------------------------------------
** Pre-set the routinename (in case of error) ** Pre-set the routinename (in case of error)
*/ */
@ -428,9 +432,12 @@
** Start by finding the table entry for this connection ** Start by finding the table entry for this connection
*/ */
for (i = 0; i < AsynSrv_n_cnct; i++) { for (i = 0; i < AsynSrv_n_cnct; i++) {
if (AsynSrv_HPS_list[i].skt != my_skt) continue; if (AsynSrv_HPS_list[i].skt != my_skt)
if (AsynSrv_HPS_list[i].port != asyn_info->port) continue; continue;
if (strcmp (AsynSrv_HPS_list[i].host, asyn_info->host) == 0) break; if (AsynSrv_HPS_list[i].port != asyn_info->port)
continue;
if (strcmp(AsynSrv_HPS_list[i].host, asyn_info->host) == 0)
break;
} }
if (i >= AsynSrv_n_cnct) { /* Did we find the entry? */ if (i >= AsynSrv_n_cnct) { /* Did we find the entry? */
AsynSrv_errcode = AsynSrv__BAD_PAR; /* No! */ AsynSrv_errcode = AsynSrv__BAD_PAR; /* No! */
@ -495,7 +502,8 @@
j++; j++;
} }
} }
for (k = j; k < AsynSrv_n_active; k++) AsynSrv_active[k] = NULL; for (k = j; k < AsynSrv_n_active; k++)
AsynSrv_active[k] = NULL;
AsynSrv_n_active = j; AsynSrv_n_active = j;
/*------------------------------------------------------ /*------------------------------------------------------
** If the link is now idle, really close it and compress ** If the link is now idle, really close it and compress
@ -508,7 +516,8 @@
recv(my_skt, buff, sizeof(buff), 0); /* And wait for his ack */ recv(my_skt, buff, sizeof(buff), 0); /* And wait for his ack */
close(my_skt); close(my_skt);
for (j = i; j < AsynSrv_n_cnct; j++) { for (j = i; j < AsynSrv_n_cnct; j++) {
memcpy ((char *) &AsynSrv_HPS_list[j], (char *) &AsynSrv_HPS_list[j+1], memcpy((char *) &AsynSrv_HPS_list[j],
(char *) &AsynSrv_HPS_list[j + 1],
sizeof(AsynSrv_HPS_list[0])); sizeof(AsynSrv_HPS_list[0]));
} }
AsynSrv_HPS_list[AsynSrv_n_cnct].skt = 0; /* Invalidate the free entry */ AsynSrv_HPS_list[AsynSrv_n_cnct].skt = 0; /* Invalidate the free entry */
@ -517,6 +526,7 @@
AsynSrv_call_depth--; AsynSrv_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_Config: Configure an open connection. ** AsynSrv_Config: Configure an open connection.
@ -524,7 +534,8 @@
int AsynSrv_Config( int AsynSrv_Config(
/* ============== /* ==============
*/ struct AsynSrv__info *asyn_info, */ struct AsynSrv__info *asyn_info,
...) { ...)
{
char buff[16]; char buff[16];
va_list ap; /* Pointer to variable args */ va_list ap; /* Pointer to variable args */
@ -558,9 +569,12 @@
} }
memcpy(asyn_info->eot, "\0\0\0\0", 4); memcpy(asyn_info->eot, "\0\0\0\0", 4);
switch (txt_ptr[0]) { switch (txt_ptr[0]) {
case '3': asyn_info->eot[3] = txt_ptr[3]; case '3':
case '2': asyn_info->eot[2] = txt_ptr[2]; asyn_info->eot[3] = txt_ptr[3];
case '1': asyn_info->eot[1] = txt_ptr[1]; case '2':
asyn_info->eot[2] = txt_ptr[2];
case '1':
asyn_info->eot[1] = txt_ptr[1];
case '0': case '0':
asyn_info->eot[0] = txt_ptr[0]; asyn_info->eot[0] = txt_ptr[0];
break; break;
@ -578,6 +592,7 @@
AsynSrv_call_depth--; AsynSrv_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_ConfigDflt: Set default values in AsynSrv_Utility ** AsynSrv_ConfigDflt: Set default values in AsynSrv_Utility
@ -587,7 +602,8 @@
int AsynSrv_ConfigDflt( int AsynSrv_ConfigDflt(
/* ================== /* ==================
*/ char *par_id, */ char *par_id,
...) { ...)
{
int i; int i;
char buff[4]; char buff[4];
va_list ap; /* Pointer to variable args */ va_list ap; /* Pointer to variable args */
@ -625,9 +641,12 @@
return False; return False;
} }
switch (txt_ptr[0]) { switch (txt_ptr[0]) {
case '3': AsynSrv_eot[3] = txt_ptr[3]; case '3':
case '2': AsynSrv_eot[2] = txt_ptr[2]; AsynSrv_eot[3] = txt_ptr[3];
case '1': AsynSrv_eot[1] = txt_ptr[1]; case '2':
AsynSrv_eot[2] = txt_ptr[2];
case '1':
AsynSrv_eot[1] = txt_ptr[1];
case '0': case '0':
AsynSrv_eot[0] = txt_ptr[0]; AsynSrv_eot[0] = txt_ptr[0];
break; break;
@ -636,9 +655,12 @@
return False; return False;
} }
switch (txt_ptr[0]) { switch (txt_ptr[0]) {
case '0': AsynSrv_eot[1] = '\0'; case '0':
case '1': AsynSrv_eot[2] = '\0'; AsynSrv_eot[1] = '\0';
case '2': AsynSrv_eot[3] = '\0'; case '1':
AsynSrv_eot[2] = '\0';
case '2':
AsynSrv_eot[3] = '\0';
} }
} else { } else {
AsynSrv_errcode = AsynSrv__BAD_PAR; AsynSrv_errcode = AsynSrv__BAD_PAR;
@ -650,6 +672,7 @@
AsynSrv_call_depth--; AsynSrv_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_ErrInfo: Return detailed status from last operation. ** AsynSrv_ErrInfo: Return detailed status from last operation.
@ -657,9 +680,8 @@
void AsynSrv_ErrInfo( void AsynSrv_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, j, k; int i, j, k;
char buff[80]; char buff[80];
@ -681,32 +703,83 @@
*my_errno = AsynSrv_errno; *my_errno = AsynSrv_errno;
*vaxc_errno = AsynSrv_vaxc_errno; *vaxc_errno = AsynSrv_vaxc_errno;
switch (AsynSrv_errcode) { switch (AsynSrv_errcode) {
case AsynSrv__BAD_HOST: strcpy (buff, "/AsynSrv__BAD_HOST"); break; case AsynSrv__BAD_HOST:
case AsynSrv__BAD_SOCKET: strcpy (buff, "/AsynSrv__BAD_SOCKET"); break; strcpy(buff, "/AsynSrv__BAD_HOST");
case AsynSrv__BAD_BIND: strcpy (buff, "/AsynSrv__BAD_BIND"); break; break;
case AsynSrv__BAD_CONNECT: strcpy (buff, "/AsynSrv__BAD_CONNECT"); break; case AsynSrv__BAD_SOCKET:
case AsynSrv__BAD_SENDLEN: strcpy (buff, "/AsynSrv__BAD_SENDLEN"); break; strcpy(buff, "/AsynSrv__BAD_SOCKET");
case AsynSrv__BAD_SEND: strcpy (buff, "/AsynSrv__BAD_SEND"); break; break;
case AsynSrv__BAD_SEND_PIPE: strcpy (buff, "/AsynSrv__BAD_SEND_PIPE"); break; case AsynSrv__BAD_BIND:
case AsynSrv__BAD_SEND_NET: strcpy (buff, "/AsynSrv__BAD_SEND_NET"); break; strcpy(buff, "/AsynSrv__BAD_BIND");
case AsynSrv__BAD_SEND_UNKN: strcpy (buff, "/AsynSrv__BAD_SEND_UNKN"); break; break;
case AsynSrv__BAD_RECV: strcpy (buff, "/AsynSrv__BAD_RECV"); break; case AsynSrv__BAD_CONNECT:
case AsynSrv__BAD_RECV_PIPE: strcpy (buff, "/AsynSrv__BAD_RECV_PIPE"); break; strcpy(buff, "/AsynSrv__BAD_CONNECT");
case AsynSrv__BAD_RECV_NET: strcpy (buff, "/AsynSrv__BAD_RECV_NET"); break; break;
case AsynSrv__BAD_RECV_UNKN: strcpy (buff, "/AsynSrv__BAD_RECV_UNKN"); break; case AsynSrv__BAD_SENDLEN:
case AsynSrv__BAD_NOT_BCD: strcpy (buff, "/AsynSrv__BAD_NOT_BCD"); break; strcpy(buff, "/AsynSrv__BAD_SENDLEN");
case AsynSrv__BAD_RECVLEN: strcpy (buff, "/AsynSrv__BAD_RECVLEN"); break; break;
case AsynSrv__BAD_FLUSH: strcpy (buff, "/AsynSrv__BAD_FLUSH"); break; case AsynSrv__BAD_SEND:
case AsynSrv__BAD_RECV1: strcpy (buff, "/AsynSrv__BAD_RECV1"); break; strcpy(buff, "/AsynSrv__BAD_SEND");
case AsynSrv__BAD_RECV1_PIPE:strcpy (buff, "/AsynSrv__BAD_RECV1_PIPE"); break; break;
case AsynSrv__BAD_RECV1_NET: strcpy (buff, "/AsynSrv__BAD_RECV1_NET"); break; case AsynSrv__BAD_SEND_PIPE:
case AsynSrv__BAD_PAR: strcpy (buff, "/AsynSrv__BAD_PAR"); break; strcpy(buff, "/AsynSrv__BAD_SEND_PIPE");
case AsynSrv__FORCED_CLOSED: strcpy (buff, "/AsynSrv__FORCED_CLOSED"); break; break;
case AsynSrv__BAD_REPLY: strcpy (buff, "/AsynSrv__BAD_REPLY"); break; case AsynSrv__BAD_SEND_NET:
case AsynSrv__BAD_CMND_LEN: strcpy (buff, "/AsynSrv__BAD_CMND_LEN"); break; strcpy(buff, "/AsynSrv__BAD_SEND_NET");
case AsynSrv__BAD_PROT_LVL: strcpy (buff, "/AsynSrv__BAD_PROT_LVL"); break; break;
case AsynSrv__NO_ROOM: strcpy (buff, "/AsynSrv__NO_ROOM"); break; case AsynSrv__BAD_SEND_UNKN:
default: sprintf (buff, "/AsynSrv__unkn_err_code: %d", AsynSrv_errcode); strcpy(buff, "/AsynSrv__BAD_SEND_UNKN");
break;
case AsynSrv__BAD_RECV:
strcpy(buff, "/AsynSrv__BAD_RECV");
break;
case AsynSrv__BAD_RECV_PIPE:
strcpy(buff, "/AsynSrv__BAD_RECV_PIPE");
break;
case AsynSrv__BAD_RECV_NET:
strcpy(buff, "/AsynSrv__BAD_RECV_NET");
break;
case AsynSrv__BAD_RECV_UNKN:
strcpy(buff, "/AsynSrv__BAD_RECV_UNKN");
break;
case AsynSrv__BAD_NOT_BCD:
strcpy(buff, "/AsynSrv__BAD_NOT_BCD");
break;
case AsynSrv__BAD_RECVLEN:
strcpy(buff, "/AsynSrv__BAD_RECVLEN");
break;
case AsynSrv__BAD_FLUSH:
strcpy(buff, "/AsynSrv__BAD_FLUSH");
break;
case AsynSrv__BAD_RECV1:
strcpy(buff, "/AsynSrv__BAD_RECV1");
break;
case AsynSrv__BAD_RECV1_PIPE:
strcpy(buff, "/AsynSrv__BAD_RECV1_PIPE");
break;
case AsynSrv__BAD_RECV1_NET:
strcpy(buff, "/AsynSrv__BAD_RECV1_NET");
break;
case AsynSrv__BAD_PAR:
strcpy(buff, "/AsynSrv__BAD_PAR");
break;
case AsynSrv__FORCED_CLOSED:
strcpy(buff, "/AsynSrv__FORCED_CLOSED");
break;
case AsynSrv__BAD_REPLY:
strcpy(buff, "/AsynSrv__BAD_REPLY");
break;
case AsynSrv__BAD_CMND_LEN:
strcpy(buff, "/AsynSrv__BAD_CMND_LEN");
break;
case AsynSrv__BAD_PROT_LVL:
strcpy(buff, "/AsynSrv__BAD_PROT_LVL");
break;
case AsynSrv__NO_ROOM:
strcpy(buff, "/AsynSrv__NO_ROOM");
break;
default:
sprintf(buff, "/AsynSrv__unkn_err_code: %d", AsynSrv_errcode);
} }
StrJoin(AsynSrv_routine[0], sizeof(AsynSrv_routine), StrJoin(AsynSrv_routine[0], sizeof(AsynSrv_routine),
AsynSrv_routine[0], buff); AsynSrv_routine[0], buff);
@ -715,6 +788,7 @@
AsynSrv_call_depth = 0; AsynSrv_call_depth = 0;
AsynSrv_errcode = 0; AsynSrv_errcode = 0;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_GetReply: Get next reply from a reply buffer. ** AsynSrv_GetReply: Get next reply from a reply buffer.
@ -722,8 +796,8 @@
char *AsynSrv_GetReply( char *AsynSrv_GetReply(
/* ================ /* ================
*/ struct AsynSrv__info *asyn_info, */ struct AsynSrv__info *asyn_info,
struct RS__RespStruct *rcve_buff, struct RS__RespStruct *rcve_buff, char *last_rply)
char *last_rply) { {
char *pntr = NULL; char *pntr = NULL;
int i, rply_len; int i, rply_len;
@ -746,13 +820,15 @@
} }
return pntr; return pntr;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_Open: Open a connection to an RS-232-C Server. ** AsynSrv_Open: Open a connection to an RS-232-C Server.
*/ */
int AsynSrv_Open( int AsynSrv_Open(
/* ============ /* ============
*/ struct AsynSrv__info *asyn_info) { */ struct AsynSrv__info *asyn_info)
{
int i, status; int i, status;
int my_skt; int my_skt;
@ -795,8 +871,10 @@
** See if a table entry for this connection already exists. ** See if a table entry for this connection already exists.
*/ */
for (i = 0; i < AsynSrv_n_cnct; i++) { for (i = 0; i < AsynSrv_n_cnct; i++) {
if (AsynSrv_HPS_list[i].port != asyn_info->port) continue; if (AsynSrv_HPS_list[i].port != asyn_info->port)
if (strcmp (AsynSrv_HPS_list[i].host, asyn_info->host) == 0) break; continue;
if (strcmp(AsynSrv_HPS_list[i].host, asyn_info->host) == 0)
break;
} }
if (i < AsynSrv_n_cnct) { /* Did we find an entry? */ if (i < AsynSrv_n_cnct) { /* Did we find an entry? */
AsynSrv_call_depth--; /* Yes */ AsynSrv_call_depth--; /* Yes */
@ -806,8 +884,10 @@
AsynSrv_n_active++; AsynSrv_n_active++;
asyn_info->skt = /* .. return the socket. */ asyn_info->skt = /* .. return the socket. */
AsynSrv_HPS_list[i].skt; AsynSrv_HPS_list[i].skt;
if (asyn_info->chan < 0) asyn_info->chan = 0; if (asyn_info->chan < 0)
if (asyn_info->chan > 255) asyn_info->chan = 0; asyn_info->chan = 0;
if (asyn_info->chan > 255)
asyn_info->chan = 0;
sprintf(buff, "%04d", asyn_info->chan); /* Convert channel # to ASCII */ sprintf(buff, "%04d", asyn_info->chan); /* Convert channel # to ASCII */
memcpy(asyn_info->chan_char, buff, sizeof(asyn_info->chan_char)); memcpy(asyn_info->chan_char, buff, sizeof(asyn_info->chan_char));
@ -842,13 +922,14 @@
** But, before going any further, do some quick checks on ** But, before going any further, do some quick checks on
** values in asyn_info. ** values in asyn_info.
*/ */
if ((asyn_info->port <= 0) || if ((asyn_info->port <= 0) || (asyn_info->port > 65535)) {
(asyn_info->port > 65535)) {
AsynSrv_errcode = AsynSrv__BAD_PAR; /* Something is bad! */ AsynSrv_errcode = AsynSrv__BAD_PAR; /* Something is bad! */
return False; return False;
} }
if (asyn_info->chan < 0) asyn_info->chan = 0; if (asyn_info->chan < 0)
if (asyn_info->chan > 255) asyn_info->chan = 0; asyn_info->chan = 0;
if (asyn_info->chan > 255)
asyn_info->chan = 0;
/*-------------------------------------------------------- /*--------------------------------------------------------
** Set up a new connection. ** Set up a new connection.
*/ */
@ -867,7 +948,8 @@
if (rmt_hostent == NULL) { if (rmt_hostent == NULL) {
AsynSrv_errcode = AsynSrv__BAD_HOST; AsynSrv_errcode = AsynSrv__BAD_HOST;
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); /* Save errno info */ GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); /* Save errno info */
fprintf (stderr, "\nAsynSrv_Open/gethostbyname: Failed to get Internet " fprintf(stderr,
"\nAsynSrv_Open/gethostbyname: Failed to get Internet "
"address of \"%s\".\n", asyn_info->host); "address of \"%s\".\n", asyn_info->host);
return False; return False;
} }
@ -1007,7 +1089,8 @@
** Complete the setup of the connection table entry ** Complete the setup of the connection table entry
*/ */
AsynSrv_HPS_list[AsynSrv_n_cnct].skt = my_skt; AsynSrv_HPS_list[AsynSrv_n_cnct].skt = my_skt;
AsynSrv_HPS_list[AsynSrv_n_cnct].protocol_code = asyn_info->protocol_code; AsynSrv_HPS_list[AsynSrv_n_cnct].protocol_code =
asyn_info->protocol_code;
memcpy(AsynSrv_HPS_list[AsynSrv_n_cnct].protocol_id, memcpy(AsynSrv_HPS_list[AsynSrv_n_cnct].protocol_id,
asyn_info->protocol_id, sizeof(asyn_info->protocol_id)); asyn_info->protocol_id, sizeof(asyn_info->protocol_id));
AsynSrv_HPS_list[AsynSrv_n_cnct].cmnd_hdr_len = asyn_info->cmnd_hdr_len; AsynSrv_HPS_list[AsynSrv_n_cnct].cmnd_hdr_len = asyn_info->cmnd_hdr_len;
@ -1023,6 +1106,7 @@
AsynSrv_call_depth = 0; AsynSrv_call_depth = 0;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_Force: Open a connection to an RS-232-C Server. ** AsynSrv_Force: Open a connection to an RS-232-C Server.
@ -1030,7 +1114,8 @@
*/ */
int AsynSrv_Force( int AsynSrv_Force(
/* ============ /* ============
*/ struct AsynSrv__info *asyn_info) { */ struct AsynSrv__info *asyn_info)
{
int i, status; int i, status;
int my_skt; int my_skt;
@ -1066,13 +1151,14 @@
** But, before going any further, do some quick checks on ** But, before going any further, do some quick checks on
** values in asyn_info. ** values in asyn_info.
*/ */
if ((asyn_info->port <= 0) || if ((asyn_info->port <= 0) || (asyn_info->port > 65535)) {
(asyn_info->port > 65535)) {
AsynSrv_errcode = AsynSrv__BAD_PAR; /* Something is bad! */ AsynSrv_errcode = AsynSrv__BAD_PAR; /* Something is bad! */
return False; return False;
} }
if (asyn_info->chan < 0) asyn_info->chan = 0; if (asyn_info->chan < 0)
if (asyn_info->chan > 255) asyn_info->chan = 0; asyn_info->chan = 0;
if (asyn_info->chan > 255)
asyn_info->chan = 0;
/*-------------------------------------------------------- /*--------------------------------------------------------
** Set up a new connection. ** Set up a new connection.
*/ */
@ -1087,7 +1173,8 @@
if (rmt_hostent == NULL) { if (rmt_hostent == NULL) {
AsynSrv_errcode = AsynSrv__BAD_HOST; AsynSrv_errcode = AsynSrv__BAD_HOST;
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); /* Save errno info */ GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); /* Save errno info */
fprintf (stderr, "\nAsynSrv_Open/gethostbyname: Failed to get Internet " fprintf(stderr,
"\nAsynSrv_Open/gethostbyname: Failed to get Internet "
"address of \"%s\".\n", asyn_info->host); "address of \"%s\".\n", asyn_info->host);
return False; return False;
} }
@ -1227,6 +1314,7 @@
AsynSrv_call_depth = 0; AsynSrv_call_depth = 0;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_SendCmnds: Send commands to RS232C server. ** AsynSrv_SendCmnds: Send commands to RS232C server.
@ -1235,8 +1323,8 @@
/* ================= /* =================
*/ struct AsynSrv__info *asyn_info, */ 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, ...)
...) { /* 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.
*/ */
@ -1261,8 +1349,7 @@
** also be marked to have been forcefully closed. ** also be marked to have been forcefully closed.
*/ */
if (asyn_info->skt <= 0) { if (asyn_info->skt <= 0) {
memset (rcve_buff->msg_size, memset(rcve_buff->msg_size, '0', sizeof(rcve_buff->msg_size));
'0', sizeof (rcve_buff->msg_size));
if ((AsynSrv_errcode == 0) && (asyn_info->skt < 0)) { if ((AsynSrv_errcode == 0) && (asyn_info->skt < 0)) {
AsynSrv_errcode = AsynSrv__FORCED_CLOSED; AsynSrv_errcode = AsynSrv__FORCED_CLOSED;
} }
@ -1274,7 +1361,8 @@
asyn_info->max_replies = asyn_info->n_replies = 0; asyn_info->max_replies = asyn_info->n_replies = 0;
asyn_info->msg_id++; /* Set up an incrementing message id */ asyn_info->msg_id++; /* Set up an incrementing message id */
if (asyn_info->msg_id > 9999) asyn_info->msg_id = 1; if (asyn_info->msg_id > 9999)
asyn_info->msg_id = 1;
sprintf(send_buff->msg_id, "%04d", asyn_info->msg_id); sprintf(send_buff->msg_id, "%04d", asyn_info->msg_id);
memcpy(send_buff->c_pcol_lvl, asyn_info->protocol_id, memcpy(send_buff->c_pcol_lvl, asyn_info->protocol_id,
@ -1332,13 +1420,13 @@
memcpy(send_buff->msg_size, text, sizeof(send_buff->msg_size)); memcpy(send_buff->msg_size, text, sizeof(send_buff->msg_size));
size += sizeof(send_buff->msg_size); size += sizeof(send_buff->msg_size);
status = send (asyn_info->skt, status = send(asyn_info->skt, (char *) send_buff, size, 0);
(char *) send_buff, size, 0);
if (status != size) { if (status != size) {
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno);
if (status == 0) { if (status == 0) {
AsynSrv_errcode = AsynSrv__BAD_SEND; /* Server exited (probably) */ AsynSrv_errcode = AsynSrv__BAD_SEND; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendCmnds/send: probable network problem"); fprintf(stderr,
"\nAsynSrv_SendCmnds/send: probable network problem");
} else if (status == -1) { } else if (status == -1) {
if (AsynSrv_errno == EPIPE) { if (AsynSrv_errno == EPIPE) {
AsynSrv_errcode = AsynSrv__BAD_SEND_PIPE; /* Server exited (probably) */ AsynSrv_errcode = AsynSrv__BAD_SEND_PIPE; /* Server exited (probably) */
@ -1362,7 +1450,8 @@
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno);
if (status == 0) { if (status == 0) {
AsynSrv_errcode = AsynSrv__BAD_RECV; /* Server exited (probably) */ AsynSrv_errcode = AsynSrv__BAD_RECV; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendCmnds/recv: probable network problem"); fprintf(stderr,
"\nAsynSrv_SendCmnds/recv: probable network problem");
} else if (status == -1) { } else if (status == -1) {
if (AsynSrv_errno == EPIPE) { if (AsynSrv_errno == EPIPE) {
AsynSrv_errcode = AsynSrv__BAD_RECV_PIPE; /* Server exited (probably) */ AsynSrv_errcode = AsynSrv__BAD_RECV_PIPE; /* Server exited (probably) */
@ -1389,12 +1478,14 @@
max_size = sizeof(*rcve_buff) - size; max_size = sizeof(*rcve_buff) - size;
if (bytes_to_come > max_size) { if (bytes_to_come > max_size) {
AsynSrv_errcode = AsynSrv__BAD_RECVLEN; AsynSrv_errcode = AsynSrv__BAD_RECVLEN;
fprintf (stderr, "\nAsynSrv_SendCmnds/recv: pending message length too big" fprintf(stderr,
"\nAsynSrv_SendCmnds/recv: pending message length too big"
" - flushing ...\n"); " - flushing ...\n");
nxt_byte_ptr = &rcve_buff->msg_size[size]; nxt_byte_ptr = &rcve_buff->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)
bytes_left = max_size;
status = recv(asyn_info->skt, nxt_byte_ptr, bytes_left, 0); status = recv(asyn_info->skt, nxt_byte_ptr, bytes_left, 0);
if (status <= 0) { if (status <= 0) {
AsynSrv_errcode = AsynSrv__BAD_FLUSH; /* TCP/IP problem during flush */ AsynSrv_errcode = AsynSrv__BAD_FLUSH; /* TCP/IP problem during flush */
@ -1423,7 +1514,8 @@
} else { } else {
if (AsynSrv_errno == EPIPE) { if (AsynSrv_errno == EPIPE) {
AsynSrv_errcode = AsynSrv__BAD_RECV1_PIPE; /* Server exited (probably) */ AsynSrv_errcode = AsynSrv__BAD_RECV1_PIPE; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendCmnds/recv/1: broken network pipe"); fprintf(stderr,
"\nAsynSrv_SendCmnds/recv/1: broken network pipe");
} else { } else {
AsynSrv_errcode = AsynSrv__BAD_RECV1_NET; /* It's some other net fault */ AsynSrv_errcode = AsynSrv__BAD_RECV1_NET; /* It's some other net fault */
perror("AsynSrv_SendCmnds/recv/1"); perror("AsynSrv_SendCmnds/recv/1");
@ -1462,4 +1554,5 @@
AsynSrv_call_depth--; AsynSrv_call_depth--;
return True; return True;
} }
/*-------------------------------------------- End of AsynSrv_Utility.C -----*/ /*-------------------------------------------- End of AsynSrv_Utility.C -----*/

View File

@ -647,8 +647,7 @@
#define MAX_OPEN 64 #define MAX_OPEN 64
int AsynSrv_SendSpecCmnd( /* A prototype for a local routine */ int AsynSrv_SendSpecCmnd( /* A prototype for a local routine */
struct AsynSrv__info *asyn_info, struct AsynSrv__info *asyn_info, char *cmnd);
char *cmnd);
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
** Global Variables ** Global Variables
*/ */
@ -659,6 +658,7 @@
static int AsynSrv_connect_tmo = 5; /* Time-out on "connect" */ static int AsynSrv_connect_tmo = 5; /* Time-out on "connect" */
static int AsynSrv_msec_tmo = 10000; /* Time-out for responses */ static int AsynSrv_msec_tmo = 10000; /* Time-out for responses */
static char AsynSrv_eot[] = { '1', '\r', '\0', '\0' }; /* Terminators */ static char AsynSrv_eot[] = { '1', '\r', '\0', '\0' }; /* Terminators */
/* /*
** The following is the list of open connections (= number of ** The following is the list of open connections (= number of
** active sockets). ** active sockets).
@ -677,7 +677,8 @@
*/ */
int AsynSrv_ChanClose( int AsynSrv_ChanClose(
/* ================= /* =================
*/ struct AsynSrv__info *asyn_info) { */ struct AsynSrv__info *asyn_info)
{
int status; int status;
char cmnd[8], rply[8]; char cmnd[8], rply[8];
@ -704,9 +705,11 @@
*/ */
status = AsynSrv_SendSpecCmnd(asyn_info, "-006"); status = AsynSrv_SendSpecCmnd(asyn_info, "-006");
if (AsynSrv_errcode == 0) AsynSrv_call_depth--; if (AsynSrv_errcode == 0)
AsynSrv_call_depth--;
return status; return status;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_Close: Close a connection to an RS-232-C server. ** AsynSrv_Close: Close a connection to an RS-232-C server.
@ -714,15 +717,18 @@
int AsynSrv_Close( int AsynSrv_Close(
/* ============= /* =============
*/ struct AsynSrv__info *asyn_info, */ struct AsynSrv__info *asyn_info,
int force_flag) { int force_flag)
{
int i, j, k, my_skt; int i, j, k, my_skt;
char buff[4]; char buff[4];
/*----------------------------------------------- /*-----------------------------------------------
*/ */
if (asyn_info == NULL) return True; /* Just return if nothing to do! */ if (asyn_info == NULL)
return True; /* Just return if nothing to do! */
my_skt = asyn_info->skt; my_skt = asyn_info->skt;
if (my_skt <= 0) return True; /* Just return if nothing to do! */ if (my_skt <= 0)
return True; /* Just return if nothing to do! */
/*----------------------------------------------- /*-----------------------------------------------
** Pre-set the routinename (in case of error) ** Pre-set the routinename (in case of error)
*/ */
@ -734,9 +740,12 @@
** Start by finding the table entry for this connection ** Start by finding the table entry for this connection
*/ */
for (i = 0; i < AsynSrv_n_cnct; i++) { for (i = 0; i < AsynSrv_n_cnct; i++) {
if (AsynSrv_HPS_list[i].skt != my_skt) continue; if (AsynSrv_HPS_list[i].skt != my_skt)
if (AsynSrv_HPS_list[i].port != asyn_info->port) continue; continue;
if (strcmp (AsynSrv_HPS_list[i].host, asyn_info->host) == 0) break; if (AsynSrv_HPS_list[i].port != asyn_info->port)
continue;
if (strcmp(AsynSrv_HPS_list[i].host, asyn_info->host) == 0)
break;
} }
if (i >= AsynSrv_n_cnct) { /* Did we find the entry? */ if (i >= AsynSrv_n_cnct) { /* Did we find the entry? */
AsynSrv_errcode = ASYNSRV__BAD_PAR; /* No! */ AsynSrv_errcode = ASYNSRV__BAD_PAR; /* No! */
@ -801,7 +810,8 @@
j++; j++;
} }
} }
for (k = j; k < AsynSrv_n_active; k++) AsynSrv_active[k] = NULL; for (k = j; k < AsynSrv_n_active; k++)
AsynSrv_active[k] = NULL;
AsynSrv_n_active = j; AsynSrv_n_active = j;
/*------------------------------------------------------ /*------------------------------------------------------
** If the link is now idle, really close it and compress ** If the link is now idle, really close it and compress
@ -814,15 +824,18 @@
recv(my_skt, buff, sizeof(buff), 0); /* And wait for his ack */ recv(my_skt, buff, sizeof(buff), 0); /* And wait for his ack */
close(my_skt); close(my_skt);
for (j = i; j < AsynSrv_n_cnct; j++) { for (j = i; j < AsynSrv_n_cnct; j++) {
memcpy ((char *) &AsynSrv_HPS_list[j], (char *) &AsynSrv_HPS_list[j+1], memcpy((char *) &AsynSrv_HPS_list[j],
(char *) &AsynSrv_HPS_list[j + 1],
sizeof(AsynSrv_HPS_list[0])); sizeof(AsynSrv_HPS_list[0]));
} }
AsynSrv_HPS_list[AsynSrv_n_cnct].skt = 0; /* Invalidate the free entry */ AsynSrv_HPS_list[AsynSrv_n_cnct].skt = 0; /* Invalidate the free entry */
AsynSrv_n_cnct--; AsynSrv_n_cnct--;
} }
if (AsynSrv_errcode == 0) AsynSrv_call_depth--; if (AsynSrv_errcode == 0)
AsynSrv_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_Config: Configure an open connection. ** AsynSrv_Config: Configure an open connection.
@ -830,7 +843,8 @@
int AsynSrv_Config( int AsynSrv_Config(
/* ============== /* ==============
*/ struct AsynSrv__info *asyn_info, */ struct AsynSrv__info *asyn_info,
...) { ...)
{
char buff[16], my_eot[4]; char buff[16], my_eot[4];
va_list ap; /* Pointer to variable args */ va_list ap; /* Pointer to variable args */
@ -865,9 +879,12 @@
} }
memcpy(my_eot, "\0\0\0\0", 4); memcpy(my_eot, "\0\0\0\0", 4);
switch (txt_ptr[0]) { switch (txt_ptr[0]) {
case '3': my_eot[3] = txt_ptr[3]; case '3':
case '2': my_eot[2] = txt_ptr[2]; my_eot[3] = txt_ptr[3];
case '1': my_eot[1] = txt_ptr[1]; case '2':
my_eot[2] = txt_ptr[2];
case '1':
my_eot[1] = txt_ptr[1];
case '0': case '0':
my_eot[0] = txt_ptr[0]; my_eot[0] = txt_ptr[0];
break; break;
@ -885,9 +902,11 @@
txt_ptr = va_arg(ap, char *); /* Get pntr to next parameter ident */ txt_ptr = va_arg(ap, char *); /* Get pntr to next parameter ident */
} }
if (AsynSrv_errcode == 0) AsynSrv_call_depth--; if (AsynSrv_errcode == 0)
AsynSrv_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_ConfigDflt: Set default values in AsynSrv_Utility ** AsynSrv_ConfigDflt: Set default values in AsynSrv_Utility
@ -897,7 +916,8 @@
int AsynSrv_ConfigDflt( int AsynSrv_ConfigDflt(
/* ================== /* ==================
*/ char *par_id, */ char *par_id,
...) { ...)
{
int i; int i;
char buff[4]; char buff[4];
va_list ap; /* Pointer to variable args */ va_list ap; /* Pointer to variable args */
@ -935,9 +955,12 @@
return False; return False;
} }
switch (txt_ptr[0]) { switch (txt_ptr[0]) {
case '3': AsynSrv_eot[3] = txt_ptr[3]; case '3':
case '2': AsynSrv_eot[2] = txt_ptr[2]; AsynSrv_eot[3] = txt_ptr[3];
case '1': AsynSrv_eot[1] = txt_ptr[1]; case '2':
AsynSrv_eot[2] = txt_ptr[2];
case '1':
AsynSrv_eot[1] = txt_ptr[1];
case '0': case '0':
AsynSrv_eot[0] = txt_ptr[0]; AsynSrv_eot[0] = txt_ptr[0];
break; break;
@ -946,9 +969,12 @@
return False; return False;
} }
switch (txt_ptr[0]) { switch (txt_ptr[0]) {
case '0': AsynSrv_eot[1] = '\0'; case '0':
case '1': AsynSrv_eot[2] = '\0'; AsynSrv_eot[1] = '\0';
case '2': AsynSrv_eot[3] = '\0'; case '1':
AsynSrv_eot[2] = '\0';
case '2':
AsynSrv_eot[3] = '\0';
} }
} else { } else {
AsynSrv_errcode = ASYNSRV__BAD_PAR; AsynSrv_errcode = ASYNSRV__BAD_PAR;
@ -957,9 +983,11 @@
txt_ptr = va_arg(ap, char *); /* Get pntr to next parameter ident */ txt_ptr = va_arg(ap, char *); /* Get pntr to next parameter ident */
} }
if (AsynSrv_errcode == 0) AsynSrv_call_depth--; if (AsynSrv_errcode == 0)
AsynSrv_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_ErrInfo: Return detailed status from last operation. ** AsynSrv_ErrInfo: Return detailed status from last operation.
@ -967,9 +995,8 @@
void AsynSrv_ErrInfo( void AsynSrv_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, j, k; int i, j, k;
char buff[80]; char buff[80];
@ -991,32 +1018,83 @@
*my_errno = AsynSrv_errno; *my_errno = AsynSrv_errno;
*vaxc_errno = AsynSrv_vaxc_errno; *vaxc_errno = AsynSrv_vaxc_errno;
switch (AsynSrv_errcode) { switch (AsynSrv_errcode) {
case ASYNSRV__BAD_BIND: strcpy (buff, "/ASYNSRV__BAD_BIND"); break; case ASYNSRV__BAD_BIND:
case ASYNSRV__BAD_CMND_LEN: strcpy (buff, "/ASYNSRV__BAD_CMND_LEN"); break; strcpy(buff, "/ASYNSRV__BAD_BIND");
case ASYNSRV__BAD_CONNECT: strcpy (buff, "/ASYNSRV__BAD_CONNECT"); break; break;
case ASYNSRV__BAD_FLUSH: strcpy (buff, "/ASYNSRV__BAD_FLUSH"); break; case ASYNSRV__BAD_CMND_LEN:
case ASYNSRV__BAD_HOST: strcpy (buff, "/ASYNSRV__BAD_HOST"); break; strcpy(buff, "/ASYNSRV__BAD_CMND_LEN");
case ASYNSRV__BAD_NOT_BCD: strcpy (buff, "/ASYNSRV__BAD_NOT_BCD"); break; break;
case ASYNSRV__BAD_PAR: strcpy (buff, "/ASYNSRV__BAD_PAR"); break; case ASYNSRV__BAD_CONNECT:
case ASYNSRV__BAD_PROT_LVL: strcpy (buff, "/ASYNSRV__BAD_PROT_LVL"); break; strcpy(buff, "/ASYNSRV__BAD_CONNECT");
case ASYNSRV__BAD_RECV: strcpy (buff, "/ASYNSRV__BAD_RECV"); break; break;
case ASYNSRV__BAD_RECV_LEN: strcpy (buff, "/ASYNSRV__BAD_RECV_LEN"); break; case ASYNSRV__BAD_FLUSH:
case ASYNSRV__BAD_RECV_NET: strcpy (buff, "/ASYNSRV__BAD_RECV_NET"); break; strcpy(buff, "/ASYNSRV__BAD_FLUSH");
case ASYNSRV__BAD_RECV_PIPE: strcpy (buff, "/ASYNSRV__BAD_RECV_PIPE"); break; break;
case ASYNSRV__BAD_RECV_UNKN: strcpy (buff, "/ASYNSRV__BAD_RECV_UNKN"); break; case ASYNSRV__BAD_HOST:
case ASYNSRV__BAD_RECV1: strcpy (buff, "/ASYNSRV__BAD_RECV1"); break; strcpy(buff, "/ASYNSRV__BAD_HOST");
case ASYNSRV__BAD_RECV1_NET: strcpy (buff, "/ASYNSRV__BAD_RECV1_NET"); break; break;
case ASYNSRV__BAD_RECV1_PIPE:strcpy (buff, "/ASYNSRV__BAD_RECV1_PIPE"); break; case ASYNSRV__BAD_NOT_BCD:
case ASYNSRV__BAD_REPLY: strcpy (buff, "/ASYNSRV__BAD_REPLY"); break; strcpy(buff, "/ASYNSRV__BAD_NOT_BCD");
case ASYNSRV__BAD_SEND: strcpy (buff, "/ASYNSRV__BAD_SEND"); break; break;
case ASYNSRV__BAD_SEND_LEN: strcpy (buff, "/ASYNSRV__BAD_SEND_LEN"); break; case ASYNSRV__BAD_PAR:
case ASYNSRV__BAD_SEND_NET: strcpy (buff, "/ASYNSRV__BAD_SEND_NET"); break; strcpy(buff, "/ASYNSRV__BAD_PAR");
case ASYNSRV__BAD_SEND_PIPE: strcpy (buff, "/ASYNSRV__BAD_SEND_PIPE"); break; break;
case ASYNSRV__BAD_SEND_UNKN: strcpy (buff, "/ASYNSRV__BAD_SEND_UNKN"); break; case ASYNSRV__BAD_PROT_LVL:
case ASYNSRV__BAD_SOCKET: strcpy (buff, "/ASYNSRV__BAD_SOCKET"); break; strcpy(buff, "/ASYNSRV__BAD_PROT_LVL");
case ASYNSRV__FORCED_CLOSED: strcpy (buff, "/ASYNSRV__FORCED_CLOSED"); break; break;
case ASYNSRV__NO_ROOM: strcpy (buff, "/ASYNSRV__NO_ROOM"); break; case ASYNSRV__BAD_RECV:
default: sprintf (buff, "/ASYNSRV__unkn_err_code: %d", AsynSrv_errcode); strcpy(buff, "/ASYNSRV__BAD_RECV");
break;
case ASYNSRV__BAD_RECV_LEN:
strcpy(buff, "/ASYNSRV__BAD_RECV_LEN");
break;
case ASYNSRV__BAD_RECV_NET:
strcpy(buff, "/ASYNSRV__BAD_RECV_NET");
break;
case ASYNSRV__BAD_RECV_PIPE:
strcpy(buff, "/ASYNSRV__BAD_RECV_PIPE");
break;
case ASYNSRV__BAD_RECV_UNKN:
strcpy(buff, "/ASYNSRV__BAD_RECV_UNKN");
break;
case ASYNSRV__BAD_RECV1:
strcpy(buff, "/ASYNSRV__BAD_RECV1");
break;
case ASYNSRV__BAD_RECV1_NET:
strcpy(buff, "/ASYNSRV__BAD_RECV1_NET");
break;
case ASYNSRV__BAD_RECV1_PIPE:
strcpy(buff, "/ASYNSRV__BAD_RECV1_PIPE");
break;
case ASYNSRV__BAD_REPLY:
strcpy(buff, "/ASYNSRV__BAD_REPLY");
break;
case ASYNSRV__BAD_SEND:
strcpy(buff, "/ASYNSRV__BAD_SEND");
break;
case ASYNSRV__BAD_SEND_LEN:
strcpy(buff, "/ASYNSRV__BAD_SEND_LEN");
break;
case ASYNSRV__BAD_SEND_NET:
strcpy(buff, "/ASYNSRV__BAD_SEND_NET");
break;
case ASYNSRV__BAD_SEND_PIPE:
strcpy(buff, "/ASYNSRV__BAD_SEND_PIPE");
break;
case ASYNSRV__BAD_SEND_UNKN:
strcpy(buff, "/ASYNSRV__BAD_SEND_UNKN");
break;
case ASYNSRV__BAD_SOCKET:
strcpy(buff, "/ASYNSRV__BAD_SOCKET");
break;
case ASYNSRV__FORCED_CLOSED:
strcpy(buff, "/ASYNSRV__FORCED_CLOSED");
break;
case ASYNSRV__NO_ROOM:
strcpy(buff, "/ASYNSRV__NO_ROOM");
break;
default:
sprintf(buff, "/ASYNSRV__unkn_err_code: %d", AsynSrv_errcode);
} }
StrJoin(AsynSrv_routine[0], sizeof(AsynSrv_routine), StrJoin(AsynSrv_routine[0], sizeof(AsynSrv_routine),
AsynSrv_routine[0], buff); AsynSrv_routine[0], buff);
@ -1025,13 +1103,15 @@
AsynSrv_call_depth = 0; AsynSrv_call_depth = 0;
AsynSrv_errcode = 0; AsynSrv_errcode = 0;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_Flush: Send a Flush command to RS232C server. ** AsynSrv_Flush: Send a Flush command to RS232C server.
*/ */
int AsynSrv_Flush( int AsynSrv_Flush(
/* ============= /* =============
*/ struct AsynSrv__info *asyn_info) { */ struct AsynSrv__info *asyn_info)
{
int status; int status;
char cmnd[8], rply[8]; char cmnd[8], rply[8];
@ -1058,9 +1138,11 @@
*/ */
status = AsynSrv_SendSpecCmnd(asyn_info, "-004"); status = AsynSrv_SendSpecCmnd(asyn_info, "-004");
if (AsynSrv_errcode == 0) AsynSrv_call_depth--; if (AsynSrv_errcode == 0)
AsynSrv_call_depth--;
return status; return status;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_GetLenTerm: Get length and terminator of given ** AsynSrv_GetLenTerm: Get length and terminator of given
@ -1069,21 +1151,24 @@
int AsynSrv_GetLenTerm( int AsynSrv_GetLenTerm(
/* ================== /* ==================
*/ struct AsynSrv__info *asyn_info, */ struct AsynSrv__info *asyn_info,
struct RS__RespStruct *rcve_buff, struct RS__RespStruct *rcve_buff, char *rply, /* In: Addr of a reply as got ..
char *rply, /* In: Addr of a reply as got ..
** .. got from _GetReply */ ** .. got from _GetReply */
int *len, /* Out: The returned length */ int *len, /* Out: The returned length */
char *term) { /* Out: The returned t'nator */ char *term)
{ /* Out: The returned t'nator */
int i; int i;
i = sscanf ((rply - asyn_info->rply_hdr_len - 1), asyn_info->rply_fmt, len); i = sscanf((rply - asyn_info->rply_hdr_len - 1), asyn_info->rply_fmt,
len);
*len = (i == 1) ? (*len - 2) : 0; *len = (i == 1) ? (*len - 2) : 0;
*term = *(rply - 1); *term = *(rply - 1);
if (i != 1) return False; if (i != 1)
return False;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_GetReply: Get next reply from a reply buffer. ** AsynSrv_GetReply: Get next reply from a reply buffer.
@ -1091,8 +1176,8 @@
char *AsynSrv_GetReply( char *AsynSrv_GetReply(
/* ================ /* ================
*/ struct AsynSrv__info *asyn_info, */ struct AsynSrv__info *asyn_info,
struct RS__RespStruct *rcve_buff, struct RS__RespStruct *rcve_buff, char *last_rply)
char *last_rply) { {
char *pntr = NULL; char *pntr = NULL;
int i, rply_len; int i, rply_len;
@ -1115,13 +1200,15 @@
} }
return pntr; return pntr;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_Open: Open a connection to an RS-232-C Server. ** AsynSrv_Open: Open a connection to an RS-232-C Server.
*/ */
int AsynSrv_Open( int AsynSrv_Open(
/* ============ /* ============
*/ struct AsynSrv__info *asyn_info) { */ struct AsynSrv__info *asyn_info)
{
int i, status; int i, status;
int my_skt; int my_skt;
@ -1165,9 +1252,12 @@
** See if a table entry for this connection already exists. ** See if a table entry for this connection already exists.
*/ */
for (i = 0; i < AsynSrv_n_cnct; i++) { for (i = 0; i < AsynSrv_n_cnct; i++) {
if (AsynSrv_HPS_list[i].status != 0) continue; if (AsynSrv_HPS_list[i].status != 0)
if (AsynSrv_HPS_list[i].port != asyn_info->port) continue; continue;
if (strcmp (AsynSrv_HPS_list[i].host, asyn_info->host) == 0) break; if (AsynSrv_HPS_list[i].port != asyn_info->port)
continue;
if (strcmp(AsynSrv_HPS_list[i].host, asyn_info->host) == 0)
break;
} }
if (i < AsynSrv_n_cnct) { /* Did we find an entry? */ if (i < AsynSrv_n_cnct) { /* Did we find an entry? */
/* Yes */ /* Yes */
@ -1177,8 +1267,10 @@
AsynSrv_n_active++; AsynSrv_n_active++;
asyn_info->skt = /* .. return the socket. */ asyn_info->skt = /* .. return the socket. */
AsynSrv_HPS_list[i].skt; AsynSrv_HPS_list[i].skt;
if (asyn_info->chan < 0) asyn_info->chan = 0; if (asyn_info->chan < 0)
if (asyn_info->chan > 255) asyn_info->chan = 0; asyn_info->chan = 0;
if (asyn_info->chan > 255)
asyn_info->chan = 0;
sprintf(buff, "%04d", asyn_info->chan); /* Convert channel # to ASCII */ sprintf(buff, "%04d", asyn_info->chan); /* Convert channel # to ASCII */
memcpy(asyn_info->chan_char, buff, sizeof(asyn_info->chan_char)); memcpy(asyn_info->chan_char, buff, sizeof(asyn_info->chan_char));
@ -1207,7 +1299,8 @@
** There is no existing connection. Open a new one. ** There is no existing connection. Open a new one.
*/ */
status = AsynSrv_OpenNew(asyn_info); status = AsynSrv_OpenNew(asyn_info);
if (!status) return False; if (!status)
return False;
/*-------------------------------------------------------- /*--------------------------------------------------------
** Allow the entry to be shared (i.e. status = 0) ** Allow the entry to be shared (i.e. status = 0)
*/ */
@ -1218,13 +1311,15 @@
AsynSrv_call_depth = 0; AsynSrv_call_depth = 0;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_OpenNew: Open a new connection to an RS-232-C Server. ** AsynSrv_OpenNew: Open a new connection to an RS-232-C Server.
*/ */
int AsynSrv_OpenNew( int AsynSrv_OpenNew(
/* =============== /* ===============
*/ struct AsynSrv__info *asyn_info) { */ struct AsynSrv__info *asyn_info)
{
int i, status; int i, status;
int my_skt; int my_skt;
@ -1283,8 +1378,7 @@
*/ */
if ((asyn_info->port <= 0) || if ((asyn_info->port <= 0) ||
(asyn_info->port > 65535) || (asyn_info->port > 65535) ||
(asyn_info->chan < 0) || (asyn_info->chan < 0) || (asyn_info->chan > 255)) {
(asyn_info->chan > 255)) {
AsynSrv_errcode = ASYNSRV__BAD_PAR; /* Something is bad! */ AsynSrv_errcode = ASYNSRV__BAD_PAR; /* Something is bad! */
return False; return False;
} }
@ -1306,7 +1400,8 @@
if (rmt_hostent == NULL) { if (rmt_hostent == NULL) {
AsynSrv_errcode = ASYNSRV__BAD_HOST; AsynSrv_errcode = ASYNSRV__BAD_HOST;
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); /* Save errno info */ GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); /* Save errno info */
fprintf (stderr, "\nAsynSrv_OpenNew/gethostbyname: Failed to get Internet " fprintf(stderr,
"\nAsynSrv_OpenNew/gethostbyname: Failed to get Internet "
"address of \"%s\".\n", asyn_info->host); "address of \"%s\".\n", asyn_info->host);
return False; return False;
} }
@ -1319,7 +1414,8 @@
if (my_skt <= 0) { if (my_skt <= 0) {
AsynSrv_errcode = ASYNSRV__BAD_SOCKET; AsynSrv_errcode = ASYNSRV__BAD_SOCKET;
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); /* Save the errno info */ GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); /* Save the errno info */
fprintf (stderr, "\nAsynSrv_OpenNew/socket: Failed to create a socket.\n"); fprintf(stderr,
"\nAsynSrv_OpenNew/socket: Failed to create a socket.\n");
return False; return False;
} }
lcl_sockname.sin_family = AF_INET; lcl_sockname.sin_family = AF_INET;
@ -1447,7 +1543,8 @@
** Complete the setup of the connection table entry ** Complete the setup of the connection table entry
*/ */
AsynSrv_HPS_list[AsynSrv_n_cnct].skt = my_skt; AsynSrv_HPS_list[AsynSrv_n_cnct].skt = my_skt;
AsynSrv_HPS_list[AsynSrv_n_cnct].protocol_code = asyn_info->protocol_code; AsynSrv_HPS_list[AsynSrv_n_cnct].protocol_code =
asyn_info->protocol_code;
memcpy(AsynSrv_HPS_list[AsynSrv_n_cnct].protocol_id, memcpy(AsynSrv_HPS_list[AsynSrv_n_cnct].protocol_id,
asyn_info->protocol_id, sizeof(asyn_info->protocol_id)); asyn_info->protocol_id, sizeof(asyn_info->protocol_id));
AsynSrv_HPS_list[AsynSrv_n_cnct].cmnd_hdr_len = asyn_info->cmnd_hdr_len; AsynSrv_HPS_list[AsynSrv_n_cnct].cmnd_hdr_len = asyn_info->cmnd_hdr_len;
@ -1464,6 +1561,7 @@
AsynSrv_call_depth--; AsynSrv_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_SendCmnds: Send commands to RS232C server. ** AsynSrv_SendCmnds: Send commands to RS232C server.
@ -1472,8 +1570,8 @@
/* ================= /* =================
*/ struct AsynSrv__info *asyn_info, */ 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, ...)
...) { /* 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.
*/ */
@ -1498,8 +1596,7 @@
** also be marked to have been forcefully closed. ** also be marked to have been forcefully closed.
*/ */
if (asyn_info->skt <= 0) { if (asyn_info->skt <= 0) {
memset (rcve_buff, memset(rcve_buff, '0', sizeof(*rcve_buff));
'0', sizeof (*rcve_buff));
if ((AsynSrv_errcode == 0) && (asyn_info->skt < 0)) { if ((AsynSrv_errcode == 0) && (asyn_info->skt < 0)) {
AsynSrv_errcode = ASYNSRV__FORCED_CLOSED; AsynSrv_errcode = ASYNSRV__FORCED_CLOSED;
} }
@ -1511,7 +1608,8 @@
asyn_info->max_replies = asyn_info->n_replies = 0; asyn_info->max_replies = asyn_info->n_replies = 0;
asyn_info->msg_id++; /* Set up an incrementing message id */ asyn_info->msg_id++; /* Set up an incrementing message id */
if (asyn_info->msg_id > 9999) asyn_info->msg_id = 1; if (asyn_info->msg_id > 9999)
asyn_info->msg_id = 1;
sprintf(send_buff->msg_id, "%04d", asyn_info->msg_id); sprintf(send_buff->msg_id, "%04d", asyn_info->msg_id);
memcpy(send_buff->c_pcol_lvl, asyn_info->protocol_id, memcpy(send_buff->c_pcol_lvl, asyn_info->protocol_id,
@ -1569,13 +1667,13 @@
memcpy(send_buff->msg_size, text, sizeof(send_buff->msg_size)); memcpy(send_buff->msg_size, text, sizeof(send_buff->msg_size));
size += sizeof(send_buff->msg_size); size += sizeof(send_buff->msg_size);
status = send (asyn_info->skt, status = send(asyn_info->skt, (char *) send_buff, size, 0);
(char *) send_buff, size, 0);
if (status != size) { if (status != size) {
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno);
if (status == 0) { if (status == 0) {
AsynSrv_errcode = ASYNSRV__BAD_SEND; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_SEND; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendCmnds/send: probable network problem"); fprintf(stderr,
"\nAsynSrv_SendCmnds/send: probable network problem");
} else if (status == -1) { } else if (status == -1) {
if (AsynSrv_errno == EPIPE) { if (AsynSrv_errno == EPIPE) {
AsynSrv_errcode = ASYNSRV__BAD_SEND_PIPE; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_SEND_PIPE; /* Server exited (probably) */
@ -1609,7 +1707,8 @@
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno);
if (status == 0) { if (status == 0) {
AsynSrv_errcode = ASYNSRV__BAD_RECV; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_RECV; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendCmnds/recv: probable network problem"); fprintf(stderr,
"\nAsynSrv_SendCmnds/recv: probable network problem");
} else if (status == -1) { } else if (status == -1) {
if (AsynSrv_errno == EPIPE) { if (AsynSrv_errno == EPIPE) {
AsynSrv_errcode = ASYNSRV__BAD_RECV_PIPE; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_RECV_PIPE; /* Server exited (probably) */
@ -1636,12 +1735,14 @@
max_size = sizeof(*rcve_buff) - size; max_size = sizeof(*rcve_buff) - size;
if (bytes_to_come > max_size) { if (bytes_to_come > max_size) {
AsynSrv_errcode = ASYNSRV__BAD_RECV_LEN; AsynSrv_errcode = ASYNSRV__BAD_RECV_LEN;
fprintf (stderr, "\nAsynSrv_SendCmnds/recv: pending message length too big" fprintf(stderr,
"\nAsynSrv_SendCmnds/recv: pending message length too big"
" - flushing ...\n"); " - flushing ...\n");
nxt_byte_ptr = &rcve_buff->msg_size[size]; nxt_byte_ptr = &rcve_buff->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)
bytes_left = max_size;
status = recv(asyn_info->skt, nxt_byte_ptr, bytes_left, 0); status = recv(asyn_info->skt, nxt_byte_ptr, bytes_left, 0);
if (status <= 0) { if (status <= 0) {
AsynSrv_errcode = ASYNSRV__BAD_FLUSH; /* TCP/IP problem during flush */ AsynSrv_errcode = ASYNSRV__BAD_FLUSH; /* TCP/IP problem during flush */
@ -1670,7 +1771,8 @@
} else { } else {
if (AsynSrv_errno == EPIPE) { if (AsynSrv_errno == EPIPE) {
AsynSrv_errcode = ASYNSRV__BAD_RECV1_PIPE; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_RECV1_PIPE; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendCmnds/recv/1: broken network pipe"); fprintf(stderr,
"\nAsynSrv_SendCmnds/recv/1: broken network pipe");
} else { } else {
AsynSrv_errcode = ASYNSRV__BAD_RECV1_NET; /* It's some other net fault */ AsynSrv_errcode = ASYNSRV__BAD_RECV1_NET; /* It's some other net fault */
perror("AsynSrv_SendCmnds/recv/1"); perror("AsynSrv_SendCmnds/recv/1");
@ -1706,9 +1808,11 @@
return False; return False;
} }
} }
if (AsynSrv_errcode == 0) AsynSrv_call_depth--; if (AsynSrv_errcode == 0)
AsynSrv_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_SendCmndsBig: Same as AsynSrv_SendCmnds but with ** AsynSrv_SendCmndsBig: Same as AsynSrv_SendCmnds but with
@ -1720,8 +1824,8 @@
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, ...)
...) { /* 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.
*/ */
@ -1747,8 +1851,7 @@
** also be marked to have been forcefully closed. ** also be marked to have been forcefully closed.
*/ */
if (asyn_info->skt <= 0) { if (asyn_info->skt <= 0) {
memset (rcve_buff->msg_size, memset(rcve_buff->msg_size, '0', sizeof(rcve_buff->msg_size));
'0', sizeof (rcve_buff->msg_size));
if ((AsynSrv_errcode == 0) && (asyn_info->skt < 0)) { if ((AsynSrv_errcode == 0) && (asyn_info->skt < 0)) {
AsynSrv_errcode = ASYNSRV__FORCED_CLOSED; AsynSrv_errcode = ASYNSRV__FORCED_CLOSED;
} }
@ -1758,12 +1861,15 @@
** Build message for server from the list of commands. ** Build message for server from the list of commands.
*/ */
if (send_buff_size < 64 || rcve_buff_size < 64) { if (send_buff_size < 64 || rcve_buff_size < 64) {
AsynSrv_errcode = ASYNSRV__BAD_PAR; return False;} AsynSrv_errcode = ASYNSRV__BAD_PAR;
return False;
}
asyn_info->max_replies = asyn_info->n_replies = 0; asyn_info->max_replies = asyn_info->n_replies = 0;
asyn_info->msg_id++; /* Set up an incrementing message id */ asyn_info->msg_id++; /* Set up an incrementing message id */
if (asyn_info->msg_id > 9999) asyn_info->msg_id = 1; if (asyn_info->msg_id > 9999)
asyn_info->msg_id = 1;
sprintf(send_buff->msg_id, "%04d", asyn_info->msg_id); sprintf(send_buff->msg_id, "%04d", asyn_info->msg_id);
memcpy(send_buff->c_pcol_lvl, asyn_info->protocol_id, memcpy(send_buff->c_pcol_lvl, asyn_info->protocol_id,
@ -1783,13 +1889,13 @@
c_len = va_arg(ap, int *); /* Get pntr to length of next cmnd string */ c_len = va_arg(ap, int *); /* Get pntr to length of next cmnd string */
ncmnds = 0; ncmnds = 0;
cmnd_lst_ptr = &send_buff->cmnds[0]; cmnd_lst_ptr = &send_buff->cmnds[0];
bytes_left = send_buff_size - bytes_left = send_buff_size - OffsetOf(struct RS__MsgStruct, cmnds[0]);
OffsetOf (struct RS__MsgStruct, cmnds[0]);
while (c_len != NULL) { while (c_len != NULL) {
txt_ptr = va_arg(ap, char *); txt_ptr = va_arg(ap, char *);
s_len = *c_len; s_len = *c_len;
if (s_len <= 0) s_len = strlen (txt_ptr); if (s_len <= 0)
s_len = strlen(txt_ptr);
size = asyn_info->cmnd_hdr_len + s_len; size = asyn_info->cmnd_hdr_len + s_len;
if (size > bytes_left) { if (size > bytes_left) {
AsynSrv_errcode = ASYNSRV__BAD_SEND_LEN; /* Too much to send */ AsynSrv_errcode = ASYNSRV__BAD_SEND_LEN; /* Too much to send */
@ -1822,24 +1928,26 @@
memcpy(send_buff->msg_size, text, sizeof(send_buff->msg_size)); memcpy(send_buff->msg_size, text, sizeof(send_buff->msg_size));
size += sizeof(send_buff->msg_size); size += sizeof(send_buff->msg_size);
status = send (asyn_info->skt, status = send(asyn_info->skt, (char *) send_buff, size, 0);
(char *) send_buff, size, 0);
if (status != size) { if (status != size) {
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno);
if (status == 0) { if (status == 0) {
AsynSrv_errcode = ASYNSRV__BAD_SEND; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_SEND; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendCmndsBig/send: probable network problem"); fprintf(stderr,
"\nAsynSrv_SendCmndsBig/send: probable network problem");
} else if (status == -1) { } else if (status == -1) {
if (AsynSrv_errno == EPIPE) { if (AsynSrv_errno == EPIPE) {
AsynSrv_errcode = ASYNSRV__BAD_SEND_PIPE; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_SEND_PIPE; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendCmndsBig/send: broken network pipe"); fprintf(stderr,
"\nAsynSrv_SendCmndsBig/send: broken network pipe");
} else { } else {
AsynSrv_errcode = ASYNSRV__BAD_SEND_NET; /* It's some other net problem */ AsynSrv_errcode = ASYNSRV__BAD_SEND_NET; /* It's some other net problem */
perror("AsynSrv_SendCmndsBig/send"); perror("AsynSrv_SendCmndsBig/send");
} }
} else { } else {
AsynSrv_errcode = ASYNSRV__BAD_SEND_UNKN; /* TCP/IP problems */ AsynSrv_errcode = ASYNSRV__BAD_SEND_UNKN; /* TCP/IP problems */
fprintf (stderr, "\nAsynSrv_SendCmndsBig/send: probable TCP/IP problem"); fprintf(stderr,
"\nAsynSrv_SendCmndsBig/send: probable TCP/IP problem");
} }
AsynSrv_Close(asyn_info, True); /* Force close TCP/IP connection */ AsynSrv_Close(asyn_info, True); /* Force close TCP/IP connection */
fprintf(stderr, " - link to server force-closed.\n"); fprintf(stderr, " - link to server force-closed.\n");
@ -1852,18 +1960,21 @@
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno);
if (status == 0) { if (status == 0) {
AsynSrv_errcode = ASYNSRV__BAD_RECV; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_RECV; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendCmndsBig/recv: probable network problem"); fprintf(stderr,
"\nAsynSrv_SendCmndsBig/recv: probable network problem");
} else if (status == -1) { } else if (status == -1) {
if (AsynSrv_errno == EPIPE) { if (AsynSrv_errno == EPIPE) {
AsynSrv_errcode = ASYNSRV__BAD_RECV_PIPE; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_RECV_PIPE; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendCmndsBig/recv: broken network pipe"); fprintf(stderr,
"\nAsynSrv_SendCmndsBig/recv: broken network pipe");
} else { } else {
AsynSrv_errcode = ASYNSRV__BAD_RECV_NET; /* It's some other net problem */ AsynSrv_errcode = ASYNSRV__BAD_RECV_NET; /* It's some other net problem */
perror("AsynSrv_SendCmndsBig/recv"); perror("AsynSrv_SendCmndsBig/recv");
} }
} else { } else {
AsynSrv_errcode = ASYNSRV__BAD_RECV_UNKN; /* TCP/IP problems */ AsynSrv_errcode = ASYNSRV__BAD_RECV_UNKN; /* TCP/IP problems */
fprintf (stderr, "\nAsynSrv_SendCmndsBig/recv: probable TCP/IP problem"); fprintf(stderr,
"\nAsynSrv_SendCmndsBig/recv: probable TCP/IP problem");
} }
AsynSrv_Close(asyn_info, True); /* Force close TCP/IP connection */ AsynSrv_Close(asyn_info, True); /* Force close TCP/IP connection */
fprintf(stderr, " - link to server force-closed.\n"); fprintf(stderr, " - link to server force-closed.\n");
@ -1884,13 +1995,15 @@
nxt_byte_ptr = &rcve_buff->msg_size[size]; nxt_byte_ptr = &rcve_buff->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)
bytes_left = max_size;
status = recv(asyn_info->skt, nxt_byte_ptr, bytes_left, 0); status = recv(asyn_info->skt, nxt_byte_ptr, bytes_left, 0);
if (status <= 0) { if (status <= 0) {
AsynSrv_errcode = ASYNSRV__BAD_FLUSH; /* TCP/IP problem during flush */ AsynSrv_errcode = ASYNSRV__BAD_FLUSH; /* TCP/IP problem during flush */
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno);
AsynSrv_Close(asyn_info, True); /* Force close TCP/IP connection */ AsynSrv_Close(asyn_info, True); /* Force close TCP/IP connection */
fprintf (stderr, "\nAsynSrv_SendCmndsBig/recv: network problem during" fprintf(stderr,
"\nAsynSrv_SendCmndsBig/recv: network problem during"
" flush.\nLink to server force-closed.\n"); " flush.\nLink to server force-closed.\n");
return False; return False;
} }
@ -1908,12 +2021,14 @@
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno);
if (status == 0) { if (status == 0) {
AsynSrv_errcode = ASYNSRV__BAD_RECV1; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_RECV1; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendCmndsBig/recv/1: probable network " fprintf(stderr,
"\nAsynSrv_SendCmndsBig/recv/1: probable network "
"problem"); "problem");
} else { } else {
if (AsynSrv_errno == EPIPE) { if (AsynSrv_errno == EPIPE) {
AsynSrv_errcode = ASYNSRV__BAD_RECV1_PIPE; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_RECV1_PIPE; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendCmndsBig/recv/1: broken network pipe"); fprintf(stderr,
"\nAsynSrv_SendCmndsBig/recv/1: broken network pipe");
} else { } else {
AsynSrv_errcode = ASYNSRV__BAD_RECV1_NET; /* It's some other net fault */ AsynSrv_errcode = ASYNSRV__BAD_RECV1_NET; /* It's some other net fault */
perror("AsynSrv_SendCmndsBig/recv/1"); perror("AsynSrv_SendCmndsBig/recv/1");
@ -1949,9 +2064,11 @@
return False; return False;
} }
} }
if (AsynSrv_errcode == 0) AsynSrv_call_depth--; if (AsynSrv_errcode == 0)
AsynSrv_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_SendSpecCmnd: Send a "special" command to an ** AsynSrv_SendSpecCmnd: Send a "special" command to an
@ -1960,7 +2077,8 @@
int AsynSrv_SendSpecCmnd( int AsynSrv_SendSpecCmnd(
/* ==================== /* ====================
*/ struct AsynSrv__info *asyn_info, */ struct AsynSrv__info *asyn_info,
char *cmnd) { char *cmnd)
{
int status; int status;
char rply[8]; char rply[8];
@ -1990,18 +2108,21 @@
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno);
if (status == 0) { if (status == 0) {
AsynSrv_errcode = ASYNSRV__BAD_SEND; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_SEND; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendSpecCmnd/send: probable network problem"); fprintf(stderr,
"\nAsynSrv_SendSpecCmnd/send: probable network problem");
} else if (status == -1) { } else if (status == -1) {
if (AsynSrv_errno == EPIPE) { if (AsynSrv_errno == EPIPE) {
AsynSrv_errcode = ASYNSRV__BAD_SEND_PIPE; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_SEND_PIPE; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendSpecCmnd/send: broken network pipe"); fprintf(stderr,
"\nAsynSrv_SendSpecCmnd/send: broken network pipe");
} else { } else {
AsynSrv_errcode = ASYNSRV__BAD_SEND_NET; /* It's some other net problem */ AsynSrv_errcode = ASYNSRV__BAD_SEND_NET; /* It's some other net problem */
perror("AsynSrv_SendSpecCmnd/send"); perror("AsynSrv_SendSpecCmnd/send");
} }
} else { } else {
AsynSrv_errcode = ASYNSRV__BAD_SEND_UNKN; /* TCP/IP problems */ AsynSrv_errcode = ASYNSRV__BAD_SEND_UNKN; /* TCP/IP problems */
fprintf (stderr, "\nAsynSrv_SendSpecCmnd/send: probable TCP/IP problem"); fprintf(stderr,
"\nAsynSrv_SendSpecCmnd/send: probable TCP/IP problem");
} }
AsynSrv_Close(asyn_info, True); /* Force close TCP/IP connection */ AsynSrv_Close(asyn_info, True); /* Force close TCP/IP connection */
fprintf(stderr, " - link to server force-closed.\n"); fprintf(stderr, " - link to server force-closed.\n");
@ -2013,18 +2134,21 @@
GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno); GetErrno(&AsynSrv_errno, &AsynSrv_vaxc_errno);
if (status == 0) { if (status == 0) {
AsynSrv_errcode = ASYNSRV__BAD_RECV; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_RECV; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendSpecCmnd/recv: probable network problem"); fprintf(stderr,
"\nAsynSrv_SendSpecCmnd/recv: probable network problem");
} else if (status == -1) { } else if (status == -1) {
if (AsynSrv_errno == EPIPE) { if (AsynSrv_errno == EPIPE) {
AsynSrv_errcode = ASYNSRV__BAD_RECV_PIPE; /* Server exited (probably) */ AsynSrv_errcode = ASYNSRV__BAD_RECV_PIPE; /* Server exited (probably) */
fprintf (stderr, "\nAsynSrv_SendSpecCmnd/recv: broken network pipe"); fprintf(stderr,
"\nAsynSrv_SendSpecCmnd/recv: broken network pipe");
} else { } else {
AsynSrv_errcode = ASYNSRV__BAD_RECV_NET; /* It's some other net problem */ AsynSrv_errcode = ASYNSRV__BAD_RECV_NET; /* It's some other net problem */
perror("AsynSrv_SendSpecCmnd/recv"); perror("AsynSrv_SendSpecCmnd/recv");
} }
} else { } else {
AsynSrv_errcode = ASYNSRV__BAD_RECV_UNKN; /* TCP/IP problems */ AsynSrv_errcode = ASYNSRV__BAD_RECV_UNKN; /* TCP/IP problems */
fprintf (stderr, "\nAsynSrv_SendSpecCmnd/recv: probable TCP/IP problem"); fprintf(stderr,
"\nAsynSrv_SendSpecCmnd/recv: probable TCP/IP problem");
} }
AsynSrv_Close(asyn_info, True); /* Force close TCP/IP connection */ AsynSrv_Close(asyn_info, True); /* Force close TCP/IP connection */
fprintf(stderr, " - link to server force-closed.\n"); fprintf(stderr, " - link to server force-closed.\n");
@ -2033,13 +2157,16 @@
if (memcmp(cmnd, rply, 4) != 0) { if (memcmp(cmnd, rply, 4) != 0) {
AsynSrv_errcode = ASYNSRV__BAD_NOT_BCD; /* Message not echoed OK */ AsynSrv_errcode = ASYNSRV__BAD_NOT_BCD; /* Message not echoed OK */
AsynSrv_Close(asyn_info, True); /* Force close TCP/IP connection */ AsynSrv_Close(asyn_info, True); /* Force close TCP/IP connection */
fprintf (stderr, "\nAsynSrv_SendSpecCmnd/recv: command not echoed correctly" fprintf(stderr,
"\nAsynSrv_SendSpecCmnd/recv: command not echoed correctly"
" - link to server force-closed.\n"); " - link to server force-closed.\n");
return False; return False;
} }
if (AsynSrv_errcode == 0) AsynSrv_call_depth--; if (AsynSrv_errcode == 0)
AsynSrv_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_Trace: Send a "TRACE" request to RS232C server. ** AsynSrv_Trace: Send a "TRACE" request to RS232C server.
@ -2047,7 +2174,8 @@
int AsynSrv_Trace( int AsynSrv_Trace(
/* ============= /* =============
*/ struct AsynSrv__info *asyn_info, */ struct AsynSrv__info *asyn_info,
int state) { int state)
{
int status; int status;
char cmnd[8], rply[8]; char cmnd[8], rply[8];
@ -2082,9 +2210,11 @@
*/ */
status = AsynSrv_SendSpecCmnd(asyn_info, cmnd); status = AsynSrv_SendSpecCmnd(asyn_info, cmnd);
if (AsynSrv_errcode == 0) AsynSrv_call_depth--; if (AsynSrv_errcode == 0)
AsynSrv_call_depth--;
return status; return status;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** AsynSrv_Trace_Write: Send a Trace_Write command to ** AsynSrv_Trace_Write: Send a Trace_Write command to
@ -2092,7 +2222,8 @@
*/ */
int AsynSrv_Trace_Write( int AsynSrv_Trace_Write(
/* =================== /* ===================
*/ struct AsynSrv__info *asyn_info) { */ struct AsynSrv__info *asyn_info)
{
int status; int status;
char cmnd[8], rply[8]; char cmnd[8], rply[8];
@ -2119,7 +2250,9 @@
*/ */
status = AsynSrv_SendSpecCmnd(asyn_info, "-005"); status = AsynSrv_SendSpecCmnd(asyn_info, "-005");
if (AsynSrv_errcode == 0) AsynSrv_call_depth--; if (AsynSrv_errcode == 0)
AsynSrv_call_depth--;
return status; return status;
} }
/*-------------------------------------------- End of AsynSrv_Utility.C -----*/ /*-------------------------------------------- End of AsynSrv_Utility.C -----*/

View File

@ -73,7 +73,9 @@
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.
@ -90,7 +92,8 @@
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.
@ -117,8 +120,10 @@
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.
@ -143,8 +148,10 @@
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.
@ -169,8 +176,10 @@
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.
@ -193,7 +202,8 @@
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;
@ -211,8 +221,10 @@
} }
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.
@ -238,15 +250,18 @@
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;
@ -266,8 +281,10 @@
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.
@ -295,27 +312,30 @@
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.
@ -335,16 +355,14 @@
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
@ -389,15 +407,18 @@
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,9 +428,11 @@
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");
@ -441,11 +464,13 @@
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
@ -469,4 +494,5 @@
return (C_gbl_status & 1); return (C_gbl_status & 1);
} }
/*=========================================== End of C_INTERFACES.C ========*/ /*=========================================== End of C_INTERFACES.C ========*/

View File

@ -38,28 +38,24 @@
/* 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)
@ -94,6 +87,7 @@
} }
return 1; return 1;
} }
/* --------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------*/
void DILLU_Close(pDILLU * pData) void DILLU_Close(pDILLU * pData)
{ {
@ -117,6 +111,7 @@
free(self); free(self);
*pData = NULL; *pData = NULL;
} }
/* --------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------*/
int DILLU_Config(pDILLU * pData, int iTmo) int DILLU_Config(pDILLU * pData, int iTmo)
{ {
@ -128,16 +123,15 @@
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)
{ {
@ -146,12 +140,12 @@
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)
{ {
@ -167,19 +161,16 @@
/* 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;
} }
@ -188,6 +179,7 @@
*fVal = fRead; *fVal = fRead;
return 1; return 1;
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
int DILLU_Set(pDILLU * pData, float fVal) int DILLU_Set(pDILLU * pData, float fVal)
{ {
@ -199,35 +191,30 @@
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;
} }
@ -236,15 +223,13 @@
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)
@ -253,16 +238,14 @@
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;
} }
@ -273,42 +256,35 @@
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 {
else
{
strcpy(pCommand, "G2\r"); 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
@ -316,71 +292,59 @@
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.;
} }
@ -390,8 +354,7 @@
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;
} }
@ -405,16 +368,14 @@
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;
} }
@ -425,13 +386,13 @@
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)
{ {
@ -440,8 +401,7 @@
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;

View File

@ -104,5 +104,3 @@
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

@ -18,7 +18,8 @@
#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.
*/ */

File diff suppressed because it is too large Load Diff

View File

@ -24,8 +24,7 @@
#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 */
@ -36,7 +35,8 @@
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,
char *argv[]);
static void EL734Error2Text(char *pBuffer, int errcode); static void EL734Error2Text(char *pBuffer, int errcode);
/*--------------------------------------------------------------------------- /*---------------------------------------------------------------------------
@ -50,6 +50,7 @@ EXTERN void EL734Murder(ClientData 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.
@ -67,34 +68,29 @@ 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;
@ -102,8 +98,7 @@ int EL734(ClientData clientData, Tcl_Interp *interp,
/* 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;
} }
@ -116,9 +111,10 @@ int EL734(ClientData clientData, Tcl_Interp *interp,
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));
@ -127,9 +123,7 @@ int EL734(ClientData clientData, Tcl_Interp *interp,
(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); EL734_ErrInfo(&pErr, &iPort, &iChannel, &iMotor);
EL734Error2Text(pBueffel, iPort); EL734Error2Text(pBueffel, iPort);
Tcl_AppendResult(interp, pBueffel, (char *) NULL); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
@ -137,6 +131,7 @@ int EL734(ClientData clientData, Tcl_Interp *interp,
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
@ -148,17 +143,14 @@ int EL734(ClientData clientData, Tcl_Interp *interp,
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);
@ -166,10 +158,8 @@ int EL734(ClientData clientData, Tcl_Interp *interp,
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);
@ -179,18 +169,14 @@ int EL734(ClientData clientData, Tcl_Interp *interp,
} }
/* 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: ",
@ -202,6 +188,7 @@ int EL734(ClientData clientData, Tcl_Interp *interp,
return TCL_OK; return TCL_OK;
} }
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
fucking standard library missing functionality!!!!!!!!!!!!!!!! fucking standard library missing functionality!!!!!!!!!!!!!!!!
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
@ -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,26 +276,16 @@ 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,
&iFRC,
&iSS,
&fPos);
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;
} } else {
else if (pData->iZeroFlag) {
{
if(pData->iZeroFlag)
{
fPos += pData->fSoftZero; fPos += pData->fSoftZero;
} }
sprintf(pBueffel, " %f", fPos); sprintf(pBueffel, " %f", fPos);
@ -325,31 +295,25 @@ EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp,
} }
/* 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;
@ -360,20 +324,16 @@ 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;
@ -384,20 +344,16 @@ 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;
@ -410,22 +366,17 @@ 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;
} }
@ -437,8 +388,7 @@ EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp,
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);
@ -446,35 +396,28 @@ EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp,
} }
/* 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;
} }
@ -486,8 +429,7 @@ EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp,
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);
@ -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, " ");
strcat(pBueffel, argv[i]); 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 = (struct RS__RplyStruct *)EL734_GetReply( pReply =
&(pData->pData),pReply); (struct RS__RplyStruct *) EL734_GetReply(&(pData->pData),
pReply);
} }
return TCL_OK; return TCL_OK;
} }
@ -538,14 +477,14 @@ EXTERN int EL734Action(ClientData clientData, Tcl_Interp *interp,
"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;

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,7 +38,8 @@ 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.
*/ */

File diff suppressed because it is too large Load Diff

View File

@ -23,12 +23,12 @@
#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,
char *argv[]);
static void EL737Error2Text(char *pBuffer, int errcode); static void EL737Error2Text(char *pBuffer, int errcode);
/*--------------------------------------------------------------------------- /*---------------------------------------------------------------------------
@ -42,6 +42,7 @@ EXTERN void EL737Murder(ClientData 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.
@ -59,26 +60,22 @@ 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;
@ -86,24 +83,20 @@ int CterEL737(ClientData clientData, Tcl_Interp *interp,
/* 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); EL737_ErrInfo(&pErr, &iPort, &iChannel, &iMotor);
EL737Error2Text(pBueffel, iPort); EL737Error2Text(pBueffel, iPort);
Tcl_AppendResult(interp, pBueffel, (char *) NULL); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
@ -111,6 +104,7 @@ int CterEL737(ClientData clientData, Tcl_Interp *interp,
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
@ -144,19 +138,16 @@ 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); EL737_ErrInfo(&pErr, &iC1, &iC2, &iC3);
EL737Error2Text(pBueffel, iC1); EL737Error2Text(pBueffel, iC1);
Tcl_AppendResult(interp, pBueffel, (char *) NULL); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
@ -172,23 +163,18 @@ EXTERN int EL737Action(ClientData clientData, Tcl_Interp *interp,
} }
/* 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); EL737_ErrInfo(&pErr, &iC1, &iC2, &iC3);
EL737Error2Text(pBueffel, iC1); EL737Error2Text(pBueffel, iC1);
Tcl_AppendResult(interp, pBueffel, (char *) NULL); 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 {
else
{
sprintf(pNumBuf, "%d", False); sprintf(pNumBuf, "%d", False);
} }
Tcl_AppendResult(interp, pNumBuf, (char *) NULL); Tcl_AppendResult(interp, pNumBuf, (char *) NULL);
@ -196,34 +182,25 @@ EXTERN int EL737Action(ClientData clientData, Tcl_Interp *interp,
} }
/* 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], Tcl_AppendResult(interp, "Usage: ", argv[0], argv[1],
" timer or monitor val", NULL); " 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], Tcl_AppendResult(interp, "Usage: ", argv[0], argv[1],
" timer or monitor val", NULL); " timer or monitor val", NULL);
return TCL_ERROR; return TCL_ERROR;
@ -231,57 +208,44 @@ EXTERN int EL737Action(ClientData clientData, Tcl_Interp *interp,
/* 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) {
{
iRet = EL737_StartCnt(&(pData->pData),(int)dVal,
&iRS);
}
if(!iRet)
{
EL737_ErrInfo(&pErr, &iC1, &iC2, &iC3); EL737_ErrInfo(&pErr, &iC1, &iC2, &iC3);
EL737Error2Text(pBueffel, iC1); EL737Error2Text(pBueffel, iC1);
Tcl_AppendResult(interp, pBueffel, (char *) NULL); 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);
if(!iRet)
{
EL737_ErrInfo(&pErr, &iC1, &iC2, &iC3); EL737_ErrInfo(&pErr, &iC1, &iC2, &iC3);
EL737Error2Text(pBueffel, iC1); EL737Error2Text(pBueffel, iC1);
Tcl_AppendResult(interp, pBueffel, (char *) NULL); 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); EL737_ErrInfo(&pErr, &iC1, &iC2, &iC3);
EL737Error2Text(pBueffel, iC1); EL737Error2Text(pBueffel, iC1);
Tcl_AppendResult(interp, pBueffel, (char *) NULL); Tcl_AppendResult(interp, pBueffel, (char *) NULL);
@ -294,14 +258,14 @@ EXTERN int EL737Action(ClientData clientData, Tcl_Interp *interp,
" 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;

View File

@ -19,8 +19,10 @@
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 =======*/

View File

@ -489,9 +489,11 @@
int EL755_AddCallStack( int EL755_AddCallStack(
/* ================== /* ==================
*/ struct EL755info *pntr, */ struct EL755info *pntr,
char *name) { char *name)
{
if (EL755_errcode != 0) return False; if (EL755_errcode != 0)
return False;
if (EL755_call_depth < 5) { if (EL755_call_depth < 5) {
StrJoin(EL755_routine[EL755_call_depth], sizeof(EL755_routine[0]), StrJoin(EL755_routine[EL755_call_depth], sizeof(EL755_routine[0]),
@ -499,7 +501,10 @@
EL755_call_depth++; EL755_call_depth++;
} }
if (pntr == NULL) {EL755_errcode = EL755__NOT_OPEN; return False;} if (pntr == NULL) {
EL755_errcode = EL755__NOT_OPEN;
return False;
}
if (pntr->asyn_info.skt <= 0) { if (pntr->asyn_info.skt <= 0) {
memset(pntr->from_host.msg_size, memset(pntr->from_host.msg_size,
@ -510,6 +515,7 @@
} }
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** EL755_Close: Close a connection to an EL755 controller. ** EL755_Close: Close a connection to an EL755 controller.
@ -517,13 +523,15 @@
int EL755_Close( int EL755_Close(
/* =========== /* ===========
*/ void **handle, */ void **handle,
int force_flag) { int force_flag)
{
struct EL755info *info_ptr; struct EL755info *info_ptr;
char buff[4]; char buff[4];
info_ptr = (struct EL755info *) *handle; info_ptr = (struct EL755info *) *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) {
@ -535,6 +543,7 @@
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** EL755_Config: Configure a connection to an EL755 controller. ** EL755_Config: Configure a connection to an EL755 controller.
@ -542,7 +551,8 @@
int EL755_Config( int EL755_Config(
/* ============ /* ============
*/ void **handle, */ void **handle,
...) { ...)
{
struct EL755info *info_ptr; struct EL755info *info_ptr;
char buff[80], rply[256], my_txt[16]; char buff[80], rply[256], my_txt[16];
@ -553,7 +563,8 @@
*/ */
info_ptr = (struct EL755info *) *handle; info_ptr = (struct EL755info *) *handle;
if (!EL755_AddCallStack (info_ptr, "EL755_Config")) return False; if (!EL755_AddCallStack(info_ptr, "EL755_Config"))
return False;
/*---------------------------------------------- /*----------------------------------------------
*/ */
va_start(ap, handle); /* Set up var arg machinery */ va_start(ap, handle); /* Set up var arg machinery */
@ -565,7 +576,8 @@
if (strcmp(my_txt, "msectmo") == 0) { if (strcmp(my_txt, "msectmo") == 0) {
intval = va_arg(ap, int); intval = va_arg(ap, int);
if ((intval < 100) || (intval > 999999)) { if ((intval < 100) || (intval > 999999)) {
EL755_errcode = EL755__BAD_PAR; return False; EL755_errcode = EL755__BAD_PAR;
return False;
} }
sprintf(buff, "%04d", intval / 100); /* Convert to ASCII as .. sprintf(buff, "%04d", intval / 100); /* Convert to ASCII as ..
** .. deci-secs */ ** .. deci-secs */
@ -579,9 +591,12 @@
} }
memcpy(info_ptr->asyn_info.eot, "\0\0\0\0", 4); memcpy(info_ptr->asyn_info.eot, "\0\0\0\0", 4);
switch (txt_ptr[0]) { switch (txt_ptr[0]) {
case '3': info_ptr->asyn_info.eot[3] = txt_ptr[3]; case '3':
case '2': info_ptr->asyn_info.eot[2] = txt_ptr[2]; info_ptr->asyn_info.eot[3] = txt_ptr[3];
case '1': info_ptr->asyn_info.eot[1] = txt_ptr[1]; case '2':
info_ptr->asyn_info.eot[2] = txt_ptr[2];
case '1':
info_ptr->asyn_info.eot[1] = txt_ptr[1];
case '0': case '0':
info_ptr->asyn_info.eot[0] = txt_ptr[0]; info_ptr->asyn_info.eot[0] = txt_ptr[0];
break; break;
@ -606,9 +621,11 @@
txt_ptr = va_arg(ap, char *); /* Get pntr to next parameter ident */ txt_ptr = va_arg(ap, char *); /* Get pntr to next parameter ident */
} }
if (EL755_errcode == 0) EL755_call_depth--; if (EL755_errcode == 0)
EL755_call_depth--;
return True; return True;
} }
/* /*
** ------------------------------------------------------------------------- ** -------------------------------------------------------------------------
** EL755_ErrInfo: Return detailed status from last operation. ** EL755_ErrInfo: Return detailed status from last operation.
@ -616,9 +633,8 @@
void EL755_ErrInfo( void EL755_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, j, k; int i, j, k;
char buff[80]; char buff[80];
@ -642,29 +658,66 @@
*my_errno = EL755_errno; *my_errno = EL755_errno;
*vaxc_errno = EL755_vaxc_errno; *vaxc_errno = EL755_vaxc_errno;
switch (EL755_errcode) { switch (EL755_errcode) {
case EL755__BAD_ASYNSRV: strcpy (buff, "/EL755__BAD_ASYNSRV"); break; case EL755__BAD_ASYNSRV:
strcpy(buff, "/EL755__BAD_ASYNSRV");
break;
case EL755__BAD_CMD: case EL755__BAD_CMD:
case EL755__BAD_DEV: strcpy (buff, "/EL755__BAD_DEV"); break; case EL755__BAD_DEV:
case EL755__BAD_ILLG: strcpy (buff, "/EL755__BAD_ILLG"); break; strcpy(buff, "/EL755__BAD_DEV");
case EL755__BAD_MALLOC: strcpy (buff, "/EL755__BAD_MALLOC"); break; break;
case EL755__BAD_OFL: strcpy (buff, "/EL755__BAD_OFL"); break; case EL755__BAD_ILLG:
case EL755__BAD_PAR: strcpy (buff, "/EL755__BAD_PAR"); break; strcpy(buff, "/EL755__BAD_ILLG");
case EL755__BAD_SOCKET: strcpy (buff, "/EL755__BAD_SOCKET"); break; break;
case EL755__BAD_TMO: strcpy (buff, "/EL755__BAD_TMO"); break; case EL755__BAD_MALLOC:
case EL755__FORCED_CLOSED: strcpy (buff, "/EL755__FORCED_CLOSED"); break; strcpy(buff, "/EL755__BAD_MALLOC");
case EL755__NOT_OPEN: strcpy (buff, "/EL755__NOT_OPEN"); break; break;
case EL755__NO_SOCKET: strcpy (buff, "/EL755__NO_SOCKET"); break; case EL755__BAD_OFL:
case EL755__OFFLINE: strcpy (buff, "/EL755__OFFLINE"); break; strcpy(buff, "/EL755__BAD_OFL");
case EL755__OUT_OF_RANGE: strcpy (buff, "/EL755__OUT_OF_RANGE"); break; break;
case EL755__OVFLOW: strcpy (buff, "/EL755__OVFLOW"); break; case EL755__BAD_PAR:
case EL755__TOO_LARGE: strcpy (buff, "/EL755__TOO_LARGE"); break; strcpy(buff, "/EL755__BAD_PAR");
case EL755__TOO_MANY: strcpy (buff, "/EL755__TOO_MANY"); break; break;
case EL755__TURNED_OFF: strcpy (buff, "/EL755__TURNED_OFF"); break; case EL755__BAD_SOCKET:
default: sprintf (buff, "/EL755__unknown_err_code: %d", EL755_errcode); strcpy(buff, "/EL755__BAD_SOCKET");
break;
case EL755__BAD_TMO:
strcpy(buff, "/EL755__BAD_TMO");
break;
case EL755__FORCED_CLOSED:
strcpy(buff, "/EL755__FORCED_CLOSED");
break;
case EL755__NOT_OPEN:
strcpy(buff, "/EL755__NOT_OPEN");
break;
case EL755__NO_SOCKET:
strcpy(buff, "/EL755__NO_SOCKET");
break;
case EL755__OFFLINE:
strcpy(buff, "/EL755__OFFLINE");
break;
case EL755__OUT_OF_RANGE:
strcpy(buff, "/EL755__OUT_OF_RANGE");
break;
case EL755__OVFLOW:
strcpy(buff, "/EL755__OVFLOW");
break;
case EL755__TOO_LARGE:
strcpy(buff, "/EL755__TOO_LARGE");
break;
case EL755__TOO_MANY:
strcpy(buff, "/EL755__TOO_MANY");
break;
case EL755__TURNED_OFF:
strcpy(buff, "/EL755__TURNED_OFF");
break;
default:
sprintf(buff, "/EL755__unknown_err_code: %d", EL755_errcode);
} }
StrJoin (EL755_routine[0], sizeof(EL755_routine), EL755_routine[0], buff); StrJoin(EL755_routine[0], sizeof(EL755_routine), EL755_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(EL755_routine[0], "/"); strcat(EL755_routine[0], "/");
StrJoin(EL755_routine[0], sizeof(EL755_routine), StrJoin(EL755_routine[0], sizeof(EL755_routine),
@ -674,6 +727,7 @@
EL755_call_depth = 0; EL755_call_depth = 0;
EL755_errcode = 0; EL755_errcode = 0;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** EL755_GetCurrents: Get currents from EL755. ** EL755_GetCurrents: Get currents from EL755.
@ -681,8 +735,8 @@
int EL755_GetCurrents( int EL755_GetCurrents(
/* ================= /* =================
*/ void **handle, */ void **handle,
float *soll, float *soll, float *ist)
float *ist) { {
int iret; int iret;
char cmnd[32]; char cmnd[32];
@ -692,18 +746,22 @@
*soll = *ist = 0.0; *soll = *ist = 0.0;
info_ptr = (struct EL755info *) *handle; info_ptr = (struct EL755info *) *handle;
if (!EL755_AddCallStack (info_ptr, "EL755_GetCurrents")) return False; if (!EL755_AddCallStack(info_ptr, "EL755_GetCurrents"))
return False;
/*---------------------------------------------- /*----------------------------------------------
** Send I command to get EL755 currents. Repeat until ** Send I command to get EL755 currents. Repeat until
** first value is same 2 times consecutively. ** first value is same 2 times consecutively.
*/ */
sprintf(cmnd, "I %d\r", info_ptr->index); sprintf(cmnd, "I %d\r", info_ptr->index);
iret = EL755_SendTillTwoVals(handle, cmnd, soll, ist); iret = EL755_SendTillTwoVals(handle, cmnd, soll, ist);
if (!iret) return False; if (!iret)
return False;
if (EL755_errcode == 0) EL755_call_depth--; if (EL755_errcode == 0)
EL755_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** EL755_Open: Open a connection to an EL755 controller. ** EL755_Open: Open a connection to an EL755 controller.
@ -711,10 +769,8 @@
int EL755_Open( int EL755_Open(
/* ========== /* ==========
*/ void **handle, */ void **handle,
char *host, char *host, int port, int chan, int indx)
int port, {
int chan,
int indx) {
int status, i; int status, i;
char tmo_save[4]; char tmo_save[4];
@ -750,19 +806,17 @@
if (!status) { if (!status) {
EL755_errcode = EL755__BAD_SOCKET; EL755_errcode = EL755__BAD_SOCKET;
GetErrno(&EL755_errno, &EL755_vaxc_errno); /* Save errno info */ GetErrno(&EL755_errno, &EL755_vaxc_errno); /* Save errno info */
EL755_ErrorLog ("EL755_Open/AsynSrv_Open", "Failed to make connection."); EL755_ErrorLog("EL755_Open/AsynSrv_Open",
"Failed to make connection.");
free(my_handle); free(my_handle);
return False; return False;
} }
memcpy(tmo_save, my_handle->asyn_info.tmo, 4); memcpy(tmo_save, my_handle->asyn_info.tmo, 4);
status = EL755_Config ((void *) &my_handle, status = EL755_Config((void *) &my_handle, "msecTmo", 100, /* Set a short time-out initially since
"msecTmo", 100, /* Set a short time-out initially since
** there should be no reason for the RMT, ** there should be no reason for the RMT,
** ECHO or ID commands to take very long. ** ECHO or ID commands to take very long.
*/ */
"eot", "1\r", "eot", "1\r", "index", indx, NULL);
"index", indx,
NULL);
if (!status) { if (!status) {
/* Some error occurred in EL755_Config - should be impossible! /* Some error occurred in EL755_Config - should be impossible!
*/ */
@ -776,19 +830,14 @@
** input buffer causing the command to be corrupted. The response is ** input buffer causing the command to be corrupted. The response is
** ignored for this reason. ** ignored for this reason.
*/ */
status = AsynSrv_SendCmnds (&my_handle->asyn_info, status = AsynSrv_SendCmnds(&my_handle->asyn_info, &my_handle->to_host, &my_handle->from_host, "RMT 1\r", /* Try to put EL755 on-line */
&my_handle->to_host, &my_handle->from_host,
"RMT 1\r", /* Try to put EL755 on-line */
"RMT 1\r", /* Try again in case type-ahead chars corrupted .. "RMT 1\r", /* Try again in case type-ahead chars corrupted ..
** .. the first attempt. */ ** .. the first attempt. */
"ECHO 0\r", /* And turn off echoing */ "ECHO 0\r", /* And turn off echoing */
NULL); NULL);
status = AsynSrv_SendCmnds(&my_handle->asyn_info, status = AsynSrv_SendCmnds(&my_handle->asyn_info,
&my_handle->to_host, &my_handle->from_host, &my_handle->to_host, &my_handle->from_host,
"RMT 1\r", "RMT 1\r", "ECHO 0\r", "ID\r", NULL);
"ECHO 0\r",
"ID\r",
NULL);
if (!status) { if (!status) {
/* Some error occurred in AsynSrv_SendCmnds. /* Some error occurred in AsynSrv_SendCmnds.
*/ */
@ -842,16 +891,19 @@
** back to the caller as a handle. ** back to the caller as a handle.
*/ */
*handle = my_handle; *handle = my_handle;
if (EL755_errcode == 0) EL755_call_depth--; if (EL755_errcode == 0)
EL755_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** EL755_PutOffline: put the EL755 off-line ** EL755_PutOffline: put the EL755 off-line
*/ */
int EL755_PutOffline( int EL755_PutOffline(
/* ================ /* ================
*/ void **handle) { */ void **handle)
{
int status; int status;
struct EL755info *info_ptr; struct EL755info *info_ptr;
@ -861,7 +913,8 @@
*/ */
info_ptr = (struct EL755info *) *handle; info_ptr = (struct EL755info *) *handle;
if (!EL755_AddCallStack (info_ptr, "EL755_PutOffline")) return False; if (!EL755_AddCallStack(info_ptr, "EL755_PutOffline"))
return False;
/*---------------------------------------------- /*----------------------------------------------
** The problem which this routine has is that the EL755 ** The problem which this routine has is that the EL755
** may already be off-line. The following is, therefore, ** may already be off-line. The following is, therefore,
@ -870,10 +923,7 @@
status = AsynSrv_SendCmnds(&info_ptr->asyn_info, status = AsynSrv_SendCmnds(&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host, &info_ptr->to_host, &info_ptr->from_host,
"RMT 1\r", "RMT 1\r",
"RMT 1\r", "RMT 1\r", "ECHO 1\r", "RMT 0\r", NULL);
"ECHO 1\r",
"RMT 0\r",
NULL);
if (!status) { if (!status) {
EL755_errcode = EL755__BAD_ASYNSRV; EL755_errcode = EL755__BAD_ASYNSRV;
return False; return False;
@ -887,16 +937,18 @@
return False; return False;
} }
rply_ptr0 = AsynSrv_GetReply ( rply_ptr0 =
&info_ptr->asyn_info, &info_ptr->from_host, NULL); AsynSrv_GetReply(&info_ptr->asyn_info, &info_ptr->from_host, NULL);
rply_ptr1 = AsynSrv_GetReply ( rply_ptr1 =
&info_ptr->asyn_info, &info_ptr->from_host, rply_ptr0); AsynSrv_GetReply(&info_ptr->asyn_info, &info_ptr->from_host,
rply_ptr0);
if ((rply_ptr0 == NULL) || (rply_ptr1 == NULL)) { if ((rply_ptr0 == NULL) || (rply_ptr1 == NULL)) {
EL755_AddCallStack(info_ptr, "NULL response"); EL755_AddCallStack(info_ptr, "NULL response");
EL755_errcode = EL755__BAD_ILLG; return False;} EL755_errcode = EL755__BAD_ILLG;
return False;
}
if ((strcmp (rply_ptr0, "RMT") == 0) && if ((strcmp(rply_ptr0, "RMT") == 0) && (strcmp(rply_ptr1, "\n0") == 0)) {
(strcmp (rply_ptr1, "\n0") == 0)) {
EL755_call_depth--; EL755_call_depth--;
return True; return True;
} }
@ -924,6 +976,7 @@
} }
return False; return False;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** EL755_PutOnline: put the EL755 on-line ** EL755_PutOnline: put the EL755 on-line
@ -931,7 +984,8 @@
int EL755_PutOnline( int EL755_PutOnline(
/* =============== /* ===============
*/ void **handle, */ void **handle,
int echo) { int echo)
{
int status, my_echo; int status, my_echo;
struct EL755info *info_ptr; struct EL755info *info_ptr;
@ -941,11 +995,13 @@
*/ */
info_ptr = (struct EL755info *) *handle; info_ptr = (struct EL755info *) *handle;
if (!EL755_AddCallStack (info_ptr, "EL755_PutOnline")) return False; if (!EL755_AddCallStack(info_ptr, "EL755_PutOnline"))
return False;
/*---------------------------------------------- /*----------------------------------------------
*/ */
if ((echo != 0) && (echo != 1)) { if ((echo != 0) && (echo != 1)) {
EL755_errcode = EL755__BAD_PAR; return False; EL755_errcode = EL755__BAD_PAR;
return False;
} }
/*---------------------------------------------- /*----------------------------------------------
** The problem which this routine has is that the state ** The problem which this routine has is that the state
@ -955,10 +1011,7 @@
sprintf(cmnd0, "ECHO %d\r", echo); sprintf(cmnd0, "ECHO %d\r", echo);
status = AsynSrv_SendCmnds(&info_ptr->asyn_info, status = AsynSrv_SendCmnds(&info_ptr->asyn_info,
&info_ptr->to_host, &info_ptr->from_host, &info_ptr->to_host, &info_ptr->from_host,
"RMT 1\r", "RMT 1\r", "RMT 1\r", cmnd0, NULL);
"RMT 1\r",
cmnd0,
NULL);
if (!status) { if (!status) {
EL755_errcode = EL755__BAD_ASYNSRV; EL755_errcode = EL755__BAD_ASYNSRV;
return False; return False;
@ -972,11 +1025,13 @@
return False; return False;
} }
rply_ptr = AsynSrv_GetReply ( rply_ptr =
&info_ptr->asyn_info, &info_ptr->from_host, NULL); AsynSrv_GetReply(&info_ptr->asyn_info, &info_ptr->from_host, NULL);
if (rply_ptr == NULL) { if (rply_ptr == NULL) {
EL755_AddCallStack(info_ptr, "NULL response"); EL755_AddCallStack(info_ptr, "NULL response");
EL755_errcode = EL755__BAD_ILLG; return False;} EL755_errcode = EL755__BAD_ILLG;
return False;
}
if ((echo == 1) && (strcmp(rply_ptr, "ECHO") == 0)) { if ((echo == 1) && (strcmp(rply_ptr, "ECHO") == 0)) {
EL755_call_depth--; EL755_call_depth--;
@ -1010,6 +1065,7 @@
} }
return False; return False;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** EL755_SendTillSameStr: Repeat a command until we get the same ** EL755_SendTillSameStr: Repeat a command until we get the same
@ -1021,9 +1077,8 @@
int EL755_SendTillSameStr( int EL755_SendTillSameStr(
/* ===================== /* =====================
*/ void **handle, */ void **handle,
char *cmnd, char *cmnd, char *rply, int rply_len)
char *rply, {
int rply_len) {
int iret, i, j, n_ovfl; int iret, i, j, n_ovfl;
struct EL755info *info_ptr; struct EL755info *info_ptr;
@ -1034,7 +1089,8 @@
*/ */
info_ptr = (struct EL755info *) *handle; info_ptr = (struct EL755info *) *handle;
if (!EL755_AddCallStack (info_ptr, "EL755_SendTillSameStr")) return False; if (!EL755_AddCallStack(info_ptr, "EL755_SendTillSameStr"))
return False;
/*---------------------------------------------- /*----------------------------------------------
** Send command. Do it in a ** Send command. Do it in a
** loop until we get the same response twice to guard ** loop until we get the same response twice to guard
@ -1048,20 +1104,32 @@
&info_ptr->to_host, &info_ptr->from_host, &info_ptr->to_host, &info_ptr->from_host,
cmnd, NULL); cmnd, NULL);
if (!iret) { if (!iret) {
EL755_errcode = EL755__BAD_ASYNSRV; return False;} EL755_errcode = EL755__BAD_ASYNSRV;
rply_ptr = AsynSrv_GetReply ( return False;
&info_ptr->asyn_info, &info_ptr->from_host, NULL); }
rply_ptr =
AsynSrv_GetReply(&info_ptr->asyn_info, &info_ptr->from_host, NULL);
if (rply_ptr == NULL) { if (rply_ptr == NULL) {
EL755_AddCallStack(info_ptr, "NULL response"); EL755_AddCallStack(info_ptr, "NULL response");
EL755_errcode = EL755__BAD_ILLG; return False;} EL755_errcode = EL755__BAD_ILLG;
return False;
}
if (strncmp(rply_ptr, "?TMO", 4) == 0) { if (strncmp(rply_ptr, "?TMO", 4) == 0) {
EL755_errcode = EL755__BAD_TMO; return False;} EL755_errcode = EL755__BAD_TMO;
return False;
}
if (strcmp(rply_ptr, "?OF") == 0) { if (strcmp(rply_ptr, "?OF") == 0) {
EL755_errcode = EL755__OFFLINE; return False;} EL755_errcode = EL755__OFFLINE;
return False;
}
if (strcmp(rply_ptr, "?OFL") == 0) { if (strcmp(rply_ptr, "?OFL") == 0) {
EL755_errcode = EL755__BAD_OFL; return False;} EL755_errcode = EL755__BAD_OFL;
return False;
}
if (strcmp(rply_ptr, "?syntax failure") == 0) { if (strcmp(rply_ptr, "?syntax failure") == 0) {
EL755_errcode = EL755__BAD_CMD; return False;} EL755_errcode = EL755__BAD_CMD;
return False;
}
if (strcmp(rply_ptr, "?OV") == 0) { /* Check for overflow. This seems if (strcmp(rply_ptr, "?OV") == 0) { /* Check for overflow. This seems
** to be an EL755 problem which ** to be an EL755 problem which
** needs fixing. In the meantime, ** needs fixing. In the meantime,
@ -1072,10 +1140,14 @@
MakePrintable(buff, sizeof(buff), buff); MakePrintable(buff, sizeof(buff), buff);
EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff); EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff);
n_ovfl++; n_ovfl++;
if (n_ovfl > 10) {EL755_errcode = EL755__TOO_MANY; return False;} if (n_ovfl > 10) {
EL755_errcode = EL755__TOO_MANY;
return False;
}
} else { } else {
n_ovfl = 0; n_ovfl = 0;
if (strncmp (rply, rply_ptr, rply_len) == 0) break; if (strncmp(rply, rply_ptr, rply_len) == 0)
break;
StrJoin(rply, rply_len, rply_ptr, ""); StrJoin(rply, rply_len, rply_ptr, "");
MakePrintable(replies[i], sizeof(replies[0]), rply_ptr); MakePrintable(replies[i], sizeof(replies[0]), rply_ptr);
i++; i++;
@ -1090,13 +1162,16 @@
(i - 1), cmnd); (i - 1), cmnd);
MakePrintable(buff, sizeof(buff), buff); MakePrintable(buff, sizeof(buff), buff);
EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff); EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff);
for (j = 0; j < i; j++) fprintf (stderr, " %d: \"%s\"\n", j, replies[j]); for (j = 0; j < i; j++)
fprintf(stderr, " %d: \"%s\"\n", j, replies[j]);
} }
if (EL755_errcode != 0) return False; if (EL755_errcode != 0)
return False;
EL755_call_depth--; EL755_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** EL755_SendTillSameVal: Repeat a command until we get the same ** EL755_SendTillSameVal: Repeat a command until we get the same
@ -1108,8 +1183,8 @@
int EL755_SendTillSameVal( int EL755_SendTillSameVal(
/* ===================== /* =====================
*/ void **handle, */ void **handle,
char *cmnd, char *cmnd, float *val)
float *val) { {
int iret, i, n_ovfl, cnt; int iret, i, n_ovfl, cnt;
struct EL755info *info_ptr; struct EL755info *info_ptr;
@ -1120,7 +1195,8 @@
*/ */
info_ptr = (struct EL755info *) *handle; info_ptr = (struct EL755info *) *handle;
if (!EL755_AddCallStack (info_ptr, "EL755_SendTillSameVal")) return False; if (!EL755_AddCallStack(info_ptr, "EL755_SendTillSameVal"))
return False;
/*---------------------------------------------- /*----------------------------------------------
** Send command. Do it in a ** Send command. Do it in a
** loop until we get the same response twice to guard ** loop until we get the same response twice to guard
@ -1135,13 +1211,17 @@
&info_ptr->to_host, &info_ptr->from_host, &info_ptr->to_host, &info_ptr->from_host,
cmnd, NULL); cmnd, NULL);
if (!iret) { if (!iret) {
EL755_errcode = EL755__BAD_ASYNSRV; return False;} EL755_errcode = EL755__BAD_ASYNSRV;
return False;
}
rply_ptr = AsynSrv_GetReply ( rply_ptr =
&info_ptr->asyn_info, &info_ptr->from_host, NULL); AsynSrv_GetReply(&info_ptr->asyn_info, &info_ptr->from_host, NULL);
if (rply_ptr == NULL) { if (rply_ptr == NULL) {
EL755_AddCallStack(info_ptr, "NULL response"); EL755_AddCallStack(info_ptr, "NULL response");
EL755_errcode = EL755__BAD_ILLG; return False;} EL755_errcode = EL755__BAD_ILLG;
return False;
}
if (strcmp(rply_ptr, "?OV") == 0) { /* Check for overflow. This seems if (strcmp(rply_ptr, "?OV") == 0) { /* Check for overflow. This seems
** to be an EL755 problem which ** to be an EL755 problem which
@ -1153,34 +1233,48 @@
MakePrintable(buff, sizeof(buff), buff); MakePrintable(buff, sizeof(buff), buff);
EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff); EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff);
n_ovfl++; n_ovfl++;
if (n_ovfl > 10) {EL755_errcode = EL755__TOO_MANY; return False;} if (n_ovfl > 10) {
EL755_errcode = EL755__TOO_MANY;
return False;
}
} else { } else {
n_ovfl = 0; n_ovfl = 0;
if (strcmp(rply_ptr, "?OF") == 0) { if (strcmp(rply_ptr, "?OF") == 0) {
EL755_errcode = EL755__OFFLINE; return False;} EL755_errcode = EL755__OFFLINE;
return False;
}
if (strcmp(rply_ptr, "?OFL") == 0) { if (strcmp(rply_ptr, "?OFL") == 0) {
EL755_errcode = EL755__BAD_OFL; return False;} EL755_errcode = EL755__BAD_OFL;
return False;
}
if (strcmp(rply_ptr, "?syntax failure") == 0) { if (strcmp(rply_ptr, "?syntax failure") == 0) {
EL755_errcode = EL755__BAD_CMD; return False;} EL755_errcode = EL755__BAD_CMD;
return False;
}
if (strcmp(rply_ptr, "?power-supply OFF") == 0) { /* If off, return 0 */ if (strcmp(rply_ptr, "?power-supply OFF") == 0) { /* If off, return 0 */
*val = 0.0; *val = 0.0;
EL755_call_depth--; return True; EL755_call_depth--;
return True;
} else { } else {
tok = strtok(rply_ptr, " "); tok = strtok(rply_ptr, " ");
if ((tok == NULL) || if ((tok == NULL) ||
(sscanf(tok, "%f%n", val, &cnt) != 1) || (sscanf(tok, "%f%n", val, &cnt) != 1) ||
(cnt != strlen(tok))) { (cnt != strlen(tok))) {
EL755_AddCallStack(info_ptr, rply_ptr); EL755_AddCallStack(info_ptr, rply_ptr);
EL755_errcode = EL755__BAD_ILLG; return False; EL755_errcode = EL755__BAD_ILLG;
return False;
} }
if (*val == last_val) break; if (*val == last_val)
break;
last_val = *val; last_val = *val;
} }
i++; i++;
} }
} }
if (last_val != *val) { if (last_val != *val) {
EL755_errcode = EL755__TOO_MANY; return False;} EL755_errcode = EL755__TOO_MANY;
return False;
}
if (i > 1) { if (i > 1) {
sprintf(buff, "Warning -- %d retries needed for Cmnd = \"%s\".", sprintf(buff, "Warning -- %d retries needed for Cmnd = \"%s\".",
@ -1189,10 +1283,12 @@
EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff); EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff);
} }
if (EL755_errcode != 0) return False; if (EL755_errcode != 0)
return False;
EL755_call_depth--; EL755_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** EL755_SendTillTwoVals: Repeat a command until we get 2 fl.pt. ** EL755_SendTillTwoVals: Repeat a command until we get 2 fl.pt.
@ -1208,9 +1304,8 @@
int EL755_SendTillTwoVals( int EL755_SendTillTwoVals(
/* ===================== /* =====================
*/ void **handle, */ void **handle,
char *cmnd, char *cmnd, float *val0, float *val1)
float *val0, {
float *val1) {
int iret, i, n_ovfl, cnt0, cnt1; int iret, i, n_ovfl, cnt0, cnt1;
struct EL755info *info_ptr; struct EL755info *info_ptr;
@ -1221,7 +1316,8 @@
*/ */
info_ptr = (struct EL755info *) *handle; info_ptr = (struct EL755info *) *handle;
if (!EL755_AddCallStack (info_ptr, "EL755_SendTillTwoVals")) return False; if (!EL755_AddCallStack(info_ptr, "EL755_SendTillTwoVals"))
return False;
/*---------------------------------------------- /*----------------------------------------------
** Send command. Do it in a ** Send command. Do it in a
** loop until we get the same response twice to guard ** loop until we get the same response twice to guard
@ -1236,13 +1332,17 @@
&info_ptr->to_host, &info_ptr->from_host, &info_ptr->to_host, &info_ptr->from_host,
cmnd, NULL); cmnd, NULL);
if (!iret) { if (!iret) {
EL755_errcode = EL755__BAD_ASYNSRV; return False;} EL755_errcode = EL755__BAD_ASYNSRV;
return False;
}
rply_ptr = AsynSrv_GetReply ( rply_ptr =
&info_ptr->asyn_info, &info_ptr->from_host, NULL); AsynSrv_GetReply(&info_ptr->asyn_info, &info_ptr->from_host, NULL);
if (rply_ptr == NULL) { if (rply_ptr == NULL) {
EL755_AddCallStack(info_ptr, "NULL response"); EL755_AddCallStack(info_ptr, "NULL response");
EL755_errcode = EL755__BAD_ILLG; return False;} EL755_errcode = EL755__BAD_ILLG;
return False;
}
if (strcmp(rply_ptr, "?OV") == 0) { /* Check for overflow. This seems if (strcmp(rply_ptr, "?OV") == 0) { /* Check for overflow. This seems
** to be an EL755 problem which ** to be an EL755 problem which
@ -1254,19 +1354,29 @@
MakePrintable(buff, sizeof(buff), buff); MakePrintable(buff, sizeof(buff), buff);
EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff); EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff);
n_ovfl++; n_ovfl++;
if (n_ovfl > 10) {EL755_errcode = EL755__TOO_MANY; return False;} if (n_ovfl > 10) {
EL755_errcode = EL755__TOO_MANY;
return False;
}
} else { } else {
n_ovfl = 0; n_ovfl = 0;
if (strcmp(rply_ptr, "?OF") == 0) { if (strcmp(rply_ptr, "?OF") == 0) {
EL755_errcode = EL755__OFFLINE; return False;} EL755_errcode = EL755__OFFLINE;
return False;
}
if (strcmp(rply_ptr, "?OFL") == 0) { if (strcmp(rply_ptr, "?OFL") == 0) {
EL755_errcode = EL755__BAD_OFL; return False;} EL755_errcode = EL755__BAD_OFL;
return False;
}
if (strcmp(rply_ptr, "?syntax failure") == 0) { if (strcmp(rply_ptr, "?syntax failure") == 0) {
EL755_errcode = EL755__BAD_CMD; return False;} EL755_errcode = EL755__BAD_CMD;
return False;
}
if (strcmp(rply_ptr, "?power-supply OFF") == 0) { /* If off, return 0 */ if (strcmp(rply_ptr, "?power-supply OFF") == 0) { /* If off, return 0 */
*val0 = 0.0; *val0 = 0.0;
*val1 = 0.0; *val1 = 0.0;
EL755_call_depth--; return True; EL755_call_depth--;
return True;
} else { } else {
tok0 = strtok(rply_ptr, " "); tok0 = strtok(rply_ptr, " ");
tok1 = strtok(NULL, " "); tok1 = strtok(NULL, " ");
@ -1274,19 +1384,22 @@
(tok1 == NULL) || (tok1 == NULL) ||
(sscanf(tok0, "%f%n", val0, &cnt0) != 1) || (sscanf(tok0, "%f%n", val0, &cnt0) != 1) ||
(sscanf(tok1, "%f%n", val1, &cnt1) != 1) || (sscanf(tok1, "%f%n", val1, &cnt1) != 1) ||
(cnt0 != strlen (tok0)) || (cnt0 != strlen(tok0)) || (cnt1 != strlen(tok1))) {
(cnt1 != strlen (tok1))) {
EL755_AddCallStack(info_ptr, rply_ptr); EL755_AddCallStack(info_ptr, rply_ptr);
EL755_errcode = EL755__BAD_ILLG; return False; EL755_errcode = EL755__BAD_ILLG;
return False;
} }
if (*val0 == last_val) break; if (*val0 == last_val)
break;
last_val = *val0; last_val = *val0;
} }
i++; i++;
} }
} }
if (last_val != *val0) { if (last_val != *val0) {
EL755_errcode = EL755__TOO_MANY; return False;} EL755_errcode = EL755__TOO_MANY;
return False;
}
if (i > 1) { if (i > 1) {
sprintf(buff, "Warning -- %d retries needed for Cmnd = \"%s\".", sprintf(buff, "Warning -- %d retries needed for Cmnd = \"%s\".",
@ -1295,10 +1408,12 @@
EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff); EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff);
} }
if (EL755_errcode != 0) return False; if (EL755_errcode != 0)
return False;
EL755_call_depth--; EL755_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** EL755_SetCurrent: Sets current via EL755. ** EL755_SetCurrent: Sets current via EL755.
@ -1306,7 +1421,8 @@
int EL755_SetCurrent( int EL755_SetCurrent(
/* ================ /* ================
*/ void **handle, */ void **handle,
float soll) { float soll)
{
int i, iret; int i, iret;
float my_soll, my_ist; float my_soll, my_ist;
@ -1316,7 +1432,8 @@
*/ */
info_ptr = (struct EL755info *) *handle; info_ptr = (struct EL755info *) *handle;
if (!EL755_AddCallStack (info_ptr, "EL755_SetCurrent")) return False; if (!EL755_AddCallStack(info_ptr, "EL755_SetCurrent"))
return False;
/*---------------------------------------------- /*----------------------------------------------
** Send I command to set EL755 current and I command ** Send I command to set EL755 current and I command
** to read back the set value. ** to read back the set value.
@ -1329,22 +1446,28 @@
while ((i < 6) && (fabs(soll - my_soll) > 0.01)) { while ((i < 6) && (fabs(soll - my_soll) > 0.01)) {
iret = EL755_SendTillSameStr(handle, cmnd, buff, sizeof(buff)); iret = EL755_SendTillSameStr(handle, cmnd, buff, sizeof(buff));
if (!iret) return False; if (!iret)
return False;
if (buff[0] == NIL) { /* We should get a null response */ if (buff[0] == NIL) { /* We should get a null response */
iret = EL755_SendTillSameVal(handle, cmnd0, &my_soll); iret = EL755_SendTillSameVal(handle, cmnd0, &my_soll);
if (!iret) return False; if (!iret)
return False;
} else if (strcmp(buff, "?value out of range") == 0) { } else if (strcmp(buff, "?value out of range") == 0) {
EL755_errcode = EL755__OUT_OF_RANGE; return False; EL755_errcode = EL755__OUT_OF_RANGE;
return False;
} else if (strcmp(buff, "?current limitation") == 0) { } else if (strcmp(buff, "?current limitation") == 0) {
EL755_errcode = EL755__TOO_LARGE; return False; EL755_errcode = EL755__TOO_LARGE;
return False;
} else if (strcmp(buff, "?power-supply OFF") == 0) { } else if (strcmp(buff, "?power-supply OFF") == 0) {
if (soll == 0.0) { /* Suppress error if trying to set zero and if (soll == 0.0) { /* Suppress error if trying to set zero and
.. power supply is off! */ .. power supply is off! */
if (EL755_errcode != 0) return False; if (EL755_errcode != 0)
return False;
EL755_call_depth--; EL755_call_depth--;
return True; return True;
} else { } else {
EL755_errcode = EL755__TURNED_OFF; return False; EL755_errcode = EL755__TURNED_OFF;
return False;
} }
} else { } else {
sprintf(buff1, "Cmnd=\"%s\" Rply=\"%.10s\"", cmnd, buff); sprintf(buff1, "Cmnd=\"%s\" Rply=\"%.10s\"", cmnd, buff);
@ -1357,7 +1480,9 @@
} }
if (fabs(soll - my_soll) > 0.01) { if (fabs(soll - my_soll) > 0.01) {
EL755_errcode = EL755__TOO_MANY; return False;} EL755_errcode = EL755__TOO_MANY;
return False;
}
if (i > 1) { if (i > 1) {
sprintf(buff, "Warning -- %d retries needed for Cmnd = \"%s\".", sprintf(buff, "Warning -- %d retries needed for Cmnd = \"%s\".",
@ -1365,10 +1490,12 @@
MakePrintable(buff, sizeof(buff), buff); MakePrintable(buff, sizeof(buff), buff);
EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff); EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff);
} }
if (EL755_errcode != 0) return False; if (EL755_errcode != 0)
return False;
EL755_call_depth--; EL755_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** EL755_Send sends a command to the EL755 and gets a reply ** EL755_Send sends a command to the EL755 and gets a reply
@ -1378,9 +1505,8 @@
int EL755_Send( int EL755_Send(
/* ===================== /* =====================
*/ void **handle, */ void **handle,
char *cmnd, char *cmnd, char *rply, int rply_len)
char *rply, {
int rply_len) {
int iret, i, j, n_ovfl; int iret, i, j, n_ovfl;
struct EL755info *info_ptr; struct EL755info *info_ptr;
@ -1391,7 +1517,8 @@
*/ */
info_ptr = (struct EL755info *) *handle; info_ptr = (struct EL755info *) *handle;
if (!EL755_AddCallStack (info_ptr, "EL755_SendTillSameStr")) return False; if (!EL755_AddCallStack(info_ptr, "EL755_SendTillSameStr"))
return False;
/*---------------------------------------------- /*----------------------------------------------
** Send command. ** Send command.
*/ */
@ -1403,20 +1530,32 @@
&info_ptr->to_host, &info_ptr->from_host, &info_ptr->to_host, &info_ptr->from_host,
cmnd, NULL); cmnd, NULL);
if (!iret) { if (!iret) {
EL755_errcode = EL755__BAD_ASYNSRV; return False;} EL755_errcode = EL755__BAD_ASYNSRV;
rply_ptr = AsynSrv_GetReply ( return False;
&info_ptr->asyn_info, &info_ptr->from_host, NULL); }
rply_ptr =
AsynSrv_GetReply(&info_ptr->asyn_info, &info_ptr->from_host, NULL);
if (rply_ptr == NULL) { if (rply_ptr == NULL) {
EL755_AddCallStack(info_ptr, "NULL response"); EL755_AddCallStack(info_ptr, "NULL response");
EL755_errcode = EL755__BAD_ILLG; return False;} EL755_errcode = EL755__BAD_ILLG;
return False;
}
if (strncmp(rply_ptr, "?TMO", 4) == 0) { if (strncmp(rply_ptr, "?TMO", 4) == 0) {
EL755_errcode = EL755__BAD_TMO; return False;} EL755_errcode = EL755__BAD_TMO;
return False;
}
if (strcmp(rply_ptr, "?OF") == 0) { if (strcmp(rply_ptr, "?OF") == 0) {
EL755_errcode = EL755__OFFLINE; return False;} EL755_errcode = EL755__OFFLINE;
return False;
}
if (strcmp(rply_ptr, "?OFL") == 0) { if (strcmp(rply_ptr, "?OFL") == 0) {
EL755_errcode = EL755__BAD_OFL; return False;} EL755_errcode = EL755__BAD_OFL;
return False;
}
if (strcmp(rply_ptr, "?syntax failure") == 0) { if (strcmp(rply_ptr, "?syntax failure") == 0) {
EL755_errcode = EL755__BAD_CMD; return False;} EL755_errcode = EL755__BAD_CMD;
return False;
}
if (strcmp(rply_ptr, "?OV") == 0) { /* Check for overflow. This seems if (strcmp(rply_ptr, "?OV") == 0) { /* Check for overflow. This seems
** to be an EL755 problem which ** to be an EL755 problem which
** needs fixing. In the meantime, ** needs fixing. In the meantime,
@ -1427,19 +1566,23 @@
MakePrintable(buff, sizeof(buff), buff); MakePrintable(buff, sizeof(buff), buff);
EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff); EL755_ErrorLog(EL755_routine[EL755_call_depth - 1], buff);
n_ovfl++; n_ovfl++;
if (n_ovfl > 10) {EL755_errcode = EL755__TOO_MANY; return False;} if (n_ovfl > 10) {
EL755_errcode = EL755__TOO_MANY;
return False;
}
} else { } else {
n_ovfl = 0; n_ovfl = 0;
if (strncmp (rply, rply_ptr, rply_len) == 0) if (strncmp(rply, rply_ptr, rply_len) == 0) {
{
return False; return False;
} }
StrJoin(rply, rply_len, rply_ptr, ""); StrJoin(rply, rply_len, rply_ptr, "");
MakePrintable(replies[i], sizeof(replies[0]), rply_ptr); MakePrintable(replies[i], sizeof(replies[0]), rply_ptr);
i++; i++;
} }
if (EL755_errcode != 0) return False; if (EL755_errcode != 0)
return False;
EL755_call_depth--; EL755_call_depth--;
return True; return True;
} }
/*-------------------------------------------- End of EL755_Utility.C =======*/ /*-------------------------------------------- End of EL755_Utility.C =======*/

View File

@ -5,8 +5,7 @@
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
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;

View File

@ -89,7 +89,8 @@
/* /*
** 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.
*/ */
@ -106,4 +107,5 @@
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 */
@ -93,4 +94,5 @@
#endif #endif
return; return;
} }
/*------------------------------------------------- End of GETERRNO.C =======*/ /*------------------------------------------------- End of GETERRNO.C =======*/

View File

@ -45,7 +45,8 @@
#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];
@ -53,8 +54,7 @@
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;
} }
@ -87,25 +85,20 @@
*/ */
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;
} }
@ -114,48 +107,42 @@
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)
{ {
@ -176,6 +163,7 @@
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)
@ -188,34 +176,28 @@
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;
} }
@ -223,24 +205,20 @@
/* 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;
} }
@ -250,6 +228,7 @@
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)
{ {
@ -258,12 +237,12 @@
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)
{ {
@ -278,38 +257,32 @@
/* 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)
{ {
@ -322,18 +295,14 @@
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);
@ -343,16 +312,13 @@
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;
} }
@ -364,29 +330,25 @@
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)
{ {
@ -395,8 +357,7 @@
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);
@ -412,7 +373,9 @@
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);

View File

@ -44,7 +44,8 @@
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
@ -120,5 +121,3 @@
#endif #endif

View File

@ -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,16 +183,46 @@
} }
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);
@ -203,6 +234,7 @@
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.
@ -210,47 +242,58 @@
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.
@ -258,19 +301,23 @@
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

@ -153,6 +153,7 @@
return 1; return 1;
} }
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
int SerialForceOpen(void **pData, char *pHost, int iPort, int iChannel) int SerialForceOpen(void **pData, char *pHost, int iPort, int iChannel)
{ {
@ -205,6 +206,7 @@
return 1; return 1;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int SerialConfig(void **pData, int iTmo) int SerialConfig(void **pData, int iTmo)
{ {
@ -213,18 +215,17 @@
my_info = (struct SerialInfo *) *pData; my_info = (struct SerialInfo *) *pData;
assert(my_info); assert(my_info);
if(iTmo < 100) if (iTmo < 100) {
{
my_info->tmo = 1; my_info->tmo = 1;
return 1; return 1;
} } else {
else
{
my_info->tmo = iTmo / 100; /* convert to deci seconds */ my_info->tmo = iTmo / 100; /* convert to deci seconds */
if(my_info->tmo > 9999)my_info->tmo = 9999; if (my_info->tmo > 9999)
my_info->tmo = 9999;
} }
return 1; return 1;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int GetSerialTmo(void **pData) int GetSerialTmo(void **pData)
{ {
@ -242,6 +243,7 @@
{ {
return GetSerialTmo(pData); return GetSerialTmo(pData);
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int SerialGetSocket(void **pData) int SerialGetSocket(void **pData)
{ {
@ -255,6 +257,7 @@
return 1; return 1;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int SerialClose(void **pData) int SerialClose(void **pData)
{ {
@ -263,7 +266,8 @@
char buff[4]; char buff[4];
info_ptr = (struct SerialInfo *) *pData; info_ptr = (struct SerialInfo *) *pData;
if (info_ptr == NULL) return True; if (info_ptr == NULL)
return True;
if (info_ptr->skt != 0) { if (info_ptr->skt != 0) {
AsynSrv_Close(&(info_ptr->sAsync), 0); AsynSrv_Close(&(info_ptr->sAsync), 0);
@ -273,6 +277,7 @@
*pData = NULL; *pData = NULL;
return True; return True;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int SerialForceClose(void **pData) int SerialForceClose(void **pData)
{ {
@ -281,7 +286,8 @@
char buff[4]; char buff[4];
info_ptr = (struct SerialInfo *) *pData; info_ptr = (struct SerialInfo *) *pData;
if (info_ptr == NULL) return True; if (info_ptr == NULL)
return True;
if (info_ptr->skt != 0) { if (info_ptr->skt != 0) {
AsynSrv_Close(&(info_ptr->sAsync), 1); AsynSrv_Close(&(info_ptr->sAsync), 1);
@ -291,21 +297,20 @@
*pData = NULL; *pData = NULL;
return True; return True;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int SerialATerm(void **pData, char *pTerm) int SerialATerm(void **pData, char *pTerm)
{ {
struct SerialInfo *my_info = NULL; struct SerialInfo *my_info = NULL;
my_info = (struct SerialInfo *) *pData; my_info = (struct SerialInfo *) *pData;
if(my_info == NULL) if (my_info == NULL) {
{
printf("Serious Programming problem: data = NULL\n"); printf("Serious Programming problem: data = NULL\n");
return 0; return 0;
} }
/* only three characters in this field */ /* only three characters in this field */
if(strlen(pTerm) > 4) if (strlen(pTerm) > 4) {
{
return 0; return 0;
} }
memset(my_info->pTerms, 0, 4); memset(my_info->pTerms, 0, 4);
@ -313,6 +318,7 @@
return 1; return 1;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int SerialAGetTerm(void **pData, char *pTerm, int iTermLen) int SerialAGetTerm(void **pData, char *pTerm, int iTermLen)
{ {
@ -325,6 +331,7 @@
return 1; return 1;
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
int SerialSendTerm(void **pData, char *pTerm) int SerialSendTerm(void **pData, char *pTerm)
{ {
@ -334,8 +341,7 @@
assert(my_info); assert(my_info);
/* only 0 characters in this field */ /* only 0 characters in this field */
if(strlen(pTerm) > 9) if (strlen(pTerm) > 9) {
{
return 0; return 0;
} }
strcpy(my_info->pSendTerm, pTerm); strcpy(my_info->pSendTerm, pTerm);
@ -363,7 +369,8 @@
** closed if an error is detected. ** closed if an error is detected.
*/ */
info_ptr = (struct SerialInfo *) *pData; info_ptr = (struct SerialInfo *) *pData;
if (info_ptr == NULL) return NOCONNECTION; if (info_ptr == NULL)
return NOCONNECTION;
if (info_ptr->skt == 0) { if (info_ptr->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));
@ -371,7 +378,8 @@
} }
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)
info_ptr->msg_id = 1;
sprintf(info_ptr->to_host.msg_id, "%4.4d", info_ptr->msg_id); sprintf(info_ptr->to_host.msg_id, "%4.4d", info_ptr->msg_id);
memcpy(info_ptr->to_host.c_pcol_lvl, RS__PROTOCOL_ID_V01B, memcpy(info_ptr->to_host.c_pcol_lvl, RS__PROTOCOL_ID_V01B,
@ -399,13 +407,10 @@
strcpy(cmnd_lst_ptr + 4, txt_ptr); strcpy(cmnd_lst_ptr + 4, txt_ptr);
/* make sure that the string is properly terminated */ /* make sure that the string is properly terminated */
if ((strstr(txt_ptr, info_ptr->pSendTerm) == 0) && if ((strstr(txt_ptr, info_ptr->pSendTerm) == 0) &&
(strlen(txt_ptr) > 0) ) (strlen(txt_ptr) > 0)) {
{
strcpy(cmnd_lst_ptr + 4 + strlen(txt_ptr), info_ptr->pSendTerm); strcpy(cmnd_lst_ptr + 4 + strlen(txt_ptr), info_ptr->pSendTerm);
c_len = strlen(txt_ptr) + strlen(info_ptr->pSendTerm); c_len = strlen(txt_ptr) + strlen(info_ptr->pSendTerm);
} } else {
else
{
c_len = strlen(txt_ptr); c_len = strlen(txt_ptr);
} }
sprintf(text, "%4.4d", c_len); sprintf(text, "%4.4d", c_len);
@ -439,6 +444,7 @@
} }
return 1; return 1;
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
int SerialReceive(void **pData, char *pBuffer, int iBufLen) int SerialReceive(void **pData, char *pBuffer, int iBufLen)
{ {
@ -461,7 +467,8 @@
** closed if an error is detected. ** closed if an error is detected.
*/ */
info_ptr = (struct SerialInfo *) *pData; info_ptr = (struct SerialInfo *) *pData;
if (info_ptr == NULL) return NOCONNECTION; if (info_ptr == NULL)
return NOCONNECTION;
if (info_ptr->skt == 0) { if (info_ptr->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));
@ -482,15 +489,11 @@
size = sizeof(info_ptr->from_host.msg_size); size = sizeof(info_ptr->from_host.msg_size);
status = recv(info_ptr->skt, info_ptr->from_host.msg_size, size, 0); status = recv(info_ptr->skt, info_ptr->from_host.msg_size, size, 0);
if (status != size) { if (status != size) {
if(status > 0) if (status > 0) {
{
iResult = EL734__BAD_RECV; /* Server exited (probably) */ iResult = EL734__BAD_RECV; /* Server exited (probably) */
} } else if (status == -1) {
else if (status == -1) {
iResult = EL734__BAD_RECV_NET; /* It's some other net problem */ iResult = EL734__BAD_RECV_NET; /* It's some other net problem */
} } else {
else
{
iResult = EL734__BAD_RECV_NET; iResult = EL734__BAD_RECV_NET;
} }
AsynSrv_Close(&(info_ptr->sAsync), 1); AsynSrv_Close(&(info_ptr->sAsync), 1);
@ -510,7 +513,8 @@
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)
bytes_left = max_size;
status = recv(info_ptr->skt, nxt_byte_ptr, bytes_left, 0); status = recv(info_ptr->skt, nxt_byte_ptr, bytes_left, 0);
if (status <= 0) { if (status <= 0) {
iResult = EL734__BAD_FLUSH; /* TCP/IP problem whilst flushing */ iResult = EL734__BAD_FLUSH; /* TCP/IP problem whilst flushing */
@ -546,20 +550,19 @@
} }
/* well, we got data, make it available */ /* well, we got data, make it available */
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 = 0; &info_ptr->max_replies) != 1)
info_ptr->max_replies = 0;
if (info_ptr->max_replies > 0) if (info_ptr->max_replies > 0)
ptr = (struct RS__RplyStruct_V01B *) info_ptr->from_host.u.rplys; ptr = (struct RS__RplyStruct_V01B *) info_ptr->from_host.u.rplys;
info_ptr->n_replies = 1; info_ptr->n_replies = 1;
if(ptr) if (ptr) {
{
strncpy(pBuffer, ptr->rply, iBufLen); strncpy(pBuffer, ptr->rply, iBufLen);
} } else {
else
{
return NOREPLY; return NOREPLY;
} }
return True; return True;
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
int SerialReceiveWithTerm(void **pData, char *pBuffer, int SerialReceiveWithTerm(void **pData, char *pBuffer,
int iBufLen, char *cTerm) int iBufLen, char *cTerm)
@ -583,7 +586,8 @@
** closed if an error is detected. ** closed if an error is detected.
*/ */
info_ptr = (struct SerialInfo *) *pData; info_ptr = (struct SerialInfo *) *pData;
if (info_ptr == NULL) return NOCONNECTION; if (info_ptr == NULL)
return NOCONNECTION;
if (info_ptr->skt == 0) { if (info_ptr->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));
@ -604,15 +608,11 @@
size = sizeof(info_ptr->from_host.msg_size); size = sizeof(info_ptr->from_host.msg_size);
status = recv(info_ptr->skt, info_ptr->from_host.msg_size, size, 0); status = recv(info_ptr->skt, info_ptr->from_host.msg_size, size, 0);
if (status != size) { if (status != size) {
if(status > 0) if (status > 0) {
{
iResult = EL734__BAD_RECV; /* Server exited (probably) */ iResult = EL734__BAD_RECV; /* Server exited (probably) */
} } else if (status == -1) {
else if (status == -1) {
iResult = EL734__BAD_RECV_NET; /* It's some other net problem */ iResult = EL734__BAD_RECV_NET; /* It's some other net problem */
} } else {
else
{
iResult = EL734__BAD_RECV_NET; iResult = EL734__BAD_RECV_NET;
} }
AsynSrv_Close(&(info_ptr->sAsync), 1); AsynSrv_Close(&(info_ptr->sAsync), 1);
@ -632,7 +632,8 @@
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)
bytes_left = max_size;
status = recv(info_ptr->skt, nxt_byte_ptr, bytes_left, 0); status = recv(info_ptr->skt, nxt_byte_ptr, bytes_left, 0);
if (status <= 0) { if (status <= 0) {
iResult = EL734__BAD_FLUSH; /* TCP/IP problem whilst flushing */ iResult = EL734__BAD_FLUSH; /* TCP/IP problem whilst flushing */
@ -668,17 +669,15 @@
} }
/* well, we got data, make it available */ /* well, we got data, make it available */
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 = 0; &info_ptr->max_replies) != 1)
info_ptr->max_replies = 0;
if (info_ptr->max_replies > 0) if (info_ptr->max_replies > 0)
ptr = (struct RS__RplyStruct_V01B *) info_ptr->from_host.u.rplys; ptr = (struct RS__RplyStruct_V01B *) info_ptr->from_host.u.rplys;
info_ptr->n_replies = 1; info_ptr->n_replies = 1;
if(ptr) if (ptr) {
{
strncpy(pBuffer, ptr->rply, iBufLen); strncpy(pBuffer, ptr->rply, iBufLen);
*cTerm = ptr->term; *cTerm = ptr->term;
} } else {
else
{
return NOREPLY; return NOREPLY;
} }
return True; return True;
@ -687,8 +686,7 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int SerialError(int iErr, char *pBuffer, int iBufLen) int SerialError(int iErr, char *pBuffer, int iBufLen)
{ {
switch(iErr) switch (iErr) {
{
case -320: case -320:
strncpy(pBuffer, "Select failed to find data", iBufLen); strncpy(pBuffer, "Select failed to find data", iBufLen);
break; break;
@ -803,6 +801,7 @@
} }
return 1; return 1;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int SerialWriteRead(void **pData, char *pCommand, int SerialWriteRead(void **pData, char *pCommand,
char *pBuffer, int iBufLen) char *pBuffer, int iBufLen)
@ -816,8 +815,7 @@
/* write */ /* write */
iRet = SerialSend(pData, pCommand); iRet = SerialSend(pData, pCommand);
if(iRet != 1) if (iRet != 1) {
{
SerialError(iRet, pBuffer, iBufLen); SerialError(iRet, pBuffer, iBufLen);
return iRet; return iRet;
} }
@ -826,27 +824,23 @@
tTarget = tCurrent = time(&tCurrent); tTarget = tCurrent = time(&tCurrent);
tTarget += pInfo->tmo * 100 - 90; tTarget += pInfo->tmo * 100 - 90;
while(tCurrent < tTarget) while (tCurrent < tTarget) {
{
pInfo->pFunc(pInfo->pData, 100); pInfo->pFunc(pInfo->pData, 100);
iRet = SerialReceive(pData, pBuffer, iBufLen); iRet = SerialReceive(pData, pBuffer, iBufLen);
if( iRet != 1) if (iRet != 1) {
{ if (iRet != SELECTFAIL) {
if(iRet != SELECTFAIL)
{
/* error ! */ /* error ! */
SerialError(iRet, pBuffer, iBufLen); SerialError(iRet, pBuffer, iBufLen);
return iRet; return iRet;
} }
} } else {
else
{
return 1; /* there is data read, we are done */ return 1; /* there is data read, we are done */
} }
tCurrent = time(&tCurrent); tCurrent = time(&tCurrent);
} }
return TIMEOUT; return TIMEOUT;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int SerialNoReply(void **pData, char *pCommand) int SerialNoReply(void **pData, char *pCommand)
{ {
@ -862,29 +856,26 @@
/* write */ /* write */
iRet = SerialSend(pData, pCommand); iRet = SerialSend(pData, pCommand);
if(iRet != 1) if (iRet != 1) {
{
pInfo->tmo = iOld; pInfo->tmo = iOld;
return iRet; return iRet;
} }
/* try some time to find a TMO */ /* try some time to find a TMO */
for(i = 0 ; i < 10; i++) for (i = 0; i < 10; i++) {
{
usleep(50); usleep(50);
SerialReceive(pData, pBuffer, 29); SerialReceive(pData, pBuffer, 29);
if(strcmp(pBuffer,"?TMO") == 0) if (strcmp(pBuffer, "?TMO") == 0) {
{
break; break;
} }
} }
if(i > 7) if (i > 7) {
{
printf("TMO received after %d cycles \n", i); printf("TMO received after %d cycles \n", i);
} }
pInfo->tmo = iOld; pInfo->tmo = iOld;
return 1; return 1;
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
void SetSerialSleep(void **pData, SerialSleep pFun, void *pUserData) void SetSerialSleep(void **pData, SerialSleep pFun, void *pUserData)
{ {
@ -896,20 +887,3 @@
pInfo->pData = pUserData; pInfo->pData = pUserData;
} }

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 (
char *out,
int out_size,
char in);
char *MakePrint (
char *text);
char *MakePrintable (
char *out,
int out_size,
char *in);
void *Map_to_ACS(); void *Map_to_ACS();
char *StrEdit ( char *StrEdit(char *out, char *in, char *ctrl, int *ln);
char *out, 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 *ctrl, int Get_TASMAD_Info(char *file_name, int *nItems, ...);
int *ln); int Get_TASMAD_Info_Filename(char *file_name, char *buf, int *bufSize);
char *StrJoin ( int Update_TASMAD_Info(char *file_name, int *nItems, ...);
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

@ -64,8 +64,7 @@
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,
@ -85,8 +84,7 @@
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);

View File

@ -322,10 +322,12 @@
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,34 +365,37 @@
} 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;
}; };
/* /*
@ -404,7 +409,8 @@
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,7 +480,8 @@
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;
}; };
/* /*
@ -477,7 +494,8 @@
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

@ -166,9 +166,8 @@
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;
return NULL;
}
/* Can't do anything!! */
if (strlen(in) <= 0) { if (strlen(in) <= 0) {
*out = NIL; *ln = 0; return out; /* Nothing to do!! */ *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
@ -190,9 +194,12 @@
*/ */
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;
@ -211,7 +218,9 @@
} 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");
} }
@ -219,7 +228,9 @@
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; in++;
case 'r': case 'R': *nxt++ = '\015'; in++; break; break;
case 't': case 'T': *nxt++ = '\011'; in++; break; case 'b':
case 'v': case 'V': *nxt++ = '\013'; in++; break; case 'B':
case '\\': *nxt++ = '\\'; in++; break; *nxt++ = '\010';
case '\'': *nxt++ = '\''; in++; break; in++;
case '\"': *nxt++ = '\"'; in++; break; break;
case '\?': *nxt++ = '\?'; in++; break; case 'f':
case 'x': case 'X': 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++; in++;
i = strspn(in, "0123456789abcdefABCDEF"); i = strspn(in, "0123456789abcdefABCDEF");
if (i > 0) { if (i > 0) {
*nxt++ = strtol (in, &in, 16); break; *nxt++ = strtol(in, &in, 16);
break;
} else { } else {
*nxt++ = '\\'; break; *nxt++ = '\\';
break;
} }
case '0': case '0':
case '1': case '1':
@ -280,7 +334,8 @@
*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;
*in++; /* Make it something unlikely */
} else { } else {
*nxt++ = *in++; *nxt++ = *in++;
} }
@ -289,14 +344,20 @@
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,7 +365,9 @@
** 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);
@ -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;
@ -372,10 +439,12 @@
} }
} }
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, '!');
@ -407,9 +476,11 @@
** 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

@ -92,15 +92,15 @@
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 */
@ -124,7 +124,8 @@
** 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)
size_b = size - size_a;
result[size_a + size_b] = NIL; result[size_a + size_b] = NIL;
for (i = (size_b - 1); i >= 0; i--) { for (i = (size_b - 1); i >= 0; i--) {
result[size_a + i] = str_b[i]; result[size_a + i] = str_b[i];
@ -135,8 +136,10 @@
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

@ -34,34 +34,29 @@
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;
@ -74,23 +69,18 @@
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++;
} }
} }
@ -98,19 +88,19 @@
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)
{ {
@ -122,16 +112,13 @@
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;
} }
@ -142,6 +129,7 @@
+ 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)
{ {
@ -153,16 +141,13 @@
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;
} }
@ -173,4 +158,3 @@
+ fFrac * (self->fVal1[i1] - self->fVal1[i1 - 1]); + fFrac * (self->fVal1[i1] - self->fVal1[i1 - 1]);
return 1; return 1;
} }

View File

@ -41,7 +41,8 @@ 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.
*/ */

View File

@ -369,13 +369,15 @@
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) {
@ -387,6 +389,7 @@
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** VelSel_Config: Configure a connection to a Velocity Selector. ** VelSel_Config: Configure a connection to a Velocity Selector.
@ -394,14 +397,15 @@
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
*/ */
@ -409,22 +413,26 @@
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')
break;
info_ptr->eot[i + 1] = eot_str[i]; 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.
@ -432,9 +440,8 @@
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];
@ -458,42 +465,107 @@
*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),
@ -503,6 +575,7 @@
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.
@ -511,7 +584,8 @@
/* ============== /* ==============
*/ 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;
@ -525,7 +599,8 @@
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;
@ -534,12 +609,14 @@
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
@ -547,8 +624,8 @@
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;
@ -589,12 +666,14 @@
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)
rply_ptr0 = (struct RS__RplyStruct *) "06\rNULL";
StrJoin(status_str, status_str_len, rply_ptr0->rply, ""); 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.
@ -602,9 +681,8 @@
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;
@ -679,7 +757,8 @@
*/ */
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);
@ -695,6 +774,7 @@
VelSel_call_depth--; VelSel_call_depth--;
return True; return True;
} }
/* /*
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** VelSel_SendCmnds - Send commands to RS232C server. ** VelSel_SendCmnds - Send commands to RS232C server.
@ -702,7 +782,8 @@
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.
*/ */
@ -745,12 +826,14 @@
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)
info_ptr->msg_id = 1;
sprintf(info_ptr->to_host.msg_id, "%04.4d", info_ptr->msg_id); 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",
info_ptr->asyn_info.chan);
sprintf(info_ptr->to_host.tmo, "%04.4d", info_ptr->tmo); 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,
@ -854,12 +937,14 @@
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)
bytes_left = max_size;
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) {
VelSel_errcode = VELSEL__BAD_FLUSH; /* TCP/IP problem whilst flushing */ VelSel_errcode = VELSEL__BAD_FLUSH; /* TCP/IP problem whilst flushing */
@ -889,7 +974,8 @@
} 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,
"\nVelSel_SendCmnds/recv/1: broken network pipe");
} else { } 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");
@ -925,4 +1011,5 @@
VelSel_call_depth--; VelSel_call_depth--;
return True; return True;
} }
/*-------------------------------------------- End of VelSel_Utility.C =======*/ /*-------------------------------------------- End of VelSel_Utility.C =======*/