FreeCalypso > hg > freecalypso-tools
comparison rvinterf/lowlevel/rvtdump.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Jun 2016 00:13:35 +0000 |
parents | |
children | 7168f63fc3b8 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
1 /* | |
2 * This program reads bytes from a serial port, parses them assuming | |
3 * TI's RVT MUX format, and prints every decoded packet. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <sys/errno.h> | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <unistd.h> | |
11 #include <time.h> | |
12 #include "../include/pktmux.h" | |
13 | |
14 extern int target_fd; | |
15 extern char *baudrate_name; | |
16 | |
17 extern u_char rxpkt[]; | |
18 extern size_t rxpkt_len; | |
19 | |
20 char *logfname; | |
21 FILE *logF; | |
22 time_t logtime; | |
23 int background; | |
24 int no_output; /* for output.c */ | |
25 | |
26 main(argc, argv) | |
27 char **argv; | |
28 { | |
29 extern char *optarg; | |
30 extern int optind; | |
31 int c; | |
32 fd_set fds; | |
33 | |
34 while ((c = getopt(argc, argv, "bB:d:l:")) != EOF) | |
35 switch (c) { | |
36 case 'b': | |
37 background++; | |
38 no_output++; /* for output.c */ | |
39 continue; | |
40 case 'B': | |
41 baudrate_name = optarg; | |
42 continue; | |
43 case 'd': | |
44 target_fd = atoi(optarg); | |
45 continue; | |
46 case 'l': | |
47 logfname = optarg; | |
48 continue; | |
49 case '?': | |
50 default: | |
51 usage: fprintf(stderr, | |
52 "usage: %s [options] ttyport\n", argv[0]); | |
53 exit(1); | |
54 } | |
55 if (background && !logfname) { | |
56 fprintf(stderr, "%s: -b is meaningless without -l\n", argv[0]); | |
57 exit(1); | |
58 } | |
59 if (target_fd <= 0) { | |
60 if (argc - optind != 1) | |
61 goto usage; | |
62 open_target_serial(argv[optind]); | |
63 } | |
64 | |
65 set_serial_nonblock(0); | |
66 setlinebuf(stdout); | |
67 if (logfname) { | |
68 logF = fopen(logfname, "w"); | |
69 if (!logF) { | |
70 perror(logfname); | |
71 exit(1); | |
72 } | |
73 setlinebuf(logF); | |
74 fprintf(logF, "*** Log of decoded RVT output ***\n"); | |
75 } | |
76 if (background) { | |
77 c = fork(); | |
78 if (c < 0) { | |
79 perror("fork"); | |
80 exit(1); | |
81 } | |
82 if (c) { | |
83 printf("rvtdump forked into background (pid %d)\n", c); | |
84 exit(0); | |
85 } | |
86 } | |
87 for (;;) { | |
88 FD_ZERO(&fds); | |
89 FD_SET(target_fd, &fds); | |
90 c = select(target_fd+1, &fds, 0, 0, 0); | |
91 time(&logtime); | |
92 if (c < 0) { | |
93 if (errno == EINTR) | |
94 continue; | |
95 perror("select"); | |
96 exit(1); | |
97 } | |
98 if (FD_ISSET(target_fd, &fds)) | |
99 process_serial_rx(); | |
100 } | |
101 } | |
102 | |
103 handle_rx_packet() | |
104 { | |
105 switch (rxpkt[0]) { | |
106 case RVT_RV_HEADER: | |
107 if (rxpkt_len < 6) | |
108 goto unknown; | |
109 print_rv_trace(); | |
110 return; | |
111 case RVT_L1_HEADER: | |
112 print_l1_trace(); | |
113 return; | |
114 case RVT_L23_HEADER: | |
115 print_g23_trace(); | |
116 return; | |
117 case RVT_TM_HEADER: | |
118 print_tm_output_raw(); | |
119 return; | |
120 case RVT_AT_HEADER: | |
121 print_ati_output(); | |
122 return; | |
123 case RVT_EXTUI_HEADER: | |
124 if (rxpkt_len < 5 || !(rxpkt_len & 1)) | |
125 goto unknown; | |
126 report_extui_packet(); | |
127 return; | |
128 case RVT_TCH_HEADER: | |
129 print_tch_output_raw(); | |
130 return; | |
131 case '*': | |
132 print_fc_lld_msg(); | |
133 return; | |
134 default: | |
135 unknown: | |
136 print_unknown_packet(); | |
137 } | |
138 } |