QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
BluetoothBleWorker.h
Go to the documentation of this file.
1#pragma once
2
3#include "BluetoothWorker.h"
4
5#include <QtBluetooth/QLowEnergyCharacteristic>
6#include <QtBluetooth/QLowEnergyController>
7#include <QtBluetooth/QLowEnergyDescriptor>
8#include <QtBluetooth/QLowEnergyService>
9#include <QtCore/QQueue>
10
12{
13 Q_OBJECT
14
15public:
16 explicit BluetoothBleWorker(const BluetoothConfiguration *config, QObject *parent = nullptr);
17 ~BluetoothBleWorker() override;
18
19protected:
20 void onSetupConnection() override;
21 void onConnectLink() override;
22 void onDisconnectLink() override;
23 void onWriteData(const QByteArray &data) override;
24 void onServiceDiscoveryTimeout() override;
25 void onResetAfterConsecutiveFailures() override;
26
27private slots:
28 void _onControllerConnected();
29 void _onControllerDisconnected();
30 void _onControllerErrorOccurred(QLowEnergyController::Error error);
31 void _onServiceDiscovered(const QBluetoothUuid &uuid);
32 void _onServiceDiscoveryFinished();
33 void _onServiceStateChanged(QLowEnergyService::ServiceState state);
34 void _onCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value);
35 void _onCharacteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &value);
36 void _onCharacteristicWritten(const QLowEnergyCharacteristic &characteristic, const QByteArray &value);
37 void _onDescriptorRead(const QLowEnergyDescriptor &descriptor, const QByteArray &value);
38 void _onDescriptorWritten(const QLowEnergyDescriptor &descriptor, const QByteArray &value);
39 void _onServiceError(QLowEnergyService::ServiceError error);
40
41private:
42 void _setupBleController();
43 void _recreateBleController();
44 void _setupBleService();
45 void _discoverServiceDetails();
46 void _enableNotifications();
47 void _writeBleData(const QByteArray &data);
48 void _findCharacteristics();
49 void _processNextBleWrite();
50 void _clearBleWriteQueue();
51
52 QPointer<QLowEnergyController> _controller;
53 QPointer<QLowEnergyService> _service;
54 QLowEnergyCharacteristic _readCharacteristic;
55 QLowEnergyCharacteristic _writeCharacteristic;
56 int _mtu = DEFAULT_ATT_MTU;
57 qint16 _rssi = 0;
58 QPointer<QTimer> _rssiTimer;
59 QQueue<QByteArray> _bleWriteQueue;
60 QByteArray _currentBleWrite;
61 bool _bleWriteInProgress = false;
62 bool _forceRandomAddressType = false;
63
64 static constexpr int MAX_BLE_QUEUE_SIZE = 100;
65 static constexpr int RSSI_POLL_INTERVAL_MS = 10000;
66 static constexpr int BLE_MIN_PACKET_SIZE = 20;
67 static constexpr int BLE_MAX_PACKET_SIZE = 512;
68 static constexpr int DEFAULT_ATT_MTU = 23;
69};
Error error
void onSetupConnection() override
void onResetAfterConsecutiveFailures() override
void onConnectLink() override
void onDisconnectLink() override
void onServiceDiscoveryTimeout() override
void onWriteData(const QByteArray &data) override