10 #include <QBluetoothDeviceInfo>
11 #include <QLowEnergyController>
12 #include <QBluetoothUuid>
14 class QBluetoothDeviceDiscoveryAgent;
15 class QLowEnergyService;
16 class QLowEnergyCharacteristic;
21 Q_PROPERTY(QString name READ getDeviceName)
22 Q_PROPERTY(QString address READ getDeviceAddress)
25 ServiceIdentifier(
const QString & s,
const QString & r,
const QString & t, QObject *parent =
nullptr)
26 :QObject(parent), serviceUuid(s), rxUuid(r), txUuid(t), service(
nullptr), mController(
nullptr),
27 mAddyType(QLowEnergyController::RandomAddress){}
29 QString getDeviceName() {
return deviceName; }
30 QString getDeviceAddress() {
return deviceAddress; }
31 void setRemoteAddressType(
int t);
37 QString deviceAddress;
39 QLowEnergyService * service;
43 bool write(
const QByteArray &
data);
44 void connectToDevice();
45 void disconnectFromDevice();
48 void onMessage(
const QByteArray & data);
51 void stateChanged(
int state);
54 void characteristicChanged(
const QLowEnergyCharacteristic & characteristic,
const QByteArray & newValue);
55 void controllerConnected();
56 void controllerServiceDiscovered(
const QBluetoothUuid & uuid);
57 void controllerStateChanged(QLowEnergyController::ControllerState state);
58 void serviceStateChanged(QLowEnergyService::ServiceState s);
61 QLowEnergyController * mController;
62 QLowEnergyController::RemoteAddressType mAddyType;
65 class Ble :
public QObject
68 Q_PROPERTY(
bool scan READ scanning WRITE startScan NOTIFY scanningChanged)
69 Q_PROPERTY(
bool debug READ debug WRITE setDebug)
72 Ble(QObject* parent =
nullptr);
74 QObject* device(
const QString & address);
76 void setDebug(
bool d);
80 void addService(
const QString & serviceUuid,
const QString & rxUuid,
const QString & txUuid);
82 void startScan(
bool scan);
87 void scanningChanged();
88 void leDeviceFound(QObject*);
92 void errorHandle(QLowEnergyController::Error err);
93 void deviceDiscovered(
const QBluetoothDeviceInfo & device);
96 QList<ServiceIdentifier*> services;
97 QBluetoothDeviceDiscoveryAgent* mDeviceDiscoveryAgent;