FreeCalypso > hg > freecalypso-sw
comparison rvinterf/lowlevel/rvtdump.c @ 174:3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 22 Nov 2013 07:41:31 +0000 |
parents | rvinterf/old/rvtdump.c@f42854da4563 |
children | 549e6cd1e77d |
comparison
equal
deleted
inserted
replaced
173:f42854da4563 | 174:3256dc6e84ae |
---|---|
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 "../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 | |
25 main(argc, argv) | |
26 char **argv; | |
27 { | |
28 extern char *optarg; | |
29 extern int optind; | |
30 int c; | |
31 fd_set fds; | |
32 | |
33 while ((c = getopt(argc, argv, "bB:d:l:")) != EOF) | |
34 switch (c) { | |
35 case 'b': | |
36 background++; | |
37 continue; | |
38 case 'B': | |
39 baudrate_name = optarg; | |
40 continue; | |
41 case 'd': | |
42 target_fd = atoi(optarg); | |
43 continue; | |
44 case 'l': | |
45 logfname = optarg; | |
46 continue; | |
47 case '?': | |
48 default: | |
49 usage: fprintf(stderr, | |
50 "usage: %s [options] ttyport\n", argv[0]); | |
51 exit(1); | |
52 } | |
53 if (background && !logfname) { | |
54 fprintf(stderr, "%s: -b is meaningless without -l\n", argv[0]); | |
55 exit(1); | |
56 } | |
57 if (target_fd <= 0) { | |
58 if (argc - optind != 1) | |
59 goto usage; | |
60 open_target_serial(argv[optind]); | |
61 } | |
62 | |
63 set_serial_nonblock(0); | |
64 setlinebuf(stdout); | |
65 if (logfname) { | |
66 logF = fopen(logfname, "w"); | |
67 if (!logF) { | |
68 perror(logfname); | |
69 exit(1); | |
70 } | |
71 fprintf(logF, "*** Log of decoded RVT output ***\n"); | |
72 setlinebuf(logF); | |
73 } | |
74 if (background) { | |
75 c = fork(); | |
76 if (c < 0) { | |
77 perror("fork"); | |
78 exit(1); | |
79 } | |
80 if (c) { | |
81 printf("rvtdump forked into background (pid %d)\n", c); | |
82 exit(0); | |
83 } | |
84 } | |
85 for (;;) { | |
86 FD_ZERO(&fds); | |
87 FD_SET(target_fd, &fds); | |
88 c = select(target_fd+1, &fds, 0, 0, 0); | |
89 time(&logtime); | |
90 if (c < 0) { | |
91 if (errno == EINTR) | |
92 continue; | |
93 perror("select"); | |
94 exit(1); | |
95 } | |
96 if (FD_ISSET(target_fd, &fds)) | |
97 process_serial_rx(); | |
98 } | |
99 } | |
100 | |
101 handle_rx_packet() | |
102 { | |
103 switch (rxpkt[0]) { | |
104 case RVT_RV_HEADER: | |
105 if (rxpkt_len < 6) | |
106 goto unknown; | |
107 print_rv_trace(); | |
108 return; | |
109 case RVT_L1_HEADER: | |
110 print_l1_trace(); | |
111 return; | |
112 case RVT_L23_HEADER: | |
113 print_g23_trace(); | |
114 return; | |
115 case RVT_TM_HEADER: | |
116 print_etm_output_raw(); | |
117 return; | |
118 default: | |
119 unknown: | |
120 print_unknown_packet(); | |
121 } | |
122 } |