FreeCalypso > hg > freecalypso-sw
comparison rvinterf/rvtdump.c @ 171:4d8e4c58df71
rvtdump: implemented Tx extension hack, compiles
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Wed, 20 Nov 2013 05:39:31 +0000 |
parents | e01e3a60c858 |
children |
comparison
equal
deleted
inserted
replaced
170:4b53bd08f345 | 171:4d8e4c58df71 |
---|---|
12 | 12 |
13 extern int target_fd; | 13 extern int target_fd; |
14 extern char *baudrate_name; | 14 extern char *baudrate_name; |
15 | 15 |
16 extern char pr_item[]; | 16 extern char pr_item[]; |
17 extern int sendsock_fd; | |
17 | 18 |
18 char *logfname; | 19 char *logfname; |
19 FILE *logF; | 20 FILE *logF; |
20 time_t logtime; | 21 time_t logtime; |
21 int background; | 22 int background, sendsock_enable; |
22 | 23 |
23 main(argc, argv) | 24 main(argc, argv) |
24 char **argv; | 25 char **argv; |
25 { | 26 { |
26 extern char *optarg; | 27 extern char *optarg; |
27 extern int optind; | 28 extern int optind; |
28 int c; | 29 int c, maxfd; |
29 fd_set fds; | 30 fd_set fds; |
30 | 31 |
31 while ((c = getopt(argc, argv, "bB:d:l:")) != EOF) | 32 while ((c = getopt(argc, argv, "bB:d:l:s")) != EOF) |
32 switch (c) { | 33 switch (c) { |
33 case 'b': | 34 case 'b': |
34 background++; | 35 background++; |
35 continue; | 36 continue; |
36 case 'B': | 37 case 'B': |
39 case 'd': | 40 case 'd': |
40 target_fd = atoi(optarg); | 41 target_fd = atoi(optarg); |
41 continue; | 42 continue; |
42 case 'l': | 43 case 'l': |
43 logfname = optarg; | 44 logfname = optarg; |
45 continue; | |
46 case 's': | |
47 sendsock_enable++; | |
44 continue; | 48 continue; |
45 case '?': | 49 case '?': |
46 default: | 50 default: |
47 usage: fprintf(stderr, | 51 usage: fprintf(stderr, |
48 "usage: %s [options] ttyport\n", argv[0]); | 52 "usage: %s [options] ttyport\n", argv[0]); |
67 exit(1); | 71 exit(1); |
68 } | 72 } |
69 fprintf(logF, "*** Log of decoded RVT output ***\n"); | 73 fprintf(logF, "*** Log of decoded RVT output ***\n"); |
70 setlinebuf(logF); | 74 setlinebuf(logF); |
71 } | 75 } |
76 if (sendsock_enable) | |
77 create_send_socket(); | |
72 if (background) { | 78 if (background) { |
73 c = fork(); | 79 c = fork(); |
74 if (c < 0) { | 80 if (c < 0) { |
75 perror("fork"); | 81 perror("fork"); |
76 exit(1); | 82 exit(1); |
78 if (c) { | 84 if (c) { |
79 printf("rvtdump forked into background (pid %d)\n", c); | 85 printf("rvtdump forked into background (pid %d)\n", c); |
80 exit(0); | 86 exit(0); |
81 } | 87 } |
82 } | 88 } |
89 maxfd = target_fd; | |
90 if (sendsock_fd > maxfd) | |
91 maxfd = sendsock_fd; | |
83 for (;;) { | 92 for (;;) { |
84 FD_ZERO(&fds); | 93 FD_ZERO(&fds); |
85 FD_SET(target_fd, &fds); | 94 FD_SET(target_fd, &fds); |
86 c = select(target_fd+1, &fds, 0, 0, 0); | 95 if (sendsock_enable) |
96 FD_SET(sendsock_fd, &fds); | |
97 c = select(maxfd+1, &fds, 0, 0, 0); | |
87 time(&logtime); | 98 time(&logtime); |
88 if (c < 0) { | 99 if (c < 0) { |
89 if (errno == EINTR) | 100 if (errno == EINTR) |
90 continue; | 101 continue; |
91 perror("select"); | 102 perror("select"); |
92 exit(1); | 103 exit(1); |
93 } | 104 } |
94 if (FD_ISSET(target_fd, &fds)) | 105 if (FD_ISSET(target_fd, &fds)) |
95 process_serial_rx(); | 106 process_serial_rx(); |
107 if (FD_ISSET(sendsock_fd, &fds)) | |
108 handle_sendsock(); | |
96 } | 109 } |
97 } | 110 } |
98 | 111 |
99 handle_rx_packet() | 112 handle_rx_packet() |
100 { | 113 { |