-
Notifications
You must be signed in to change notification settings - Fork 0
/
bt_rfcomm.h
56 lines (42 loc) · 1.37 KB
/
bt_rfcomm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef BT_RFCOMM_H
#define BT_RFCOMM_H
#include <QObject>
#include <QString>
#include <QBluetoothServiceInfo>
#include <QBluetoothServiceDiscoveryAgent>
#include <QBluetoothSocket>
class BTRfcomm : public QObject
{
Q_OBJECT
public:
explicit BTRfcomm(QObject *parent = nullptr);
~BTRfcomm();
Q_INVOKABLE void startDiscovery();
Q_INVOKABLE void stopDiscovery();
Q_PROPERTY(bool isDiscovering READ getServiceDiscoveryStatus)
Q_INVOKABLE void connectDevice(QString address);
Q_INVOKABLE void disconnectDevice();
Q_INVOKABLE void sendLine(QString line);
signals:
void discovered(QString name, QString address);
void discoveryFinished();
void discoveryError(QString error);
void connected(QString deviceAddress);
void disconnected();
void connectionError(QString error);
void lineReceived(QString line);
private slots:
void onServiceDiscovered(const QBluetoothServiceInfo &service);
void onServiceDiscoveryFinished();
void onServiceDiscoveryError(QBluetoothServiceDiscoveryAgent::Error error);
void onSocketReadyRead();
void onSocketConnected();
void onSocketDisconnected();
void onSocketError(QBluetoothSocket::SocketError);
private:
QBluetoothServiceDiscoveryAgent *m_discoveryAgent;
QBluetoothSocket *m_socket;
QString m_data;
bool getServiceDiscoveryStatus();
};
#endif // BT_RFCOMM_H