enki/interactions/Bluetooth.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_BLUETOOTH_H
00035 #define __ENKI_BLUETOOTH_H
00036 
00037 #include "../PhysicalEngine.h"
00038 #include "../Interaction.h"
00039 
00040 
00041 #include <queue>
00042 
00047 namespace Enki
00048 {   
00049 
00051 
00052     class Bluetooth: public GlobalInteraction
00053     {
00054 protected:
00055         friend class BluetoothBase;
00056         
00058         double range;
00059         
00061         unsigned nbConnections;
00063         unsigned maxConnections;
00065         unsigned address;
00066         
00068         char** rxBuffer;
00070         char** txBuffer;
00072         unsigned rxBufferSize;
00074         unsigned txBufferSize;
00076         bool* receptionFlags;
00078         unsigned* destAddress;
00080         unsigned* sizeToSend;
00082         unsigned* sizeReceived;
00083         
00085         bool updateAddress;
00087         bool randomAddress;
00088         
00090         std::queue<unsigned> connectToRobot;
00092         std::queue<unsigned> closeConnectionToRobot;
00093         
00095         unsigned* transmissionError;
00097         char connectionError;
00099         char disconnectionError;
00100         
00102         void cancelRxBuffer();
00104         void cancelTxBuffer();
00106         void cancelAllData();
00108         void initAllData();
00109         
00110 public:
00112         enum Errors
00113         {
00115             BT_NO_ERROR = 0,
00117             ADDRESS_UNKNOWN = 1,
00119             DISTANCE_EXCEEDED = 2,
00121             TOO_MANY_CONNECTIONS = 3,
00123             RECEPTION_BUFFER_FULL = 4
00124         };
00125 
00128         Bluetooth(Robot* owner,double range, unsigned maxConnections, unsigned rxbuffersize, unsigned txbuffersize,unsigned address);
00130         virtual ~Bluetooth();
00131         
00133         virtual void step(double dt, World *w);
00134         
00136         void setAddress(unsigned address);
00138         unsigned getAddress();
00139         
00141         void connectTo(unsigned address);
00143         bool closeConnection(unsigned index);
00144         
00146         bool didIReceive();
00148         bool didIReceive(unsigned source);
00150         bool* getReceptionFlags();
00152         const char* getRxBuffer(unsigned source);
00154         unsigned getSizeReceived(unsigned source);
00155         
00157         bool sendDataTo(unsigned dest,char* data,unsigned size);
00159         unsigned* getTransmissionError();
00161         bool isThereTxError();
00162         
00164         unsigned getConnectionError();
00166         unsigned getDisconnectionError();
00167         
00169         unsigned getTxBufferSize();
00171         void changeTxBufferSize(unsigned size);
00172         
00174         unsigned getRxBufferSize();
00176         void changeRxBufferSize(unsigned size);
00177         
00179         unsigned getMaxConnections();
00181         void changeMaxConnections(unsigned size);
00182         
00184         unsigned getNbConnections();
00186         unsigned* getConnectedAddresses();
00187         
00188     };
00189     
00190 }
00191 
00192 #endif

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