annotate rvinterf/rvtdump.c @ 126:811b138f1bed

rvtdump utility written, compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 31 Oct 2013 19:59:16 +0000
parents
children f4f0c8738dcb
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>
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 extern int target_fd;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 extern char *baudrate_name;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 main(argc, argv)
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 char **argv;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 extern char *optarg;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 extern int optind;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 int c;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 fd_set fds;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 while ((c = getopt(argc, argv, "b:d:")) != EOF)
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 switch (c) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 case 'b':
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 baudrate_name = optarg;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 continue;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 case 'd':
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 target_fd = atoi(optarg);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 continue;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 case '?':
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 default:
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 usage: fprintf(stderr,
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 "usage: %s [-b baudrate] ttyport\n", argv[0]);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 exit(1);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 if (target_fd <= 0) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 if (argc - optind != 1)
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 goto usage;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 open_target_serial(argv[optind]);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 set_serial_nonblock(0);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 for (;;) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 FD_ZERO(&fds);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 FD_SET(target_fd, &fds);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 c = select(target_fd+1, &fds, 0, 0, 0);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 if (c < 0) {
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 if (errno == EINTR)
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 continue;
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 perror("select");
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 exit(1);
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 if (FD_ISSET(target_fd, &fds))
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 process_serial_rx();
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 }
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 handle_rx_packet()
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 print_rx_packet();
811b138f1bed rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 }