enki/BluetoothBase.h

Go to the documentation of this file.
00001 /*
00002     Enki - a fast 2D robot simulator
00003     Copyright (C) 1999-2008 Stephane Magnenat <stephane at magnenat dot net>
00004     Copyright (C) 2004-2005 Markus Waibel <markus dot waibel at epfl dot ch>
00005     Copyright (c) 2004-2005 Antoine Beyeler <abeyeler at ab-ware dot com>
00006     Copyright (C) 2005-2006 Laboratory of Intelligent Systems, EPFL, Lausanne
00007     Copyright (C) 2006-2008 Laboratory of Robotics Systems, EPFL, Lausanne
00008     See AUTHORS for details
00009 
00010     This program is free software; the authors of any publication 
00011     arising from research using this software are asked to add the 
00012     following reference:
00013     Enki - a fast 2D robot simulator
00014     http://lis.epfl.ch/enki
00015     Stephane Magnenat <stephane at magnenat dot net>,
00016     Markus Waibel <markus dot waibel at epfl dot ch>
00017     Laboratory of Intelligent Systems, EPFL, Lausanne.
00018 
00019     You can redistribute this program and/or modify
00020     it under the terms of the GNU General Public License as published by
00021     the Free Software Foundation; either version 2 of the License, or
00022     (at your option) any later version.
00023 
00024     This program is distributed in the hope that it will be useful,
00025     but WITHOUT ANY WARRANTY; without even the implied warranty of
00026     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00027     GNU General Public License for more details.
00028 
00029     You should have received a copy of the GNU General Public License
00030     along with this program; if not, write to the Free Software
00031     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00032 */
00033 
00034 #ifndef __ENKI_BLUETOOTHBASE_H
00035 #define __ENKI_BLUETOOTHBASE_H
00036 
00037 #include "PhysicalEngine.h"
00038 
00039 #include <valarray>
00040 #include <list>
00041 #include <queue>
00042 
00043 
00048 namespace Enki
00049 {
00050     class Bluetooth;
00051 
00053 
00054     class BluetoothBase
00055     {
00056     protected:
00058         struct BtClients
00059         {
00061             Bluetooth* owner;
00063             unsigned address;
00064         };
00065         
00067         struct Connections
00068         {
00070             Bluetooth* source;
00072             unsigned destaddress;
00073         };
00074         
00076         struct Transmissions
00077         {
00079             Bluetooth* source;
00081             unsigned address;
00083             char* data;
00085             unsigned size;
00086         };
00087         
00089         std::list<BtClients> clients;
00091         std::queue<Connections> connectbuffer;
00093         std::queue<Connections> disconnectbuffer;
00095         std::queue<Transmissions> transmissions;
00096         
00098         bool bbSendDataTo(Bluetooth* source, unsigned address, char* data, unsigned size);
00100         bool bbConnectTo(Bluetooth* source,unsigned address);
00102         bool bbCloseConnection(Bluetooth* source,unsigned address);
00103         
00105         Bluetooth* getAddress(unsigned address);
00107         bool checkDistance(Bluetooth* source, Bluetooth* destination);
00108         
00109     public:
00111         enum Errors
00112         {
00114             BT_NO_ERROR = 0,
00116             ADDRESS_UNKNOWN = 1,
00118             DISTANCE_EXCEEDED = 2,
00120             TOO_MANY_CONNECTIONS = 3,
00122             RECEPTION_BUFFER_FULL = 4
00123         };
00124 
00125 
00127         BluetoothBase();
00129         virtual ~BluetoothBase();
00130         
00132         bool registerClient(Bluetooth* owner, unsigned address);
00134         bool removeClient(Bluetooth* owner);
00135         
00137         void sendDataTo(Bluetooth* source, unsigned address, char* data, unsigned size);
00139         void connectTo(Bluetooth* source,unsigned address);
00141         void closeConnection(Bluetooth* source,unsigned address);
00142         
00144         virtual void step(double dt, World *w);
00145     };
00146 
00147 }
00148 
00149 #endif

Generated on Sun Mar 1 03:10:09 2009 for Enki by  doxygen 1.5.1