model_wifi.cc
Go to the documentation of this file.
1 //
3 // File: model_wifi.cc
4 // Authors: Benoit Morisset, Richard Vaughan
5 // Date: 2 March 2006
6 //
7 // CVS info:
8 // $Source: /home/tcollett/stagecvs/playerstage-cvs/code/stage/libstage/model_wifi.cc,v $
9 // $Author: rtv $
10 // $Revision$
11 //
13 
27 #include <sys/time.h>
28 #include "gui.h"
29 
30 // Number pulled directly from my ass
31 #define STG_WIFI_WATTS 2.5
32 
33 //#define DEBUG
34 
35 #include "stage_internal.h"
36 
37 // defined in model.c
38 int _model_update( model_t* mod, void* unused );
39 
40 // standard callbacks
41 extern "C" {
42 
43  // declare functions used as callbacks
44  static int wifi_update( model_t* mod, void* unused );
45  static int wifi_startup( model_t* mod, void* unused );
46  static int wifi_shutdown( model_t* mod, void* unused );
47  static int wifi_load( model_t* mod, void* unused );
48 
49  // implented by the gui in some other file
50  void gui_wifi_init( model_t* mod );
51 
52 
53  int
54  wifi_init( model_t* mod )
55  {
56  // we don't consume any power until subscribed
57  mod->watts = 0.0;
58 
59  // override the default methods; these will be called by the simualtion
60  // engine
61  model_add_callback( mod, &mod->startup, wifi_startup, NULL );
62  model_add_callback( mod, &mod->shutdown, wifi_shutdown, NULL );
63  model_add_callback( mod, &mod->load, wifi_load, NULL );
64 
65  // sensible wifi defaults; it doesn't take up any physical space
66  Geom geom;
67  geom.pose.x = 0.0;
68  geom.pose.y = 0.0;
69  geom.pose.a = 0.0;
70  geom.size.x = 0.0;
71  geom.size.y = 0.0;
72  model_set_geom( mod, &geom );
73 
74  // wifi is invisible
75  model_set_obstacle_return( mod, 0 );
76  model_set_laser_return( mod, LaserTransparent );
77  model_set_blob_return( mod, 0 );
78  model_set_color( mod, (color_t)0 );
79 
80  gui_wifi_init(mod);
81 
82  return 0;
83  }
84 
85  int
86  wifi_update( model_t* mod, void* unused )
87  {
88  // no work to do if we're unsubscribed
89  if( mod->subs < 1 )
90  return 0;
91 
92  puts("wifi_update");
93 
94  // Retrieve current configuration
95  wifi_config_t cfg;
96  memcpy(&cfg, mod->cfg, sizeof(cfg));
97 
98  // Retrieve current geometry
99  Geom geom;
100  model_get_geom( mod, &geom );
101 
102  // get the sensor's pose in global coords
103  Pose pz;
104  memcpy( &pz, &geom.pose, sizeof(pz) );
105  model_local_to_global( mod, &pz );
106 
107 
108  // We'll store current data here
109  wifi_data_t data;
110 
111  // DO RADIO PROPAGATION HERE, and fill in the data structure
112 
113  // publish the new stuff
114  model_set_data( mod, &data, sizeof(data));
115 
116  // inherit standard update behaviour
117  _model_update( mod, NULL );
118 
119  return 0; //ok
120  }
121 
122  int
123  wifi_startup( model_t* mod, void* unused )
124  {
125  PRINT_DEBUG( "wifi startup" );
126  model_add_callback( mod, &mod->startup, wifi_startup, NULL );
127  model_set_watts( mod, STG_WIFI_WATTS );
128  return 0; // ok
129  }
130 
131  int
132  wifi_shutdown( model_t* mod, void* unused )
133  {
134  PRINT_DEBUG( "wifi shutdown" );
135  model_remove_callback( mod, &mod->startup, wifi_startup );
136  model_set_watts( mod, 0 );
137  return 0; // ok
138  }
139 
140  int
141  wifi_load( model_t* mod, void* unused )
142  {
143  wifi_config_t cfg;
144 
145  // TODO: read wifi params from the world file
146 
147  model_set_cfg( mod, &cfg, sizeof(cfg));
148 
149  return 0;
150  }
151 
152 } // ends extern "C"
static int wifi_load(model_t *mod, void *unused)
Definition: model_wifi.cc:141
int wifi_init(model_t *mod)
Definition: model_wifi.cc:54
#define STG_WIFI_WATTS
Definition: model_wifi.cc:31
static int wifi_update(model_t *mod, void *unused)
Definition: model_wifi.cc:86
static int wifi_startup(model_t *mod, void *unused)
Definition: model_wifi.cc:123
static int wifi_shutdown(model_t *mod, void *unused)
Definition: model_wifi.cc:132
void gui_wifi_init(model_t *mod)
int _model_update(model_t *mod, void *unused)
#define PRINT_DEBUG(m)
Definition: stage.hh:666


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 Mon Jun 10 2019 15:06:09