1 /*
2 *
3 * Copyright (c) 2005 The Regents of the University of California. All
4 * rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * - Neither the name of the University nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30
31 #include <ar.h>
32 #include <emrun/emrun.h>
33
34 /*
35 * ar_main
36 *
37 * acoustic ranging module
38 */
39
40
41 void usage(char *name)
42 {
43 misc_print_usage
44 (name,
45 "",
46 " --log-ar-details <logfile>: saves trace of ranging experiments\n"
47 " Format must be %%d, for nodeid\n"
48 " e.g. /mnt/nfs/expt1/details-%%d\n"
49 " --log-raw <logfile>: format string to save raw dumps\n"
50 " Format must be %%d %%s %%d, for chirp-index, notation, nodeid\n"
51 " e.g. /mnt/nfs/expt1/raw-%%d-%%s-%%d\n"
52 " --raw-text: Save raw data as text files\n"
53 " --array <orig,8cm,12cm> Select array type (12cm default)\n"
54 );
55 exit(1);
56 }
57
58 void ar_shutdown(void *data)
59 {
60 //ar_state_t *ar = (ar_state_t *)data;
61 elog(LOG_NOTICE, "Shutting down ar service");
62 exit(0);
63 }
64
65
66 ar_state_t _ar = {
67 flood_interface: "flood",
68 sensor_interface: "vxp",
69 sound_dev: "hw:%d,%d",
70 curr_temperature: 20,
71 curr_RH: 10,
72 gpio_channel: -1,
73 use_first_swing: 1,
74 simple_selfrange: 1
75 };
76
77 int main(int argc, char **argv)
78 {
79 /* generic init */
80 misc_init(&argc, argv, CVSTAG);
81
82 _ar.send_index = random();
83
84 if (misc_parse_out_switch(&argc, argv, "help", 'h'))
85 usage(argv[0]);
86
87 char *array = misc_parse_out_option(&argc, argv, "array", 0);
88 if (ar_update_array_spec(&_ar, array ? array : "12cm") < 0) {
89 usage(argv[0]);
90 }
91
92 /* parse ard log option */
93 _ar.ar_log_file = misc_parse_out_option(&argc, argv, "log-ar-details", 0);
94 _ar.ar_log_raw = misc_parse_out_option(&argc, argv, "log-raw", 0);
95 _ar.raw_as_text = misc_parse_out_switch(&argc, argv, "raw-text", 0);
96 _ar.log_timestamps = misc_parse_out_switch(&argc, argv, "logstamps", 0);
97
98 /* parse platform */
99 _ar.platform = misc_parse_out_option(&argc, argv, "platform", 0);
100 misc_parse_option_as_int(&argc, argv, "gpio-channel", 0, &(_ar.gpio_channel));
101
102 /* parse ard log option */
103 _ar.dump_files_ctrl_string = misc_parse_out_option(&argc, argv, "dump-files", 0);
104
105 /* parse measurement opts */
106 ssync_parse_measurement_opts(&argc, argv);
107
108 /* card index */
109 misc_parse_option_as_uint(&argc, argv, "card_index", 0, &(_ar.card_index));
110
111 /* init the different devices and modules */
112 ar_send_init(&_ar);
113 ar_thread_init(&_ar);
114 ar_net_init(&_ar);
115 ar_table_init(&_ar);
116
117 if (misc_args_remain(&argc, argv))
118 usage(argv[0]);
119
120 /* init connection to timesync */
121 sync_event_init();
122
123 emrun_opts_t emrun_opts = {
124 shutdown: ar_shutdown,
125 data: &_ar
126 };
127 emrun_init(&emrun_opts); /* this init should be done last */
128
129 /* run */
130 elog_g(LOG_INFO, "Acoustic Ranging Service starting...");
131
132 g_main();
133 return 0;
134 }
135
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.