FreeCalypso > hg > freecalypso-sw
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/rvtdump.c Thu Oct 31 19:59:16 2013 +0000 @@ -0,0 +1,62 @@ +/* + * This program reads bytes from a serial port, parses them assuming + * TI's RVT MUX format, and prints every decoded packet. + */ + +#include <sys/types.h> +#include <sys/errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +extern int target_fd; +extern char *baudrate_name; + +main(argc, argv) + char **argv; +{ + extern char *optarg; + extern int optind; + int c; + fd_set fds; + + while ((c = getopt(argc, argv, "b:d:")) != EOF) + switch (c) { + case 'b': + baudrate_name = optarg; + continue; + case 'd': + target_fd = atoi(optarg); + continue; + case '?': + default: +usage: fprintf(stderr, + "usage: %s [-b baudrate] ttyport\n", argv[0]); + exit(1); + } + if (target_fd <= 0) { + if (argc - optind != 1) + goto usage; + open_target_serial(argv[optind]); + } + + set_serial_nonblock(0); + for (;;) { + FD_ZERO(&fds); + FD_SET(target_fd, &fds); + c = select(target_fd+1, &fds, 0, 0, 0); + if (c < 0) { + if (errno == EINTR) + continue; + perror("select"); + exit(1); + } + if (FD_ISSET(target_fd, &fds)) + process_serial_rx(); + } +} + +handle_rx_packet() +{ + print_rx_packet(); +}