aboutsummaryrefslogtreecommitdiffstats
path: root/core/libdivecomputer.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2020-09-19 14:16:08 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-09-19 19:26:26 -0700
commite1befbea0aaa537945741ae9d14e590f4ca5171b (patch)
treeb17e2b10fcb5e35d85655d08ffe31d067547d409 /core/libdivecomputer.c
parent9e50ab87dc89d72ad803d65e09a66b20fd3787e2 (diff)
downloadsubsurface-e1befbea0aaa537945741ae9d14e590f4ca5171b.tar.gz
core/bluetooth: switch to use libdivecomputer rfcomm support
The Qt based implementation apparently got broken at some point and now fails to connect to rfcomm dive computers like the Shearwater Petrel. This uses the libdivecomputer rfcomm backend. Tested to work with bluez on Linux as well as with the native Windows implementation. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/libdivecomputer.c')
-rw-r--r--core/libdivecomputer.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index c3f62bbcf..47b261b7b 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -28,6 +28,7 @@
#include <libdivecomputer/usb.h>
#include <libdivecomputer/serial.h>
#include <libdivecomputer/irda.h>
+#include <libdivecomputer/bluetooth.h>
#include "libdivecomputer.h"
#include "core/version.h"
@@ -1340,6 +1341,30 @@ static dc_status_t irda_device_open(dc_iostream_t **iostream, dc_context_t *cont
return dc_irda_open(&data->iostream, context, address, 1);
}
+static dc_status_t bluetooth_device_open(dc_iostream_t **iostream, dc_context_t *context, device_data_t *data)
+{
+ dc_bluetooth_address_t address = 0;
+ dc_iterator_t *iterator = NULL;
+ dc_bluetooth_device_t *device = NULL;
+
+ // Try to find the rfcomm device address
+ dc_bluetooth_iterator_new (&iterator, context, data->descriptor);
+ while (dc_iterator_next (iterator, &device) == DC_STATUS_SUCCESS) {
+ address = dc_bluetooth_device_get_address (device);
+ dc_bluetooth_device_free (device);
+ break;
+ }
+ dc_iterator_free (iterator);
+
+ if (!address) {
+ report_error("No rfcomm device found");
+ return DC_STATUS_NODEVICE;
+ }
+
+ dev_info(data, "Opening rfcomm address %u", address);
+ return dc_bluetooth_open(&data->iostream, context, address, 0);
+}
+
dc_status_t divecomputer_device_open(device_data_t *data)
{
dc_status_t rc;
@@ -1358,7 +1383,7 @@ dc_status_t divecomputer_device_open(device_data_t *data)
#ifdef BT_SUPPORT
if (transports & DC_TRANSPORT_BLUETOOTH) {
dev_info(data, "Opening rfcomm stream %s", data->devname);
- rc = rfcomm_stream_open(&data->iostream, context, data->devname);
+ rc = bluetooth_device_open(&data->iostream, context, data);
if (rc == DC_STATUS_SUCCESS)
return rc;
}