aboutsummaryrefslogtreecommitdiffstats
path: root/core/qt-ble.h
AgeCommit message (Collapse)Author
2020-10-24cleanup: remove dc_user_device_tGravatar Berthold Stoeger
The same structure was defined as "struct dc_user_device_t" and typedefed as "device_data_t". Unify this. Since there are much more of the latter, remove the former. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-01-27Update to new libdivecomputer versionGravatar Linus Torvalds
Jef has changed the libdivecomputer iostream layer and extended it in two different ways: - iostram's now have a 'poll()' method, which does what the name implies: waits for data to be available with a timeout. - iostreams now have a 'ioctl()' method, which can be used to implement miscellaneous operations. Right now the two ones that you can do are "set latency" (this replaces the old 'set_latency()' method) and "get BLE name" (this replaces our 'get_name()' method that was never part of the upstream libdivecomputer interfaces) Neither of these is all that complicated, and the transition is fairly obvious. HOWEVER. I have absolutely no idea how to do 'poll()' on Windows sockets, and I have no intention of figuring it out. We use a direct socket interface to implement the (non-BLE) RFCOMM bluetooth serial protocol, and I'm not sure why Windows is so special here. I suspect - but cannot test - that we should just switch the Windows RFCOMM implementation over to the use the same QtBluetooth code that we use on other platforms. I assume that the Windows Bluetooth support was originally not sufficiently good for that, but these days we depend on Qt doing BLE for us even on Windows, so presumably FRCOMM works too. That would be a nice cleanup, and would make 'poll()' work on RFCOMM under Windows too. However, since I can't test it, I've not done that, but instead just made the Windows RFCOMM 'poll()' method always return success. That may or may not get the thing limping along. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-04-12get rid of some foreach and Q_FOREACH constructsGravatar Rolf Eike Beer
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>
2018-10-08qt-ble: add 'get_name()' function to expose the BLE name to libdivecomputerGravatar Linus Torvalds
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>
2018-10-06qt-ble: add support for libdivecomputer 'set_timeout()' functionGravatar Linus Torvalds
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>
2018-10-06qt-ble: add support to wait for descriptor write completionGravatar Linus Torvalds
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>
2018-09-23qt-ble: set up infrastructure for better preferred service choiceGravatar Linus Torvalds
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>
2018-04-24Convert our custom IO model to new libdivecomputer IO modelGravatar Linus Torvalds
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>
2017-07-19iOS build: need to more includesGravatar Dirk Hohndel
It's kinda odd this builds fine on other OSs, but whatever. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-11OSTC over BLE: take care of creditsGravatar Jan Mulder
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>
2017-07-04Address code reviewGravatar Jan Mulder
Addresses code review by Dirk. No functional changes. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-04OSTC over BLE: filter and track OSTC credit trafficGravatar Jan Mulder
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>
2017-07-04Use waitFor instead of timerGravatar Jan Mulder
See e79bede0aa5b3bd. We rather use wait in combination with spinning the event loop. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-04OSTC over BLE: initialize Terminal I/O clientGravatar Jan Mulder
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>
2017-06-27Use SSRF_CUSTOM_IO v2 to implement device data quirks for BLE GATTGravatar Linus Torvalds
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>
2017-06-27Ensure all found BLE services are trackedGravatar Alex Blasche
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>
2017-06-24BLE support: add SPDX headersGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-24Very early and likely quite broken BLE GATT codeGravatar Linus Torvalds
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>