BLEProthesisInterfaceQtWorker.h
Go to the documentation of this file.
1#pragma once
2
3#include <mutex>
4
5#include <QBluetoothDeviceDiscoveryAgent>
6#include <QBluetoothDeviceInfo>
7#include <QLowEnergyController>
8#include <QLowEnergyService>
9#include <QThread>
10
12
13class BLEProthesisInterfaceQtWorker : public QThread
14{
15 Q_OBJECT
16public:
18 BLEProthesisInterfaceQtWorker(const QString& mac, BLEProthesisInterface& owner);
20
21 void kill();
22 void sendCommand(const std::string& cmd);
23
24private:
25 void cleanup();
26
27protected:
28 void timerEvent(QTimerEvent* event) override;
29signals:
30 void resultReady(const QString& s);
31private slots:
32 //dev discover
33 void deviceDiscovered(const QBluetoothDeviceInfo& device);
34 void deviceDiscoverFinished();
35 void deviceDiscoverError(QBluetoothDeviceDiscoveryAgent::Error);
36 void deviceConnected();
37 void deviceDisconnected();
38 //service discovery
39 void serviceDiscovered(const QBluetoothUuid& gatt);
40 void serviceDiscoverFinished();
41 void controllerError(QLowEnergyController::Error error);
42 //communication
43 void receiveDeviceDisconnec(const QLowEnergyDescriptor& d, const QByteArray& value);
44
45 void serviceStateChanged(QLowEnergyService::ServiceState s);
46 void readData(const QLowEnergyCharacteristic& c, const QByteArray& value);
47
48private:
49 template <BLEProthesisInterface::SensorValueProtocol P>
50 void consumeData();
51
53 QString _mac;
54
55 //management (sensor/control)
56 int _timer{-1};
57 std::atomic_bool _killed{false};
58
59 QString _valueAkk;
60
61 QString _cmd;
62 std::mutex _cmdMutex;
63 //ble discover
64 QBluetoothDeviceDiscoveryAgent* _deviceDiscoveryAgent{nullptr};
65 QBluetoothDeviceInfo _currentDevice;
66 bool _deviceDiscovered{false};
67 //ble dev
68 QLowEnergyController* _control{nullptr};
69 //ble ser
70 bool _serviceDiscovered{false};
71 QLowEnergyDescriptor _notificationDescTx;
72 QLowEnergyService* _service{nullptr};
73};
constexpr T c
void resultReady(const QString &s)
BLEProthesisInterfaceQtWorker(const QString &mac, BLEProthesisInterface &owner)
void timerEvent(QTimerEvent *event) override