See https://www.kdab.com/goodbye-q_foreach/
This is reduced to the places where the container is const or can be made const
without the need to always introduce an extra variable. Sadly qAsConst (Qt 5.7)
and std::as_const (C++17) are not available in all supported setups.
Also do some minor cleanups along the way.
Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
Some divecomputer backends (ok, right now really only the Aqualung i770R
and i300C) want to know the bluetooth name of the dive computer they
connect to, because the name contains identifying information like the
serial number.
This just adds the support for that to our Qt BLE code.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Because some BLE operations can be very slow (device and service
discovery etc), we have some rather excessive default timeout for BLE
(currently set to 12 seconds).
But once we actually have started doing IO, that long timeout can be a
big performance problem, when the libdivecomputer backend has support
for retry and packet loss.
For that reason, libdivecomputer has a 'set_timeout()' function that
allows the divecomputer backend to say how quickly it expects the dive
computer to answer before the backend will start resending packets.
Let's just implement that for the actual IO side of BLE too. The
default timeout value remains the general BLE timeout, and this only
affects the actual IO phase, but it improves things enormously for the
case where there is packet loss at that point.
For example, on the Aqualung i770R, the timeout for packet loss ends up
now being just one second rather than the full 12 seconds of default BLE
timeout. Which gets the retry going much faster.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
When we enable notifications, we actually want to make sure to wait for
that write to have completed before we start communicating with the
device, because otherwise we might lose notification events.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
We used to just pick the first non-standard service we found (with a
special case for the Heinrichs Weikamp dive computers that have an
actual registered standard service).
We then waited for that service to finish discovery, and started using
it.
This changes the logic to wait for _all_ services to finish discovery,
and then after that we pick the one we like best. Right now the rule
for picking a preferred service is the same one we had before, but the
difference is that we now have the full discovery data, so we *could* do
something better.
Plus this makes our debug messages a lot more legible, when we don't
have the mix of overlapping service discovery with the actual IO we do
to the preferred service.
NOTE! This doesn't much matter for most of the dive computers that we
currently support BLE for. They don't tend to have a lot of odd
services.
But at least both the Mares BlueLink and the Garmin Descent both have
multiple services and it's not obvious which one to use, and this will
make it not only easier to debug those, it will make it easier to pick
the right preferred service descriptor to use.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This converts our old custom IO model to the new model that
libdivecomputer introduced. This is partly based on Jef's rough patch
to make things build, with further work by me.
The FTDI code is temporarily disabled here, because it will need to be
integrated with the new way of opening devices.
The ble_serial code goes away entirely, since now libdivecomputer knows
about BLE transport natively, and doesn't need to have any serial
wrapper around it.
Signed-off-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Handle credits. Do not just ask for maximum credits all the time as this
will stop the download. Also do not let the credits go back to 0 (while
this might work, this is not tested). Getting back the 0 credits stops
the download, and even when it can be restarted, it is less efficient
(and not needed). Notice also that it takes some time before a grant
request is honoured. During testing I saw reception of up to 25 packets
between request and grant. So a lower bound for the request of
32 packets seems resonable.
One aspect the Telit/Stollmann TIO puzzeled me. Sections 4.1 and 4.2
both talk about credits, but my hyphothesis is that there are two
credits counters in play. One for traffic either way. This commit
only deals with credits granted by Subsurface to the OSTC to send
data. Credits granted by the OSTC to allow Subsurface to send new
commands is NOT part of this commit, and is seemingly not needed
in our scenario. As we only send new commands to the OSTC when
a previous one is finished (per HW's interface spec), the OSTC
does not run out of credits to receive commands.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
1) As the OSTC sends data to the BLE central role (the SSRF client) over 2
characteristics, we have to filter the administrative credit data from
the actual dive data that it received. The characteristcStateChanged
function is adapted for this.
2) We have to be sure that the Terminal Client I/O is fully defined during
opening the connecton to the OSTC. From 6d505b24f0c15 we can see
that the last step in setting up the terminal interface is the grant
of credits. This is done by writing to the proper (the only one, with
id = 0x2902) descriptor of the credits RX characteristic. The here
added slot is triggered on the completion of write of credits marking
the final stage of the setup.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This initalizes the Terminal I/O client as described in paragraph 3 of
http://www.telit.com/fileadmin/user_upload/products/Downloads/sr-rf/BlueMod/TIO_Implementation_Guide_r04.pdf
This is for all Heinrichs Weikamp computers, that use referenced BT/BLE hardware
module from Telit Wireless Solutions (Formerly Stollmann E+V GmbH). The 16 bit
UUID 0xFEFB (or a derived 128 bit UUID starting with 0x0000FEFB is a
clear indication that the OSTC is equipped with this BT/BLE hardware.
Furthermore, most devices equipped with this BT/BLE hardware have BT addresses
starting with 00:80:25:...
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Right now we have a quirk for Shearwater devices to set the random
address flag, but also to handle the differences at read/write time.
With this, I can finally download from both the Suunto EON Steel and the
Shearwater Perdix AI with the same binary.
It's not *pretty*, but it works.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
If a device has more than one service the order of service discovery
determined the selection of the service that we intend to interact
with. This assumption is not accurate and is even platform dependent.
Thinking ahead, it is likely that some devices may require us to keep
track and interact with multiple services at the time.
The new logic still suffers from the fact that there is no way
to select the correct service for interaction. This will require
higher level stack changes.
Signed-off-by: Alex Blasche <alexander.blasche@qt.io>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This is some very early and hacky code to be able to access BLE-enabled
dive computers that use the GATT protocol to send packets back and forth
(which seems to be pretty much all of them: a vendor-specific GATT
service with a write characteristic and a notification characteristic
for reading).
For testing only. But it does successfully let me download dives from
my EON Steel and my Scubapro G2.
NOTE! There are several very hacky pieces in here, including just
"knowing" that the write characteristic is the first one, and the
notification characteristic is second. The code should actually check
the properties rather than have those kinds of hardcoded assumptions.
It also checks "vendor specific" by looking at the UUID string
representation, and knowing that the standard ones start with zero.
Crazily, there doesn't seem to be any normal way to test for this,
although I guess that maybe the uuid.minimumSize() function could be
used.
There are other nasty corners. Don't complain, send me patches.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>