59#define F__SWAP(ps,l,pd) f_swaplw((int *)ps,(int)l,(int *)pd)
113#include <sys/types.h>
115#include <sys/timeb.h>
151int swapw(
unsigned short *,
unsigned short *,
unsigned int);
152int swapl(
unsigned int *,
unsigned int *,
unsigned int);
157#define TCP__TIMEOUT 3000
159#define STDOUT_BUFIO_ 1
189 char c_node[32], c_retmsg[256];
191 int l_len_lw2, l_sts, l_retval;
200 if (p_clnt_filter == NULL)
202 printf(
"E-%s: calloc(,...s_clnt_filter) failed!\n",
c_modnam);
203 printf(
"F-%s: aborting program execution!\n",
c_modnam);
210 memset( (
void *) p_clnt_filter, 0,
sizeof(
struct s_clnt_filter) );
213 p_clnt_filter->
l_endian = GPS__ENV_ENDIAN;
241 printf(
"E-%s: Severe Error in f_fltdscr! Status:%d\n",
251 strncpy(c_node,pc_node,
sizeof(c_node));
260 printf(
"E-%s: Error connecting node:%s, port:%d. Msg:\n",
274 i_s = i_s - i_m * 60;
285 printf(
"E-%s: Error in f_write_tcp(p_flt,...)! Status:%d. Msg:\n",
296 if (p_clntbuf == NULL)
298 printf(
"E-%s: malloc(p_clntbuf) failed!\n",
c_modnam);
299 printf(
"F-%s: aborting program execution!\n",
c_modnam);
311 memset(p_clntbuf,0,
sizeof(
struct s_clntbuf));
318 printf(
"E-%s: Error reading 1st buffer: f_read_server()!\n",
c_modnam);
343 printf(
"F-%s: Error swapping first buffer from client\n",
380 int l_len_lw2, l_sts, l_retval;
382 unsigned int *pl_inbuf;
391 printf(
"E-%s: Error sending acknowledge: f_send_ackn()!\n",
c_modnam);
415 printf(
"E-%s: Error reading buffer: f_read_server()!\n",
c_modnam);
431 l_sts =
F__SWAP(pl_inbuf, l_len_lw2, 0);
449 if((strstr(p_clntbuf->
c_message,
"no event data") == NULL) &&
450 (strstr(p_clntbuf->
c_message,
"flushed") == NULL))
451 printf(
"MSG-type:W: %s\n", p_clntbuf->
c_message);
454 printf(
"MSG-type:E: %s\n", p_clntbuf->
c_message);
457 printf(
"MSG-type:F: %s\n", p_clntbuf->
c_message);
491 ps_int += ps_ve10_1->
l_dlen/2 + 2;
507 printf(
"E-%s: Error sending acknowledge: f_send_ackn()!\n",
c_modnam);
559 static char flt_modnam[] =
"f_fltdscr";
564 short i_fltdescnt = 0;
567 short i, i_flt_len = 0,
568 i_fltblkbeg, i_fltblkend, j;
569 short if_newfltblk = 1;
570 short i_next_fltblk = 0;
572 int l_evtdescr, *pl_evtdescr, *pl_sev1descr, *pl_sev2descr;
573 short i_lasevtflt, i_1stsevflt;
575 int unsigned l_retsts = 0;
579 printf(
"--->D-%s: addr_filter p:%p\n", flt_modnam, p_clnt_filter);
591 printf(
"D-%s: i:%d opc:%x flt_len:%d\n",
597 if (i == i_next_fltblk)
619 i_next_fltblk = i + i_flt_len;
621 i_fltblkend = i_next_fltblk - 1;
631 printf(
"W-%s: >1 write blocks, previous one(s) ignored!\n",
633 l_retsts = l_retsts | 2;
649 if (i_fltdescnt == 0)
678 printf(
"E-%s: Filter specification %d invalid for events\n",
685 printf(
"E-%s: Filter specification %d invalid for subevents\n",
694 if (p_opc1->
b3_opc != 0) {
695 printf(
"W-%s: Take all. Set opcode to 0, next time\n",
698 l_retsts = l_retsts | 2;
759 printf(
"W-%s: FLTSPEC %d NOT FOUND\n",
762 l_retsts = l_retsts | 2;
771 printf(
"E-%s: The write filter is missing! Filter is invalid!\n",
777 printf(
"E-%s: The filter itself is missing! Filter is invalid!\n",
794 i_1stsevflt = i_fltdescnt;
796 for (i = 1; i < i_fltdescnt; i++) {
807 (i_1stsevflt == i_fltdescnt) )
810 if (i_1stsevflt < i_lasevtflt) {
812 "W-%s 1stsevflt:%d lastevtflt:%d. Evt flt should come first\n",
816 l_retsts = l_retsts | 2;
818 pl_evtdescr = (
int *) &p_clnt_filter->
flt_descr[i_lasevtflt];
819 l_evtdescr = *pl_evtdescr;
821 for (j = i_lasevtflt; j > i_1stsevflt; j--) {
822 pl_sev1descr = (
int *) &p_clnt_filter->
flt_descr[j-1];
823 pl_sev2descr = (
int *) &p_clnt_filter->
flt_descr[j];
824 *pl_sev2descr = *pl_sev1descr;
826 pl_evtdescr = (
int *) &p_clnt_filter->
flt_descr[i_1stsevflt];
827 *pl_evtdescr = l_evtdescr;
852 return(l_retsts | 1);
902 static char fltrd_modnam[] =
"f_fltrd";
904 struct s_opc1 *p_opc1 = NULL;
907 char c_line[80], c_comment[80], *c_fsts, *p_com, *p_minus;
908 short i_fltblklen = 0;
913 int unsigned l_pattern;
915 int unsigned l_offset_unsigned;
917 short i_evtsev,i_selflt,i_selwrt,i_opc,i_lnkf1,
919 short if_hex, if_comment;
921 char *fgets(
char *str,
int maxchar, FILE *file_ptr);
925 if ( (infile = fopen(c_file,
"r")) == 0)
927 sprintf(c_retmsg,
"E-%s: fopen(File=%s) ",
935 printf(
"Filter definition from file %s\n", c_file);
936 printf(
"=======================================\n");
942 memset(c_line,0,
sizeof(c_line));
944 if ( (c_fsts = fgets(c_line,
sizeof(c_line), infile)) == 0)
947 printf(
"D-%s: File=%s: Last input line.\n",
954 p_com = strpbrk(c_line,
"!/*");
957 strncpy(c_comment, p_com,
sizeof(c_comment));
960 printf(
" - D: comment:%s", c_comment);
964 l_scan = sscanf(c_line,
"%hd", &i_fltblklen);
965 if (if_comment && (l_scan < 1) )
966 goto m_read_nxtblklen;
968 if (l_scan == EOF || l_scan == 0 || c_fsts == NULL)
971 printf(
"D-%s: Last input line.\n",c_file);
977 printf(
"E-%s: too long. Last filter block ignored\n",
983 printf(
"D-%s: Fltblklen:%d\n", fltrd_modnam, i_fltblklen);
985 for (i = i_currflt; i < i_fltblklen + i_currflt; i++)
989 memset(c_line,0,
sizeof(c_line));
991 if ( (c_fsts = fgets(c_line,
sizeof(c_line), infile)) == 0)
993 sprintf(c_retmsg,
"E-%s: Error reading:fgets(File=%s) ",
1002 printf(
"D-%s: line:%s", fltrd_modnam, c_line);
1005 p_com = strpbrk(c_line,
"!/*");
1006 if (p_com != NULL) {
1008 strncpy(c_comment, p_com,
sizeof(c_comment));
1011 printf(
" - D: comment:%s", c_comment);
1014 l_scan = sscanf(c_line,
"%hd %hd %hd %hd %hd %hd %hd %u %d",
1029 p_minus = strchr(c_line,
'-');
1031 if (p_minus != NULL)
1034 l_scan = sscanf(c_line,
"%hd %hd %hd %hd %hd %hd %hd %x %x",
1043 &l_offset_unsigned);
1045 l_offset = (p_minus != NULL) ? -1*(
int)l_offset_unsigned : l_offset_unsigned;
1050 goto m_read_nxtline;
1053 "E-%s: scanned only %d(of 9) var., last 2 must be dec or hexa\n",
1063 "%s es:%d f:%d w:%d opc:%d lf1:%d lf2:%d flt:%d p:%x o:%x",
1064 (if_hex) ?
"HEX:" :
"DEC:",
1073 (
unsigned) l_offset);
1074 printf(
"D-%s: %s\n", fltrd_modnam, c_retmsg);
1146 static char typflt_modnam[] =
"f_typflt";
1154 short i_fltdescnt, j, i;
1168 "Write:%s %s Filter:%s %s object OPCODE mask",
1169 (p_clnt_filter->
if_wrtevt > 0) ?
"EVENT" :
"",
1170 (p_clnt_filter->
if_wrtsev > 0) ?
"SUBEVENT" :
"",
1171 (p_clnt_filter->
if_fltevt > 0) ?
"EVENT" :
"",
1172 (p_clnt_filter->
if_fltsev > 0) ?
"SUBEVENT" :
"");
1173 for (i = 0; i < i_fltdescnt; i++) {
1182 printf(
"\n<<%s>>\n", (p_opc1->
b1_lnkf2 == 1) ?
"A_N_D" :
"O_R" );
1183 printf(
"\n=>>FILTER set %d :",i);
1184 printf(
" Select:%s Filter:%s Write:%s Filter[%d:%d]:\n",
1185 (p_opc1->
b1_evtsev == 1) ?
"EVENT" :
"SUBEVENT",
1186 (p_opc1->
b1_selflt == 1) ?
"ON" :
"OFF",
1187 (p_opc1->
b1_selwrt == 1) ?
"ON" :
"OFF",
1199 " Filter set id is fltspec:%d == mask:H%x (see 1st filt. below)\n",
1207 j <= p_flt_descr->h_fltblkend;
1214 printf(
" <%s>\n", (p_opc1->
b1_lnkf1 == 1) ?
"A_N_D" :
"O_R" );
1216 printf(
" =>%2d: opcode: ", i + 1);
1218 switch (p_opc1->
b3_opc) {
1221 printf(
"!! (ALL) ");
1225 printf(
"== (IDENT) ");
1230 printf(
"&& (ANY) ");
1235 printf(
"&= (INCL) ");
1240 printf(
"^= (EXCL) ");
1254 printf(
"W-OPCODE %d NOT FOUND\n",p_opc1->
b3_opc);
1259 if (p_opc1->
b3_opc != 0) {
1261 printf(
"W-%s: Take all. Opcode is %d\n",
1271 printf(
"trigger:%2d",p_pat1->
i_trigger);
1272 printf(
" (mask:%d offs:%d %s)\n",
1276 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1282 printf(
"mask:H%x offset:%d %s\n",
1295 printf(
" (mask:%d offs:%d %s)\n",
1299 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1306 printf(
"subtype:%d ",
1308 printf(
" (mask:%d offs:%d %s)\n",
1312 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1320 printf(
"type:%d subtype:%d",
1323 printf(
" (mask:H%x offs:%d %s)\n",
1327 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1335 printf(
"procid:%d ",
1337 printf(
" (mask:%d offs:%d %s)\n",
1341 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1348 printf(
"subcrate:%d control:%d",
1350 ((
unsigned) (p_filter->
l_pattern & 0xFF00)) >> 8);
1351 printf(
" (mask:H%x offs:%d %s)\n",
1355 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1363 printf(
"procid:%2d subcr:%d contr:%d",
1367 printf(
" (mask:H%x offs:%d %s)\n",
1371 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1376 printf(
"W-FLTSPEC %d NOT FOUND\n",p_opc1->
h_fltspec);
1381 printf(
"E-%s: Filter specification %d invalid for events\n",
1387 printf(
"E-%s: Filter specification %d invalid for subevents\n",
1455 int l_status1, ii, im, *pl;
1456 int l_bytrec, l_2ndbuf_byt;
1457 int l_buftord, l_buffertype;
1458 static char readserv_modnam[] =
"f_read_server";
1466#ifndef DISABLE_POLLING_TIMEOUT
1471 _tmout = arg_timeout;
1486 printf(
"D-%s: **Rd 1st Buf: at %p to %p = %d bytes\n",
1496#ifndef DISABLE_POLLING_TIMEOUT
1517 printf(
"E-%s: Error reading first buffer. Msg follows:",readserv_modnam);
1531 printf(
"D-%s: Need swap to receive from %s to %s ENDIAN\n",
1533 (p_clntbuf->
l_endian == 0) ?
"LITTLE" :
"BIG",
1534 (GPS__ENV_ENDIAN == 0) ?
"LITTLE" :
"BIG");
1536 l_status1 =
F__SWAP(&l_buftord, 1, 0);
1537 if (l_status1 != 0) printf(
"E-%s: Error swapping l_buftord. l_sts:%d\n", readserv_modnam,l_status1);
1538 l_status1 =
F__SWAP(&l_bytrec , 1, 0);
1539 if (l_status1 != 0) printf(
"E-%s: Error swapping l_bytrec l_sts:%d\n", readserv_modnam,l_status1);
1541 if (l_status1 != 0) printf(
"E-%s: Error swapping l_buffertype l_sts:%d\n", readserv_modnam,l_status1);
1543 printf(
"D-%s: buffers:%d, bytes:%d, buffertype:%d\n",
1554 printf(
"E-%s: Buffer sent:%d Bytes_to_rd:%d > %d\n",
1571 printf(
"D-%s: begin of c_buffer[148] in LW (all hex)\n", readserv_modnam);
1572 pl = (
int *) &p_clntbuf->
c_buffer[148];
1575 printf(
"%p:%8x ",pl,*(pl));
1577 printf(
"%p:%8x ",pl,*(pl));
1579 printf(
"%p:%8x ",pl,*(pl));
1583 printf(
"D-%s: **Rd 2nd Buf: at %p (buf[%d]) to %p = %d b\n",
1590 *p_bytrd += l_2ndbuf_byt;
1594 if(l_bytrec > l_maxbytes)
1597 l_bytrec=(int)(1.2*(
float)l_bytrec);
1598 l_bytrec=((l_bytrec>>12)+1);
1599 l_bytrec=(l_bytrec<<12);
1601 pc = (
char*) malloc(l_bytrec);
1603 for(ii=0;ii<l_bytrec/4;ii++) *pl_d++ = 0;
1612 im=l_2ndbuf_byt/16384;
1613 l_2ndbuf_byt=l_2ndbuf_byt%16384;
1614 for(ii=0;ii<im;ii++)
1616 l_status1 =
f_stc_read( pl,16384,i_chan,arg_timeout);
1620 if(l_2ndbuf_byt > 0)
1622 l_status1 =
f_stc_read( pl,l_2ndbuf_byt,i_chan,arg_timeout);
1626 printf(
"E-%s: Error reading second buffer. Msg follows:",readserv_modnam);
1633 printf(
"D-%s: begin of c_buffer[148] in LW (all hex)\n", readserv_modnam);
1634 pl = (
int *) &p_clntbuf->
c_buffer[148];
1637 printf(
"%p:%8x ",pl,*(pl));
1639 printf(
"%p:%8x ",pl,*(pl));
1641 printf(
"%p:%8x ",pl,*(pl));
1652 s_ackn.l_ack_buf = l_buftord;
1653 s_ackn.l_ack_bytes = *p_bytrd;
1705 static char sackn_modnam[] =
"f_send_ackn";
1709 printf(
"I-%s s_ackn.l_clnt_sts:%d l_clnt_sts:%d\n",
1728 printf(
"E-%s: Error in f_stc_write(&s_ackn,...)! Msg follows:",
1777 for ( ; *
l !=
'\0'; ++
l, ++u)
1833 for (i = 1; i <= v_mem[0]; i++)
1835 if(v_mem[i] != 0) free((
void *) v_mem[i]);
1845 v_mem[++v_mem[0]] = (ADDRS) p_keyb;
int swapl(unsigned int *, unsigned int *, unsigned int)
int swapw(unsigned short *, unsigned short *, unsigned int)
static int unsigned l_endian_serv
static int unsigned lf_swap
int f_evcli_con(s_evt_channel *ps_chan, char *pc_node, int l_aport, int l_aevents, int l_asample)
void f_clnup(ADDRS[], int *)
static struct @220236141250170110137007007213107222364030057077 s_ackn
void f_clnup_save(ADDRS[], int *)
int f_read_server(s_evt_channel *, int *, int, int)
int f_evcli_close(s_evt_channel *ps_chan)
int f_typflt(struct s_clnt_filter *p_clnt_filter)
int f_fltrd(struct s_clnt_filter *p_clnt_filter, char *c_file)
static struct s_tcpcomm s_tcpcomm_ec
void f_strtoupper(char *u, char *l)
#define F__SWAP(ps, l, pd)
int f_evcli_evt(s_evt_channel *ps_chan)
int f_evcli_buf(s_evt_channel *ps_chan)
int f_fltdscr(struct s_clnt_filter *)
int f_send_ackn(int, int)
INTS4 f_stc_write(void *p_buffer, INTS4 i_buflen, INTS4 i_channel)
INTS4 f_stc_read(void *p_buffer, INTS4 i_buflen, INTS4 i_channel, INTS4 i_timeout)
INTS4 f_stc_connectserver(CHARS *c_node, INTS4 l_port, INTS4 *pi_channel, struct s_tcpcomm *ps_client)
INTS4 f_stc_discclient(INTS4 i_channel)
INTS4 f_stc_close(struct s_tcpcomm *ps_tcp)
INTS4 f_stc_disperror(INTS4 i_error, CHARS *c_dest, INTS4 i_out)
struct s_filter filter[GPS__MAXFLT]
struct s_flt_descr flt_descr[GPS__MAXFLTDESCR]
int unsigned l_buffertype
char c_buffer[GPS__OUTBUFSIZ]
int unsigned l_inbuf_read_cnt
char c_message[CLNT__MSGLEN]