summaryrefslogtreecommitdiffstats
path: root/core/btdiscovery.cpp
diff options
context:
space:
mode:
authorGravatar Jan Mulder <jlmulder@xs4all.nl>2017-06-10 14:22:28 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-06-12 10:59:05 -0700
commit5142d7409f9dc9a102ae9b5898b43b57621c660c (patch)
tree2a8f14ceffbaaf6d9a3cb78568412772c16c386f /core/btdiscovery.cpp
parenta43cafa515f339b2a10069e7ebe926964449d447 (diff)
downloadsubsurface-5142d7409f9dc9a102ae9b5898b43b57621c660c.tar.gz
Mobile: add BT name to vendor/product capability
This adds a central function to convert a BT name to a vendor/product pair known to Subsurface. This allows interfacing from a paired BT dive computer, without actively selecting its type, but by selecting it from the list of paired BT devices. So, after this, downloading from multiple (paired) DCs is also possible. And not the niced piece of code ... Signed-off-by: Jan Mulder <jlmulder@xs4all.nl> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/btdiscovery.cpp')
-rw-r--r--core/btdiscovery.cpp41
1 files changed, 36 insertions, 5 deletions
diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp
index 3159c3d30..5a93174a6 100644
--- a/core/btdiscovery.cpp
+++ b/core/btdiscovery.cpp
@@ -2,10 +2,36 @@
#include "btdiscovery.h"
#include "downloadfromdcthread.h"
+#include "core/libdivecomputer.h"
#include <QDebug>
+extern QMap<QString, dc_descriptor_t *> descriptorLookup;
+
BTDiscovery *BTDiscovery::m_instance = NULL;
+static dc_descriptor_t *getDeviceType(QString btName)
+// central function to convert a BT name to a Subsurface known vendor/model pair
+{
+ QString vendor, product;
+
+ if (btName.startsWith("OSTC")) {
+ vendor = "Heinrichs Weikamp";
+ if (btName.mid(4,2) == "3#") product = "OSTC 3";
+ else if (btName.mid(4,2) == "3+") product = "OSTC 3+";
+ else if (btName.mid(4,2) == "s#") product = "OSTC Sport";
+ else if (btName.mid(4,2) == "4-") product = "OSTC 4";
+ else if (btName.mid(4,2) == "2-") product = "OSTC 2N";
+ // all OSTCs are HW_FAMILY_OSTC_3, so when we do not know,
+ // just try this
+ else product = "OSTC 3"; // all OSTCs are HW_FAMILY_OSTC_3
+ }
+
+ if (!vendor.isEmpty() && !product.isEmpty())
+ return(descriptorLookup[vendor + product]);
+
+ return(NULL);
+}
+
BTDiscovery::BTDiscovery(QObject *parent)
{
Q_UNUSED(parent)
@@ -68,11 +94,13 @@ void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
btPairedDevices.append(this_d);
struct btVendorProduct btVP;
- QString newDevice = device.name();
+ QString newDevice;
+ dc_descriptor_t *newDC = getDeviceType(device.name());
+ if (newDC)
+ newDevice = dc_descriptor_get_product(newDC);
+ else
+ newDevice = device.name();
- // all the HW OSTC BT computers show up as "OSTC" + some other text, depending on model
- if (newDevice.startsWith("OSTC"))
- newDevice = "OSTC 3";
QList<QBluetoothUuid> serviceUuids = device.serviceUuids();
foreach (QBluetoothUuid id, serviceUuids) {
addBtUuid(id);
@@ -80,11 +108,12 @@ void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
}
qDebug() << "Found new device:" << newDevice << device.address();
QString vendor;
- foreach (vendor, productList.keys()) {
+ if (newDC) foreach (vendor, productList.keys()) {
if (productList[vendor].contains(newDevice)) {
qDebug() << "this could be a " + vendor + " " +
(newDevice == "OSTC 3" ? "OSTC family" : newDevice);
btVP.btdi = device;
+ btVP.dcDescriptor = newDC;
btVP.vendorIdx = vendorList.indexOf(vendor);
btVP.productIdx = productList[vendor].indexOf(newDevice);
qDebug() << "adding new btDCs entry (detected DC)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btdi.address();;
@@ -95,6 +124,7 @@ void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
productList[QObject::tr("Paired Bluetooth Devices")].append(this_d.name + " (" + this_d.address.toString() + ")");
btVP.btdi = device;
+ btVP.dcDescriptor = newDC;
btVP.vendorIdx = vendorList.indexOf(QObject::tr("Paired Bluetooth Devices"));
btVP.productIdx = productList[QObject::tr("Paired Bluetooth Devices")].indexOf(this_d.name);
qDebug() << "adding new btDCs entry (all paired)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btdi.address();
@@ -174,4 +204,5 @@ bool BTDiscovery::checkException(const char* method, const QAndroidJniObject *ob
return result;
}
#endif // Q_OS_ANDROID
+
#endif // BT_SUPPORT