mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Do a better job of picking which transport to use
If the user specified bluetooth, we really should pick bluetooth, not probe and possibly fall back to something else. We should also honor the users choice of BLE vs classic BT. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
fd359f5a88
commit
901991afbe
1 changed files with 42 additions and 8 deletions
|
@ -1200,25 +1200,59 @@ void logfunc(dc_context_t *context, dc_loglevel_t loglevel, const char *file, un
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the transports supported by us (as opposed to
|
||||
* the list of transports supported by a particular
|
||||
* dive computer).
|
||||
*
|
||||
* This could have various platform rules too..
|
||||
*/
|
||||
static unsigned int get_supported_transports(device_data_t *data)
|
||||
{
|
||||
unsigned int supported;
|
||||
|
||||
/*
|
||||
* We don't support BT or BLE unless bluetooth_mode was set,
|
||||
* and if it was we won't try any of the other transports.
|
||||
*/
|
||||
supported = ~(DC_TRANSPORT_BLUETOOTH | DC_TRANSPORT_BLE);
|
||||
if (data->bluetooth_mode) {
|
||||
supported = ~supported;
|
||||
if (!strncmp(data->devname, "LE:", 3))
|
||||
supported = DC_TRANSPORT_BLE;
|
||||
}
|
||||
|
||||
return supported;
|
||||
}
|
||||
|
||||
|
||||
dc_status_t divecomputer_device_open(device_data_t *data)
|
||||
{
|
||||
dc_status_t rc;
|
||||
dc_descriptor_t *descriptor = data->descriptor;
|
||||
dc_context_t *context = data->context;
|
||||
unsigned int transports;
|
||||
transports = dc_descriptor_get_transports(descriptor);
|
||||
unsigned int transports, supported;
|
||||
|
||||
#ifdef BLE_SUPPORT
|
||||
if (data->bluetooth_mode && (transports & DC_TRANSPORT_BLE)) {
|
||||
rc = ble_packet_open(&data->iostream, context, data->devname, data);
|
||||
transports = dc_descriptor_get_transports(descriptor);
|
||||
supported = get_supported_transports(data);
|
||||
|
||||
transports &= supported;
|
||||
if (!transports) {
|
||||
report_error("Dive computer transport not supported");
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
|
||||
#ifdef BT_SUPPORT
|
||||
if (transports & DC_TRANSPORT_BLUETOOTH) {
|
||||
rc = rfcomm_stream_open(&data->iostream, context, data->devname);
|
||||
if (rc == DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BT_SUPPORT
|
||||
if (data->bluetooth_mode && (transports & DC_TRANSPORT_BLUETOOTH)) {
|
||||
rc = rfcomm_stream_open(&data->iostream, context, data->devname);
|
||||
#ifdef BLE_SUPPORT
|
||||
if (transports & DC_TRANSPORT_BLE) {
|
||||
rc = ble_packet_open(&data->iostream, context, data->devname, data);
|
||||
if (rc == DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue