00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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