Enki  1.9
BluetoothBase.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_BLUETOOTHBASE_H
35 #define __ENKI_BLUETOOTHBASE_H
36 
37 #include "PhysicalEngine.h"
38 
39 #include <valarray>
40 #include <list>
41 #include <queue>
42 
43 
48 namespace Enki
49 {
50  class Bluetooth;
51 
53 
55  {
56  protected:
58  struct BtClients
59  {
63  unsigned address;
64  };
65 
67  struct Connections
68  {
72  unsigned destaddress;
73  };
74 
77  {
81  unsigned address;
83  char* data;
85  unsigned size;
86  };
87 
89  std::list<BtClients> clients;
91  std::queue<Connections> connectbuffer;
93  std::queue<Connections> disconnectbuffer;
95  std::queue<Transmissions> transmissions;
96 
98  bool bbSendDataTo(Bluetooth* source, unsigned address, char* data, unsigned size);
100  bool bbConnectTo(Bluetooth* source,unsigned address);
102  bool bbCloseConnection(Bluetooth* source,unsigned address);
103 
105  Bluetooth* getAddress(unsigned address);
107  bool checkDistance(Bluetooth* source, Bluetooth* destination);
108 
109  public:
111  enum Errors
112  {
123  };
124 
126  BluetoothBase();
128  virtual ~BluetoothBase();
129 
131  bool registerClient(Bluetooth* owner, unsigned address);
134 
136  void sendDataTo(Bluetooth* source, unsigned address, char* data, unsigned size);
138  void connectTo(Bluetooth* source,unsigned address);
140  void closeConnection(Bluetooth* source,unsigned address);
141 
143  virtual void step(double dt, World *w);
144  };
145 
146 }
147 
148 #endif
std::queue< Connections > disconnectbuffer
Queue of the connection to be closed.
Definition: BluetoothBase.h:93
unsigned destaddress
Destination address of the connection.
Definition: BluetoothBase.h:72
Implementation of a Bluetooth base coordinating the Bluetooth modules.
Definition: BluetoothBase.h:54
No error occured during the last step.
Definition: BluetoothBase.h:114
unsigned address
Address of the associated bluetooth module.
Definition: BluetoothBase.h:63
bool bbConnectTo(Bluetooth *source, unsigned address)
Execute the previously scheduled connections.
Definition: BluetoothBase.cpp:153
bool bbCloseConnection(Bluetooth *source, unsigned address)
Execute the previously scheduled disconnections.
Definition: BluetoothBase.cpp:191
std::list< BtClients > clients
List of registered Bluetooth module.
Definition: BluetoothBase.h:89
char * data
Pointer to a buffer containing the data to be sent.
Definition: BluetoothBase.h:83
bool registerClient(Bluetooth *owner, unsigned address)
Register a module Bluetooth with its associated address.
Definition: BluetoothBase.cpp:67
BluetoothBase()
Constructor.
Definition: BluetoothBase.cpp:46
Structure associating a pointer to a bluetooth module to its address.
Definition: BluetoothBase.h:58
The address used was unknown.
Definition: BluetoothBase.h:116
unsigned size
Size in byte of the data to be sent.
Definition: BluetoothBase.h:85
The reception buffer is full and no additional data can be written.
Definition: BluetoothBase.h:122
bool bbSendDataTo(Bluetooth *source, unsigned address, char *data, unsigned size)
Execute the previously scheduled transfer of data.
Definition: BluetoothBase.cpp:107
Bluetooth * owner
Pointer to a bluetooth module.
Definition: BluetoothBase.h:61
Enki is the namespace of the Enki simulator. All Enki functions and classes excepted the math one are...
Definition: BluetoothBase.cpp:44
void closeConnection(Bluetooth *source, unsigned address)
Schedule a disconnection between two Bluetooth Module.
Definition: BluetoothBase.cpp:263
void connectTo(Bluetooth *source, unsigned address)
Schedule a connection to another Bluetooth module.
Definition: BluetoothBase.cpp:252
Errors
Bluetooth transmission errors.
Definition: BluetoothBase.h:111
No additional connection can be made as the robot is already at maximum.
Definition: BluetoothBase.h:120
unsigned address
Address of the module receiving the data.
Definition: BluetoothBase.h:81
Information needed to establish a connection or a disconnection.
Definition: BluetoothBase.h:67
The world is the container of all objects and robots.
Definition: PhysicalEngine.h:411
bool checkDistance(Bluetooth *source, Bluetooth *destination)
Check if the distance between the two modules is small enough for communication.
Definition: BluetoothBase.cpp:226
bool removeClient(Bluetooth *owner)
Remove a previously registered Bluetooth module.
Definition: BluetoothBase.cpp:93
void sendDataTo(Bluetooth *source, unsigned address, char *data, unsigned size)
Schedule a transmission of data to be sent during the next step.
Definition: BluetoothBase.cpp:241
Implementation of an onboard Bluetooth module.
Definition: Bluetooth.h:52
Bluetooth * getAddress(unsigned address)
Return the pointer of the Bluetooth module associated with "address".
Definition: BluetoothBase.cpp:56
The distance between the 2 robots is too great.
Definition: BluetoothBase.h:118
Information needed to send data along an established connection.
Definition: BluetoothBase.h:76
Bluetooth * source
Pointer to the Bluetooth module acting as the source.
Definition: BluetoothBase.h:70
virtual void step(double dt, World *w)
Execute the previously scheduled operations.
Definition: BluetoothBase.cpp:275
virtual ~BluetoothBase()
Destructor.
Definition: BluetoothBase.cpp:51
The core of Enki.
std::queue< Transmissions > transmissions
Queue of the data to be transmitted.
Definition: BluetoothBase.h:95
Bluetooth * source
Pointer to the module sending the data.
Definition: BluetoothBase.h:79
std::queue< Connections > connectbuffer
Queue of the connection to be established.
Definition: BluetoothBase.h:91