Changeset 5142d74 in subsurface


Ignore:
Timestamp:
Jun 12, 2017, 10:59:05 AM (12 days ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
23df593
Parents:
a43cafa
git-author:
Jan Mulder <jlmulder@…> (06/10/17 05:22:28)
git-committer:
Dirk Hohndel <dirk@…> (06/12/17 10:59:05)
Message:

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@…>
Signed-off-by: Dirk Hohndel <dirk@…>

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • core/btdiscovery.cpp

    ra43cafa r5142d74  
    33#include "btdiscovery.h"
    44#include "downloadfromdcthread.h"
     5#include "core/libdivecomputer.h"
    56#include <QDebug>
    67
     8extern QMap<QString, dc_descriptor_t *> descriptorLookup;
     9
    710BTDiscovery *BTDiscovery::m_instance = NULL;
     11
     12static dc_descriptor_t *getDeviceType(QString btName)
     13// central function to convert a BT name to a Subsurface known vendor/model pair
     14{
     15        QString vendor, product;
     16
     17        if (btName.startsWith("OSTC")) {
     18                vendor = "Heinrichs Weikamp";
     19                if (btName.mid(4,2) == "3#") product = "OSTC 3";
     20                else if (btName.mid(4,2) == "3+") product = "OSTC 3+";
     21                else if (btName.mid(4,2) == "s#") product = "OSTC Sport";
     22                else if (btName.mid(4,2) == "4-") product = "OSTC 4";
     23                else if (btName.mid(4,2) == "2-") product = "OSTC 2N";
     24                // all OSTCs are HW_FAMILY_OSTC_3, so when we do not know,
     25                // just try this
     26                else product = "OSTC 3"; // all OSTCs are HW_FAMILY_OSTC_3
     27        }
     28
     29        if (!vendor.isEmpty() && !product.isEmpty())
     30                return(descriptorLookup[vendor + product]);
     31
     32        return(NULL);
     33}
    834
    935BTDiscovery::BTDiscovery(QObject *parent)
     
    6995        struct btVendorProduct btVP;
    7096
    71         QString newDevice = device.name();
    72 
    73         // all the HW OSTC BT computers show up as "OSTC" + some other text, depending on model
    74         if (newDevice.startsWith("OSTC"))
    75                 newDevice = "OSTC 3";
     97        QString newDevice;
     98        dc_descriptor_t *newDC = getDeviceType(device.name());
     99        if (newDC)
     100                newDevice = dc_descriptor_get_product(newDC);
     101         else
     102                newDevice = device.name();
     103
    76104        QList<QBluetoothUuid> serviceUuids = device.serviceUuids();
    77105        foreach (QBluetoothUuid id, serviceUuids) {
     
    81109        qDebug() << "Found new device:" << newDevice << device.address();
    82110        QString vendor;
    83         foreach (vendor, productList.keys()) {
     111        if (newDC) foreach (vendor, productList.keys()) {
    84112                if (productList[vendor].contains(newDevice)) {
    85113                        qDebug() << "this could be a " + vendor + " " +
    86114                                        (newDevice == "OSTC 3" ? "OSTC family" : newDevice);
    87115                        btVP.btdi = device;
     116                        btVP.dcDescriptor = newDC;
    88117                        btVP.vendorIdx = vendorList.indexOf(vendor);
    89118                        btVP.productIdx = productList[vendor].indexOf(newDevice);
     
    96125
    97126        btVP.btdi = device;
     127        btVP.dcDescriptor = newDC;
    98128        btVP.vendorIdx = vendorList.indexOf(QObject::tr("Paired Bluetooth Devices"));
    99129        btVP.productIdx = productList[QObject::tr("Paired Bluetooth Devices")].indexOf(this_d.name);
     
    175205}
    176206#endif // Q_OS_ANDROID
     207
    177208#endif // BT_SUPPORT
  • core/btdiscovery.h

    r790c0dc r5142d74  
    1010#include <QBluetoothDeviceDiscoveryAgent>
    1111#include <QBluetoothUuid>
     12#include "core/libdivecomputer.h"
    1213
    1314struct btVendorProduct {
    1415        QBluetoothDeviceInfo btdi;
     16        dc_descriptor_t *dcDescriptor;
    1517        int vendorIdx;
    1618        int productIdx;
    1719};
     20
     21static dc_descriptor_t *getDeviceType(QString btName);
    1822
    1923#endif
  • core/downloadfromdcthread.cpp

    r790c0dc r5142d74  
    250250
    251251        // Pick the vendor of the first confirmed find of a DC (if any), but
    252         // only return a true vendow, and not our virtual one
     252        // only return a true vendor, and not our virtual one
    253253        if (!btDCs.isEmpty() && currentText != QObject::tr("Paired Bluetooth Devices")) {
    254254                qDebug() << "getDetectedVendorIndex" << currentText << btDCs.first().vendorIdx;
     
    312312                return btAddr;
    313313        }
    314 
     314#endif
    315315        return QString();
    316 #endif
    317 }
     316}
     317
     318QString DCDeviceData::getDeviceDescriptorVendor(const QString &currentVendorText,
     319                                                const QString &currentProductText)
     320{
     321#if defined(BT_SUPPORT)
     322        QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
     323        QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
     324
     325        // Pull the vendor from the first found dive computer that is been
     326        // detected as a possible real dive computer (and not some other paired
     327        // BT device
     328        if (currentVendorText != QObject::tr("Paired Bluetooth Devices") && !btDCs.isEmpty()) {
     329                QString dcVendor =  dc_descriptor_get_vendor(btDCs.first().dcDescriptor);
     330                qDebug() << "getDeviceDescriptorVendor" << dcVendor;
     331                return dcVendor;
     332        }
     333
     334        // if the above fails, pull vendor from the selected paired device
     335        // unsure being a dive computer
     336        if (currentVendorText == QObject::tr("Paired Bluetooth Devices")) {
     337                int i =  productList[currentVendorText].indexOf(currentProductText);
     338                QString dcVendor = dc_descriptor_get_vendor(btAllDevices[i].dcDescriptor);
     339                qDebug() << "getDeviceDescriptorVendor" << dcVendor;
     340                return dcVendor;
     341        }
     342#endif
     343        return NULL;
     344}
     345
     346QString DCDeviceData::getDeviceDescriptorProduct(const QString &currentVendorText,
     347                                                 const QString &currentProductText)
     348{
     349#if defined(BT_SUPPORT)
     350        QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
     351        QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
     352
     353        // Pull the product from the first found dive computer that is been
     354        // detected as a possible real dive computer (and not some other paired
     355        // BT device
     356        if (currentVendorText != QObject::tr("Paired Bluetooth Devices") && !btDCs.isEmpty()) {
     357                QString dcProduct =  dc_descriptor_get_product(btDCs.first().dcDescriptor);
     358                qDebug() << "getDeviceDescriptorProduct" << dcProduct;
     359                return dcProduct;
     360        }
     361
     362        // if the above fails, pull product from the selected paired device
     363        // unsure being a dive computer
     364        if (currentVendorText == QObject::tr("Paired Bluetooth Devices")) {
     365                int i =  productList[currentVendorText].indexOf(currentProductText);
     366                QString dcProduct = dc_descriptor_get_product(btAllDevices[i].dcDescriptor);
     367                qDebug() << "getDeviceDescriptorProduct" << dcProduct;
     368                return dcProduct;
     369        }
     370#endif
     371        return NULL;
     372}
  • core/downloadfromdcthread.h

    r790c0dc r5142d74  
    5151        Q_INVOKABLE QString getDetectedDeviceAddress(const QString &currentVendorText,
    5252                                                     const QString &currentProductText);
     53        Q_INVOKABLE QString getDeviceDescriptorVendor(const QString &currentVendorText,
     54                                                      const QString &currentProductText);
     55        Q_INVOKABLE QString getDeviceDescriptorProduct(const QString &currentVendorText,
     56                                                       const QString &currentProductText);
    5357
    5458public slots:
  • mobile-widgets/qml/DownloadFromDiveComputer.qml

    r790c0dc r5142d74  
    9494                                                if (addr !== "")
    9595                                                downloadThread.deviceData.devName = addr
     96                                                var vendor = downloadThread.deviceData.getDeviceDescriptorVendor(comboVendor.currentText,
     97                                                                                                                                                                                 comboProduct.currentText)
     98                                                downloadThread.deviceData.vendor = vendor;
     99
     100                                                var product = downloadThread.deviceData.getDeviceDescriptorProduct(comboVendor.currentText,
     101                                                                                                                                                                                 comboProduct.currentText)
     102                                                downloadThread.deviceData.product = product;
    96103                                        }
    97104                                        manager.appendTextToLog("DCDownloadThread started for " + downloadThread.deviceData.devName)
Note: See TracChangeset for help on using the changeset viewer.