(file) Return to ar_main.c CVS log (file) Jump to this file's LXR Page (dir) Up to [CENS] / emstar / devel / loc / ar

File: [CENS] / emstar / devel / loc / ar / ar_main.c (download) / (as text)
Revision: 1.16, Thu Nov 30 02:09:36 2006 UTC (2 years, 11 months ago) by girod
Branch: MAIN
CVS Tags: pregeonet, PRE_TOSNIC_FIX, PRE_64BIT, HEAD, CYCLOPS_RELEASE_CANDIDATE_2_0, CYCLOPS_PRERELEASE_STABLE, CENTROUTE_EMSTAR_SOCKETS, AMARSS_JR_DEPLOYMENT_6_05_07
Changes since 1.15: +2 -2 lines
lots of changes for v2 boxes.

/*
 *
 * Copyright (c) 2005 The Regents of the University of California.  All 
 * rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Neither the name of the University nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include <ar.h>
#include <emrun/emrun.h>

/*
 * ar_main
 *
 * acoustic ranging module
 */


void usage(char *name)
{
  misc_print_usage
    (name, 
     "",
     "  --log-ar-details <logfile>:  saves trace of ranging experiments\n"
     "                               Format must be %%d, for nodeid\n"
     "                               e.g.  /mnt/nfs/expt1/details-%%d\n"
     "  --log-raw <logfile>:         format string to save raw dumps\n"
     "                               Format must be %%d %%s %%d, for chirp-index, notation, nodeid\n"
     "                               e.g.  /mnt/nfs/expt1/raw-%%d-%%s-%%d\n"
     "  --raw-text:                  Save raw data as text files\n"
     "  --array <orig,8cm,12cm>      Select array type (12cm default)\n"
     );
  exit(1);
}

void ar_shutdown(void *data)
{
  //ar_state_t *ar = (ar_state_t *)data;
  elog(LOG_NOTICE, "Shutting down ar service");
  exit(0);
}


ar_state_t _ar = {
  flood_interface: "flood",
  sensor_interface: "vxp",
  sound_dev: "hw:%d,%d",
  curr_temperature: 20,
  curr_RH: 10,
  gpio_channel: -1,
  use_first_swing: 1,
  simple_selfrange: 1
};

int main(int argc, char **argv)
{
  /* generic init */
  misc_init(&argc, argv, CVSTAG);

  _ar.send_index = random();

  if (misc_parse_out_switch(&argc, argv, "help", 'h'))
    usage(argv[0]);

  char *array = misc_parse_out_option(&argc, argv, "array", 0);
  if (ar_update_array_spec(&_ar, array ? array : "12cm") < 0) {
    usage(argv[0]);
  }

  /* parse ard log option */
  _ar.ar_log_file = misc_parse_out_option(&argc, argv, "log-ar-details", 0);
  _ar.ar_log_raw = misc_parse_out_option(&argc, argv, "log-raw", 0);
  _ar.raw_as_text = misc_parse_out_switch(&argc, argv, "raw-text", 0);
  _ar.log_timestamps = misc_parse_out_switch(&argc, argv, "logstamps", 0);

  /* parse platform */
  _ar.platform = misc_parse_out_option(&argc, argv, "platform", 0);
  misc_parse_option_as_int(&argc, argv, "gpio-channel", 0, &(_ar.gpio_channel));
  
  /* parse ard log option */
  _ar.dump_files_ctrl_string = misc_parse_out_option(&argc, argv, "dump-files", 0);

  /* parse measurement opts */
  ssync_parse_measurement_opts(&argc, argv);

  /* card index */
  misc_parse_option_as_uint(&argc, argv, "card_index", 0, &(_ar.card_index));

  /* init the different devices and modules */
  ar_send_init(&_ar);
  ar_thread_init(&_ar);
  ar_net_init(&_ar); 
  ar_table_init(&_ar); 

  if (misc_args_remain(&argc, argv))
    usage(argv[0]);

  /* init connection to timesync */
  sync_event_init();

  emrun_opts_t emrun_opts = {
    shutdown: ar_shutdown,
    data: &_ar
  };
  emrun_init(&emrun_opts); /* this init should be done last */
    
  /* run */
  elog_g(LOG_INFO, "Acoustic Ranging Service starting...");
  
  g_main();
  return 0;
}

CENS CVS Mailing List
Powered by
ViewCVS 0.9.2