From 5695ef956b9395dbe924b097a96359c5acacb53f Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 16 Sep 2017 20:15:15 -0700 Subject: BLE: if there's no address, use the UUID instead This is not just for IOS, the same applies on a Mac. But I see no issue with enabling that for all OSs. Signed-off-by: Dirk Hohndel --- core/btdiscovery.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp index cab44b4a6..90eb2e844 100644 --- a/core/btdiscovery.cpp +++ b/core/btdiscovery.cpp @@ -174,11 +174,10 @@ QString markBLEAddress(const QBluetoothDeviceInfo *device) flags = device->coreConfigurations(); if (flags == QBluetoothDeviceInfo::LowEnergyCoreConfiguration) prefix = "LE:"; -#if defined(Q_OS_IOS) - return prefix + device->deviceUuid().toString(); -#else - return prefix + device->address().toString(); -#endif + if (device->address().isNull()) + return prefix + device->deviceUuid().toString(); + else + return prefix + device->address().toString(); } void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device) -- cgit v1.2.3-70-g09d2 From db38a7023db5ebf1c58e8bc652071d8f509bd001 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 16 Sep 2017 20:19:41 -0700 Subject: BLE: helper function to get QBtDeviceInfo from UUID Right now this will only work if you scan for your BLE dive computer every time. Ideally we should simply initiate a scan and look for that address if it's not found in the hash. Signed-off-by: Dirk Hohndel --- core/btdiscovery.cpp | 14 ++++++++++++++ core/btdiscovery.h | 3 +++ 2 files changed, 17 insertions(+) (limited to 'core') diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp index 90eb2e844..729ee9851 100644 --- a/core/btdiscovery.cpp +++ b/core/btdiscovery.cpp @@ -307,4 +307,18 @@ bool BTDiscovery::checkException(const char* method, const QAndroidJniObject *ob } #endif // Q_OS_ANDROID +QHash btDeviceInfo; + +void saveBtDeviceInfo(const char* devaddr, QBluetoothDeviceInfo deviceInfo) +{ + btDeviceInfo[devaddr] = deviceInfo; +} + +QBluetoothDeviceInfo getBtDeviceInfo(const char* devaddr) +{ + if (btDeviceInfo.contains(devaddr)) + return btDeviceInfo[devaddr]; + qDebug() << "need to scan for" << devaddr; + return QBluetoothDeviceInfo(); +} #endif // BT_SUPPORT diff --git a/core/btdiscovery.h b/core/btdiscovery.h index 71df24f24..160890c73 100644 --- a/core/btdiscovery.h +++ b/core/btdiscovery.h @@ -18,6 +18,9 @@ #include #endif +void saveBtDeviceInfo(const char* devaddr, QBluetoothDeviceInfo deviceInfo); +QBluetoothDeviceInfo getBtDeviceInfo(const char* devaddr); + class ConnectionListModel : public QAbstractListModel { Q_OBJECT public: -- cgit v1.2.3-70-g09d2 From 26e610c3f409e771c4e0e7ba955db7f4155b8825 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 16 Sep 2017 20:21:46 -0700 Subject: BLE: create controller from QBtDeviceInfo Creating it from an address is a) deprecated and b) impossible on Mac or iOS. Signed-off-by: Dirk Hohndel --- core/qt-ble.cpp | 6 +++--- desktop-widgets/btdeviceselectiondialog.cpp | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index 9867528c8..eca615fbe 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -16,6 +16,7 @@ #include "libdivecomputer.h" #include "core/qt-ble.h" +#include "core/btdiscovery.h" #if defined(SSRF_CUSTOM_IO) @@ -287,12 +288,11 @@ dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *d if (!strncmp(devaddr, "LE:", 3)) devaddr += 3; - QBluetoothAddress remoteDeviceAddress(devaddr); - // HACK ALERT! Qt 5.9 needs this for proper Bluez operation qputenv("QT_DEFAULT_CENTRAL_SERVICES", "1"); - QLowEnergyController *controller = new QLowEnergyController(remoteDeviceAddress); + QBluetoothDeviceInfo remoteDevice = getBtDeviceInfo(devaddr); + QLowEnergyController *controller = QLowEnergyController::createCentral(remoteDevice); qDebug() << "qt_ble_open(" << devaddr << ")"; diff --git a/desktop-widgets/btdeviceselectiondialog.cpp b/desktop-widgets/btdeviceselectiondialog.cpp index eb05c4f42..cf70daa3f 100644 --- a/desktop-widgets/btdeviceselectiondialog.cpp +++ b/desktop-widgets/btdeviceselectiondialog.cpp @@ -152,7 +152,9 @@ void BtDeviceSelectionDialog::on_save_clicked() // Save the selected device selectedRemoteDeviceInfo = QSharedPointer(new QBluetoothDeviceInfo(remoteDeviceInfo)); - + QString address = remoteDeviceInfo.address().isNull() ? remoteDeviceInfo.deviceUuid().toString() : + remoteDeviceInfo.address().toString(); + saveBtDeviceInfo(address.toUtf8().constData(), remoteDeviceInfo); if (remoteDeviceDiscoveryAgent->isActive()) { // Stop the SDP agent if the clear button is pressed and enable the Scan button remoteDeviceDiscoveryAgent->stop(); -- cgit v1.2.3-70-g09d2 From 90d73924c227bddd4be93d90df1d1d03c8716f81 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 17 Sep 2017 09:48:52 -0700 Subject: BLE: try to pick the correct descriptor to write to The ordering on Mac appears to be random, but after looking through the various successful logs of BLE downloads, it seems we always wrote to the ClientCharacteristicConfiguration descriptor. So try to find that one first, and only grab the first descriptor in the list if we didn't find a ClientCharacteristicConfiguration descriptor. Signed-off-by: Dirk Hohndel --- core/qt-ble.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index eca615fbe..92a78ae65 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -382,8 +382,19 @@ dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *d qDebug() << "Descriptor:" << d.name() << "uuid:" << d.uuid().toString(); if (!l.isEmpty()) { - d = l.first(); - qDebug() << "now writing \"0x0100\" to the first descriptor"; + bool foundCCC = false; + foreach (d, l) { + if (d.type() == QBluetoothUuid::ClientCharacteristicConfiguration) { + // pick the correct characteristic + foundCCC = true; + break; + } + } + if (!foundCCC) + // if we didn't find a ClientCharacteristicConfiguration, try the first one + d = l.first(); + + qDebug() << "now writing \"0x0100\" to the descriptor" << d.uuid().toString(); ble->preferredService()->writeDescriptor(d, QByteArray::fromHex("0100")); } -- cgit v1.2.3-70-g09d2 From 731d9dc9bdf967ecc3d544de62ced6c3c469f6fa Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 17 Sep 2017 14:46:44 -0700 Subject: DC download: tell user when no new dives were found Otherwise it almost looks like something went wrong with the download. Signed-off-by: Dirk Hohndel --- core/libdivecomputer.c | 1 + 1 file changed, 1 insertion(+) (limited to 'core') diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index ebffad2bf..e6b600644 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -1121,6 +1121,7 @@ const char *do_libdivecomputer_import(device_data_t *data) /* TODO: Show the logfile to the user on error. */ dc_device_close(data->device); data->device = NULL; + dev_info(data, translate("gettextFromC", "No new dives downloaded from dive computer")); } dc_context_free(data->context); -- cgit v1.2.3-70-g09d2