view cmu200/main.c @ 104:7ad0495991ed

autocal: use the new ERROR_RFFAIL exit code
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Dec 2017 07:01:13 +0000
parents 348c29b7d02a
children
line wrap: on
line source

/*
 * This module contains the main() function for fc-cmu200d.
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

int target_fd;

char *bind_socket_pathname = "/tmp/fc_rftest_socket";
char *cmu200_tx_name = "TX";
int cmu200_rf_port = 2;

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

	while ((c = getopt(argc, argv, "12ac:t:")) != EOF)
		switch (c) {
		case '1':
			cmu200_rf_port = 1;
			continue;
		case '2':
			cmu200_rf_port = 2;
			continue;
		case 'a':
			cmu200_tx_name = "AUXT";
			continue;
		case 'c':
			read_cable_conf_file(optarg);
			continue;
		case 't':
			bind_socket_pathname = optarg;
			continue;
		default:
usage:			fprintf(stderr,
				"usage: %s [options] serial-port baud\n",
				argv[0]);
			exit(1);
		}
	if (argc - optind != 2)
		goto usage;

	open_target_serial(argv[optind], argv[optind+1]);
	set_serial_nonblock(0);
	setlinebuf(stdout);	/* to allow logging with tee */
	init_cmu200();
	create_listener_socket();
	signal(SIGPIPE, SIG_IGN);
	for (;;) {
		get_socket_connection();
		handle_session();
	}
}