2017-06-25 05:00:52 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-06-13 02:47:50 +00:00
|
|
|
#ifndef QT_BLE_H
|
|
|
|
#define QT_BLE_H
|
|
|
|
|
2017-07-18 21:42:38 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include "core/libdivecomputer.h"
|
2017-06-27 12:56:30 +00:00
|
|
|
#include <QVector>
|
2017-06-13 02:47:50 +00:00
|
|
|
#include <QLowEnergyController>
|
|
|
|
#include <QEventLoop>
|
|
|
|
|
2017-07-03 17:24:39 +00:00
|
|
|
#define HW_OSTC_BLE_DATA_RX 0
|
|
|
|
#define HW_OSTC_BLE_DATA_TX 1
|
|
|
|
#define HW_OSTC_BLE_CREDITS_RX 2
|
|
|
|
#define HW_OSTC_BLE_CREDITS_TX 3
|
|
|
|
|
2017-06-13 02:47:50 +00:00
|
|
|
class BLEObject : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-06-27 22:14:27 +00:00
|
|
|
BLEObject(QLowEnergyController *c, dc_user_device_t *);
|
2017-06-13 02:47:50 +00:00
|
|
|
~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);
|
2017-06-27 12:56:30 +00:00
|
|
|
|
|
|
|
//TODO: need better mode of selecting the desired service than below
|
|
|
|
inline QLowEnergyService *preferredService()
|
|
|
|
{ return services.isEmpty() ? nullptr : services[0]; }
|
2017-06-13 02:47:50 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void addService(const QBluetoothUuid &newService);
|
|
|
|
void serviceStateChanged(QLowEnergyService::ServiceState s);
|
|
|
|
void characteristcStateChanged(const QLowEnergyCharacteristic &c, const QByteArray &value);
|
2017-07-03 19:21:02 +00:00
|
|
|
void characteristicWritten(const QLowEnergyCharacteristic &c, const QByteArray &value);
|
2017-06-13 02:47:50 +00:00
|
|
|
void writeCompleted(const QLowEnergyDescriptor &d, const QByteArray &value);
|
2017-07-04 14:40:33 +00:00
|
|
|
dc_status_t setupHwTerminalIo(QList<QLowEnergyCharacteristic>);
|
2017-07-05 16:37:21 +00:00
|
|
|
dc_status_t setHwCredit(unsigned int c);
|
2017-06-13 02:47:50 +00:00
|
|
|
private:
|
2017-06-27 12:56:30 +00:00
|
|
|
QVector<QLowEnergyService *> services;
|
|
|
|
|
|
|
|
QLowEnergyController *controller = nullptr;
|
2017-06-13 02:47:50 +00:00
|
|
|
QList<QByteArray> receivedPackets;
|
2017-07-03 17:24:39 +00:00
|
|
|
bool isCharacteristicWritten;
|
2017-06-27 22:14:27 +00:00
|
|
|
dc_user_device_t *device;
|
2017-07-05 16:37:21 +00:00
|
|
|
unsigned int hw_credit = 0;
|
2017-07-03 17:24:39 +00:00
|
|
|
|
|
|
|
QList<QUuid> hwAllCharacteristics = {
|
|
|
|
"{00000001-0000-1000-8000-008025000000}", // HW_OSTC_BLE_DATA_RX
|
|
|
|
"{00000002-0000-1000-8000-008025000000}", // HW_OSTC_BLE_DATA_TX
|
|
|
|
"{00000003-0000-1000-8000-008025000000}", // HW_OSTC_BLE_CREDITS_RX
|
|
|
|
"{00000004-0000-1000-8000-008025000000}" // HW_OSTC_BLE_CREDITS_TX
|
|
|
|
};
|
2017-06-13 02:47:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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
|