Code Search for Developers
 
 
  

as.cc from EmStar at Krugle


Show as.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.
 *
 */
 


/*
 *  simple example of using a motor device
 */

#include "devel/as-emstar/ds.h"
__BEGIN_DECLS
#include <libdev/include/query_client.h>
#include <motors/motor_nims.h>
#include "sensor_nims.h"
__END_DECLS

#include "sensor_state.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);
}


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

	fprintf( stderr, "IN AS\n" );
	fflush( stderr );
//exit(-1);

elog(LOG_ERR, "IN AS\n" );
  /* 
   * check options
   */
  int	index = 0;
  char  cc;
  float   tmp_f[4], dx, dy;
  char  * tmp_p;

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

  int c;
  int option_index = 0;
  static struct option long_options[] = {
      {"help", 0, 0, 'h'},
      {"dimension", 0, 0, 'd'},
      {"watch", 0, 0, 'w'},
      {"binary", 0, 0, 'b'},
      {"verbose", 0, 0, 'v'},
      {"migrate", 0, 0, 'm'},
      {"command", 0, 0, 'c'},
      {"pixel-resolution", 0, 0, 'p'},
      {"vga", 0, 0, 'g'},
      {"low resolution threshold", 0, 0, 'r'},
      {"variance threshold", 0, 0, 't'},
      {"alpha", 0, 0, 'a'},
      {"sample-file-name", 0, 0, 's'},
      {0, 0, 0, 0}
    };
    
  as->field->VGA_mode = false;
	  
  while (1) {

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

    switch (c) {
      case '?':
      case 'h':
      	  ms_client_usage(argv[0]);
          break;

      case 'v':
	  as->set_verbose( true );
	  break;

      case 'm':
	  index = optind;

	  fprintf( stderr, "%s\n", argv[index] );

	  cc = * argv[index];

	  if  ( ( cc == 'y') || ( cc == 'Y') )
		as->migrate_samples = true;
	  else        as->migrate_samples = false;
	  break;

      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, "-s: %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;

      case 'r':
	  index = optind;
	  fprintf( stderr, "-resolution threshold: %s\n", argv[index] );
	  tmp_p = argv[ index ];
	  index ++;
	  as->set_low_res_thre( atoi( tmp_p ) );
	  
	  break;

      case 'a':
	  index = optind;
	  fprintf( stderr, "-alpha: %s\n", argv[index] );
	  tmp_p = argv[ index ];
	  index ++;
	  as->set_alpha( atof( tmp_p ) );
	  
	  break;

      case 't':
	  index = optind;
	  fprintf( stderr, "-variance threshold: %s\n", argv[index] );
	  tmp_p = argv[ index ];
	  index ++;
	  as->set_variance_thre( atof( tmp_p ) );
	  
	  break;

      case 's':
	  index = optind;
	  fprintf( stderr, "-sample log file name: %s\n", argv[index] );
	  as->sample_fname = argv[ index ];
	  
	  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; 

  as_misc_init( as );

elog( LOG_ERR, "Before send the 1st REC to matlab\n" );

  //send the initial rectangle to the Matlab..
  send_rec_to_matlab(as, as->field->pixel_upper_left, as->field->pixel_lower_right);

elog( LOG_ERR, "After send the 1st REC to matlab\n" );

  as_prepare_samples( as );
  
  if  ( ! as->sample_list.empty() )
	take_first_sample( as, &(as->sample_list) );

  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