aboutsummaryrefslogtreecommitdiffstats
path: root/core/qtserialbluetooth.cpp
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-06-18core: fix compile issue with older g++Gravatar Dirk Hohndel
Having the full list of all members in the exact order should be enough to get g++ to accept the named initializers. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-06-18core: fix libdivecomputer dc_custom callbacks structuresGravatar Linus Torvalds
The last time those changed, we forgot to update serial_ftdi. In that change set_latency had been removed from libdivecomputer and poll and ioctl had been added. This caused the callbacks to no longer be aligned correctly and the functions were called with the wrong arguments through the wrong function pointers, leading to crashes. Instead of the fragile assumptions about order and type of function pointers, use named initializers. And while we are at it, fix that for the bluetooth implementation as well. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-14iostream: fix incorrect rfcomm error case when writingGravatar Linus Torvalds
This is the exact same case as the previous commit, just for the writing side. Once again, it's the subsurface rfcomm iostream code that can return DC_STATUS_SUCCESS with a byte count of zero when something goes wrong with the write. And once again, our libdivecomputer iostream code didn't try to be robust and protect itself from that case. The fix is equivalent, although slightly simpler, since the write side doesn't have the whole timeout issue. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-03-14iostream: fix incorrect rfcomm error case when readingGravatar Linus Torvalds
We had two independent bugs here, both of which needed to fire for this to cause a problem. This fixes both of them. The first bug was that our rfcomm code would return DC_STATUS_SUCCESS with a zero-sized read when a timeout happened, or when the rfcomm socket had disconnected. That makes absolutely no sense. We should return DC_STATUS_TIMEOUT on timeout, and DC_STATUS_IO if the socket has disconnected without any data. The fix to this is to make the whole rfcomm iostream read logic much simpler: there's no need to loop at all for partial results, because the libdivecomputer iostream side will do the loop for us (and handle partial results much better: it knows if the target backend can handle those partial results or not). The second bug was in our libdivecomputer iostream read() function, which reacted very badly to this bad return value. This updates our libdivecomputer branch to one that is more careful about things. Reported-by: linuxcrash <albin@mrty.ch> Debugged-by: Jef Driesen <jef@libdivecomputer.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-01-27core/qtserialbluetooth.cpp: use QEventLoop for pollingGravatar Lubomir I. Ivanov
The Qt docs here: https://doc.qt.io/qt-5/qbluetoothsocket.html#details and here: https://doc.qt.io/qt-5/qabstractsocket.html#waitForReadyRead say that waitForReadyRead() does not work for QBluetoothSocket and that it's flaky on Windows for the underlying QAbstractSocket. Use a QEventLoop and a QTimer to poll the readyRead() signal. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2020-01-27rfcomm: make Windows use QtBluetooth tooGravatar Linus Torvalds
Windows had it's own direct socket implementation for rfcomm (ie legacy BT), while all the other platforms used QtBluetooth. This makes Windows do the same thing. Hopefully modern Qt libraries now work well enough on the Windows platform for this to work, but I can't test it. We can make a test build that Windows people can try, though. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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-03-27drop support for Qt 5.4 and beforeGravatar Rolf Eike Beer
The oldest version tested on TravisCI is Qt 5.5, which is also what is in Ubuntu 16.04. Drop all the older cruft, noone should use that anymore. Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
2018-12-27Core: fix BT on Linux, workaround Qt bug on 5.12.0Gravatar Jan Mulder
After upgrading to Qt 5.12.0, download over BT from a DC did not work any more. On the console the message "Connecting to port is not supported (Uuid required)". Linus noticed earlier that we do rather strange processing in this part of the code related to selecting port 1 or port 5. This all seems not needed (any more), but broader testing is advised. This being stripped from the code, the mentioned error from Qt persisted. That is strange in itself, as we did not reference port numbers any more. Step 2 in this commit is actually using an uuid to the call to connectToService. Choosing an uuid seems relatively straightforward as we can use the same one we already use for Android. That is the default BT RFCOMM Serial Port Profile uuid. Interestingly, when changing to this uuid we run immediately in a Qt runtime error telling us "QDBusPendingReply: type ManagedObjectList is not registered with QtDBus.". For these 2 unexpected Qt messages, QTBUG-72742 was made. Studying the Qt source code at this point reveals a possible workaround. Simply create a local QBluetoothLocalDevice object, which, behind the scenes registers the Qt internal ManagedObjectList with QtDBus. In the meantime, Qt agrees that QTBUG-72742 is valid, and that a fix is to be expected in a future version. At that point in time, the declaration of the QBluetoothLocalDevice can be deleted again. In the end, interfacing over BT works again. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
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-07-13Make sure our libdivecomputer custom IO interfaces have sleep functionsGravatar Linus Torvalds
When I switched over from our own custom IO implementation to the new upstream custom IO model in libdivecomputer, I completely missed the fact that the libdivecomputer custom IO model also does a custom _sleep_ function. I'm not entirely sure what the point was, and it broke things even in libdivecopmputer itself when some of the new sleep functions were broken. Anyway, we didn't export any sleep functions at all for the bluetooth, BLE and FTDI cases, the the libdivecomputer code didn't fall back to any sane default sleep implementation either, so the end result was no sleeping at all. Which didn't matter for most divecomputers. But it seems like at least some OSTC dive computers did care, at least in certain situations, and both Miika and Anton had trouble downloading with their OSTC Sport dive computers. Using the serial line protocol and the legacy /dev/rfcomm model worked fine, because then it used the sleeping functions in the POSIX serial code inside libdivecomputer. This just adds trivial sleeping functions for the affected download protocols. Maybe I should have just made libdivecomputer have a sane default instead, but this wasn't hard either (the hard part was trying to figure out why the downloads worked for some people and not for others). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-05-24core: replace (void) with no parameter nameGravatar jan Iversen
Unused parameters in C++ are "silenced" by removing the name. Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-21core: Change Q_UNUSED to no parameter nameGravatar jan Iversen
C++ permits use of parameters without name, which signals unused Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-20core: marked unused parameterGravatar jan Iversen
Add Q_UNUSED to unused parameter Signed-off-by: Jan Iversen <jani@apache.org>
2018-04-25Compile fix when compiling without BLE enabledGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.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>
2018-04-13Fix typosGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-13Subsurface update for upstream libdivecomputer changesGravatar Linus Torvalds
So because I merged with upstream libdivecomputer, and it no longer does the "halfduplex emulation" thing in the IO layer, and instead does it in the only Suunto backend that needed it, that also affected our custom IO layer in subsurface. Sure, I could have left a dummy interface and left subsurface with some ugly dead code, but it's really better to just get rid of the code. So when Dirk pulls in the libdivecomputer updates from https://github.com/torvalds/libdc-for-dirk.git Subsurface-branch this patch to remove the halfduplex code in subsurface is also needed. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: Stefan Fuchs <sfuchs@gmx.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-11-20Fix typo: successfull -> successful and succesfully -> successfullyGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-10-20Silence random warningsGravatar Dirk Hohndel
None of these seem to point to actual issues, so let's quiet them. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-09-22BLE: big writes to connected DC (OSTC firmware)Gravatar Jan Mulder
Most writes to a connected DC are small, typically some command bytes to get DC in download mode, or to set some parameter. All this just worked over BLE, however, sending a full firmware update (on an OSTC device) failed, as the underlying BLE interface can only handle small 20 byte BLE packets at once. So, send max ble->packet_size chuncks at once. Tested for the following cases (linux desktop with OSTC3 over BLE): 1) normal download of dive data. 2) read and write settings from configure UI 3) update firmware (from 2.15 to 2.15) And to my surprise, no flow control credit administration is required here. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-08-26Remove unused functionGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-19BLE serial read/write bufferGravatar Jan Mulder
The adapted define was confusingly wrong. Apparently, the BUFSIZ define was coming from some include file, and was dependent on platform (Linux 8K, Andorid 1K). Simple rewrite to a new define and a proper value for both Linux and Android. If 4K is big enhough, is a little uncertain, as its depends on the read behavior of all libdivecomputer parsers using this serial BLE interface. The buffer size needed (on read, as that is the most prominent direction when interfacing with DCs) is (most likely) 2x the maximum block the libdc parsers request at once. I did not study all parsers, but the Shearwater parser request 20 bytes at once (we know that from the 1 packet at the time read, we had before). The OSTC parser request 1K blocks for data that is longer than 1K (like profiles, header tables). The 1K we had on Android was working for Shearwater, Eon Steel, but not for OSTC,as its reads 1K at the time at max, and overflowing the buffer. So 32k or 64k seems way to big (as in, much bigger than any libdc read). Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-11OSTC over BLE: read a long as neededGravatar Jan Mulder
See also b409e9fc91d87bbd5 and 709c1df2af4b87. The OSTC parser cannot handle reads of single 20 byte BLE packages in serial mode. Instead of doing a deeper down agressive read, we can read on the serial level more subtile. As the parser is requesting a specific number of bytes, we just read that number of bytes and return them. As the 20 byte BLE packets do (obviously) not align with the reading requirement of the libdc parser, a little housekeeing needs to be done in between individual reads. CAVEAT 1: In contradiction to 709c1df2af4b87, this is supposed to work for all parsers that properly specify the needed bytes to fetch. CAVEAT 2: All above tested on Linux Desktop with bluez stack. Subsurface mobile is step 2. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-06-27WhitespaceGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-27BLE code: address some compiler warningsGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-27Switch over to SSRF_CUSTOM_IO v2Gravatar Linus Torvalds
I hate changing the IO interfaces this often, but when I converted the custom serial interface to the more generic custom IO interface, I intentionally left the legacy serial operations alone, because I didn't want to change something I didn't care about. But it turns out that leaving them with the old calling convention caused extra problems when converting the bluetooth serial code to have the BLE GATT packet fall-back, which requires mixing two kinds of operations. Also, the packet_open() routine was passed a copy of the 'dc_context_t', which makes it possible to update the 'dc_custom_io_t' field on the fly at open time. That makes a lot of chaining operations much simpler, since now you can chain the 'custom_io_t' at open time and then libdivecomputer will automatically call the new routines instead of the old ones. That dc_context_t availability gets rid of all the if (device && device->ops) return device->ops->serial_xyz(..); hackery inside the rfcomm routines - now we can just at open time do a simple dc_context_set_custom_io(context, &ble_serial_ops); to switch things over to the BLE version of the serial code instead. Finally, SSRF_CUSTOM_IO v2 added an opaque "dc_user_device_t" pointer argument to the custom_io descriptor, which gets filled in as the custom_io is registered with the download context. Note that unlike most opaque pointers, this one is opaque to *libdivecomputer*, and the type is supposed to be supplied by the user. We define the "dc_user_device_t" as our old "struct device_data_t", making it "struct user_device_t" instead. That means that the IO routines now get passed the device info showing what device they are supposed to download for. That, in turn, means that now our BLE GATT open code can take the device type it opens for into account if it wants to. And it will want to, since the rules for Shearwater are different from the rules for Suunto, for example. NOTE! Because of the interface change with libdivecomputer, this will need a flag-day again where libdivecomputer and subsurface are updated together. It may not be the last time, either. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-26BT serial: recognize LE-only devices, and fall back to emulated serialGravatar Linus Torvalds
This is somewhat hacky, but it allows at least the Shearwater libdivecomputer backend to continue to treat even the BLE GATT model as just a serial protocol. What it does is create a special "emulate serial behavior over the packetized BLE protocol" helper layer, that qtserialbluetooth falls back on when rfcomm is not available. NOTE! This still requires some BLE packet code changes to work with the odd way that Shearwater sets up their BLE GATT communication. So note that no further patches are necessary to *libdivecomputer*, but some updates are needed for the subsurface qt-ble.cpp code. I have those updates in my tree, and this code is all tested on my Perdix AI, but those patches are currently too ugly to commit as-is. I've cleaned up this "fake serial" code sufficiently, that cleanup comes next. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> 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>
2017-06-22Convert to new libdivecomputer custom IO modelGravatar Linus Torvalds
Instead of being "custom serial", it's a IO model that allows serial or packet modes, independently of each other (ie you can have a bluetooth device that does serial over BT rfcomm and packet-based communication over BLE GATT with the same serial operations that describe both cases). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-05-31Android BT download: hardcode UUIDGravatar Dirk Hohndel
While it seemed logical to use the advertized service UUID that doesn't appear to be working - instead using this hard coded UUID seems to do the trick. I now did a successful download from my Shearwater Petrel. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-31Android BT: use NoSecurity for connectionGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-31Android: connect to BT via uuid instead of portGravatar Dirk Hohndel
We remember the offered service uuids as we detect the device and then try the first one - likely this needs to be fixed / tuned to pick the right one if multiple uuids are offered. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29Add SPDX header to remaining core filesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-28Change the Bluetooth connect call signatureGravatar Robert C. Helling
By copying a line from the Linux bluetooth code I can download from OSTC dive computers on Mac. Don't ask me why this works. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-03-12qtserialbluetooth.cpp: mark qt_serial_get_transmitted() as unusedGravatar Lubomir I. Ivanov
The function is unused, to silence the warning add the "unused" GCC attribute to the function declaration. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-18Fix compile error on WindowsGravatar Dirk Hohndel
We need to return a DC_STATUS here. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-17Rewrite libdivecomputer custom serial codeGravatar Anton Lundin
This rewrites the custom serial code to use the new api which I implemented in the Subsurface-branch of libdivecomputer. This is a bit to big patch but I haven't had the time to break it down into more sensible patches. This rewrite enables us to support more ftdi based divecomputer communication and is tested with both a OSTC3, OSTC2N and a Suunto Vyper, all over the libftdi driver. The bluetooth code paths are tested to, and should work as before. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04Move subsurface-core to core and qt-mobile to mobile-widgetsGravatar Dirk Hohndel
Having subsurface-core as a directory name really messes with autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an autocomplete conflict and also was inconsistent with the desktop-widget name for the directory containing the "other" UI. And while cleaning up the resulting change in the path name for include files, I decided to clean up those even more to make them consistent overall. This could have been handled in more commits, but since this requires a make clean before the build, it seemed more sensible to do it all in one. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>