228
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <sys/errno.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <stdio.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <stdlib.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <unistd.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <rvinterf/exitcodes.h>
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 char *socket_pathname = "/tmp/rvinterf_socket";
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 int sock;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 int adccal_a, adccal_b;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 main(argc, argv)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 char **argv;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern int optind;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern char *optarg;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 int c, sopt = 0;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 fd_set fds;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 while ((c = getopt(argc, argv, "s:")) != EOF)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 switch (c) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 case 's':
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 socket_pathname = optarg;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 sopt++;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 continue;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 case '?':
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 default:
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 /* error msg already printed */
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 exit(ERROR_USAGE);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (argc != optind + 2) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 fprintf(stderr, "usage: %s adccal-a adccal-b\n", argv[0]);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 exit(ERROR_USAGE);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 adccal_a = atoi(argv[optind]);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 adccal_b = atoi(argv[optind+1]);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 connect_local_socket();
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 init();
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 for (;;) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 FD_ZERO(&fds);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 FD_SET(sock, &fds);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 c = select(sock+1, &fds, 0, 0, 0);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (c < 0) {
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (errno == EINTR)
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 continue;
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 perror("select");
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(ERROR_UNIX);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (FD_ISSET(sock, &fds))
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 handle_rvinterf_input();
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 fflush(stdout);
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 }
|
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 }
|