comparison 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
comparison
equal deleted inserted replaced
125:17c1e2a38418 126:811b138f1bed
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
12 extern int target_fd;
13 extern char *baudrate_name;
14
15 main(argc, argv)
16 char **argv;
17 {
18 extern char *optarg;
19 extern int optind;
20 int c;
21 fd_set fds;
22
23 while ((c = getopt(argc, argv, "b:d:")) != EOF)
24 switch (c) {
25 case 'b':
26 baudrate_name = optarg;
27 continue;
28 case 'd':
29 target_fd = atoi(optarg);
30 continue;
31 case '?':
32 default:
33 usage: fprintf(stderr,
34 "usage: %s [-b baudrate] ttyport\n", argv[0]);
35 exit(1);
36 }
37 if (target_fd <= 0) {
38 if (argc - optind != 1)
39 goto usage;
40 open_target_serial(argv[optind]);
41 }
42
43 set_serial_nonblock(0);
44 for (;;) {
45 FD_ZERO(&fds);
46 FD_SET(target_fd, &fds);
47 c = select(target_fd+1, &fds, 0, 0, 0);
48 if (c < 0) {
49 if (errno == EINTR)
50 continue;
51 perror("select");
52 exit(1);
53 }
54 if (FD_ISSET(target_fd, &fds))
55 process_serial_rx();
56 }
57 }
58
59 handle_rx_packet()
60 {
61 print_rx_packet();
62 }