diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2020-09-19 14:16:08 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-09-19 19:26:26 -0700 |
commit | e1befbea0aaa537945741ae9d14e590f4ca5171b (patch) | |
tree | b17e2b10fcb5e35d85655d08ffe31d067547d409 | |
parent | 9e50ab87dc89d72ad803d65e09a66b20fd3787e2 (diff) | |
download | subsurface-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>
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | core/libdivecomputer.c | 27 |
2 files changed, 29 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 61cb33822..3bb4f040a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,6 +154,9 @@ endif() pkg_config_library(LIBZIP libzip REQUIRED) if(NOT ANDROID) + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + pkg_config_library(BLUEZ bluez REQUIRED) + endif() pkg_config_library(LIBUSB libusb-1.0 QUIET) endif() 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; } |