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
205 char c_node[32], c_retmsg[256];
207 int l_len_lw2, l_sts, l_retval;
213 if (p_clnt_filter == NULL)
215 printf(
"E-%s: calloc(,...s_clnt_filter) failed!\n",
c_modnam);
216 printf(
"F-%s: aborting program execution!\n",
c_modnam);
223 memset( (
void *) p_clnt_filter, 0,
sizeof(
struct s_clnt_filter) );
226 p_clnt_filter->
l_endian = GPS__ENV_ENDIAN;
254 printf(
"E-%s: Severe Error in f_fltdscr! Status:%d\n",
264 strncpy(c_node,pc_node,
sizeof(c_node));
273 printf(
"E-%s: Error connecting node:%s, port:%d. Msg:\n",
287 i_s = i_s - i_m * 60;
298 printf(
"E-%s: Error in f_write_tcp(p_flt,...)! Status:%d. Msg:\n",
309 if (p_clntbuf == NULL)
311 printf(
"E-%s: malloc(p_clntbuf) failed!\n",
c_modnam);
312 printf(
"F-%s: aborting program execution!\n",
c_modnam);
324 memset(p_clntbuf,0,
sizeof(
struct s_clntbuf));
331 printf(
"E-%s: Error reading 1st buffer: f_read_server()!\n",
c_modnam);
354 printf(
"F-%s: Error swapping first buffer from client\n",
391 int l_len_lw2, l_sts, l_retval;
400 printf(
"E-%s: Error sending acknowledge: f_send_ackn()!\n",
c_modnam);
424 printf(
"E-%s: Error reading buffer: f_read_server()!\n",
c_modnam);
457 case 2:
if((strstr(p_clntbuf->
c_message,
"no event data") == NULL)&
458 (strstr(p_clntbuf->
c_message,
"flushed") == NULL))
459 printf(
"MSG-type:W: %s\n", p_clntbuf->
c_message);
break;
460 case 4: printf(
"MSG-type:E: %s\n", p_clntbuf->
c_message);
break;
461 case 8: printf(
"MSG-type:F: %s\n", p_clntbuf->
c_message);
break;
462 default: printf(
"Unknown MSG-type:%d:\n%s\n",p_clntbuf->
l_msgtyp,p_clntbuf->
c_message);
492 ps_int += ps_ve10_1->
l_dlen/2 + 2;
508 printf(
"E-%s: Error sending acknowledge: f_send_ackn()!\n",
c_modnam);
559 static char c_modnam[] =
"f_fltdscr";
564 short i_fltdescnt = 0;
566 short i_fltblkcnt = 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", c_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;
632 printf(
"W-%s: >1 write blocks, previous one(s) ignored!\n",
634 l_retsts = l_retsts | 2;
650 if (i_fltdescnt == 0)
652 i_descr = i_fltdescnt;
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;
775 printf(
"E-%s: The write filter is missing! Filter is invalid!\n",
781 printf(
"E-%s: The filter itself is missing! Filter is invalid!\n",
798 i_1stsevflt = i_fltdescnt;
800 for (i = 1; i < i_fltdescnt; 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;
856 return(l_retsts | 1);
915 char c_line[80], c_comment[80], *c_fsts, *p_com, *p_minus;
916 short i_fltblklen = 0;
921 int unsigned l_pattern;
923 int unsigned l_offset_unsigned;
925 short i_evtsev,i_selflt,i_selwrt,i_opc,i_lnkf1,
927 short if_hex, if_comment;
929 char *fgets(
char *str,
int maxchar, FILE *file_ptr);
933 if ( (infile = fopen(c_file,
"r")) == 0)
935 sprintf(c_retmsg,
"E-%s: fopen(File=%s) ",
943 printf(
"Filter definition from file %s\n", c_file);
944 printf(
"=======================================\n");
950 memset(c_line,0,
sizeof(c_line));
952 if ( (c_fsts = fgets(c_line,
sizeof(c_line), infile)) == 0)
955 printf(
"D-%s: File=%s: Last input line.\n",
962 p_com = strpbrk(c_line,
"!/*");
965 strncpy(c_comment, p_com,
sizeof(c_comment));
968 printf(
" - D: comment:%s", c_comment);
972 l_scan = sscanf(c_line,
"%hd", &i_fltblklen);
973 if (if_comment && (l_scan < 1) )
974 goto m_read_nxtblklen;
976 if (l_scan == EOF || l_scan == 0 || c_fsts == NULL)
979 printf(
"D-%s: Last input line.\n",c_file);
985 printf(
"E-%s: too long. Last filter block ignored\n",
991 printf(
"D-%s: Fltblklen:%d\n", c_modnam, i_fltblklen);
993 for (i = i_currflt; i < i_fltblklen + i_currflt; i++)
997 memset(c_line,0,
sizeof(c_line));
999 if ( (c_fsts = fgets(c_line,
sizeof(c_line), infile)) == 0)
1001 sprintf(c_retmsg,
"E-%s: Error reading:fgets(File=%s) ",
1010 printf(
"D-%s: line:%s", c_modnam, c_line);
1013 p_com = strpbrk(c_line,
"!/*");
1014 if (p_com != NULL) {
1016 strncpy(c_comment, p_com,
sizeof(c_comment));
1019 printf(
" - D: comment:%s", c_comment);
1022 l_scan = sscanf(c_line,
"%hd %hd %hd %hd %hd %hd %hd %u %d",
1037 p_minus = strchr(c_line,
'-');
1039 if (p_minus != NULL)
1042 l_scan = sscanf(c_line,
"%hd %hd %hd %hd %hd %hd %hd %x %x",
1051 &l_offset_unsigned);
1053 l_offset = (p_minus != NULL) ? -1*(
int)l_offset_unsigned : l_offset_unsigned;
1058 goto m_read_nxtline;
1061 "E-%s: scanned only %d(of 9) var., last 2 must be dec or hexa\n",
1071 "%s es:%d f:%d w:%d opc:%d lf1:%d lf2:%d flt:%d p:%x o:%x",
1072 (if_hex) ?
"HEX:" :
"DEC:",
1081 (
unsigned) l_offset);
1082 printf(
"D-%s: %s\n", c_modnam, c_retmsg);
1085 p_filter = (
struct s_filter *) &p_clnt_filter->filter[i];
1155 static char c_modnam[] =
"f_typflt";
1163 short i_fltdescnt, j, i;
1168 i_fltdescnt = p_clnt_filter->flt_descr[0].i_descriptors;
1177 "Write:%s %s Filter:%s %s object OPCODE mask",
1178 (p_clnt_filter->if_wrtevt > 0) ?
"EVENT" :
"",
1179 (p_clnt_filter->if_wrtsev > 0) ?
"SUBEVENT" :
"",
1180 (p_clnt_filter->if_fltevt > 0) ?
"EVENT" :
"",
1181 (p_clnt_filter->if_fltsev > 0) ?
"SUBEVENT" :
"");
1182 for (i = 0; i < i_fltdescnt; i++) {
1183 p_flt_descr = (
struct s_flt_descr *) &p_clnt_filter->flt_descr[i];
1185 &p_clnt_filter->filter[(int)p_flt_descr->
h_fltblkbeg];
1191 printf(
"\n<<%s>>\n", (p_opc1->
b1_lnkf2 == 1) ?
"A_N_D" :
"O_R" );
1192 printf(
"\n=>>FILTER set %d :",i);
1193 printf(
" Select:%s Filter:%s Write:%s Filter[%d:%d]:\n",
1194 (p_opc1->
b1_evtsev == 1) ?
"EVENT" :
"SUBEVENT",
1195 (p_opc1->
b1_selflt == 1) ?
"ON" :
"OFF",
1196 (p_opc1->
b1_selwrt == 1) ?
"ON" :
"OFF",
1205 &p_clnt_filter->filter[(
int)p_flt_descr->
h_fltblkbeg];
1208 " Filter set id is fltspec:%d == mask:H%x (see 1st filt. below)\n",
1216 j <= p_flt_descr->h_fltblkend;
1218 p_filter = (
struct s_filter *) &p_clnt_filter->filter[j];
1223 printf(
" <%s>\n", (p_opc1->
b1_lnkf1 == 1) ?
"A_N_D" :
"O_R" );
1225 printf(
" =>%2d: opcode: ", i + 1);
1227 switch (p_opc1->
b3_opc) {
1230 printf(
"!! (ALL) ");
1234 printf(
"== (IDENT) ");
1239 printf(
"&& (ANY) ");
1244 printf(
"&= (INCL) ");
1249 printf(
"^= (EXCL) ");
1263 printf(
"W-OPCODE %d NOT FOUND\n",p_opc1->
b3_opc);
1268 if (p_opc1->
b3_opc != 0) {
1270 printf(
"W-%s: Take all. Opcode is %d\n",
1280 printf(
"trigger:%2d",p_pat1->
i_trigger);
1281 printf(
" (mask:%d offs:%d %s)\n",
1285 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1291 printf(
"mask:H%x offset:%d %s\n",
1304 printf(
" (mask:%d offs:%d %s)\n",
1308 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1315 printf(
"subtype:%d ",
1317 printf(
" (mask:%d offs:%d %s)\n",
1321 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1329 printf(
"type:%d subtype:%d",
1332 printf(
" (mask:H%x offs:%d %s)\n",
1336 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1344 printf(
"procid:%d ",
1346 printf(
" (mask:%d offs:%d %s)\n",
1350 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1357 printf(
"subcrate:%d control:%d",
1359 ((
unsigned) (p_filter->
l_pattern & 0xFF00)) >> 8);
1360 printf(
" (mask:H%x offs:%d %s)\n",
1364 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1372 printf(
"procid:%2d subcr:%d contr:%d",
1376 printf(
" (mask:H%x offs:%d %s)\n",
1380 (p_filter->
l_offset >= 0) ?
"LW" :
"W");
1385 printf(
"W-FLTSPEC %d NOT FOUND\n",p_opc1->
h_fltspec);
1390 printf(
"E-%s: Filter specification %d invalid for events\n",
1396 printf(
"E-%s: Filter specification %d invalid for subevents\n",
1465 int l_bytrec, l_2ndbuf_byt;
1466 int l_buftord, l_buffertype;
1467 static char c_modnam[] =
"f_read_server";
1473 #ifndef DISABLE_POLLING_TIMEOUT
1493 printf(
"D-%s: **Rd 1st Buf: at %p to %p = %d bytes\n",
1503 #ifndef DISABLE_POLLING_TIMEOUT
1517 (
int) CLNT__SMALLBUF,
1524 printf(
"E-%s: Error reading first buffer. Msg follows:",c_modnam);
1538 printf(
"D-%s: Need swap to receive from %s to %s ENDIAN\n",
1540 (p_clntbuf->
l_endian == 0) ?
"LITTLE" :
"BIG",
1541 (GPS__ENV_ENDIAN == 0) ?
"LITTLE" :
"BIG");
1543 l_status =
F__SWAP(&l_buftord, 1, 0);
1544 if (l_status != 0) printf(
"E-%s: Error swapping l_buftord. l_sts:%d\n", c_modnam,l_status);
1545 l_status =
F__SWAP(&l_bytrec , 1, 0);
1546 if (l_status != 0) printf(
"E-%s: Error swapping l_bytrec l_sts:%d\n", c_modnam,l_status);
1547 l_status =
F__SWAP(&l_buffertype, 1, 0);
1548 if (l_status != 0) printf(
"E-%s: Error swapping l_buffertype l_sts:%d\n", c_modnam,l_status);
1550 printf(
"D-%s: buffers:%d, bytes:%d, buffertype:%d\n",
1559 if (l_bytrec > CLNT__SMALLBUF)
1561 printf(
"E-%s: Buffer sent:%d Bytes_to_rd:%d > %d\n",
1580 printf(
"D-%s: begin of c_buffer[148] in LW (all hex)\n", c_modnam);
1581 pl = (
int *) &p_clntbuf->
c_buffer[148];
1584 printf(
"%p:%8x ",pl,*(pl));
1586 printf(
"%p:%8x ",pl,*(pl));
1588 printf(
"%p:%8x ",pl,*(pl));
1592 printf(
"D-%s: **Rd 2nd Buf: at %p (buf[%d]) to %p = %d b\n",
1599 *p_bytrd += l_2ndbuf_byt;
1603 if(l_bytrec > l_maxbytes)
1606 l_bytrec=(int)(1.2*(
float)l_bytrec);
1607 l_bytrec=((l_bytrec>>12)+1);
1608 l_bytrec=(l_bytrec<<12);
1610 pc = (
char*) malloc(l_bytrec);
1612 for(ii=0;ii<l_bytrec/4;ii++) *pl_d++ = 0;
1615 for(ii=0;ii<CLNT__SMALLBUF/4;ii++) *pl_d++ = *pl_s++;
1621 im=l_2ndbuf_byt/16384;
1622 l_2ndbuf_byt=l_2ndbuf_byt%16384;
1623 for(ii=0;ii<im;ii++)
1625 l_status =
f_stc_read( pl,16384,i_chan,l_timeout);
1629 if(l_2ndbuf_byt > 0)
1631 l_status =
f_stc_read( pl,l_2ndbuf_byt,i_chan,l_timeout);
1635 printf(
"E-%s: Error reading second buffer. Msg follows:",c_modnam);
1644 printf(
"D-%s: begin of c_buffer[148] in LW (all hex)\n", c_modnam);
1645 pl = (
int *) &p_clntbuf->
c_buffer[148];
1648 printf(
"%p:%8x ",pl,*(pl));
1650 printf(
"%p:%8x ",pl,*(pl));
1652 printf(
"%p:%8x ",pl,*(pl));
1663 s_ackn.l_ack_buf = l_buftord;
1664 s_ackn.l_ack_bytes = *p_bytrd;
1667 if ((l_buffertype & 8) != 0)
1718 static char c_modnam[] =
"f_send_ackn";
1722 printf(
"I-%s s_ackn.l_clnt_sts:%d l_clnt_sts:%d\n",
1741 printf(
"E-%s: Error in f_stc_write(&s_ackn,...)! Msg follows:",
1791 for ( ; *l !=
'\0'; ++
l, ++u)
1849 for (i = 1; i <= v_mem[0]; i++)
1851 if(v_mem[i] != 0) free((
int *) v_mem[i]);
1863 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 *)
struct s_flt_descr flt_descr[GPS__MAXFLTDESCR]
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)