Merge PR #507: Some more fixes in the BT discovery
This commit is contained in:
commit
f0c4ec7005
@ -68,6 +68,11 @@ QVariant SortFilterProxyModel::data(int row, const QString &role) const
|
|||||||
return QSortFilterProxyModel::data(index(row, 0), roleId);
|
return QSortFilterProxyModel::data(index(row, 0), roleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SortFilterProxyModel::mapToSource(int index) const
|
||||||
|
{
|
||||||
|
return QSortFilterProxyModel::mapToSource(this->index(index, 0)).row();
|
||||||
|
}
|
||||||
|
|
||||||
bool SortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
bool SortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
||||||
{
|
{
|
||||||
if (!m_filterList.isEmpty() && !m_filterRoleName.isEmpty()) {
|
if (!m_filterList.isEmpty() && !m_filterRoleName.isEmpty()) {
|
||||||
|
|||||||
@ -27,6 +27,7 @@ public:
|
|||||||
void setSortOrder(Qt::SortOrder sortOrder);
|
void setSortOrder(Qt::SortOrder sortOrder);
|
||||||
|
|
||||||
Q_INVOKABLE QVariant data(int row, const QString &role) const;
|
Q_INVOKABLE QVariant data(int row, const QString &role) const;
|
||||||
|
Q_INVOKABLE int mapToSource(int index) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void filterRoleNameChanged();
|
void filterRoleNameChanged();
|
||||||
|
|||||||
@ -124,7 +124,7 @@ void BluetoothDiscovery::setDiscoveryEnabled(bool discoveryEnabled)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_discoveryEnabled = discoveryEnabled;
|
m_discoveryEnabled = discoveryEnabled;
|
||||||
emit discoveringChanged();
|
emit discoveryEnabledChanged(m_discoveryEnabled);
|
||||||
|
|
||||||
if (m_discoveryEnabled) {
|
if (m_discoveryEnabled) {
|
||||||
start();
|
start();
|
||||||
@ -176,8 +176,7 @@ void BluetoothDiscovery::deviceDiscovered(const QBluetoothDeviceInfo &deviceInfo
|
|||||||
{
|
{
|
||||||
if (!deviceInfo.isValid()
|
if (!deviceInfo.isValid()
|
||||||
|| !deviceInfo.coreConfigurations().testFlag(QBluetoothDeviceInfo::LowEnergyCoreConfiguration)
|
|| !deviceInfo.coreConfigurations().testFlag(QBluetoothDeviceInfo::LowEnergyCoreConfiguration)
|
||||||
|| deviceInfo.name().isEmpty()
|
|| deviceInfo.name().isEmpty()) {
|
||||||
|| deviceInfo.isCached()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +234,7 @@ void BluetoothDiscovery::start()
|
|||||||
m_discoveryAgent->stop();
|
m_discoveryAgent->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// m_deviceInfos->clearModel();
|
m_deviceInfos->clearModel();
|
||||||
|
|
||||||
qDebug() << "BluetoothDiscovery: Starting discovery.";
|
qDebug() << "BluetoothDiscovery: Starting discovery.";
|
||||||
m_discoveryAgent->start();
|
m_discoveryAgent->start();
|
||||||
|
|||||||
@ -30,7 +30,7 @@ BtWiFiSetup::BtWiFiSetup(QObject *parent) : QObject(parent)
|
|||||||
|
|
||||||
void BtWiFiSetup::connectToDevice(const BluetoothDeviceInfo *device)
|
void BtWiFiSetup::connectToDevice(const BluetoothDeviceInfo *device)
|
||||||
{
|
{
|
||||||
qDebug() << "device" << device;
|
qDebug() << "Connecting to device" << device->address() << device->name();
|
||||||
if (m_btController) {
|
if (m_btController) {
|
||||||
delete m_btController;
|
delete m_btController;
|
||||||
m_currentConnection = nullptr;
|
m_currentConnection = nullptr;
|
||||||
@ -38,7 +38,6 @@ void BtWiFiSetup::connectToDevice(const BluetoothDeviceInfo *device)
|
|||||||
m_accessPoints->clearModel();
|
m_accessPoints->clearModel();
|
||||||
m_bluetoothStatus = BluetoothStatusDisconnected;
|
m_bluetoothStatus = BluetoothStatusDisconnected;
|
||||||
emit bluetoothStatusChanged(m_bluetoothStatus);
|
emit bluetoothStatusChanged(m_bluetoothStatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_btController = QLowEnergyController::createCentral(device->bluetoothDeviceInfo(), this);
|
m_btController = QLowEnergyController::createCentral(device->bluetoothDeviceInfo(), this);
|
||||||
@ -47,7 +46,7 @@ void BtWiFiSetup::connectToDevice(const BluetoothDeviceInfo *device)
|
|||||||
m_btController->discoverServices();
|
m_btController->discoverServices();
|
||||||
m_bluetoothStatus = BluetoothStatusConnectedToBluetooth;
|
m_bluetoothStatus = BluetoothStatusConnectedToBluetooth;
|
||||||
emit bluetoothStatusChanged(m_bluetoothStatus);
|
emit bluetoothStatusChanged(m_bluetoothStatus);
|
||||||
});
|
}, Qt::QueuedConnection);
|
||||||
|
|
||||||
connect(m_btController, &QLowEnergyController::disconnected, this, [this](){
|
connect(m_btController, &QLowEnergyController::disconnected, this, [this](){
|
||||||
qDebug() << "Bluetooth disconnected";
|
qDebug() << "Bluetooth disconnected";
|
||||||
@ -58,13 +57,13 @@ void BtWiFiSetup::connectToDevice(const BluetoothDeviceInfo *device)
|
|||||||
m_currentConnection = nullptr;
|
m_currentConnection = nullptr;
|
||||||
emit currentConnectionChanged();
|
emit currentConnectionChanged();
|
||||||
m_accessPoints->clearModel();
|
m_accessPoints->clearModel();
|
||||||
});
|
}, Qt::QueuedConnection);
|
||||||
|
|
||||||
typedef void (QLowEnergyController::*errorsSignal)(QLowEnergyController::Error);
|
typedef void (QLowEnergyController::*errorsSignal)(QLowEnergyController::Error);
|
||||||
connect(m_btController, static_cast<errorsSignal>(&QLowEnergyController::error), this, [this](QLowEnergyController::Error error){
|
connect(m_btController, static_cast<errorsSignal>(&QLowEnergyController::error), this, [this](QLowEnergyController::Error error){
|
||||||
qDebug() << "Bluetooth error:" << error;
|
qDebug() << "Bluetooth error:" << error;
|
||||||
emit this->bluetoothConnectionError();
|
emit this->bluetoothConnectionError();
|
||||||
});
|
}, Qt::QueuedConnection);
|
||||||
|
|
||||||
connect(m_btController, &QLowEnergyController::discoveryFinished, this, [this](){
|
connect(m_btController, &QLowEnergyController::discoveryFinished, this, [this](){
|
||||||
qDebug() << "Bluetooth service discovery finished";
|
qDebug() << "Bluetooth service discovery finished";
|
||||||
@ -85,8 +84,9 @@ void BtWiFiSetup::disconnectFromDevice()
|
|||||||
|
|
||||||
void BtWiFiSetup::connectDeviceToWiFi(const QString &ssid, const QString &password)
|
void BtWiFiSetup::connectDeviceToWiFi(const QString &ssid, const QString &password)
|
||||||
{
|
{
|
||||||
if (m_bluetoothStatus != BluetoothStatusConnectedToBluetooth) {
|
if (m_bluetoothStatus < BluetoothStatusConnectedToBluetooth) {
|
||||||
qWarning() << "Cannot connect to wifi in state" << m_bluetoothStatus;
|
qWarning() << "Cannot connect to wifi in state" << m_bluetoothStatus;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap request;
|
QVariantMap request;
|
||||||
@ -219,7 +219,12 @@ void BtWiFiSetup::setupServices()
|
|||||||
|
|
||||||
if (!m_wifiService || !m_deviceInformationService || !m_networkService) {
|
if (!m_wifiService || !m_deviceInformationService || !m_networkService) {
|
||||||
qWarning() << "Required services not found on remote device.";
|
qWarning() << "Required services not found on remote device.";
|
||||||
m_btController->disconnectFromDevice();
|
if (m_btController->property("retries").toInt() < 3) {
|
||||||
|
m_btController->discoverServices();
|
||||||
|
m_btController->setProperty("retries", m_btController->property("retries").toInt() + 1);
|
||||||
|
} else {
|
||||||
|
m_btController->disconnectFromDevice();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,6 +327,7 @@ void BtWiFiSetup::processWiFiPacket(const QVariantMap &data)
|
|||||||
WirelessServiceResponse responseCode = (WirelessServiceResponse)data.value("r").toInt();
|
WirelessServiceResponse responseCode = (WirelessServiceResponse)data.value("r").toInt();
|
||||||
if (responseCode != WirelessServiceResponseSuccess) {
|
if (responseCode != WirelessServiceResponseSuccess) {
|
||||||
qWarning() << "Error in wifi command" << command << ":" << responseCode;
|
qWarning() << "Error in wifi command" << command << ":" << responseCode;
|
||||||
|
emit wifiSetupError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user