Code Search for Developers
 
 
  

data_replay_misc.cc from EmStar at Krugle


Show data_replay_misc.cc syntax highlighted

//header file for data structure 
//

#include   "stdio.h"
#include   "stdlib.h"
#include   "string.h"
#include   "ctype.h"
#include   <unistd.h>

#include "math.h"
#include "vector"
using namespace std;

#include  "algorithm"
#define   BUFSIZE	5000

__BEGIN_DECLS
#include   "data_replay.h"
__END_DECLS

typedef	  vector<int>  IntVector;
typedef   vector<DataItem *> DataVector;

void * read_input(char *fname)
{
    FILE  * f_input;
    char   buf[BUFSIZE];
    float	d_tmp, d_x, d_y;
    DataVector  * datalist = new DataVector;

    DataItem * cur_node;
    f_input = fopen( fname, "r" );
    if  ( f_input == NULL )
    {
 	fprintf( stderr, "open file read error\n" );
	exit( 1 );
    }

    while  ( fgets( buf, BUFSIZE, f_input ) != NULL )
    {
	if ( sscanf( buf, "%f %f %f", &d_x, &d_y, &d_tmp ) == 3 )
	{
	    cur_node = new  DataItem;
       	    cur_node->x = d_x;
	    cur_node->y = d_y;
	    cur_node->val = d_tmp;

	    datalist->push_back(cur_node);
  	}
    }

    return  datalist;
}


Sample_Type  value_at_loc(void * datalist, loc_world pos )
{
    DataVector * data_list = (DataVector *) datalist;
    DataItem  * data;
    float   minx, miny, dx, dy, index_x, index_y;
    loc_world   loc_nearest;
    
    minx = MAX_INT;
    miny = MAX_INT;
    
    
    for ( unsigned int i=0; i< data_list->size(); i++ )
    {
	data = (* data_list)[i];
     	
	if  ( (data->x == pos.x) && (data->y == pos.y) )
	    return  data->val;
	
	dx = fabs(data->x - pos.x);
	dy = fabs(data->y - pos.y);
	
	if  ( (dx + dy) < (minx + miny) )
	{
	    minx = dx;
	    index_x = data->x;
	    miny = dy;
	    index_y = data->y;
	}
	
    }

    if  ( (minx < MAX_INT) && (miny < MAX_INT) )
    {
	loc_nearest.x = index_x;
	loc_nearest.y = index_y;
    
	return  ( value_at_loc(data_list, loc_nearest ) );
    }	    

    return  INVALID_VALUE;
}




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

  README
  data_replay.c
  data_replay_misc.cc
  mote_packet.c
  motor_command.c
  motor_sensor_dev.c
  sim_motor_nims.h
  sim_sensor_nims.h