00001 #ifndef _STAGE_PLAYER_DRIVER_H
00002 #define _STAGE_PLAYER_DRIVER_H
00003
00004 #include <unistd.h>
00005 #include <string.h>
00006 #include <math.h>
00007
00008 #include <libplayercore/playercore.h>
00009
00010 #include "../libstage/stage_internal.hh"
00011
00012 #define DRIVER_ERROR(X) printf( "Stage driver error: %s\n", X )
00013
00014
00015 class Interface;
00016 class StgTime;
00017
00018 class StgDriver : public Driver
00019 {
00020 public:
00021
00022 StgDriver(ConfigFile* cf, int section);
00023
00024
00025 ~StgDriver(void);
00026
00027
00028 virtual int Setup();
00029 virtual int Shutdown();
00030 virtual int ProcessMessage(QueuePointer &resp_queue,
00031 player_msghdr * hdr,
00032 void * data);
00033 virtual int Subscribe(player_devaddr_t addr);
00034 virtual int Unsubscribe(player_devaddr_t addr);
00035
00038 virtual void Update();
00039
00041 static StgWorld* world;
00042
00044 Interface* LookupDevice( player_devaddr_t addr );
00045
00046 StgModel* LocateModel( char* basename,
00047 player_devaddr_t* addr,
00048 char* typestr);
00049
00050 protected:
00051
00053 GPtrArray* devices;
00054 };
00055
00056
00057 class Interface
00058 {
00059 public:
00060 Interface(player_devaddr_t addr,
00061 StgDriver* driver,
00062 ConfigFile* cf,
00063 int section );
00064
00065 virtual ~Interface( void ){ };
00066
00067 player_devaddr_t addr;
00068 double last_publish_time;
00069 double publish_interval_msec;
00070
00071 StgDriver* driver;
00072
00073 virtual int ProcessMessage(QueuePointer &resp_queue,
00074 player_msghdr_t* hdr,
00075 void* data) { return(-1); }
00076
00077 virtual void Publish( void ){};
00078 virtual void Subscribe( void ){};
00079 virtual void Unsubscribe( void ){};
00080 };
00081
00082
00083 class InterfaceSimulation : public Interface
00084 {
00085 public:
00086 InterfaceSimulation( player_devaddr_t addr, StgDriver* driver,ConfigFile* cf, int section );
00087 virtual ~InterfaceSimulation( void ){ };
00088 virtual int ProcessMessage(QueuePointer & resp_queue,
00089 player_msghdr_t* hdr,
00090 void* data);
00091 };
00092
00093
00094 class InterfaceModel
00095
00096 : public Interface
00097 {
00098 public:
00099 InterfaceModel( player_devaddr_t addr,
00100 StgDriver* driver,
00101 ConfigFile* cf,
00102 int section,
00103 char* typestr );
00104
00105 StgModel* mod;
00106
00107 virtual ~InterfaceModel( void ){ };
00108
00109 virtual void Subscribe( void ){ this->mod->Subscribe(); };
00110 virtual void Unsubscribe( void ){ this->mod->Unsubscribe(); };
00111 };
00112
00113
00114 class InterfacePosition : public InterfaceModel
00115 {
00116 public:
00117 InterfacePosition( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00118 virtual ~InterfacePosition( void ){ };
00119 virtual void Publish( void );
00120 virtual int ProcessMessage(QueuePointer & resp_queue,
00121 player_msghdr_t* hdr,
00122 void* data);
00123 };
00124
00125 class InterfaceGripper : public InterfaceModel
00126 {
00127 public:
00128 InterfaceGripper( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00129 virtual ~InterfaceGripper( void ){ };
00130 virtual int ProcessMessage(QueuePointer & resp_queue,
00131 player_msghdr_t* hdr,
00132 void* data);
00133 virtual void Publish( void );
00134 };
00135
00136 class InterfaceWifi : public InterfaceModel
00137 {
00138 public:
00139 InterfaceWifi( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00140 virtual ~InterfaceWifi( void ){ };
00141 virtual int ProcessMessage(QueuePointer & resp_queue,
00142 player_msghdr_t* hdr,
00143 void* data);
00144 virtual void Publish( void );
00145 };
00146
00147 class InterfaceSpeech : public InterfaceModel
00148 {
00149 public:
00150 InterfaceSpeech( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00151 virtual ~InterfaceSpeech( void ){ };
00152 virtual int ProcessMessage(QueuePointer & resp_queue,
00153 player_msghdr_t* hdr,
00154 void* data);
00155 virtual void Publish( void );
00156 };
00157
00158 class InterfaceLaser : public InterfaceModel
00159 {
00160 private:
00161 int scan_id;
00162 public:
00163 InterfaceLaser( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00164 virtual ~InterfaceLaser( void ){ };
00165 virtual int ProcessMessage(QueuePointer & resp_queue,
00166 player_msghdr_t* hdr,
00167 void* data);
00168 virtual void Publish( void );
00169 };
00170
00171 class InterfacePower : public InterfaceModel
00172 {
00173 public:
00174 InterfacePower( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00175 virtual ~InterfacePower( void ){ };
00176
00177 virtual int ProcessMessage( QueuePointer & resp_queue,
00178 player_msghdr * hdr,
00179 void * data );
00180
00181 virtual void Publish( void );
00182 };
00183
00184 class InterfaceFiducial : public InterfaceModel
00185 {
00186 public:
00187 InterfaceFiducial( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00188 virtual ~InterfaceFiducial( void ){ };
00189
00190 virtual void Publish( void );
00191 virtual int ProcessMessage(QueuePointer & resp_queue,
00192 player_msghdr_t* hdr,
00193 void* data);
00194 };
00195
00196
00197 class InterfaceBlobfinder : public InterfaceModel
00198 {
00199 public:
00200 InterfaceBlobfinder( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00201 virtual ~InterfaceBlobfinder( void ){ };
00202
00203 virtual int ProcessMessage( QueuePointer & resp_queue,
00204 player_msghdr * hdr,
00205 void * data );
00206 virtual void Publish( void );
00207 };
00208
00209 class InterfacePtz : public InterfaceModel
00210 {
00211 public:
00212 InterfacePtz( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00213 virtual ~InterfacePtz( void ){ };
00214
00215 virtual int ProcessMessage( QueuePointer & resp_queue,
00216 player_msghdr * hdr,
00217 void * data );
00218 virtual void Publish( void );
00219 };
00220
00221 class InterfaceSonar : public InterfaceModel
00222 {
00223 public:
00224 InterfaceSonar( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00225 virtual ~InterfaceSonar( void ){ };
00226
00227 virtual int ProcessMessage( QueuePointer & resp_queue,
00228 player_msghdr * hdr,
00229 void * data );
00230 virtual void Publish( void );
00231 };
00232
00233
00234 class InterfaceBumper : public InterfaceModel
00235 {
00236 public:
00237 InterfaceBumper( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00238 virtual ~InterfaceBumper( void ){ };
00239
00240 virtual int ProcessMessage( QueuePointer & resp_queue,
00241 player_msghdr * hdr,
00242 void * data );
00243 virtual void Publish( void );
00244 };
00245
00246 class InterfaceLocalize : public InterfaceModel
00247 {
00248 public:
00249 InterfaceLocalize( player_devaddr_t addr,
00250 StgDriver* driver,
00251 ConfigFile* cf,
00252 int section );
00253
00254 virtual ~InterfaceLocalize( void ){ };
00255
00256 virtual void Publish( void );
00257 virtual int ProcessMessage(QueuePointer & resp_queue,
00258 player_msghdr_t* hdr,
00259 void* data);
00260 };
00261
00262 class InterfaceMap : public InterfaceModel
00263 {
00264 public:
00265 InterfaceMap( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00266 virtual ~InterfaceMap( void ){ };
00267
00268 virtual int ProcessMessage( QueuePointer & resp_queue,
00269 player_msghdr * hdr,
00270 void * data );
00271
00272
00273
00274
00275 int HandleMsgReqInfo( QueuePointer & resp_queue,
00276 player_msghdr * hdr,
00277 void * data );
00278 int HandleMsgReqData( QueuePointer & resp_queue,
00279 player_msghdr * hdr,
00280 void * data );
00281 };
00282
00283 class InterfaceGraphics3d : public InterfaceModel
00284 {
00285 public:
00286 InterfaceGraphics3d( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf, int section );
00287 virtual ~InterfaceGraphics3d( void );
00288
00289 virtual int ProcessMessage( QueuePointer & resp_queue,
00290 player_msghdr * hdr,
00291 void * data );
00292 virtual void Publish( void );
00293
00294 private:
00295
00296 void StoreCommand( int type, void* data );
00297
00298 GList* commands;
00299 bool rebuild_displaylist;
00300 int displaylist;
00301
00302
00303 void Clear( void );
00304 };
00305
00307 class StTime : public PlayerTime
00308 {
00309 private:
00310 StgDriver* driver;
00311
00312 public:
00313
00314 StTime( StgDriver* driver );
00315
00316
00317 virtual ~StTime();
00318
00319
00320 int GetTime(struct timeval* time);
00321 int GetTimeDouble(double* time);
00322 };
00323
00324
00325 #endif