59 #define F__SWAP(ps,l,pd) f_swaplw((int *)ps,(int)l,(int *)pd)
105 #define _POSIX_SOURCE
113 #include <sys/types.h>
115 #include <sys/timeb.h>
117 #include <sys/time.h>
164 int swapw(
unsigned short *,
unsigned short *,
unsigned int);
165 int swapl(
unsigned int *,
unsigned int *,
unsigned int);
169 #define TCP__TIMEOUT 3000
170 #define FLUSH__TIME 3
171 #define STDOUT_BUFIO_ 1
202 short i, i_h, i_m, i_s;
203 char arg[80], c_hms[16], c_help[4];
205 char c_node[32], c_name[32], c_retmsg[256];
212 if (p_clnt_filter == NULL)
214 printf(
"E-%s: calloc(,...s_clnt_filter) failed!\n",
c_modnam);
215 printf(
"F-%s: aborting program execution!\n",
c_modnam);
222 memset( (
void *) p_clnt_filter, 0,
sizeof(
struct s_clnt_filter) );
225 p_clnt_filter->
l_endian = GPS__ENV_ENDIAN;
253 printf(
"E-%s: Severe Error in f_fltdscr! Status:%d\n",
263 strcpy(c_node,pc_node);
272 printf(
"E-%s: Error connecting node:%s, port:%d. Msg:\n",
285 i_s = i_s - i_m * 60;
296 printf(
"E-%s: Error in f_write_tcp(p_flt,...)! Status:%d. Msg:\n",
307 if (p_clntbuf == NULL)
309 printf(
"E-%s: malloc(p_clntbuf) failed!\n",
c_modnam);
310 printf(
"F-%s: aborting program execution!\n",
c_modnam);
322 memset(p_clntbuf,0,
sizeof(
struct s_clntbuf));
329 printf(
"E-%s: Error reading 1st buffer: f_read_server()!\n",
c_modnam);
352 printf(
"F-%s: Error swapping first buffer from client\n",
395 printf(
"E-%s: Error sending acknowledge: f_send_ackn()!\n",
c_modnam);
418 printf(
"E-%s: Error reading buffer: f_read_server()!\n",
c_modnam);
451 case 2:
if((strstr(p_clntbuf->
c_message,
"no event data") == NULL)&
452 (strstr(p_clntbuf->
c_message,
"flushed") == NULL))
453 printf(
"MSG-type:W: %s\n", p_clntbuf->
c_message);
break;
454 case 4: printf(
"MSG-type:E: %s\n", p_clntbuf->
c_message);
break;
455 case 8: printf(
"MSG-type:F: %s\n", p_clntbuf->
c_message);
break;
456 default: printf(
"Unknown MSG-type:%d:\n%s\n",p_clntbuf->
l_msgtyp,p_clntbuf->
c_message);
486 ps_int += ps_ve10_1->
l_dlen/2 + 2;
502 printf(
"E-%s: Error sending acknowledge: f_send_ackn()!\n",
c_modnam);
555 static char c_modnam[] =
"f_fltdscr";
563 short i_fltdescnt = 0;
565 short i_fltblkcnt = 0;
567 i_fltblkbeg, i_fltblkend, j;
568 short if_newfltblk = 1;
569 short i_next_fltblk = 0;
571 int l_evtdescr, *pl_evtdescr, *pl_sev1descr, *pl_sev2descr;
572 short i_lasevtflt, i_1stsevflt;
575 int unsigned l_retsts = 0;
579 printf(
"--->D-%s: addr_filter p:%d\n", c_modnam, p_clnt_filter);
582 p_flt_descr = (
struct s_flt_descr *) &p_clnt_filter->flt_descr[0];
587 p_filter = (
struct s_filter *) &p_clnt_filter->filter[i];
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;
626 p_flt_descr = (
struct s_flt_descr *) &p_clnt_filter->flt_descr[0];
630 p_clnt_filter->flt_descr[0].i_descriptors <= 0)
632 printf(
"W-%s: >1 write blocks, previous one(s) ignored!\n",
634 l_retsts = l_retsts | 2;
644 p_clnt_filter->if_wrtevt = (p_opc1->
b1_evtsev == 1) ? 1 : 0;
645 p_clnt_filter->if_wrtsev = (p_opc1->
b1_evtsev != 1) ? 1 : 0;
650 if (i_fltdescnt == 0)
652 i_descr = i_fltdescnt;
654 &p_clnt_filter->flt_descr[i_fltdescnt];
662 p_clnt_filter->if_fltevt = 1;
664 p_clnt_filter->if_fltsev = 1;
680 printf(
"E-%s: Filter specification %d invalid for events\n",
687 printf(
"E-%s: Filter specification %d invalid for subevents\n",
698 if (p_opc1->
b3_opc != 0) {
699 printf(
"W-%s: Take all. Set opcode to 0, next time\n",
702 l_retsts = l_retsts | 2;
763 printf(
"W-%s: FLTSPEC %d NOT FOUND\n",
766 l_retsts = l_retsts | 2;
773 p_flt_descr = (
struct s_flt_descr *) &p_clnt_filter->flt_descr[0];
775 printf(
"E-%s: The write filter is missing! Filter is invalid!\n",
780 if (!(p_clnt_filter->if_fltevt || p_clnt_filter->if_fltsev)) {
781 printf(
"E-%s: The filter itself is missing! Filter is invalid!\n",
795 if ( (p_clnt_filter->if_fltevt == 1) && (p_clnt_filter->if_fltsev == 1) ) {
798 i_1stsevflt = i_fltdescnt;
800 for (i = 1; i < i_fltdescnt; i++) {
801 p_flt_descr = (
struct s_flt_descr *) &p_clnt_filter->flt_descr[i];
811 (i_1stsevflt == i_fltdescnt) )
814 if (i_1stsevflt < i_lasevtflt) {
816 "W-%s 1stsevflt:%d lastevtflt:%d. Evt flt should come first\n",
820 l_retsts = l_retsts | 2;
822 pl_evtdescr = (
int *) &p_clnt_filter->flt_descr[i_lasevtflt];
823 l_evtdescr = *pl_evtdescr;
825 for (j = i_lasevtflt; j > i_1stsevflt; j--) {
826 pl_sev1descr = (
int *) &p_clnt_filter->flt_descr[j-1];
827 pl_sev2descr = (
int *) &p_clnt_filter->flt_descr[j];
828 *pl_sev2descr = *pl_sev1descr;
830 pl_evtdescr = (
int *) &p_clnt_filter->flt_descr[i_1stsevflt];
831 *pl_evtdescr = l_evtdescr;
840 p_clnt_filter->flt_descr[0].i_descriptors = i_fltdescnt;
845 if (p_clnt_filter->if_fltsev == 1) {
846 for (i = 1; i < p_clnt_filter->flt_descr[0].i_descriptors; i++) {
847 p_flt_descr = (
struct s_flt_descr *) &p_clnt_filter->flt_descr[i];
856 return(l_retsts | 1);
919 char c_line[80], c_comment[80], *c_fsts, *p_com, *p_minus;
920 short i_fltblklen = 0;
925 int unsigned l_pattern;
928 short i_evtsev,i_selflt,i_selwrt,i_opc,i_lnkf1,
930 short if_hex, if_comment;
932 char *fgets(
char *str,
int maxchar, FILE *file_ptr);
936 if ( (infile = fopen(c_file,
"r")) == 0)
938 sprintf(c_retmsg,
"E-%s: fopen(File=%s) ",
946 printf(
"Filter definition from file %s\n", c_file);
947 printf(
"=======================================\n");
953 memset(c_line,0,
sizeof(c_line));
955 if ( (c_fsts = fgets(c_line,
sizeof(c_line), infile)) == 0)
958 printf(
"D-%s: File=%s: Last input line.\n",
965 p_com = strpbrk(c_line,
"!/*");
969 strcpy(c_comment,p_com);
972 printf(
" - D: comment:%s", c_comment);
976 l_scan = sscanf(c_line,
"%hd", &i_fltblklen);
977 if (if_comment && (l_scan < 1) )
978 goto m_read_nxtblklen;
980 if (l_scan == EOF || l_scan == 0 || c_fsts == NULL)
983 printf(
"D-%s: Last input line.\n",c_file);
989 printf(
"E-%s: too long. Last filter block ignored\n",
995 printf(
"D-%s: Fltblklen:%d\n", c_modnam, i_fltblklen);
997 for (i = i_currflt; i < i_fltblklen + i_currflt; i++)
1001 memset(c_line,0,
sizeof(c_line));
1003 if ( (c_fsts = fgets(c_line,
sizeof(c_line), infile)) == 0)
1005 sprintf(c_retmsg,
"E-%s: Error reading:fgets(File=%s) ",
1014 printf(
"D-%s: line:%s", c_modnam, c_line);
1017 p_com = strpbrk(c_line,
"!/*");
1021 strcpy(c_comment,p_com);
1024 printf(
" - D: comment:%s", c_comment);
1028 l_scan = sscanf(c_line,
"%hd %hd %hd %hd %hd %hd %hd %ld %ld",
1043 p_minus = strchr(c_line,
'-');
1048 l_scan = sscanf(c_line,
"%hd %hd %hd %hd %hd %hd %hd %lx %lx",
1059 l_offset = (p_minus != NULL) ? -l_offset : l_offset;
1064 goto m_read_nxtline;
1067 "E-%s: scanned only %d(of 9) var., last 2 must be dec or hexa\n",
1078 "%s es:%d f:%d w:%d opc:%d lf1:%d lf2:%d flt:%d p:%x o:%x",
1079 (if_hex) ?
"HEX:" :
"DEC:",
1089 printf(
"D-%s: %s\n", c_modnam, c_retmsg);
1092 p_filter = (
struct s_filter *) &p_clnt_filter->filter[i];
1162 static char c_modnam[] =
"f_typflt";
1170 short i_fltdescnt, j, i;
1175 i_fltdescnt = p_clnt_filter->flt_descr[0].i_descriptors;
1184 "Write:%s %s Filter:%s %s object OPCODE mask",
1185 (p_clnt_filter->if_wrtevt > 0) ?
"EVENT" :
"",
1186 (p_clnt_filter->if_wrtsev > 0) ?
"SUBEVENT" :
"",
1187 (p_clnt_filter->if_fltevt > 0) ?
"EVENT" :
"",
1188 (p_clnt_filter->if_fltsev > 0) ?
"SUBEVENT" :
"");
1189 for (i = 0; i < i_fltdescnt; i++) {
1190 p_flt_descr = (
struct s_flt_descr *) &p_clnt_filter->flt_descr[i];
1198 printf(
"\n<<%s>>\n", (p_opc1->
b1_lnkf2 == 1) ?
"A_N_D" :
"O_R" );
1199 printf(
"\n=>>FILTER set %d :",i);
1200 printf(
" Select:%s Filter:%s Write:%s Filter[%d:%d]:\n",
1201 (p_opc1->
b1_evtsev == 1) ?
"EVENT" :
"SUBEVENT",
1202 (p_opc1->
b1_selflt == 1) ?
"ON" :
"OFF",
1203 (p_opc1->
b1_selwrt == 1) ?
"ON" :
"OFF",
1215 " Filter set id is fltspec:%d == mask:H%x (see 1st filt. below)\n",
1223 j <= p_flt_descr->h_fltblkend;
1225 p_filter = (
struct s_filter *) &p_clnt_filter->filter[j];
1230 printf(
" <%s>\n", (p_opc1->
b1_lnkf1 == 1) ?
"A_N_D" :
"O_R" );
1232 printf(
" =>%2d: opcode: ", i + 1);
1234 switch (p_opc1->
b3_opc) {
1237 printf(
"!! (ALL) ");
1241 printf(
"== (IDENT) ");
1246 printf(
"&& (ANY) ");
1251 printf(
"&= (INCL) ");
1256 printf(
"^= (EXCL) ");
1270 printf(
"W-OPCODE %d NOT FOUND\n",p_opc1->
b3_opc);
1275 if (p_opc1->
b3_opc != 0) {
1277 printf(
"W-%s: Take all. Opcode is %d\n",
1287 printf(
"trigger:%2d",p_pat1->
i_trigger);
1288 printf(
" (mask:%d offs:%d %s)\n",
1292 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1298 printf(
"mask:H%x offset:%d %s\n",
1311 printf(
" (mask:%d offs:%d %s)\n",
1315 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1322 printf(
"subtype:%d ",
1324 printf(
" (mask:%d offs:%d %s)\n",
1328 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1336 printf(
"type:%d subtype:%d",
1339 printf(
" (mask:H%x offs:%d %s)\n",
1343 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1351 printf(
"procid:%d ",
1353 printf(
" (mask:%d offs:%d %s)\n",
1357 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1364 printf(
"subcrate:%d control:%d",
1366 ((
unsigned) (p_filter->
l_pattern & 0xFF00)) >> 8);
1367 printf(
" (mask:H%x offs:%d %s)\n",
1371 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1379 printf(
"procid:%2d subcr:%d contr:%d",
1383 printf(
" (mask:H%x offs:%d %s)\n",
1387 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1392 printf(
"W-FLTSPEC %d NOT FOUND\n",p_opc1->
h_fltspec);
1397 printf(
"E-%s: Filter specification %d invalid for events\n",
1403 printf(
"E-%s: Filter specification %d invalid for subevents\n",
1476 int l_bytrec, l_2ndbuf_byt;
1477 int l_buftord, l_buffertype;
1478 static char c_modnam[] =
"f_read_server";
1486 p_clntbuf = (
struct s_clntbuf *) ps_chan->pc_io_buf;
1487 l_maxbytes=ps_chan->l_io_buf_size;
1493 "D-%s: **Rd 1st Buf: at %8x to %8x = %d bytes\n",
1508 printf(
"E-%s: Error reading first buffer. Msg follows:",c_modnam);
1522 printf(
"D-%s: Need swap to receive from %s to %s ENDIAN\n",
1524 (p_clntbuf->
l_endian == 0) ?
"LITTLE" :
"BIG",
1525 (GPS__ENV_ENDIAN == 0) ?
"LITTLE" :
"BIG");
1527 l_status =
F__SWAP(&l_buftord, 1, 0);
1528 if (l_status != 0) printf(
"E-%s: Error swapping l_buftord. l_sts:%d\n", c_modnam,l_status);
1529 l_status =
F__SWAP(&l_bytrec , 1, 0);
1530 if (l_status != 0) printf(
"E-%s: Error swapping l_bytrec l_sts:%d\n", c_modnam,l_status);
1531 l_status =
F__SWAP(&l_buffertype, 1, 0);
1532 if (l_status != 0) printf(
"E-%s: Error swapping l_buffertype l_sts:%d\n", c_modnam,l_status);
1534 printf(
"D-%s: buffers:%d, bytes:%d, buffertype:%d\n",
1543 if (l_bytrec > CLNT__SMALLBUF)
1545 printf(
"E-%s: Buffer sent:%d Bytes_to_rd:%d > %d\n",
1564 printf(
"D-%s: begin of c_buffer[148] in LW (all hex)\n", c_modnam);
1565 pl = (
int *) &p_clntbuf->
c_buffer[148];
1568 printf(
"%8x:%8x ",pl,*(pl));
1570 printf(
"%8x:%8x ",pl,*(pl));
1572 printf(
"%8x:%8x ",pl,*(pl));
1577 printf(
"D-%s: **Rd 2nd Buf: at %8x (buf[%d]) to %8x = %d b\n",
1584 *p_bytrd += l_2ndbuf_byt;
1588 if(l_bytrec > l_maxbytes)
1591 l_bytrec=(int)(1.2*(
float)l_bytrec);
1592 l_bytrec=((l_bytrec>>12)+1);
1593 l_bytrec=(l_bytrec<<12);
1595 pc = (
char*) malloc(l_bytrec);
1597 for(ii=0;ii<l_bytrec/4;ii++) *pl_d++ = 0;
1599 pl_s=(
int *)ps_chan->pc_io_buf;
1600 for(ii=0;ii<CLNT__SMALLBUF/4;ii++) *pl_d++ = *pl_s++;
1601 ps_chan->pc_io_buf = pc;
1602 ps_chan->l_io_buf_size = l_bytrec;
1606 im=l_2ndbuf_byt/16384;
1607 l_2ndbuf_byt=l_2ndbuf_byt%16384;
1608 for(ii=0;ii<im;ii++)
1610 l_status =
f_stc_read( pl,16384,i_chan,l_timeout);
1614 if(l_2ndbuf_byt > 0)
1616 l_status =
f_stc_read( pl,l_2ndbuf_byt,i_chan,l_timeout);
1620 printf(
"E-%s: Error reading second buffer. Msg follows:",c_modnam);
1629 printf(
"D-%s: begin of c_buffer[148] in LW (all hex)\n", c_modnam);
1630 pl = (
int *) &p_clntbuf->
c_buffer[148];
1633 printf(
"%8x:%8x ",pl,*(pl));
1635 printf(
"%8x:%8x ",pl,*(pl));
1637 printf(
"%8x:%8x ",pl,*(pl));
1648 s_ackn.l_ack_buf = l_buftord;
1649 s_ackn.l_ack_bytes = *p_bytrd;
1652 if ((l_buffertype & 8) != 0)
1703 static char c_modnam[] =
"f_send_ackn";
1707 printf(
"I-%s s_ackn.l_clnt_sts:%d l_clnt_sts:%d\n",
1726 printf(
"E-%s: Error in f_stc_write(&s_ackn,...)! Msg follows:",
1776 for ( ; *l !=
'\0'; ++
l, ++u)
1832 static char c_modnam[] =
"f_clnup";
1836 for (i = 1; i <= v_mem[0]; i++)
1839 if(v_mem[i] != 0) free((
int *) v_mem[i]);
1852 static char c_modnam[] =
"f_clnup";
1857 v_mem[++v_mem[0]] = (long) p_keyb;
int f_evcli_evt(s_evt_channel *ps_chan)
void f_strtoupper(char *u, char *l)
int unsigned l_inbuf_read_cnt
INTS4 f_stc_close(struct s_tcpcomm *ps_tcp)
INTS4 f_stc_read(void *p_buffer, INTS4 i_buflen, INTS4 i_channel, INTS4 i_timeout)
INTS4 f_stc_write(void *p_buffer, INTS4 i_buflen, INTS4 i_channel)
int f_send_ackn(int, int)
static int unsigned lf_swap
INTS4 f_stc_disperror(INTS4 i_error, CHARS *c_dest, INTS4 i_out)
int f_evcli_close(s_evt_channel *ps_chan)
int f_read_server(s_evt_channel *, int *, int, int)
static struct s_tcpcomm s_tcpcomm_ec
INTS4 f_stc_discclient(INTS4 i_channel)
int swapw(unsigned short *, unsigned short *, unsigned int)
INTS4 f_stc_connectserver(CHARS *c_node, INTS4 l_port, INTS4 *pi_channel, struct s_tcpcomm *ps_client)
int f_evcli_buf(s_evt_channel *ps_chan)
struct s_clntbuf * p_clntbuf
void f_clnup(long[], int *)
struct s_clnt_filter * p_clnt_filter
struct s_filter filter[GPS__MAXFLT]
char c_message[CLNT__MSGLEN]
unsigned short * pi_inbuf
static int unsigned l_endian_serv
int swapl(unsigned int *, unsigned int *, unsigned int)
int f_typflt(struct s_clnt_filter *p_clnt_filter)
int unsigned l_buffertype
int f_fltrd(struct s_clnt_filter *p_clnt_filter, char *c_file)
void f_clnup_save(long[], int *)
function if(typeof JSROOT!="object")
#define F__SWAP(ps, l, pd)
int f_fltdscr(struct s_clnt_filter *)
char c_buffer[GPS__OUTBUFSIZ]
int f_evcli_con(s_evt_channel *ps_chan, char *pc_node, int l_aport, int l_aevents, int l_asample)