summaryrefslogtreecommitdiffstats
path: root/qtserialbluetooth.cpp
diff options
context:
space:
mode:
authorGravatar Claudiu Olteanu <olteanu.claudiu@ymail.com>2015-07-13 23:37:49 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-13 15:21:30 -0700
commitc6c706c28a90c78617c911b8c9c1192e6800d8f7 (patch)
tree66f945ed3d2160107071905bd54d8e6d91f3b097 /qtserialbluetooth.cpp
parent521183dc736b26afd8719bc83dfb41bfe62c1c70 (diff)
downloadsubsurface-c6c706c28a90c78617c911b8c9c1192e6800d8f7.tar.gz
Use SPP's uuid to connect to a device on Android platform
On Android, a Bluetooth connection to a service cannot be established using a port. Therefore we use the uuid of the Serial Port Profile service to connect to the remote BT device. Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qtserialbluetooth.cpp')
-rw-r--r--qtserialbluetooth.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/qtserialbluetooth.cpp b/qtserialbluetooth.cpp
index f06f24e89..95f3611cf 100644
--- a/qtserialbluetooth.cpp
+++ b/qtserialbluetooth.cpp
@@ -54,6 +54,7 @@ static int qt_serial_open(serial_t **out, dc_context_t *context, const char* dev
timer.setSingleShot(true);
loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
+#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
// First try to connect on RFCOMM channel 1. This is the default channel for most devices
QBluetoothAddress remoteDeviceAddress(devaddr);
serial_port->socket->connectToService(remoteDeviceAddress, 1);
@@ -79,8 +80,22 @@ static int qt_serial_open(serial_t **out, dc_context_t *context, const char* dev
loop.exec();
}
}
+#elif defined(Q_OS_ANDROID)
+ // Try to connect to the device using the uuid of the Serial Port Profile service
+ QBluetoothAddress remoteDeviceAddress(devaddr);
+ serial_port->socket->connectToService(remoteDeviceAddress, QBluetoothUuid(QBluetoothUuid::SerialPort));
+ timer.start(msec);
+ loop.exec();
- if (serial_port->socket->socketDescriptor() == -1 || serial_port->socket->state() != QBluetoothSocket::ConnectedState) {
+ if (serial_port->socket->state() == QBluetoothSocket::ConnectingState ||
+ serial_port->socket->state() == QBluetoothSocket::ServiceLookupState) {
+ // It seems that the connection step took more than expected. Wait another 20 seconds.
+ qDebug() << "The connection step took more than expected. Wait another 20 seconds";
+ timer.start(4 * msec);
+ loop.exec();
+ }
+#endif
+ if (serial_port->socket->state() != QBluetoothSocket::ConnectedState) {
free (serial_port);
// Get the latest error and try to match it with one from libdivecomputer