From 68bf0e39903cf30a712652c7cc2fc49279d3a410 Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Sun, 18 Mar 2018 00:46:20 +0100 Subject: [PATCH] Change service registration data --- src/btservice/AndroidBluetoothService.cpp | 20 ++++++++++++++------ src/btservice/btservice.cpp | 23 +++++++++++------------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/btservice/AndroidBluetoothService.cpp b/src/btservice/AndroidBluetoothService.cpp index 4da4867..f178662 100644 --- a/src/btservice/AndroidBluetoothService.cpp +++ b/src/btservice/AndroidBluetoothService.cpp @@ -27,13 +27,19 @@ namespace btservice AndroidBluetoothService::AndroidBluetoothService(uint16_t portNumber) { + //"4de17a00-52cb-11e6-bdf4-0800200c9a66"; + //"669a0c20-0008-f4bd-e611-cb52007ae14d"; + const QBluetoothUuid serviceUuid(QLatin1String("4de17a00-52cb-11e6-bdf4-0800200c9a66")); + + QBluetoothServiceInfo::Sequence classId; + classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort)); + serviceInfo_.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList, classId); + classId.prepend(QVariant::fromValue(serviceUuid)); + serviceInfo_.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId); serviceInfo_.setAttribute(QBluetoothServiceInfo::ServiceName, "OpenAuto Bluetooth Service"); serviceInfo_.setAttribute(QBluetoothServiceInfo::ServiceDescription, "AndroidAuto WiFi projection automatic setup"); serviceInfo_.setAttribute(QBluetoothServiceInfo::ServiceProvider, "f1xstudio.com"); - - //"4de17a00-52cb-11e6-bdf4-0800200c9a66"; - //"669a0c20-0008-f4bd-e611-cb52007ae14d"; - serviceInfo_.setServiceUuid(QBluetoothUuid(QString("4de17a00-52cb-11e6-bdf4-0800200c9a66"))); + serviceInfo_.setServiceUuid(serviceUuid); QBluetoothServiceInfo::Sequence publicBrowse; publicBrowse << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup)); @@ -41,9 +47,11 @@ AndroidBluetoothService::AndroidBluetoothService(uint16_t portNumber) QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; - + protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)); + protocolDescriptorList.append(QVariant::fromValue(protocol)); + protocol.clear(); protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm)) - << QVariant::fromValue(portNumber); + << QVariant::fromValue(quint16(portNumber)); protocolDescriptorList.append(QVariant::fromValue(protocol)); serviceInfo_.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); } diff --git a/src/btservice/btservice.cpp b/src/btservice/btservice.cpp index 3bdc209..e759c81 100644 --- a/src/btservice/btservice.cpp +++ b/src/btservice/btservice.cpp @@ -29,8 +29,18 @@ int main(int argc, char* argv[]) const QBluetoothAddress address; const uint16_t portNumber = 5000; - btservice::AndroidBluetoothService androidBluetoothService(portNumber); + btservice::AndroidBluetoothServer androidBluetoothServer; + if(!androidBluetoothServer.start(address, portNumber)) + { + OPENAUTO_LOG(error) << "[btservice] Server start failed."; + return 2; + } + + OPENAUTO_LOG(info) << "[btservice] Listening for connections, address: " << address.toString().toStdString() + << ", port: " << portNumber; + + btservice::AndroidBluetoothService androidBluetoothService(portNumber); if(!androidBluetoothService.registerService(address)) { OPENAUTO_LOG(error) << "[btservice] Service registration failed."; @@ -41,17 +51,6 @@ int main(int argc, char* argv[]) OPENAUTO_LOG(info) << "[btservice] Service registered, port: " << portNumber; } - btservice::AndroidBluetoothServer androidBluetoothServer; - - if(!androidBluetoothServer.start(address, portNumber)) - { - OPENAUTO_LOG(error) << "[btservice] Server start failed."; - return 2; - } - - OPENAUTO_LOG(info) << "[btservice] Listening for connections, address: " << address.toString().toStdString() - << ", port: " << portNumber; - qApplication.exec(); androidBluetoothService.unregisterService();