model_wifi.cc
Go to the documentation of this file.
00001 
00002 //
00003 // File: model_wifi.cc
00004 // Authors: Benoit Morisset, Richard Vaughan
00005 // Date: 2 March 2006
00006 //
00007 // CVS info:
00008 //  $Source: /home/tcollett/stagecvs/playerstage-cvs/code/stage/libstage/model_wifi.cc,v $
00009 //  $Author: rtv $
00010 //  $Revision$
00011 //
00013 
00027 #include <sys/time.h>
00028 #include "gui.h"
00029 
00030 // Number pulled directly from my ass
00031 #define STG_WIFI_WATTS 2.5
00032 
00033 //#define DEBUG
00034 
00035 #include "stage_internal.h"
00036 
00037 // defined in model.c
00038 int _model_update( model_t* mod, void* unused );
00039 
00040 // standard callbacks
00041 extern "C" {
00042 
00043         // declare functions used as callbacks
00044         static int wifi_update( model_t* mod, void* unused );
00045         static int wifi_startup( model_t* mod, void* unused );
00046         static int wifi_shutdown( model_t* mod, void* unused );
00047         static int wifi_load( model_t* mod, void* unused );
00048 
00049         // implented by the gui in some other file
00050         void gui_wifi_init( model_t* mod );
00051 
00052 
00053         int 
00054                 wifi_init( model_t* mod )
00055                 {
00056                         // we don't consume any power until subscribed
00057                         mod->watts = 0.0;
00058 
00059                         // override the default methods; these will be called by the simualtion
00060                         // engine
00061                         model_add_callback( mod, &mod->startup, wifi_startup, NULL );
00062                         model_add_callback( mod, &mod->shutdown, wifi_shutdown, NULL );
00063                         model_add_callback( mod, &mod->load, wifi_load, NULL );
00064 
00065                         // sensible wifi defaults; it doesn't take up any physical space
00066                         Geom geom;
00067                         geom.pose.x = 0.0;
00068                         geom.pose.y = 0.0;
00069                         geom.pose.a = 0.0;
00070                         geom.size.x = 0.0;
00071                         geom.size.y = 0.0;
00072                         model_set_geom( mod, &geom );
00073 
00074                         // wifi is invisible
00075                         model_set_obstacle_return( mod, 0 );
00076                         model_set_laser_return( mod, LaserTransparent );
00077                         model_set_blob_return( mod, 0 );
00078                         model_set_color( mod, (color_t)0 );
00079 
00080                         gui_wifi_init(mod);
00081 
00082                         return 0;
00083                 }
00084 
00085         int 
00086                 wifi_update( model_t* mod, void* unused )
00087                 {   
00088                         // no work to do if we're unsubscribed
00089                         if( mod->subs < 1 )
00090                                 return 0;
00091 
00092                         puts("wifi_update");
00093 
00094                         // Retrieve current configuration
00095                         wifi_config_t cfg;
00096                         memcpy(&cfg, mod->cfg, sizeof(cfg));
00097 
00098                         // Retrieve current geometry
00099                         Geom geom;
00100                         model_get_geom( mod, &geom );
00101 
00102                         // get the sensor's pose in global coords
00103                         Pose pz;
00104                         memcpy( &pz, &geom.pose, sizeof(pz) );
00105                         model_local_to_global( mod, &pz );
00106 
00107 
00108                         // We'll store current data here
00109                         wifi_data_t data;
00110 
00111                         // DO RADIO PROPAGATION HERE, and fill in the data structure
00112 
00113                         // publish the new stuff
00114                         model_set_data( mod, &data, sizeof(data));
00115 
00116                         // inherit standard update behaviour
00117                         _model_update( mod, NULL );
00118 
00119                         return 0; //ok
00120                 }
00121 
00122         int 
00123                 wifi_startup( model_t* mod, void* unused )
00124                 { 
00125                         PRINT_DEBUG( "wifi startup" );
00126                         model_add_callback( mod, &mod->startup, wifi_startup, NULL );
00127                         model_set_watts( mod, STG_WIFI_WATTS );
00128                         return 0; // ok
00129                 }
00130 
00131         int 
00132                 wifi_shutdown( model_t* mod, void* unused )
00133                 {
00134                         PRINT_DEBUG( "wifi shutdown" );
00135                         model_remove_callback( mod, &mod->startup, wifi_startup );
00136                         model_set_watts( mod, 0 );
00137                         return 0; // ok
00138                 }
00139 
00140         int
00141                 wifi_load( model_t* mod, void* unused )
00142                 {
00143                         wifi_config_t cfg;
00144 
00145                         // TODO: read wifi params from the world file
00146 
00147                         model_set_cfg( mod, &cfg, sizeof(cfg));
00148 
00149                         return 0;
00150                 }
00151 
00152 } // ends extern "C"


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Thu Aug 27 2015 15:20:57