Show as-restart.cc syntax highlighted
/* ex: set tabstop=4 expandtab shiftwidth=4 softtabstop=4: */
/*
*
* 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"
#undef OPEN_NEW_LOG_FOR_EACH_SCAN
void as_free_all( Adaptive_Sampling *as )
{
//release memory starting from root
//then release memory for those list..
//FIXME:check STL .clear(), see if it release memory for each object.
//check push_back to make sure there is no loose pointer floating around
//check _new_, to make sure each _new_ will correspond to some memory deallocation function, free or delete
//
if ( as->root != NULL )
free_tree( as->root );
free_samples( &(as->sample_list) );
as->cur_sp = NULL;
as->root = NULL;
as->stratum_node_work_queue.clear();
as->stratum_node_cur_queue.clear();
#ifdef OPEN_NEW_LOG_FOR_EACH_SCAN
if ( as->sd() > -1 )
close(as->sd());
if ( as->sample_fd() != NULL )
fclose(as->sample_fd());
#endif
//send refresh frame msg to Matlab
send_cmd_to_matlab(as, REFRESH);
}
void as_restart_misc_init(Adaptive_Sampling *as)
{
//create the root node
as->root = new Stratum_Node(as->field->pixel_upper_left.x, as->field->pixel_upper_left.y, as->field->pixel_lower_right.x, as->field->pixel_lower_right.y, NULL, 0 );
as->stratum_node_work_queue.push_back( as->root );
//use the same sample file, and same connection to Matlab. so donot open new ones here..
//O/w need to open new Matlab connection, and new file to save samples see as_misc_init()
//FIXME: Need to refresh Matlab
//Send a special graph refresh command to Matlab.
//In matlab, do _hold off_, so start a new graph, instead of drawing on the old one..
//send the root bounding box to matlab.
send_rec_to_matlab(as, as->root->upper_left, as->root->lower_right);
}
//if the target region is too small relative to the sampling density, return -1
//o/w return 0;
int as_restart_prep(Adaptive_Sampling *as, loc_world upper_l, loc_world lower_r)
{
//set current position
//as->pos.x = cur_pos.x;
//as->pos.y = cur_pos.y;
// command_motor(as, cur_pos, MOTOR_POS );
//set field to scan
as->field->SetWorldCoord( upper_l.x, upper_l.y, lower_r.x, lower_r.y );
as->field->set_pixel_size(as->field->pixel_size_x, as->field->pixel_size_y);
//free all memory in as;
//release memory starting from root
as_free_all( as );
as_misc_init(as);
fprintf( as->sample_fd(), "Samples\n" );
elog( LOG_ERR, "before PREP samples\n" );
as_prepare_samples( as );
elog( LOG_ERR, "after PREP samples\n" );
if ( ! as->sample_list.empty() )
{
take_first_sample( as, &(as->sample_list) );
return 0;
} else {
return -1;
}
}
void free_samples(Samples *list)
{
Sample * s_p;
if (list == NULL)
return;
for (unsigned int i=0; i< list->size(); i++)
{
s_p = (*list)[i];
if ( s_p != NULL )
delete s_p;
}
list->clear();
// delete list;
}
void free_tree(Stratum_Node * t)
{
if ( t == NULL )
return;
//free the space for Samples
free_samples( t->samples );
delete t->samples;
t->samples = NULL;
if ( t->child[0] != NULL )
{
for (unsigned int i=0; i< MAX_CHILDREN; i++)
{
free_tree(t->child[i] );
}
} else {
//if this node is a leaf node, delete it;
delete t;
}
}
See more files for this project here
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