ITS
BluetoothBridge.cpp
Go to the documentation of this file.
2 
4 {
5  startServer();
6  m_A2F = new App2Fac(rfcommServer, btSocket, denm);
7  m_F2A = new Fac2App(btSocket, denm);
8 
9  m_A2FThread = new QThread;
10  m_F2AThread = new QThread;
11 
12  QObject::connect(m_A2F, SIGNAL(newBTSocket(QBluetoothSocket*)), m_F2A, SLOT(newBTSocket(QBluetoothSocket*)));
13 
14  m_A2F->moveToThread(m_A2FThread);
15  m_F2A->moveToThread(m_F2AThread);
16 
17  m_A2FThread->start();
18  m_F2AThread->start();
19 }
20 
22 {
23  static const QLatin1String serviceUuid("e8e10f95-1a70-4b27-9ccf-02010264e9c8");
24 
25  QBluetoothLocalDevice localDevice;
26  QString localDeviceName;
27 
28  // Check if Bluetooth is available on this device
29  qInfo() << "Checking for Bluetooth device";
30  if(localDevice.isValid()) {
31 
32  // Turn Bluetooth on
33  qInfo() << "Turning on Bluetooth device";
34  localDevice.powerOn();
35 
36  // Read local device name
37  qInfo() << "Reading Bluetooth device name";
38  localDeviceName = localDevice.name();
39 
40  // Make it visible to others
41  qInfo() << "Making Bluetooth device visible";
42  localDevice.setHostMode(QBluetoothLocalDevice::HostDiscoverable);
43  }
44  else
45  qWarning() << "No connected Bluetooth device found";
46 
47  rfcommServer = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this);
48  if(!rfcommServer->listen(localDevice.address())){
49  qWarning() << "Cannot bind Bluetooth device to" << localDevice.address();
50  return;
51  }
52 
53 
54  QBluetoothServiceInfo::Sequence classId;
55 
56  classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
57  serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList, classId);
58 
59  classId.prepend(QVariant::fromValue(QBluetoothUuid(serviceUuid)));
60 
61  serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId);
62 
63  serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, tr("DENM BT forwarder"));
64  serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceDescription, tr("Forward DENM from and to Android"));
65  serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, tr("URCA"));
66 
67  serviceInfo.setServiceUuid(QBluetoothUuid(serviceUuid));
68 
69  QBluetoothServiceInfo::Sequence publicBrowse;
70  publicBrowse << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
71  serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList, publicBrowse);
72 
73  QBluetoothServiceInfo::Sequence protocolDescriptorList;
74  QBluetoothServiceInfo::Sequence protocol;
75  protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap));
76  protocolDescriptorList.append(QVariant::fromValue(protocol));
77  protocol.clear();
78  protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
79  << QVariant::fromValue(quint8(rfcommServer->serverPort()));
80  protocolDescriptorList.append(QVariant::fromValue(protocol));
81  serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
82  protocolDescriptorList);
83 
84  serviceInfo.registerService(localDevice.address());
85 
86  qInfo() << rfcommServer->serverAddress().toString() << rfcommServer->serverPort() << rfcommServer->serverType();
87 
88 }
QBluetoothSocket * btSocket
QBluetoothServer * rfcommServer
QThread * m_F2AThread
QBluetoothServiceInfo serviceInfo
BluetoothBridge(ParameterDENM *denm)
QThread * m_A2FThread