mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Update to new libdivecomputer version
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>
This commit is contained in:
parent
5b81997459
commit
9543f53150
4 changed files with 75 additions and 11 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <QLoggingCategory>
|
||||
|
||||
#include <libdivecomputer/version.h>
|
||||
#include <libdivecomputer/ble.h>
|
||||
|
||||
#include "libdivecomputer.h"
|
||||
#include "core/qt-ble.h"
|
||||
|
@ -198,10 +199,8 @@ dc_status_t BLEObject::write(const void *data, size_t size, size_t *actual)
|
|||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)
|
||||
dc_status_t BLEObject::poll(int timeout)
|
||||
{
|
||||
if (actual)
|
||||
*actual = 0;
|
||||
if (receivedPackets.isEmpty()) {
|
||||
QList<QLowEnergyCharacteristic> list = preferredService()->characteristics();
|
||||
if (list.isEmpty())
|
||||
|
@ -215,6 +214,21 @@ dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)
|
|||
return DC_STATUS_TIMEOUT;
|
||||
}
|
||||
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)
|
||||
{
|
||||
dc_status_t rc;
|
||||
|
||||
if (actual)
|
||||
*actual = 0;
|
||||
|
||||
// Wait for a packet
|
||||
rc = poll(timeout);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
QByteArray packet = receivedPackets.takeFirst();
|
||||
|
||||
// Did we get more than asked for?
|
||||
|
@ -549,10 +563,24 @@ dc_status_t qt_ble_write(void *io, const void* data, size_t size, size_t *actual
|
|||
return ble->write(data, size, actual);
|
||||
}
|
||||
|
||||
const char *qt_ble_get_name(void *io)
|
||||
dc_status_t qt_ble_poll(void *io, int timeout)
|
||||
{
|
||||
BLEObject *ble = (BLEObject *) io;
|
||||
return ble->get_name();
|
||||
|
||||
return ble->poll(timeout);
|
||||
}
|
||||
|
||||
dc_status_t qt_ble_ioctl(void *io, unsigned int request, void *data, size_t size)
|
||||
{
|
||||
BLEObject *ble = (BLEObject *) io;
|
||||
|
||||
switch (request) {
|
||||
case DC_IOCTL_BLE_GET_NAME:
|
||||
return ble->get_name((char *) data, size);
|
||||
default:
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} /* extern "C" */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue