Add network manager state changed and error handling
This commit is contained in:
parent
d52f983880
commit
51aee3352e
@ -8,6 +8,10 @@ import Mea 1.0
|
|||||||
|
|
||||||
Page {
|
Page {
|
||||||
id: root
|
id: root
|
||||||
|
header: GuhHeader {
|
||||||
|
text: qsTr("Establish bluetooth connection")
|
||||||
|
onBackPressed: pageStack.pop()
|
||||||
|
}
|
||||||
|
|
||||||
property string name
|
property string name
|
||||||
property string address
|
property string address
|
||||||
@ -40,13 +44,6 @@ Page {
|
|||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
|
||||||
Label {
|
|
||||||
wrapMode: Text.WordWrap
|
|
||||||
font.pixelSize: app.largeFont
|
|
||||||
Layout.fillWidth: true
|
|
||||||
text: qsTr("Establish bluetooth LE connection")
|
|
||||||
}
|
|
||||||
|
|
||||||
BusyIndicator {
|
BusyIndicator {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
running: true
|
running: true
|
||||||
|
|||||||
@ -33,6 +33,15 @@ Page {
|
|||||||
|
|
||||||
Component.onCompleted: networkManger.manager.loadNetworks()
|
Component.onCompleted: networkManger.manager.loadNetworks()
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: networkManger.manager
|
||||||
|
onErrorOccured: {
|
||||||
|
print("Error occured", errorMessage)
|
||||||
|
errorDialog.errorText = errorMessage
|
||||||
|
errorDialog.open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
visible: networkManger.manager.initialized
|
visible: networkManger.manager.initialized
|
||||||
@ -191,6 +200,29 @@ Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Dialog {
|
||||||
|
id: errorDialog
|
||||||
|
width: Math.min(parent.width * .9, 400)
|
||||||
|
x: (parent.width - width) / 2
|
||||||
|
y: (parent.height - height) / 2
|
||||||
|
standardButtons: Dialog.Ok
|
||||||
|
|
||||||
|
property string errorText
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
anchors { left: parent.left; right: parent.right; top: parent.top }
|
||||||
|
spacing: app.margins
|
||||||
|
|
||||||
|
Label {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
text: errorDialog.errorText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: settingsPage
|
id: settingsPage
|
||||||
|
|
||||||
@ -205,7 +237,6 @@ Page {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: app.margins
|
anchors.margins: app.margins
|
||||||
|
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
anchors.margins: app.margins
|
anchors.margins: app.margins
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
@ -240,6 +271,13 @@ Page {
|
|||||||
|
|
||||||
ThinDivider { }
|
ThinDivider { }
|
||||||
|
|
||||||
|
Label {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
text: qsTr("Bluetooth device information")
|
||||||
|
}
|
||||||
|
|
||||||
|
ThinDivider { }
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
anchors.margins: app.margins
|
anchors.margins: app.margins
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|||||||
@ -23,7 +23,6 @@ CustomViewBase {
|
|||||||
Component.onCompleted: updateTimer.start();
|
Component.onCompleted: updateTimer.start();
|
||||||
onAverageChanged: updateTimer.start()
|
onAverageChanged: updateTimer.start()
|
||||||
onStartTimeChanged: updateTimer.start();
|
onStartTimeChanged: updateTimer.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
|
|||||||
@ -58,7 +58,7 @@ Page {
|
|||||||
header: Rectangle {
|
header: Rectangle {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: app.margins * 3
|
height: app.margins * 3
|
||||||
color: "white"
|
color: Material.primary
|
||||||
z: 2
|
z: 2
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
|
|||||||
@ -311,9 +311,9 @@ void WirelessSetupManager::pressPushButton()
|
|||||||
void WirelessSetupManager::checkInitialized()
|
void WirelessSetupManager::checkInitialized()
|
||||||
{
|
{
|
||||||
setInitialized(m_deviceInformationService->state() == QLowEnergyService::ServiceDiscovered
|
setInitialized(m_deviceInformationService->state() == QLowEnergyService::ServiceDiscovered
|
||||||
&& m_netwokService->state() == QLowEnergyService::ServiceDiscovered
|
&& m_netwokService->state() == QLowEnergyService::ServiceDiscovered
|
||||||
&& m_wifiService->state() == QLowEnergyService::ServiceDiscovered
|
&& m_wifiService->state() == QLowEnergyService::ServiceDiscovered
|
||||||
&& m_systemService->state() == QLowEnergyService::ServiceDiscovered);
|
&& m_systemService->state() == QLowEnergyService::ServiceDiscovered);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WirelessSetupManager::setModelNumber(const QString &modelNumber)
|
void WirelessSetupManager::setModelNumber(const QString &modelNumber)
|
||||||
@ -434,7 +434,7 @@ void WirelessSetupManager::setWirelessStatus(int wirelessStatus)
|
|||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
m_wirelessStatus = tr("Prepare");
|
m_wirelessStatus = tr("Prepare");
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
m_wirelessStatus = tr("Configure");
|
m_wirelessStatus = tr("Configure");
|
||||||
break;
|
break;
|
||||||
@ -544,6 +544,31 @@ void WirelessSetupManager::processWifiResponse(const QVariantMap &response)
|
|||||||
|
|
||||||
if (responseCode != WirelessServiceResponseSuccess) {
|
if (responseCode != WirelessServiceResponseSuccess) {
|
||||||
qWarning() << "WifiSetupManager: Got error for command" << command << responseCode;
|
qWarning() << "WifiSetupManager: Got error for command" << command << responseCode;
|
||||||
|
|
||||||
|
switch (responseCode) {
|
||||||
|
case WirelessServiceResponseIvalidCommand:
|
||||||
|
emit errorOccured(tr("Invalid command."));
|
||||||
|
break;
|
||||||
|
case WirelessServiceResponseIvalidParameters:
|
||||||
|
emit errorOccured(tr("Invalid parameters."));
|
||||||
|
break;
|
||||||
|
case WirelessServiceResponseNetworkManagerNotAvailable:
|
||||||
|
emit errorOccured(tr("There is no networkmanager available on the device."));
|
||||||
|
break;
|
||||||
|
case WirelessServiceResponseWirelessNotAvailable:
|
||||||
|
emit errorOccured(tr("There is no wireless device available on the device."));
|
||||||
|
break;
|
||||||
|
case WirelessServiceResponseWirelessNotEnabled:
|
||||||
|
emit errorOccured(tr("The wireless networking is disabled on the device."));
|
||||||
|
break;
|
||||||
|
case WirelessServiceResponseNetworkingNotEnabled:
|
||||||
|
emit errorOccured(tr("The networking is disabled on the device."));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
emit errorOccured("Unknown error occured.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -866,33 +891,62 @@ void WirelessSetupManager::onWifiServiceCharacteristicChanged(const QLowEnergyCh
|
|||||||
{
|
{
|
||||||
Q_UNUSED(characteristic)
|
Q_UNUSED(characteristic)
|
||||||
|
|
||||||
// Check if currently reading
|
if (characteristic.uuid() == wifiResponseCharacteristicUuid) {
|
||||||
if (m_readingResponse) {
|
// Check if currently reading
|
||||||
m_inputDataStream.append(value);
|
if (m_readingResponse) {
|
||||||
} else {
|
m_inputDataStream.append(value);
|
||||||
m_inputDataStream.clear();
|
} else {
|
||||||
m_readingResponse = true;
|
|
||||||
m_inputDataStream.append(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If command finished
|
|
||||||
if (value.endsWith('\n')) {
|
|
||||||
QJsonParseError error;
|
|
||||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(m_inputDataStream, &error);
|
|
||||||
if (error.error != QJsonParseError::NoError) {
|
|
||||||
qWarning() << "Got invalid json object" << m_inputDataStream;
|
|
||||||
m_inputDataStream.clear();
|
m_inputDataStream.clear();
|
||||||
m_readingResponse = false;
|
m_readingResponse = true;
|
||||||
return;
|
m_inputDataStream.append(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Got command stream" << qUtf8Printable(jsonDocument.toJson());
|
// If command finished
|
||||||
|
if (value.endsWith('\n')) {
|
||||||
|
QJsonParseError error;
|
||||||
|
QJsonDocument jsonDocument = QJsonDocument::fromJson(m_inputDataStream, &error);
|
||||||
|
if (error.error != QJsonParseError::NoError) {
|
||||||
|
qWarning() << "Got invalid json object" << m_inputDataStream;
|
||||||
|
m_inputDataStream.clear();
|
||||||
|
m_readingResponse = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
processWifiResponse(jsonDocument.toVariant().toMap());
|
qDebug() << "Got command stream" << qUtf8Printable(jsonDocument.toJson());
|
||||||
|
|
||||||
m_inputDataStream.clear();
|
processWifiResponse(jsonDocument.toVariant().toMap());
|
||||||
m_readingResponse = false;
|
|
||||||
|
m_inputDataStream.clear();
|
||||||
|
m_readingResponse = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (characteristic.uuid() == wifiStatusCharacteristicUuid) {
|
||||||
|
qDebug() << "Wireless status changed:" << value;
|
||||||
|
setWirelessStatus(value.toHex().toUInt(0, 16));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (characteristic.uuid() == networkStatusCharacteristicUuid) {
|
||||||
|
qDebug() << "Network status changed:" << value.toHex().toUInt(0, 16);
|
||||||
|
setNetworkStatus(value.toHex().toUInt(0, 16));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (characteristic.uuid() == networkingEnabledCharacteristicUuid) {
|
||||||
|
qDebug() << "Networking enabled changed" << (bool)value.toHex().toUInt(0, 16);
|
||||||
|
setNetworkingEnabled((bool)value.toHex().toUInt(0, 16));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (characteristic.uuid() == wirelessEnabledCharacteristicUuid) {
|
||||||
|
qDebug() << "Wireless enabled changed" << (bool)value.toHex().toUInt(0, 16);
|
||||||
|
setWirelessEnabled((bool)value.toHex().toUInt(0, 16));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Bluetooth: Unhandled service characteristic changed" << characteristic.uuid() << value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WirelessSetupManager::onWifiServiceReadFinished(const QLowEnergyCharacteristic &characteristic, const QByteArray &value)
|
void WirelessSetupManager::onWifiServiceReadFinished(const QLowEnergyCharacteristic &characteristic, const QByteArray &value)
|
||||||
|
|||||||
@ -44,7 +44,6 @@ class WirelessSetupManager : public BluetoothDevice
|
|||||||
Q_PROPERTY(QString firmwareRevision READ firmwareRevision NOTIFY firmwareRevisionChanged)
|
Q_PROPERTY(QString firmwareRevision READ firmwareRevision NOTIFY firmwareRevisionChanged)
|
||||||
Q_PROPERTY(QString hardwareRevision READ hardwareRevision NOTIFY hardwareRevisionChanged)
|
Q_PROPERTY(QString hardwareRevision READ hardwareRevision NOTIFY hardwareRevisionChanged)
|
||||||
|
|
||||||
|
|
||||||
Q_PROPERTY(QString networkStatus READ networkStatus NOTIFY networkStatusChanged)
|
Q_PROPERTY(QString networkStatus READ networkStatus NOTIFY networkStatusChanged)
|
||||||
Q_PROPERTY(QString wirelessStatus READ wirelessStatus NOTIFY wirelessStatusChanged)
|
Q_PROPERTY(QString wirelessStatus READ wirelessStatus NOTIFY wirelessStatusChanged)
|
||||||
Q_PROPERTY(bool networkingEnabled READ networkingEnabled NOTIFY networkingEnabledChanged)
|
Q_PROPERTY(bool networkingEnabled READ networkingEnabled NOTIFY networkingEnabledChanged)
|
||||||
@ -208,6 +207,8 @@ signals:
|
|||||||
void networkingEnabledChanged();
|
void networkingEnabledChanged();
|
||||||
void wirelessEnabledChanged();
|
void wirelessEnabledChanged();
|
||||||
|
|
||||||
|
void errorOccured(const QString &errorMessage);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onConnectedChanged();
|
void onConnectedChanged();
|
||||||
void onServiceDiscoveryFinished();
|
void onServiceDiscoveryFinished();
|
||||||
|
|||||||
Reference in New Issue
Block a user