summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-05-30 17:50:31 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-05-31 10:15:40 -0700
commit286bac6d30cf0b9ba5ad2a1fb6cce3287d5aa544 (patch)
tree4fd4645a2fb4a6d86c8a8006a74253bc118d5c9e /core
parent782caf5fa6b983658d9119db9b36c24b1522dc0b (diff)
downloadsubsurface-286bac6d30cf0b9ba5ad2a1fb6cce3287d5aa544.tar.gz
Android: connect to BT via uuid instead of port
We remember the offered service uuids as we detect the device and then try the first one - likely this needs to be fixed / tuned to pick the right one if multiple uuids are offered. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r--core/qtserialbluetooth.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/core/qtserialbluetooth.cpp b/core/qtserialbluetooth.cpp
index b8c57204e..e14d8e9f9 100644
--- a/core/qtserialbluetooth.cpp
+++ b/core/qtserialbluetooth.cpp
@@ -19,6 +19,18 @@
#include <libdivecomputer/custom_serial.h>
+QList<QBluetoothUuid> registeredUuids;
+
+static QBluetoothUuid getBtUuid()
+{
+ return registeredUuids.first();
+}
+
+void addBtUuid(QBluetoothUuid uuid)
+{
+ registeredUuids << uuid;
+}
+
extern "C" {
typedef struct qt_serial_t {
/*
@@ -32,6 +44,7 @@ typedef struct qt_serial_t {
long timeout;
} qt_serial_t;
+
static dc_status_t qt_serial_open(void **userdata, const char* devaddr)
{
// Allocate memory.
@@ -133,7 +146,13 @@ static dc_status_t qt_serial_open(void **userdata, const char* devaddr)
#elif defined(Q_OS_ANDROID) || (QT_VERSION >= 0x050500 && defined(Q_OS_MAC))
// Try to connect to the device using the uuid of the Serial Port Profile service
QBluetoothAddress remoteDeviceAddress(devaddr);
+#if defined(Q_OS_ANDROID)
+ QBluetoothUuid uuid = getBtUuid();
+ qDebug() << "connecting to Uuid" << uuid;
+ serial_port->socket->connectToService(remoteDeviceAddress, uuid, QIODevice::ReadWrite | QIODevice::Unbuffered);
+#else
serial_port->socket->connectToService(remoteDeviceAddress, 1, QIODevice::ReadWrite | QIODevice::Unbuffered);
+#endif
timer.start(msec);
loop.exec();