Change service registration data

pull/53/head
michal.szwaj 2018-03-18 00:46:20 +01:00
parent 2c84f2afc5
commit 68bf0e3990
2 changed files with 25 additions and 18 deletions

View File

@ -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);
}

View File

@ -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();