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 
11 #include "BLEProthesisInterface.h"
12 
13 class BLEProthesisInterfaceQtWorker : public QThread
14 {
15  Q_OBJECT
16 public:
18  BLEProthesisInterfaceQtWorker(const QString& mac, BLEProthesisInterface& owner);
20 
21  void kill();
22  void sendCommand(const std::string& cmd);
23 
24 private:
25  void cleanup();
26 
27 protected:
28  void timerEvent(QTimerEvent* event) override;
29 signals:
30  void resultReady(const QString& s);
31 private 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 
48 private:
49  template <BLEProthesisInterface::SensorValueProtocol P>
50  void consumeData();
51 
52  BLEProthesisInterface* _owner;
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 };
BLEProthesisInterfaceQtWorker::resultReady
void resultReady(const QString &s)
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
BLEProthesisInterface::State
State
Definition: BLEProthesisInterface.h:13
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
BLEProthesisInterfaceQtWorker::timerEvent
void timerEvent(QTimerEvent *event) override
Definition: BLEProthesisInterfaceQtWorker.cpp:68
BLEProthesisInterfaceQtWorker
Definition: BLEProthesisInterfaceQtWorker.h:13
BLEProthesisInterfaceQtWorker::sendCommand
void sendCommand(const std::string &cmd)
Definition: BLEProthesisInterfaceQtWorker.cpp:28
BLEProthesisInterfaceQtWorker::~BLEProthesisInterfaceQtWorker
~BLEProthesisInterfaceQtWorker()
Definition: BLEProthesisInterfaceQtWorker.cpp:16
BLEProthesisInterfaceQtWorker::BLEProthesisInterfaceQtWorker
BLEProthesisInterfaceQtWorker(const QString &mac, BLEProthesisInterface &owner)
Definition: BLEProthesisInterfaceQtWorker.cpp:9
BLEProthesisInterface
Definition: BLEProthesisInterface.h:10
BLEProthesisInterface.h
BLEProthesisInterfaceQtWorker::kill
void kill()
Definition: BLEProthesisInterfaceQtWorker.cpp:22
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33