/
devicetab.h
140 lines (121 loc) · 5.26 KB
/
devicetab.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef DEVICETAB_H
#define DEVICETAB_H
#include <QWidget>
#include <QTreeWidget>
#include <QBluetoothHostInfo>
#include <QBluetoothDeviceDiscoveryAgent>
#include <QSerialPortInfo>
#include <QSerialPort>
#include "mysettings.h"
#include "connection.h"
namespace Ui
{
class DeviceTab;
}
class DeviceTab : public QWidget
{
Q_OBJECT
public:
struct SP_ID
{
// identify a serial port device
quint16 m_vid = 0, m_pid = 0;
QString m_serialNumber;
SP_ID(quint16 vid, quint16 pid, const QString& serialNumber) :
m_vid(vid), m_pid(pid), m_serialNumber(serialNumber) {}
SP_ID(const QSerialPortInfo &info) :
SP_ID(info.vendorIdentifier(), info.productIdentifier(), info.serialNumber()) {}
SP_ID(const QString& str);
QString toString() const;
// (bool)(a.matches(b)) means a can use b's arguments
// 0: unmatch 1: match 2: the same
quint8 matches(const SP_ID& id) const;
explicit operator bool() const; // SP_ID is invalid or not
};
static const QMap<QString, QString> m_historyPrefix;
explicit DeviceTab(QWidget *parent = nullptr);
~DeviceTab();
void initSettings();
void setConnection(Connection* conn);
public slots:
void refreshTargetList();
void saveTCPClientPreference(const Connection::NetworkArgument &arg);
void saveUDPPreference(const Connection::NetworkArgument &arg);
void saveSPPreference(const Connection::SerialPortArgument& arg);
void getAvailableTypes(bool useFirstValid = false);
void onClientCountChanged();
void Net_onDeleteButtonClicked();
void syncUDPPreference();
void syncTCPClientPreference();
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
private:
Ui::DeviceTab *ui;
MySettings* settings;
Connection* m_connection = nullptr;
QIntValidator* m_netPortValidator;
QBluetoothDeviceDiscoveryAgent *BTClient_discoveryAgent = nullptr;
QHash<QString, int> m_shownBTDevices;
QLowEnergyController *m_BLEController = nullptr;
QHash<QBluetoothUuid, QTreeWidgetItem*> m_discoveredBLEServices;
const QString m_autoLocalAddress = tr("(Auto)");
const QString m_anyLocalAddress = tr("(Any)");
int m_maxHistoryNum;
// default value is defined in initSettings() and SettingsTab::loadPreference()
QList<Connection::SerialPortArgument> m_SPArgHistory;
QMap<QString, int> m_SPArgHistoryIndex;
QList<Connection::BTArgument> m_BLECArgHistory;
QMap<QString, int> m_BLECArgHistoryIndex;
QList<Connection::NetworkArgument> m_TCPClientHistory, m_UDPHistory;
bool m_isBLECLoaded = false;
void initUI();
#ifdef Q_OS_ANDROID
void getBondedTarget(bool isBLE);
#endif
void setBTClientDiscoveryAgent(QBluetoothAddress adapterAddress = QBluetoothAddress());
void BLEC_addService(const QBluetoothUuid &serviceUUID, QTreeWidgetItem *parentItem = nullptr);
void BLEC_addCharacteristic(const QLowEnergyCharacteristic& c, QTreeWidgetItem *parentItem);
void BLEC_addDescriptor(const QLowEnergyDescriptor &descriptor, QTreeWidgetItem *parentItem);
QString BLE_getCharacteristicPropertyString(const QLowEnergyCharacteristic &c);
qint64 updateBTAdapterList();
qint64 updateNetInterfaceList();
QBluetoothUuid String2UUID(const QString &string);
QString UUID2String(const QBluetoothUuid &UUID);
void loadSPPreference(const Connection::SerialPortArgument &arg = Connection::SerialPortArgument(), bool loadPortName = true);
void loadNetPreference(const Connection::NetworkArgument &arg, Connection::Type type);
void showNetArgumentHistory(const QList<Connection::NetworkArgument> &arg, Connection::Type type);
SP_ID SP_getPortID(int rowInList);
bool SP_hasDuplicateID(int rowInList);
bool SP_hasDuplicateID(const SP_ID& spid);
int SP_getMatchedHistoryIndex(int rowInList);
signals:
void connTypeChanged(Connection::Type type);
void argumentChanged();
void clientCountChanged();
private slots:
void on_openButton_clicked();
void on_closeButton_clicked();
void onTargetListCellClicked(int row, int column);
void BTdiscoverFinished();
void BTdeviceDiscovered(const QBluetoothDeviceInfo &device);
void on_typeBox_currentIndexChanged(int index);
void on_refreshButton_clicked();
void on_BTClient_adapterBox_activated(int index);
void on_BTServer_serviceNameEdit_editingFinished();
void on_BTServer_adapterBox_activated(int index);
void Net_onRemoteChanged();
void on_Net_localAddrBox_currentIndexChanged(int index);
void on_SP_baudRateBox_currentIndexChanged(int index);
void on_SP_dataBitsBox_currentIndexChanged(int index);
void on_SP_stopBitsBox_currentIndexChanged(int index);
void on_SP_parityBox_currentIndexChanged(int index);
void on_SP_flowControlBox_currentIndexChanged(int index);
void on_BLEC_connectButton_clicked();
void BLEC_onRootServiceDiscovered(const QBluetoothUuid &newService);
void BLEC_onServiceDetailDiscovered(QLowEnergyService::ServiceState newState);
void on_BTServer_deviceList_cellChanged(int row, int column);
void on_Net_addrPortList_cellChanged(int row, int column);
void on_BLEC_ServiceUUIDBox_currentTextChanged(const QString &arg1);
void on_BTClient_serviceUUIDBox_clicked();
};
#endif // DEVICETAB_H