-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
60 lines (44 loc) · 1.22 KB
/
main.cpp
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
#include "bluetoothtools.h"
int main()
{
BluetoothTools bt ;
std::vector< std::pair < std::string , std::string > > devices ;
size_t num ;
std::cout << "Start Scanning..." << std::endl ;
num = bt.scan_devices ( devices , 25 ) ;
for ( unsigned int i = 0 ; i < num ; i++ )
{
std::cout << i << ", "
<< "ADDRESS : " << devices [ i ].first
<< ", "
<< "NAME : " << devices [ i ].second
<< std::endl ;
}
if ( num == 0 )
{
std::cout << " device not found " << std::endl ;
return -1 ;
}
std::cout << "Select device: " << std::endl ;
unsigned int k ;
std::cin >> k ;
int status = bt.pair_device ( devices [ k ].first , "0000" ) ;
if ( status != 0 )
{
std::cout << "pairing error =(" << std::endl ;
return -1 ;
}
std::cout << "Pairing successful" << std::endl ;
status = bt.connect_device( devices [ k ].first );
if ( status != 0 )
{
std::cout << "connect error =(" << std::endl ;
}
while ( true )
{
char buff [ 256 ] = { } ;
bt.recv ( buff, 256 );
std::cout << buff << std::endl ;
}
return 0 ;
}