Code Search for Developers
 
 
  

as-with-ta.cc from EmStar at Krugle


Show as-with-ta.cc syntax highlighted

/*
 *
 * Copyright (c) 2003 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 "devel/as-emstar/ds.h"
__BEGIN_DECLS
#include <libdev/include/query_client.h>
#include <libdev/include/query_dev.h>
#include <motors/motor_nims.h>
#include "sensor_nims.h"
__END_DECLS

#include "sensor_state.h"
#include  "tcp_socket.h"

buf_t *log_buf=NULL;

void ms_client_usage(char *n)
{
    fprintf(stderr, "%s -d <motor device name> <motor command name>\n", n);
    exit(1);
}

void as_usage(query_context_t *q, buf_t *buf)
{
	  bufprintf(buf, "command to move motor to a position (m, n) is move:x=m:y=n\n");
}

int main(int argc, char **argv)
{

  /* 
   * check options
   */
  int	index = 0;
  float   tmp_f[4], dx, dy;
  char  * tmp_p;

  Adaptive_Sampling  *as = new  Adaptive_Sampling;
  as->field = new  Field;

  memset( as->field, 0, sizeof(Field) );

  int c;
  int option_index = 0;
  static struct option long_options[] = {
      {"dimension", 0, 0, 'd'},
      {"watch", 0, 0, 'w'},
      {"binary", 0, 0, 'b'},
      {"command", 0, 0, 'c'},
      {"pixel-resolution", 0, 0, 'p'},
      {"vga", 0, 0, 'g'},
      {0, 0, 0, 0}
    };
    
  as->field->VGA_mode = false;
  char *key;

  if ((key = misc_parse_out_option(&argc, argv, "help", 'h'))) {
     ms_client_usage(argv[0]);
  }

  if ((key = misc_parse_out_option(&argc, argv, "verbose", 'v'))) {
  	as->set_verbose( true );
  }

  if ((key = misc_parse_out_option(&argc, argv, "migrate", 'm'))) {
	fprintf( stderr, "migrate %s\n", key );

	if  ( ( key[0] == 'y') || ( key[0] == 'Y') )
		as->migrate_samples = true;
	else        as->migrate_samples = false;
  }
	  
/*
  if ((key = misc_parse_out_option(&argc, argv, "dimension", 'd'))) {
  }
*/

  if ((key = misc_parse_out_option(&argc, argv, "low-resolution-threshold", 'r'))) {
	fprintf( stderr, "-resolution threshold: %s\n", key );
	as->set_low_res_thre( atoi(key) );
  }

  if ((key = misc_parse_out_option(&argc, argv, "alpha", 'a'))) {
	  fprintf( stderr, "-alpha: %s\n", key );
	  as->set_alpha( atof( key ) );
  }

  if ((key = misc_parse_out_option(&argc, argv, "variance-threshold", 't'))) {
	  fprintf( stderr, "-variance threshold: %s\n", key );
	  as->set_variance_thre( atof(key) );
  }

  if ((key = misc_parse_out_option(&argc, argv, "sample-file-name", 's'))) {
	  fprintf(stderr, "-sample log file name: %s\n", key);
	  as->sample_fname = key;
  }

  if ((key = misc_parse_out_option(&argc, argv, "sensor-device", 'e'))) {
	  fprintf(stderr, "-sensor device name: %s\n", key);
	  strcpy(as->sensor_device_name, key);
  }

  if ((key = misc_parse_out_option(&argc, argv, "matlab-ip", 'l'))) {
	  fprintf(stderr, "matlab IP: %s\n", key);
	  strcpy(as->matlab_ip, key);
  }

  while (1) {

    c = getopt_long (argc, argv, "h?dwcbvmpgtras",
		     long_options, &option_index);
    if (c == -1)
      break;

    switch (c) {

      case 'd':
	//get dimension information
	  index = optind ;
	  fprintf( stderr, "-d: %s, %s\n", argv[index], argv[index+1] );
	  for  (int i=0; i< 4; i++ )
	  {
		tmp_p = argv[ index ];
		index ++;
		tmp_f[i] = atof( tmp_p );
	  }

	  as->field->SetWorldCoord(tmp_f[0], tmp_f[1], tmp_f[2], tmp_f[3]);
	  break;


      case 'g':
	  index = optind ;
	  fprintf( stderr, "-g: %s, %s\n", argv[index], argv[index+1] );
	  for  (int i=0; i< 4; i++ )
	  {
		tmp_p = argv[ index ];
		index ++;
		tmp_f[i] = atof( tmp_p );
	  }

	  as->field->SetVGACoord(tmp_f[0], tmp_f[1], tmp_f[2], tmp_f[3]);
	  break;

      case 'p':
	  index = optind;
	  fprintf( stderr, "-pixel size: %s, %s\n", argv[index], argv[index+1] );
	  for  (int i=0; i< 2; i++ )
	  {
	      tmp_p = argv[ index ];
	      index ++;
	      tmp_f[i] = atof( tmp_p );
	  }
	  
	  dx = tmp_f[0];
	  dy = tmp_f[1];
	  
	  break;

      default:
	  abort();

    }
  }

elog(LOG_ERR, "After processing\n" );

  if  ( as->verbose() )
	fprintf( stderr, "%d %f %f %f %f %f %f \n", as->migrate_samples, as->field->world_upper_left.x, as->field->world_upper_left.y, as->field->world_lower_right.x, as->field->world_lower_right.y, dx, dy);

  //convert the dimension of the field (<fx1,fy1>, <fx2, fy2>) to
  //pixels.
  as->field->set_pixel_size( dx, dy );

  query_client_opts_t opts = { };
  opts.device = NIMS_MOTOR_CONTROLLER_DEV;
  as->motor_opts = & opts; 

  {
  query_dev_opts_t qdev_opts = {};
  
  qdev_opts.device.devname= NIMS_AS_CONTROLLER_DEV;
  qdev_opts.device.device_info=  as;

  qdev_opts.usage = as_usage;
  qdev_opts.process = as_process;

  if (query_dev_new(&qdev_opts, &(as->query_ctx_ref) ) < 0)
	elog( LOG_ERR, "unable to create query device for AS\n");
  }

  {
    status_dev_opts_t s_opts = {};
    s_opts.device.devname = NIMS_AS_STATUS_DEV;
    s_opts.device.device_info = as;
    s_opts.printable = as_status_print;
    s_opts.binary = as_status_binary;

    if (g_status_dev(&s_opts, &(as->status_ref)) < 0) {
	elog(LOG_CRIT, "Unable to create status device: %m");
	exit(1);
    }
  }

  g_main();
  
  return 0;
}






See more files for this project here

EmStar

EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.

Project homepage: http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other

  as-misc.cc
  as-restart.cc
  as-with-ta.cc
  as.cc
  as_process.cc
  move_n_sample.cc
  sim_sensor_client.cc
  socket_server.cc
  tcp_client.cc
  tcp_func.c