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 
10 #include "BLEProthesisInterface.h"
11 
12 #include <QThread>
13 
14 
15 class BLEProthesisInterfaceQtWorker : public QThread
16 {
17  Q_OBJECT
18 public:
20  BLEProthesisInterfaceQtWorker(const QString& mac, BLEProthesisInterface& owner);
22 
23  void kill();
24  void sendCommand(const std::string& cmd);
25 private:
26  void cleanup();
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 private:
48  template<BLEProthesisInterface::SensorValueProtocol P> void consumeData();
49 
50  BLEProthesisInterface* _owner;
51  QString _mac;
52 
53  //management (sensor/control)
54  int _timer{-1};
55  std::atomic_bool _killed{false};
56 
57  QString _valueAkk;
58 
59  QString _cmd;
60  std::mutex _cmdMutex;
61  //ble discover
62  QBluetoothDeviceDiscoveryAgent* _deviceDiscoveryAgent{nullptr};
63  QBluetoothDeviceInfo _currentDevice;
64  bool _deviceDiscovered{false};
65  //ble dev
66  QLowEnergyController* _control{nullptr};
67  //ble ser
68  bool _serviceDiscovered{false};
69  QLowEnergyDescriptor _notificationDescTx;
70  QLowEnergyService* _service{nullptr};
71 };
BLEProthesisInterfaceQtWorker::resultReady
void resultReady(const QString &s)
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
BLEProthesisInterface::State
State
Definition: BLEProthesisInterface.h:13
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
BLEProthesisInterfaceQtWorker::timerEvent
void timerEvent(QTimerEvent *event) override
Definition: BLEProthesisInterfaceQtWorker.cpp:64
BLEProthesisInterfaceQtWorker
Definition: BLEProthesisInterfaceQtWorker.h:15
BLEProthesisInterfaceQtWorker::sendCommand
void sendCommand(const std::string &cmd)
Definition: BLEProthesisInterfaceQtWorker.cpp:26
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:21
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33