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 {
|
||||
id: root
|
||||
header: GuhHeader {
|
||||
text: qsTr("Establish bluetooth connection")
|
||||
onBackPressed: pageStack.pop()
|
||||
}
|
||||
|
||||
property string name
|
||||
property string address
|
||||
@ -40,13 +44,6 @@ Page {
|
||||
ColumnLayout {
|
||||
anchors.centerIn: parent
|
||||
|
||||
Label {
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: app.largeFont
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Establish bluetooth LE connection")
|
||||
}
|
||||
|
||||
BusyIndicator {
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
running: true
|
||||
|
||||
@ -33,6 +33,15 @@ Page {
|
||||
|
||||
Component.onCompleted: networkManger.manager.loadNetworks()
|
||||
|
||||
Connections {
|
||||
target: networkManger.manager
|
||||
onErrorOccured: {
|
||||
print("Error occured", errorMessage)
|
||||
errorDialog.errorText = errorMessage
|
||||
errorDialog.open()
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
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 {
|
||||
id: settingsPage
|
||||
|
||||
@ -205,7 +237,6 @@ Page {
|
||||
anchors.fill: parent
|
||||
anchors.margins: app.margins
|
||||
|
||||
|
||||
RowLayout {
|
||||
anchors.margins: app.margins
|
||||
Layout.fillWidth: true
|
||||
@ -240,6 +271,13 @@ Page {
|
||||
|
||||
ThinDivider { }
|
||||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Bluetooth device information")
|
||||
}
|
||||
|
||||
ThinDivider { }
|
||||
|
||||
RowLayout {
|
||||
anchors.margins: app.margins
|
||||
Layout.fillWidth: true
|
||||
|
||||
@ -23,7 +23,6 @@ CustomViewBase {
|
||||
Component.onCompleted: updateTimer.start();
|
||||
onAverageChanged: updateTimer.start()
|
||||
onStartTimeChanged: updateTimer.start();
|
||||
|
||||
}
|
||||
|
||||
Timer {
|
||||
|
||||
@ -58,7 +58,7 @@ Page {
|
||||
header: Rectangle {
|
||||
width: parent.width
|
||||
height: app.margins * 3
|
||||
color: "white"
|
||||
color: Material.primary
|
||||
z: 2
|
||||
|
||||
Row {
|
||||
|
||||
@ -311,9 +311,9 @@ void WirelessSetupManager::pressPushButton()
|
||||
void WirelessSetupManager::checkInitialized()
|
||||
{
|
||||
setInitialized(m_deviceInformationService->state() == QLowEnergyService::ServiceDiscovered
|
||||
&& m_netwokService->state() == QLowEnergyService::ServiceDiscovered
|
||||
&& m_wifiService->state() == QLowEnergyService::ServiceDiscovered
|
||||
&& m_systemService->state() == QLowEnergyService::ServiceDiscovered);
|
||||
&& m_netwokService->state() == QLowEnergyService::ServiceDiscovered
|
||||
&& m_wifiService->state() == QLowEnergyService::ServiceDiscovered
|
||||
&& m_systemService->state() == QLowEnergyService::ServiceDiscovered);
|
||||
}
|
||||
|
||||
void WirelessSetupManager::setModelNumber(const QString &modelNumber)
|
||||
@ -434,7 +434,7 @@ void WirelessSetupManager::setWirelessStatus(int wirelessStatus)
|
||||
break;
|
||||
case 4:
|
||||
m_wirelessStatus = tr("Prepare");
|
||||
break;
|
||||
break;
|
||||
case 5:
|
||||
m_wirelessStatus = tr("Configure");
|
||||
break;
|
||||
@ -544,6 +544,31 @@ void WirelessSetupManager::processWifiResponse(const QVariantMap &response)
|
||||
|
||||
if (responseCode != WirelessServiceResponseSuccess) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -866,33 +891,62 @@ void WirelessSetupManager::onWifiServiceCharacteristicChanged(const QLowEnergyCh
|
||||
{
|
||||
Q_UNUSED(characteristic)
|
||||
|
||||
// Check if currently reading
|
||||
if (m_readingResponse) {
|
||||
m_inputDataStream.append(value);
|
||||
} else {
|
||||
m_inputDataStream.clear();
|
||||
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;
|
||||
if (characteristic.uuid() == wifiResponseCharacteristicUuid) {
|
||||
// Check if currently reading
|
||||
if (m_readingResponse) {
|
||||
m_inputDataStream.append(value);
|
||||
} else {
|
||||
m_inputDataStream.clear();
|
||||
m_readingResponse = false;
|
||||
return;
|
||||
m_readingResponse = true;
|
||||
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();
|
||||
m_readingResponse = false;
|
||||
processWifiResponse(jsonDocument.toVariant().toMap());
|
||||
|
||||
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)
|
||||
|
||||
@ -44,7 +44,6 @@ class WirelessSetupManager : public BluetoothDevice
|
||||
Q_PROPERTY(QString firmwareRevision READ firmwareRevision NOTIFY firmwareRevisionChanged)
|
||||
Q_PROPERTY(QString hardwareRevision READ hardwareRevision NOTIFY hardwareRevisionChanged)
|
||||
|
||||
|
||||
Q_PROPERTY(QString networkStatus READ networkStatus NOTIFY networkStatusChanged)
|
||||
Q_PROPERTY(QString wirelessStatus READ wirelessStatus NOTIFY wirelessStatusChanged)
|
||||
Q_PROPERTY(bool networkingEnabled READ networkingEnabled NOTIFY networkingEnabledChanged)
|
||||
@ -208,6 +207,8 @@ signals:
|
||||
void networkingEnabledChanged();
|
||||
void wirelessEnabledChanged();
|
||||
|
||||
void errorOccured(const QString &errorMessage);
|
||||
|
||||
private slots:
|
||||
void onConnectedChanged();
|
||||
void onServiceDiscoveryFinished();
|
||||
|
||||
Reference in New Issue
Block a user