-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBTClient.cpp
More file actions
59 lines (48 loc) · 1.45 KB
/
BTClient.cpp
File metadata and controls
59 lines (48 loc) · 1.45 KB
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 "BTClient.h"
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
#include <QDBusConnection>
#include <QVariant>
#include <QDebug>
BTClient::BTClient(QObject *parent) : QObject (parent)
{
QDBusConnection bus = QDBusConnection::systemBus ();
bool success = bus.connect ("org.bluez", "", "org.bluez.Adapter", "PropertyChanged", this, SLOT (btStateChanged (QString, QDBusVariant)));
qDebug () << success;
if (success == false)
qWarning("Cannot connect to org.bluez.Adapter::PropertyChanged signal.");
}
BTClient::~BTClient ()
{
}
void
BTClient::connectToServer ()
{
struct sockaddr_rc addr = { 0 };
int s, status;
//char dest[18] = "00:02:72:B0:00:26";
char dest[18] = "00:1F:81:00:08:30";
// allocate a socket
s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
// set the connection parameters (who to connect to)
addr.rc_family = AF_BLUETOOTH;
addr.rc_channel = (uint8_t) 25;
str2ba( dest, &addr.rc_bdaddr );
// connect to server
//status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
// send a message
if( status == 0 ) {
status = write(s, "hello!", 6);
}
if( status < 0 ) perror("uh oh");
close(s);
}
void
BTClient::btStateChanged (QString key, QDBusVariant value)
{
QVariant v = value.variant ();
qDebug () << "Property:" << key << " changed to " << v.toString ();
}