annotate rvinterf/rvtdump.c @ 170:4b53bd08f345

gsm-fw/riviera/rvt/rvt_task.c: formatting (readability) cleanup
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 20 Nov 2013 04:05:18 +0000
parents e01e3a60c858
children 4d8e4c58df71
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This program reads bytes from a serial port, parses them assuming
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * TI's RVT MUX format, and prints every decoded packet.
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <sys/errno.h>
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdio.h>
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdlib.h>
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <unistd.h>
134
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
11 #include <time.h>
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 extern int target_fd;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 extern char *baudrate_name;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
16 extern char pr_item[];
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
17
134
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
18 char *logfname;
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
19 FILE *logF;
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
20 time_t logtime;
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
21 int background;
134
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
22
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 main(argc, argv)
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 char **argv;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 extern char *optarg;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 extern int optind;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 int c;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 fd_set fds;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
31 while ((c = getopt(argc, argv, "bB:d:l:")) != EOF)
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 switch (c) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 case 'b':
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
34 background++;
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
35 continue;
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
36 case 'B':
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 baudrate_name = optarg;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 continue;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 case 'd':
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 target_fd = atoi(optarg);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 continue;
134
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
42 case 'l':
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
43 logfname = optarg;
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
44 continue;
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 case '?':
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 default:
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 usage: fprintf(stderr,
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
48 "usage: %s [options] ttyport\n", argv[0]);
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 exit(1);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 }
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
51 if (background && !logfname) {
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
52 fprintf(stderr, "%s: -b is meaningless without -l\n", argv[0]);
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
53 exit(1);
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
54 }
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 if (target_fd <= 0) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 if (argc - optind != 1)
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 goto usage;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 open_target_serial(argv[optind]);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 set_serial_nonblock(0);
127
f4f0c8738dcb rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 126
diff changeset
62 setlinebuf(stdout);
134
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
63 if (logfname) {
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
64 logF = fopen(logfname, "w");
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
65 if (!logF) {
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
66 perror(logfname);
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
67 exit(1);
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
68 }
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
69 fprintf(logF, "*** Log of decoded RVT output ***\n");
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
70 setlinebuf(logF);
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
71 }
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
72 if (background) {
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
73 c = fork();
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
74 if (c < 0) {
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
75 perror("fork");
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
76 exit(1);
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
77 }
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
78 if (c) {
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
79 printf("rvtdump forked into background (pid %d)\n", c);
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
80 exit(0);
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
81 }
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
82 }
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 for (;;) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 FD_ZERO(&fds);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 FD_SET(target_fd, &fds);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 c = select(target_fd+1, &fds, 0, 0, 0);
134
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
87 time(&logtime);
126
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 if (c < 0) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 if (errno == EINTR)
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 continue;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 perror("select");
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 exit(1);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 if (FD_ISSET(target_fd, &fds))
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 process_serial_rx();
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 handle_rx_packet()
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 print_rx_packet();
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 }
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
103
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
104 print_item()
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
105 {
169
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
106 if (!background)
e01e3a60c858 rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 134
diff changeset
107 printf("%s\n", pr_item);
134
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
108 if (logF)
e0d56e9be8a2 rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
109 log_item();
133
56b53c289785 rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 127
diff changeset
110 }