On Wed, Apr 25, 2018 at 8:43 AM, Dirk Hohndel <d...@hohndel.org> wrote: > > We should now focus on figuring out the problems with the Shearwater > downloads. > For some people these fail on rfcomm, for some they fail on BLE but succeed on > rfcomm, and it seems that some can't download from their Shearwater devices at > all...
So attached is a trial patch. It makes sense to me, but I don't have any rfcomm devices to try with. What it does is: - create a notion of "supported protocols" - use the "bluetooth_mode" to switch that between "BT and BLE" and "everything _but_ BT and BLE" - take the "LE:" prefix into account when in bluetooth mode, and limit things to _only_ BLE in that case - limit the final set of protocols to the bitwise logical and of the "dive computer supports this protocol" and "we support this protocol". - and finally, try rfcomm _before_ trying BLE What the *effect* of this should be: - we don't try the crazy "fall back on other protocols" if bluetooth_mode was set - we actually start taking that "LE:" prefix into account again. - people who prefer rfcomm won't have us trying BLE first but it's entirely untested. Well - it builds for me, and my Perdix AI still downloads, but I obviously can't test the case that really matters. Linus
core/libdivecomputer.c | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 6c2ceaca7..680b5cf95 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -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; + unsigned int transports, supported; + transports = dc_descriptor_get_transports(descriptor); + supported = get_supported_transports(data); -#ifdef BLE_SUPPORT - if (data->bluetooth_mode && (transports & DC_TRANSPORT_BLE)) { - rc = ble_packet_open(&data->iostream, context, data->devname, 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; }
_______________________________________________ subsurface mailing list subsurface@subsurface-divelog.org http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface