view rvinterf/rvtdump.c @ 157:e48ea5875df7

gsm-fw: SPI task code compiles and links
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 17 Nov 2013 09:17:06 +0000
parents e0d56e9be8a2
children e01e3a60c858
line wrap: on
line source

/*
 * 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>
#include <time.h>

extern int target_fd;
extern char *baudrate_name;

extern char pr_item[];

char *logfname;
FILE *logF;
time_t logtime;

main(argc, argv)
	char **argv;
{
	extern char *optarg;
	extern int optind;
	int c;
	fd_set fds;

	while ((c = getopt(argc, argv, "b:d:l:")) != EOF)
		switch (c) {
		case 'b':
			baudrate_name = optarg;
			continue;
		case 'd':
			target_fd = atoi(optarg);
			continue;
		case 'l':
			logfname = 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);
	setlinebuf(stdout);
	if (logfname) {
		logF = fopen(logfname, "w");
		if (!logF) {
			perror(logfname);
			exit(1);
		}
		fprintf(logF, "*** Log of decoded RVT output ***\n");
		setlinebuf(logF);
	}
	for (;;) {
		FD_ZERO(&fds);
		FD_SET(target_fd, &fds);
		c = select(target_fd+1, &fds, 0, 0, 0);
		time(&logtime);
		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();
}

print_item()
{
	printf("%s\n", pr_item);
	if (logF)
		log_item();
}