Enki  1.9
Bluetooth.h
Go to the documentation of this file.
1 /*
2  Enki - a fast 2D robot simulator
3  Copyright (C) 1999-2016 Stephane Magnenat <stephane at magnenat dot net>
4  Copyright (C) 2004-2005 Markus Waibel <markus dot waibel at epfl dot ch>
5  Copyright (c) 2004-2005 Antoine Beyeler <abeyeler at ab-ware dot com>
6  Copyright (C) 2005-2006 Laboratory of Intelligent Systems, EPFL, Lausanne
7  Copyright (C) 2006-2008 Laboratory of Robotics Systems, EPFL, Lausanne
8  See AUTHORS for details
9 
10  This program is free software; the authors of any publication
11  arising from research using this software are asked to add the
12  following reference:
13  Enki - a fast 2D robot simulator
14  http://home.gna.org/enki
15  Stephane Magnenat <stephane at magnenat dot net>,
16  Markus Waibel <markus dot waibel at epfl dot ch>
17  Laboratory of Intelligent Systems, EPFL, Lausanne.
18 
19  You can redistribute this program and/or modify
20  it under the terms of the GNU General Public License as published by
21  the Free Software Foundation; either version 2 of the License, or
22  (at your option) any later version.
23 
24  This program is distributed in the hope that it will be useful,
25  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  GNU General Public License for more details.
28 
29  You should have received a copy of the GNU General Public License
30  along with this program; if not, write to the Free Software
31  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 */
33 
34 #ifndef __ENKI_BLUETOOTH_H
35 #define __ENKI_BLUETOOTH_H
36 
37 #include "../PhysicalEngine.h"
38 #include "../Interaction.h"
39 
40 
41 #include <queue>
42 
47 namespace Enki
48 {
49 
51 
53  {
54 protected:
55  friend class BluetoothBase;
56 
58  double range;
59 
61  unsigned nbConnections;
63  unsigned maxConnections;
65  unsigned address;
66 
68  char** rxBuffer;
70  char** txBuffer;
72  unsigned rxBufferSize;
74  unsigned txBufferSize;
78  unsigned* destAddress;
80  unsigned* sizeToSend;
82  unsigned* sizeReceived;
83 
88 
90  std::queue<unsigned> connectToRobot;
92  std::queue<unsigned> closeConnectionToRobot;
93 
95  unsigned* transmissionError;
100 
102  void cancelRxBuffer();
104  void cancelTxBuffer();
106  void cancelAllData();
108  void initAllData();
109 
110 public:
112  enum Errors
113  {
124  };
125 
128  Bluetooth(Robot* owner,double range, unsigned maxConnections, unsigned rxbuffersize, unsigned txbuffersize,unsigned address);
130  virtual ~Bluetooth();
131 
133  virtual void step(double dt, World *w);
134 
136  void setAddress(unsigned address);
138  unsigned getAddress();
139 
141  void connectTo(unsigned address);
143  bool closeConnection(unsigned index);
144 
146  bool didIReceive();
148  bool didIReceive(unsigned source);
150  bool* getReceptionFlags();
152  const char* getRxBuffer(unsigned source);
154  unsigned getSizeReceived(unsigned source);
155 
157  bool sendDataTo(unsigned dest,char* data,unsigned size);
159  unsigned* getTransmissionError();
161  bool isThereTxError();
162 
164  unsigned getConnectionError();
166  unsigned getDisconnectionError();
167 
169  unsigned getTxBufferSize();
171  void changeTxBufferSize(unsigned size);
172 
174  unsigned getRxBufferSize();
176  void changeRxBufferSize(unsigned size);
177 
179  unsigned getMaxConnections();
181  void changeMaxConnections(unsigned size);
182 
184  unsigned getNbConnections();
186  unsigned* getConnectedAddresses();
187 
188  };
189 
190 }
191 
192 #endif
unsigned getMaxConnections()
Return the maximum number of simultaneous connections supported by this module.
Definition: Bluetooth.cpp:130
unsigned getRxBufferSize()
Return the size of the reception buffers.
Definition: Bluetooth.cpp:284
void cancelTxBuffer()
Deallocate the memory dedicated for the transmission buffer.
Definition: Bluetooth.cpp:77
bool sendDataTo(unsigned dest, char *data, unsigned size)
Send data to the module of address "dest".
Definition: Bluetooth.cpp:239
const char * getRxBuffer(unsigned source)
Return the reception buffer associated with another module of address "source".
Definition: Bluetooth.cpp:178
Implementation of a Bluetooth base coordinating the Bluetooth modules.
Definition: BluetoothBase.h:54
bool closeConnection(unsigned index)
Close an established connection with another module.
Definition: Bluetooth.cpp:220
char ** rxBuffer
Reception buffers for data coming from other connected modules.
Definition: Bluetooth.h:68
The distance between the 2 robots is too great.
Definition: Bluetooth.h:119
double range
Range of the interaction.
Definition: Bluetooth.h:58
unsigned getAddress()
Return the address of the module.
Definition: Bluetooth.cpp:135
void connectTo(unsigned address)
Initiate a connection with another module.
Definition: Bluetooth.cpp:214
void cancelAllData()
Deallocate all the memory.
Definition: Bluetooth.cpp:84
unsigned * transmissionError
Flags indicating transmission errors.
Definition: Bluetooth.h:95
unsigned getDisconnectionError()
Return the status of the disconnection error flag.
Definition: Bluetooth.cpp:361
void setAddress(unsigned address)
Change the address of the module.
Definition: Bluetooth.cpp:123
unsigned * sizeToSend
Size of the data to send.
Definition: Bluetooth.h:80
unsigned rxBufferSize
Size of each buffer for the reception of data.
Definition: Bluetooth.h:72
std::queue< unsigned > connectToRobot
Queue containing request for connection to other modules.
Definition: Bluetooth.h:90
Enki is the namespace of the Enki simulator. All Enki functions and classes excepted the math one are...
Definition: BluetoothBase.cpp:44
No additional connection can be made as the robot is already at maximum.
Definition: Bluetooth.h:121
void cancelRxBuffer()
Deallocate the memory dedicated for the reception buffer.
Definition: Bluetooth.cpp:70
void changeTxBufferSize(unsigned size)
Modify the size of the transmission buffers.
Definition: Bluetooth.cpp:303
unsigned * sizeReceived
Size of the data received.
Definition: Bluetooth.h:82
bool isThereTxError()
Indicate if an error of transmission occured during the last step.
Definition: Bluetooth.cpp:266
unsigned getConnectionError()
Return the status of the connection error flag.
Definition: Bluetooth.cpp:356
No error occured during the last step.
Definition: Bluetooth.h:115
unsigned maxConnections
Maximum number of simultaneous connections supported.
Definition: Bluetooth.h:63
Bluetooth(Robot *owner, double range, unsigned maxConnections, unsigned rxbuffersize, unsigned txbuffersize, unsigned address)
Constructor e.g.
Definition: Bluetooth.cpp:46
bool * getReceptionFlags()
Return the reception flags indicating from which module data was received.
Definition: Bluetooth.cpp:173
Errors
Error that bluetooth communication can produce.
Definition: Bluetooth.h:112
char ** txBuffer
Transmission buffers for data sent to other connected modules.
Definition: Bluetooth.h:70
unsigned nbConnections
Number of connections currently established.
Definition: Bluetooth.h:61
char disconnectionError
Flag indicating an error involving the disconnection from another robot.
Definition: Bluetooth.h:99
bool randomAddress
Flag indicating that the current address has been assigned randomly.
Definition: Bluetooth.h:87
bool * receptionFlags
Flags signalling the reception of data.
Definition: Bluetooth.h:76
bool updateAddress
Flag indicating a change in the address of the module.
Definition: Bluetooth.h:85
unsigned getSizeReceived(unsigned source)
Return the amount of data received from another module of address "source" during the last step...
Definition: Bluetooth.cpp:196
The world is the container of all objects and robots.
Definition: PhysicalEngine.h:411
std::queue< unsigned > closeConnectionToRobot
Queue containing request for closing the connection with other modules.
Definition: Bluetooth.h:92
Interacts with the whole world.
Definition: Interaction.h:93
unsigned address
Address of the Bluetooth module.
Definition: Bluetooth.h:65
virtual ~Bluetooth()
Destructor.
Definition: Bluetooth.cpp:65
Implementation of an onboard Bluetooth module.
Definition: Bluetooth.h:52
Robot * owner
The physical object that owns the interaction.
Definition: Interaction.h:97
void initAllData()
Initialise all the data structure requires by the module.
Definition: Bluetooth.cpp:102
virtual void step(double dt, World *w)
On every timestep, send the commands recorded to the bluetooth Base to be executed.
Definition: Bluetooth.cpp:314
void changeMaxConnections(unsigned size)
Change the maximum number of simultaneous connections supported by this module.
Definition: Bluetooth.cpp:276
unsigned * destAddress
Addresses of the connected modules.
Definition: Bluetooth.h:78
unsigned getTxBufferSize()
Return the size of the transmission buffers.
Definition: Bluetooth.cpp:298
unsigned txBufferSize
Size of each buffer for the transmission of data.
Definition: Bluetooth.h:74
char connectionError
Flag indicating an error involving the connection toward another robot.
Definition: Bluetooth.h:97
bool didIReceive()
Indicate if data was received during the last step.
Definition: Bluetooth.cpp:150
unsigned * getTransmissionError()
Return the flags indicating on which connection a transmission error occured.
Definition: Bluetooth.cpp:261
void changeRxBufferSize(unsigned size)
Modify the size of the reception buffers.
Definition: Bluetooth.cpp:289
unsigned getNbConnections()
Return the number of established connections to other modules.
Definition: Bluetooth.cpp:140
The address used was unknown.
Definition: Bluetooth.h:117
unsigned * getConnectedAddresses()
Return the addresses of the other connected modules.
Definition: Bluetooth.cpp:145
The reception buffer is full and no additional data can be written.
Definition: Bluetooth.h:123
A robot is a PhysicalObject that has additional interactions and a controller.
Definition: PhysicalEngine.h:379