-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluetoothAction.h
155 lines (145 loc) · 4.59 KB
/
bluetoothAction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Cpp Code File: mainBluetooth.cpp
* Very small Soccer - Bluetooth Team 2015.
* Descrição: Programa principal de comunicação que envia dados para cada robô (N robôs) atraves do bluetooth de uma workstatioN (computador).
* Decription: Main program of communication that send data to each robots (N robots) by bluetooth from one workstation (PC).
*
* autor: [email protected]
* Natal, 17/09/2015, 16:00h
*/
#ifndef __BLUETOOTHACTION_H__
#define __BLUETOOTHACTION_H__
// #include <stdio.h>
// #include <unistd.h>
// #include <stdlib.h>
#include <vector>
#include <string>
#include <sys/socket.h> /*communications stuffs by socket - also used by bluetooth */
#include <bluetooth/bluetooth.h> /*lib for bluetooth comm*/
#include <bluetooth/hci.h> /*lib for bluetooth comm*/
#include <bluetooth/hci_lib.h> /*lib for bluetooth comm*/
#include <bluetooth/rfcomm.h> /*lib for bluetooth comm*/
#include <bluetooth/l2cap.h>/*lib for bluetooth l2acp*/
/*Class body*/
/**
* Classe de comunicação, que envia dados para cada robô (N robôs) atraves do bluetooth de uma workstatioN (computador).
*/
class BluetoothAction {
private:
/*constants variables*/
int LEN_BUFFER;
int NUM_BT_DEVICES;
int LEN_ADDR_BT_DEVICES;
/*socket variables*/
struct sockaddr_rc addr; //RFCOMM
struct sockaddr_l2 addr2;
std::vector<std::string> dest;
int sock[10];
int status[10];
std::vector<int> tmp_status;
public:
/*header methods*/
BluetoothAction();
//BluetoothAction(int len_buff = 0, int num_bt_dv = 0);
~BluetoothAction();
/**
* Envia uma mensagem para o idBt com tamanho maximo de LEN_BUFFER
* @param int id id do destino.
* @param char message mensagem que sera enviada.
* @return true em caso de falha, false caso contrario.
*/
bool sendBluetoothMessage(const unsigned int, const unsigned char []);
/**
* Envia uma mensagem para o idBt com tamanho maximo de LEN_BUFFER
* @param int id id do destino.
* @param int id do destino.
* @param char message mensagem que sera enviada.
* @return true em caso de falha, false caso contrario.
*/
bool sendBluetoothMessage(const unsigned int id, const uint8_t* message, const int len_buffer);
// int recvBluetoothMessage(const int idBt, uint8_t*buffer, int lengthMax);
int recvBluetoothMessage(const int idBt, uint8_t*buffer, int lengthMax, int timeout = 20);
// int recvBluetoothMessage();
/**
* Encerra multiplas conexoes, do id 0 até bt.
* @param int bt último idBt fechado.
*/
void closeBluetooths(int);
/**
* Encerra uma conexao.
* @param int idBt bluetooth ID que sera fechado.
*/
void closeBluetoothById(int);
/**
* Metodo para se conectar com um dos MAC destinos por meio do ID retornado pelo
* metodo setBluetoothAddr.
* @param int idBt id do destino.
*/
void initBluetoothById(int);
/**
* Tenta realizar conexões com todos os NUM_BT_DEVICES adicionados.
*/
void initBluetoothDevices();//init devices based RFCOMM protocol
/**
* [initBluetoothDevicesL2CAP description]
* @param int [description]
* @return [description]
*/
int initBluetoothDevicesL2CAP(int);//init devices based L2CAP protocol
/**
* [findActiveBluetoothDevice description]
* @return [description]
*/
int findActiveBluetoothDevice(void);
//getters
/**
* [getDest description]
* @return [description]
*/
std::vector<std::string> getDest(void);
/**
* [getLenBuffer description]
* @return [description]
*/
int getLenBuffer(void);
/**
* [getNumBTDevices description]
* @return [description]
*/
int getNumBTDevices(void);
/**
* [getLenAddrBTDevices description]
* @return [description]
*/
int getLenAddrBTDevices(void);
/**
* [getBluetoothAddr description]
* @param int [description]
* @return [description]
*/
std::string getBluetoothAddr(int);
/*setters*/
void setLenBuffer(int);
/**
* [setNumBTDevices description]
* @param int [description]
*/
void setNumBTDevices(int);
/**
* [setLenAddrBTDevices description]
* @param int [description]
*/
void setLenAddrBTDevices(int);
/**
* Adiciona um novo endereco de destino.
* @param std::string Endereco MAC do destino.
* @return id do sock.
*/
int setBluetoothAddr(std::string);
/**
* [getStatus description]
* @return [description]
*/
std::vector<int> getStatus();
};
#endif