comparison cmu200/main.c @ 37:498b90f6e224

fc-cmu200d: added command line options
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 27 May 2017 01:58:06 +0000
parents 6d7079a81e8b
children 3ec82dc1dbda
comparison
equal deleted inserted replaced
36:d348d47f8a04 37:498b90f6e224
2 * This module contains the main() function for fc-cmu200d. 2 * This module contains the main() function for fc-cmu200d.
3 */ 3 */
4 4
5 #include <stdio.h> 5 #include <stdio.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <unistd.h>
7 8
8 int target_fd; 9 int target_fd;
9 10
10 static char default_socket_pathname[] = "/tmp/fc_rftest_socket"; 11 char *bind_socket_pathname = "/tmp/fc_rftest_socket";
11 12 char *cmu200_tx_name = "TX";
12 char *bind_socket_pathname; 13 int cmu200_rf_port = 2;
13 14
14 main(argc, argv) 15 main(argc, argv)
15 char **argv; 16 char **argv;
16 { 17 {
17 if (argc < 3 || argc > 4) { 18 extern char *optarg;
18 fprintf(stderr, 19 extern int optind;
19 "usage: %s serial-port baud [socket-pathname]\n", 20 int c;
20 argv[0]); 21
21 exit(1); 22 while ((c = getopt(argc, argv, "1at:")) != EOF)
22 } 23 switch (c) {
23 open_target_serial(argv[1], argv[2]); 24 case '1':
25 cmu200_rf_port = 1;
26 continue;
27 case 'a':
28 cmu200_tx_name = "AUXT";
29 continue;
30 case 't':
31 bind_socket_pathname = optarg;
32 continue;
33 default:
34 usage: fprintf(stderr,
35 "usage: %s [options] serial-port baud\n",
36 argv[0]);
37 exit(1);
38 }
39 if (argc - optind != 2)
40 goto usage;
41
42 open_target_serial(argv[optind], argv[optind+1]);
24 set_serial_nonblock(0); 43 set_serial_nonblock(0);
25 setlinebuf(stdout); /* to allow logging with tee */ 44 setlinebuf(stdout); /* to allow logging with tee */
26 init_cmu200(); 45 init_cmu200();
27 if (argc > 3)
28 bind_socket_pathname = argv[3];
29 else
30 bind_socket_pathname = default_socket_pathname;
31 create_listener_socket(); 46 create_listener_socket();
32 for (;;) { 47 for (;;) {
33 get_socket_connection(); 48 get_socket_connection();
34 handle_session(); 49 handle_session();
35 } 50 }