aboutsummaryrefslogtreecommitdiffstats
path: root/core/qt-ble.h
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2017-06-12 19:47:50 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-06-24 21:58:01 -0700
commit196adb591bd167bc4ee3387c7836f037d106cb5b (patch)
tree6ae3f2cc92f56a3b792af5a690d330ae13cb8392 /core/qt-ble.h
parent03badea06f2bcfa9ebd6e7033710ac01ffac103f (diff)
downloadsubsurface-196adb591bd167bc4ee3387c7836f037d106cb5b.tar.gz
Very early and likely quite broken BLE GATT code
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>
Diffstat (limited to 'core/qt-ble.h')
-rw-r--r--core/qt-ble.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/core/qt-ble.h b/core/qt-ble.h
new file mode 100644
index 000000000..b819b0123
--- /dev/null
+++ b/core/qt-ble.h
@@ -0,0 +1,38 @@
+#ifndef QT_BLE_H
+#define QT_BLE_H
+
+#include <QLowEnergyController>
+#include <QEventLoop>
+
+class BLEObject : public QObject
+{
+ Q_OBJECT
+
+public:
+ BLEObject(QLowEnergyController *c);
+ ~BLEObject();
+ dc_status_t write(const void* data, size_t size, size_t *actual);
+ dc_status_t read(void* data, size_t size, size_t *actual);
+ QLowEnergyService *service;
+
+public slots:
+ void addService(const QBluetoothUuid &newService);
+ void serviceStateChanged(QLowEnergyService::ServiceState s);
+ void characteristcStateChanged(const QLowEnergyCharacteristic &c, const QByteArray &value);
+ void writeCompleted(const QLowEnergyDescriptor &d, const QByteArray &value);
+
+private:
+ QLowEnergyController *controller;
+ QList<QByteArray> receivedPackets;
+ QEventLoop waitForPacket;
+};
+
+
+extern "C" {
+dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *name);
+dc_status_t qt_ble_read(dc_custom_io_t *io, void* data, size_t size, size_t *actual);
+dc_status_t qt_ble_write(dc_custom_io_t *io, const void* data, size_t size, size_t *actual);
+dc_status_t qt_ble_close(dc_custom_io_t *io);
+}
+
+#endif