diff --git a/qgcresources.qrc b/qgcresources.qrc index c75675999204de85af8158ca7b2317a300045cb1..df0f9bc0f6de68f88b030f4a723ee8a134c8491d 100644 --- a/qgcresources.qrc +++ b/qgcresources.qrc @@ -145,6 +145,8 @@ src/ui/toolbar/Images/TelemRSSI.svg src/ui/toolbar/Images/Yield.svg src/MissionManager/CogWheel.svg + src/AutoPilotPlugins/Common/Images/StationMode.svg + src/AutoPilotPlugins/Common/Images/APMode.svg resources/Antenna_RC.svg diff --git a/src/AutoPilotPlugins/Common/ESP8266Component.qml b/src/AutoPilotPlugins/Common/ESP8266Component.qml index ea191452f16002ddebdd79d1ac3957ff683d15e4..29521cdae23af19232ed496b851d260f6c4eee09 100644 --- a/src/AutoPilotPlugins/Common/ESP8266Component.qml +++ b/src/AutoPilotPlugins/Common/ESP8266Component.qml @@ -40,13 +40,16 @@ QGCView { QGCPalette { id: palette; colorGroupEnabled: panel.enabled } - property int _firstColumn: ScreenTools.defaultFontPixelWidth * 20 - property int _secondColumn: ScreenTools.defaultFontPixelWidth * 12 + property real _margins: ScreenTools.defaultFontPixelHeight + property real _middleRowWidth: ScreenTools.defaultFontPixelWidth * 18 + property real _editFieldWidth: ScreenTools.defaultFontPixelWidth * 18 + property real _labelWidth: ScreenTools.defaultFontPixelWidth * 10 + property real _statusWidth: ScreenTools.defaultFontPixelWidth * 5 + readonly property string dialogTitle: qsTr("controller WiFi Bridge") property int stStatus: XMLHttpRequest.UNSENT property int stErrorCount: 0 - property bool stEnabled: false - property bool stResetCounters: false + property bool stResetCounters:false ESP8266ComponentController { id: controller @@ -64,7 +67,9 @@ QGCView { function updateStatus() { timer.stop() var req = new XMLHttpRequest; - var url = "http://192.168.4.1/status.json" + var url = "http://" + url += controller.wifiIPAddress + url += "/status.json" if(stResetCounters) { url = url + "?r=1" stResetCounters = false @@ -77,24 +82,21 @@ QGCView { if (objectArray.errors !== undefined) { console.log(qsTr("Error fetching WiFi Bridge Status: %1").arg(objectArray.errors[0].message)) stErrorCount = stErrorCount + 1 - if(stErrorCount < 2 && stEnabled) + if(stErrorCount < 2) timer.start() } else { - if(stEnabled) { - //-- This should work but it doesn't - // var n = 34523453.345 - // n.toLocaleString() - // "34,523,453.345" - vpackets.text = thisThingHasNoNumberLocaleSupport(objectArray["vpackets"]) - vsent.text = thisThingHasNoNumberLocaleSupport(objectArray["vsent"]) - vlost.text = thisThingHasNoNumberLocaleSupport(objectArray["vlost"]) - gpackets.text = thisThingHasNoNumberLocaleSupport(objectArray["gpackets"]) - gsent.text = thisThingHasNoNumberLocaleSupport(objectArray["gsent"]) - glost.text = thisThingHasNoNumberLocaleSupport(objectArray["glost"]) - stErrorCount = 0 - wifiStatus.visible = true - timer.start() - } + //-- This should work but it doesn't + // var n = 34523453.345 + // n.toLocaleString() + // "34,523,453.345" + vpackets.text = thisThingHasNoNumberLocaleSupport(objectArray["vpackets"]) + vsent.text = thisThingHasNoNumberLocaleSupport(objectArray["vsent"]) + vlost.text = thisThingHasNoNumberLocaleSupport(objectArray["vlost"]) + gpackets.text = thisThingHasNoNumberLocaleSupport(objectArray["gpackets"]) + gsent.text = thisThingHasNoNumberLocaleSupport(objectArray["gsent"]) + glost.text = thisThingHasNoNumberLocaleSupport(objectArray["glost"]) + stErrorCount = 0 + timer.start() } } } @@ -105,8 +107,10 @@ QGCView { timer.interval = 1000 timer.repeat = true timer.triggered.connect(updateStatus) + timer.start() } + property Fact wifiMode: controller.getParameterFact(controller.componentID, "WIFI_MODE", false) //-- Don't bitch about missing as this is new property Fact wifiChannel: controller.getParameterFact(controller.componentID, "WIFI_CHANNEL") property Fact hostPort: controller.getParameterFact(controller.componentID, "WIFI_UDP_HPORT") property Fact clientPort: controller.getParameterFact(controller.componentID, "WIFI_UDP_CPORT") @@ -116,265 +120,353 @@ QGCView { anchors.fill: parent Flickable { - anchors.fill: parent - clip: true - contentHeight: innerColumn.height - contentWidth: panel.width - boundsBehavior: Flickable.StopAtBounds - flickableDirection: Flickable.VerticalFlick - + clip: true + anchors.fill: parent + contentHeight: mainCol.height + flickableDirection: Flickable.VerticalFlick Column { - id: innerColumn - width: panel.width - spacing: ScreenTools.defaultFontPixelHeight * 0.5 - + id: mainCol + spacing: _margins + anchors.horizontalCenter: parent.horizontalCenter + Item { width: 1; height: _margins * 0.5; } QGCLabel { - text: qsTr("WiFi Bridge Settings") - font.weight: Font.DemiBold + text: qsTr("ESP WiFi Bridge Settings") + font.weight: Font.DemiBold } - Rectangle { - width: parent.width - height: wifiStatus.visible ? Math.max(wifiCol.height, wifiStatus.height) + (ScreenTools.defaultFontPixelHeight * 2) : wifiCol.height + (ScreenTools.defaultFontPixelHeight * 2) - color: palette.windowShade + color: palette.windowShade + width: statusLayout.width + _margins * 4 + height: settingsRow.height + _margins * 2 Row { - anchors.verticalCenter: parent.verticalCenter - spacing: ScreenTools.defaultFontPixelWidth - Rectangle { - height: parent.height - width: 1 - color: palette.window + id: settingsRow + spacing: _margins + anchors.centerIn: parent + Item { width: _margins * 0.5; height: 1; } + QGCColoredImage { + color: palette.text + height: ScreenTools.defaultFontPixelWidth * 10 + width: ScreenTools.defaultFontPixelWidth * 12 + mipmap: true + fillMode: Image.PreserveAspectFit + source: wifiMode ? (wifiMode.value === 0 ? "/qmlimages/APMode.svg" : "/qmlimages/StationMode.svg") : "/qmlimages/APMode.svg" + anchors.verticalCenter: parent.verticalCenter } + Item { width: _margins * 0.5; height: 1; } Column { - id: wifiCol - anchors.verticalCenter: parent.verticalCenter - spacing: ScreenTools.defaultFontPixelHeight / 2 + spacing: _margins * 0.5 + anchors.verticalCenter: parent.verticalCenter Row { - spacing: ScreenTools.defaultFontPixelWidth + visible: wifiMode QGCLabel { - text: qsTr("WiFi Channel") - width: _firstColumn - anchors.baseline: channelField.baseline + text: qsTr("WiFi Mode") + width: _middleRowWidth + anchors.baseline: modeField.baseline } QGCComboBox { - id: channelField - width: _secondColumn - model: controller.wifiChannels - currentIndex: wifiChannel ? wifiChannel.value - 1 : 0 + id: modeField + width: _editFieldWidth + model: ["Access Point Mode", "Station Mode"] + currentIndex: wifiMode ? wifiMode.value : 0 onActivated: { - wifiChannel.value = index + 1 - } - } - } - Row { - spacing: ScreenTools.defaultFontPixelWidth - QGCLabel { - text: qsTr("WiFi SSID") - width: _firstColumn - anchors.baseline: ssidField.baseline - } - QGCTextField { - id: ssidField - width: _secondColumn - text: controller.wifiSSID - maximumLength: 16 - onEditingFinished: { - controller.wifiSSID = text + wifiMode.value = index } } } Row { - spacing: ScreenTools.defaultFontPixelWidth QGCLabel { - text: qsTr("WiFi Password") - width: _firstColumn - anchors.baseline: passwordField.baseline - } - QGCTextField { - id: passwordField - width: _secondColumn - text: controller.wifiPassword - maximumLength: 16 - onEditingFinished: { - controller.wifiPassword = text - } - } - } - Row { - spacing: ScreenTools.defaultFontPixelWidth - QGCLabel { - text: qsTr("UART Baud Rate") - width: _firstColumn - anchors.baseline: baudField.baseline + text: qsTr("WiFi Channel") + width: _middleRowWidth + anchors.baseline: channelField.baseline } QGCComboBox { - id: baudField - width: _secondColumn - model: controller.baudRates - currentIndex: controller.baudIndex + id: channelField + width: _editFieldWidth + enabled: wifiMode && wifiMode.value === 0 + model: controller.wifiChannels + currentIndex: wifiChannel ? wifiChannel.value - 1 : 0 onActivated: { - controller.baudIndex = index + wifiChannel.value = index + 1 } } } Row { - spacing: ScreenTools.defaultFontPixelWidth QGCLabel { - text: qsTr("QGC UDP Port") - width: _firstColumn - anchors.baseline: qgcportField.baseline + text: qsTr("WiFi AP SSID") + width: _middleRowWidth + anchors.baseline: ssidField.baseline } QGCTextField { - id: qgcportField - width: _secondColumn - text: hostPort ? hostPort.valueString : "" - validator: IntValidator {bottom: 1024; top: 65535;} - inputMethodHints: Qt.ImhDigitsOnly + id: ssidField + width: _editFieldWidth + text: controller.wifiSSID + maximumLength: 16 onEditingFinished: { - hostPort.value = text + controller.wifiSSID = text } } } - } - Rectangle { - height: parent.height - width: 1 - color: palette.text - visible: wifiStatus.visible - } - Column { - id: wifiStatus - anchors.margins: ScreenTools.defaultFontPixelHeight / 2 - spacing: ScreenTools.defaultFontPixelHeight / 2 - visible: false - QGCLabel { - text: qsTr("Bridge/Vehicle Link") - font.weight: Font.DemiBold - } - Row { - spacing: ScreenTools.defaultFontPixelWidth - QGCLabel { - text: qsTr("Messages Received") - width: _firstColumn - } - QGCLabel { - id: vpackets - } - } - Row { - spacing: ScreenTools.defaultFontPixelWidth - QGCLabel { - text: qsTr("Messages Lost") - width: _firstColumn - } - QGCLabel { - id: vlost - } - } - Row { - spacing: ScreenTools.defaultFontPixelWidth - QGCLabel { - text: qsTr("Messages Sent") - width: _firstColumn - } - QGCLabel { - id: vsent - } - } - Rectangle { - height: 1 - width: parent.width - color: palette.text - } - QGCLabel { - text: qsTr("Bridge/QGC Link") - font.weight: Font.DemiBold - } - Row { - spacing: ScreenTools.defaultFontPixelWidth - QGCLabel { - text: qsTr("Messages Received") - width: _firstColumn - } - QGCLabel { - id: gpackets - } - } Row { - spacing: ScreenTools.defaultFontPixelWidth QGCLabel { - text: qsTr("Messages Lost") - width: _firstColumn + text: qsTr("WiFi AP Password") + width: _middleRowWidth + anchors.baseline: passwordField.baseline } - QGCLabel { - id: glost + QGCTextField { + id: passwordField + width: _editFieldWidth + text: controller.wifiPassword + maximumLength: 16 + onEditingFinished: { + controller.wifiPassword = text + } } } Row { - spacing: ScreenTools.defaultFontPixelWidth QGCLabel { - text: qsTr("Messages Sent") - width: _firstColumn + text: qsTr("WiFi STA SSID") + width: _middleRowWidth + anchors.baseline: stassidField.baseline } - QGCLabel { - id: gsent + QGCTextField { + id: stassidField + width: _editFieldWidth + text: controller.wifiSSIDSta + maximumLength: 16 + enabled: wifiMode && wifiMode.value === 1 + onEditingFinished: { + controller.wifiSSIDSta = text + } } } - Rectangle { - height: 1 - width: parent.width - color: palette.text - } - QGCLabel { - text: qsTr("QGC/Bridge Link") - font.weight: Font.DemiBold - } Row { - spacing: ScreenTools.defaultFontPixelWidth QGCLabel { - text: qsTr("Messages Received") - width: _firstColumn + text: qsTr("WiFi STA Password") + width: _middleRowWidth + anchors.baseline: passwordStaField.baseline } - QGCLabel { - text: controller.vehicle ? thisThingHasNoNumberLocaleSupport(controller.vehicle.messagesReceived) : 0 + QGCTextField { + id: passwordStaField + width: _editFieldWidth + text: controller.wifiPasswordSta + maximumLength: 16 + enabled: wifiMode && wifiMode.value === 1 + onEditingFinished: { + controller.wifiPasswordSta = text + } } } Row { - spacing: ScreenTools.defaultFontPixelWidth QGCLabel { - text: qsTr("Messages Lost") - width: _firstColumn + text: qsTr("UART Baud Rate") + width: _middleRowWidth + anchors.baseline: baudField.baseline } - QGCLabel { - text: controller.vehicle ? thisThingHasNoNumberLocaleSupport(controller.vehicle.messagesLost) : 0 + QGCComboBox { + id: baudField + width: _editFieldWidth + model: controller.baudRates + currentIndex: controller.baudIndex + onActivated: { + controller.baudIndex = index + } } } Row { - spacing: ScreenTools.defaultFontPixelWidth QGCLabel { - text: qsTr("Messages Sent") - width: _firstColumn + text: qsTr("QGC UDP Port") + width: _middleRowWidth + anchors.baseline: qgcportField.baseline } - QGCLabel { - text: controller.vehicle ? thisThingHasNoNumberLocaleSupport(controller.vehicle.messagesSent) : 0 + QGCTextField { + id: qgcportField + width: _editFieldWidth + text: hostPort ? hostPort.valueString : "" + validator: IntValidator {bottom: 1024; top: 65535;} + inputMethodHints: Qt.ImhDigitsOnly + onEditingFinished: { + hostPort.value = text + } } } } } } + QGCLabel { + text: qsTr("ESP WiFi Bridge Status") + font.weight: Font.DemiBold + } + Rectangle { + color: palette.windowShade + width: statusLayout.width + _margins * 4 + height: statusLayout.height + _margins * 2 + GridLayout { + id: statusLayout + columns: 3 + columnSpacing: _margins * 2 + anchors.centerIn: parent + QGCLabel { + text: qsTr("Bridge/Vehicle Link") + Layout.alignment: Qt.AlignHCenter + } + QGCLabel { + text: qsTr("Bridge/QGC Link") + Layout.alignment: Qt.AlignHCenter + } + QGCLabel { + text: qsTr("QGC/Bridge Link") + Layout.alignment: Qt.AlignHCenter + } + Row { + spacing: _margins + QGCLabel { + text: qsTr("Messages Received") + font.pixelSize: ScreenTools.smallFontPixelSize + width: _labelWidth + } + QGCLabel { + id: vpackets + font.pixelSize: ScreenTools.smallFontPixelSize + width: _statusWidth + horizontalAlignment: Text.AlignRight + font.family: "Monospace" + } + } + Row { + spacing: _margins + QGCLabel { + font.pixelSize: ScreenTools.smallFontPixelSize + text: qsTr("Messages Received") + width: _labelWidth + } + QGCLabel { + id: gpackets + font.pixelSize: ScreenTools.smallFontPixelSize + width: _statusWidth + horizontalAlignment: Text.AlignRight + font.family: "Monospace" + } + } + Row { + spacing: _margins + QGCLabel { + font.pixelSize: ScreenTools.smallFontPixelSize + text: qsTr("Messages Received") + width: _labelWidth + } + QGCLabel { + font.pixelSize: ScreenTools.smallFontPixelSize + text: controller.vehicle ? thisThingHasNoNumberLocaleSupport(controller.vehicle.messagesReceived) : 0 + width: _statusWidth + horizontalAlignment: Text.AlignRight + font.family: "Monospace" + } + } + Row { + spacing: _margins + QGCLabel { + text: qsTr("Messages Lost") + font.pixelSize: ScreenTools.smallFontPixelSize + width: _labelWidth + } + QGCLabel { + id: vlost + width: _statusWidth + horizontalAlignment: Text.AlignRight + font.pixelSize: ScreenTools.smallFontPixelSize + font.family: "Monospace" + } + } + Row { + spacing: _margins + QGCLabel { + text: qsTr("Messages Lost") + font.pixelSize: ScreenTools.smallFontPixelSize + width: _labelWidth + } + QGCLabel { + id: glost + width: _statusWidth + horizontalAlignment: Text.AlignRight + font.pixelSize: ScreenTools.smallFontPixelSize + font.family: "Monospace" + } + } + Row { + spacing: _margins + QGCLabel { + text: qsTr("Messages Lost") + font.pixelSize: ScreenTools.smallFontPixelSize + width: _labelWidth + } + QGCLabel { + text: controller.vehicle ? thisThingHasNoNumberLocaleSupport(controller.vehicle.messagesLost) : 0 + width: _statusWidth + horizontalAlignment: Text.AlignRight + font.pixelSize: ScreenTools.smallFontPixelSize + font.family: "Monospace" + } + } + Row { + spacing: _margins + QGCLabel { + text: qsTr("Messages Sent") + font.pixelSize: ScreenTools.smallFontPixelSize + width: _labelWidth + } + QGCLabel { + id: vsent + width: _statusWidth + horizontalAlignment: Text.AlignRight + font.pixelSize: ScreenTools.smallFontPixelSize + font.family: "Monospace" + } + } + Row { + spacing: _margins + QGCLabel { + text: qsTr("Messages Sent") + font.pixelSize: ScreenTools.smallFontPixelSize + width: _labelWidth + } + QGCLabel { + id: gsent + width: _statusWidth + horizontalAlignment: Text.AlignRight + font.pixelSize: ScreenTools.smallFontPixelSize + font.family: "Monospace" + } + } + Row { + spacing: _margins + QGCLabel { + text: qsTr("Messages Sent") + font.pixelSize: ScreenTools.smallFontPixelSize + width: _labelWidth + } + QGCLabel { + text: controller.vehicle ? thisThingHasNoNumberLocaleSupport(controller.vehicle.messagesSent) : 0 + width: _statusWidth + horizontalAlignment: Text.AlignRight + font.pixelSize: ScreenTools.smallFontPixelSize + font.family: "Monospace" + } + } + } + } Row { - spacing: ScreenTools.defaultFontPixelWidth * 1.5 + spacing: _margins + anchors.horizontalCenter: parent.horizontalCenter QGCButton { - text: qsTr("Restore Defaults") - width: ScreenTools.defaultFontPixelWidth * 16 + text: qsTr("Restore Defaults") + width: ScreenTools.defaultFontPixelWidth * 16 onClicked: { controller.restoreDefaults() } } QGCButton { - text: qsTr("Restart WiFi Bridge") - enabled: !controller.busy - width: ScreenTools.defaultFontPixelWidth * 16 + text: qsTr("Restart WiFi Bridge") + enabled: !controller.busy + width: ScreenTools.defaultFontPixelWidth * 16 onClicked: { rebootDialog.visible = true } @@ -395,23 +487,8 @@ QGCView { } } QGCButton { - text: stEnabled ? qsTr("Hide Status") : qsTr("Show Status") - width: ScreenTools.defaultFontPixelWidth * 16 - onClicked: { - stEnabled = !stEnabled - if(stEnabled) - updateStatus() - else { - wifiStatus.visible = false - timer.stop() - } - } - } - QGCButton { - text: qsTr("Reset Counters") - visible: stEnabled - enabled: stEnabled - width: ScreenTools.defaultFontPixelWidth * 16 + text: qsTr("Reset Counters") + width: ScreenTools.defaultFontPixelWidth * 16 onClicked: { stResetCounters = true; updateStatus() diff --git a/src/AutoPilotPlugins/Common/ESP8266ComponentController.cc b/src/AutoPilotPlugins/Common/ESP8266ComponentController.cc index c2e83626dd2703fd76184b81f1e13f5a4eb288f6..36028db08d1644ae5a6ea59287c569c25e5a37a9 100644 --- a/src/AutoPilotPlugins/Common/ESP8266ComponentController.cc +++ b/src/AutoPilotPlugins/Common/ESP8266ComponentController.cc @@ -1,24 +1,24 @@ /*===================================================================== - + QGroundControl Open Source Ground Control Station - + (c) 2009, 2016 QGROUNDCONTROL PROJECT - + This file is part of the QGROUNDCONTROL project - + QGROUNDCONTROL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + QGROUNDCONTROL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with QGROUNDCONTROL. If not, see . - + ======================================================================*/ /// @file @@ -30,6 +30,9 @@ #include "QGCApplication.h" #include "UAS.h" +#include +#include + QGC_LOGGING_CATEGORY(ESP8266ComponentControllerLog, "ESP8266ComponentControllerLog") #define MAX_RETRIES 5 @@ -74,6 +77,21 @@ ESP8266ComponentController::version() return versionString; } +//----------------------------------------------------------------------------- +QString +ESP8266ComponentController::wifiIPAddress() +{ + if(_ipAddress.isEmpty()) { + if(parameterExists(MAV_COMP_ID_UDP_BRIDGE, "WIFI_IPADDRESS")) { + QHostAddress address(qFromBigEndian(getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_IPADDRESS")->rawValue().toUInt())); + _ipAddress = address.toString(); + } else { + _ipAddress = "192.168.4.1"; + } + } + return _ipAddress; +} + //----------------------------------------------------------------------------- QString ESP8266ComponentController::wifiSSID() @@ -152,6 +170,94 @@ ESP8266ComponentController::setWifiPassword(QString password) f4->setRawValue(QVariant(u)); } +//----------------------------------------------------------------------------- +QString +ESP8266ComponentController::wifiSSIDSta() +{ + if(!parameterExists(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSIDSTA1")) { + return QString(); + } + uint32_t s1 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSIDSTA1")->rawValue().toUInt(); + uint32_t s2 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSIDSTA2")->rawValue().toUInt(); + uint32_t s3 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSIDSTA3")->rawValue().toUInt(); + uint32_t s4 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSIDSTA4")->rawValue().toUInt(); + char tmp[20]; + memcpy(&tmp[0], &s1, sizeof(uint32_t)); + memcpy(&tmp[4], &s2, sizeof(uint32_t)); + memcpy(&tmp[8], &s3, sizeof(uint32_t)); + memcpy(&tmp[12], &s4, sizeof(uint32_t)); + return QString(tmp); +} + +//----------------------------------------------------------------------------- +void +ESP8266ComponentController::setWifiSSIDSta(QString ssid) +{ + if(parameterExists(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSIDSTA1")) { + char tmp[20]; + memset(tmp, 0, sizeof(tmp)); + std::string sid = ssid.toStdString(); + strncpy(tmp, sid.c_str(), sizeof(tmp)); + Fact* f1 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSIDSTA1"); + Fact* f2 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSIDSTA2"); + Fact* f3 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSIDSTA3"); + Fact* f4 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSIDSTA4"); + uint32_t u; + memcpy(&u, &tmp[0], sizeof(uint32_t)); + f1->setRawValue(QVariant(u)); + memcpy(&u, &tmp[4], sizeof(uint32_t)); + f2->setRawValue(QVariant(u)); + memcpy(&u, &tmp[8], sizeof(uint32_t)); + f3->setRawValue(QVariant(u)); + memcpy(&u, &tmp[12], sizeof(uint32_t)); + f4->setRawValue(QVariant(u)); + } +} + +//----------------------------------------------------------------------------- +QString +ESP8266ComponentController::wifiPasswordSta() +{ + if(!parameterExists(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PWDSTA1")) { + return QString(); + } + uint32_t s1 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PWDSTA1")->rawValue().toUInt(); + uint32_t s2 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PWDSTA2")->rawValue().toUInt(); + uint32_t s3 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PWDSTA3")->rawValue().toUInt(); + uint32_t s4 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PWDSTA4")->rawValue().toUInt(); + char tmp[20]; + memcpy(&tmp[0], &s1, sizeof(uint32_t)); + memcpy(&tmp[4], &s2, sizeof(uint32_t)); + memcpy(&tmp[8], &s3, sizeof(uint32_t)); + memcpy(&tmp[12], &s4, sizeof(uint32_t)); + return QString(tmp); +} + +//----------------------------------------------------------------------------- +void +ESP8266ComponentController::setWifiPasswordSta(QString password) +{ + if(parameterExists(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PWDSTA1")) { + char tmp[20]; + memset(tmp, 0, sizeof(tmp)); + std::string pwd = password.toStdString(); + strncpy(tmp, pwd.c_str(), sizeof(tmp)); + Fact* f1 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PWDSTA1"); + Fact* f2 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PWDSTA2"); + Fact* f3 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PWDSTA3"); + Fact* f4 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PWDSTA4"); + uint32_t u; + memcpy(&u, &tmp[0], sizeof(uint32_t)); + f1->setRawValue(QVariant(u)); + memcpy(&u, &tmp[4], sizeof(uint32_t)); + f2->setRawValue(QVariant(u)); + memcpy(&u, &tmp[8], sizeof(uint32_t)); + f3->setRawValue(QVariant(u)); + memcpy(&u, &tmp[12], sizeof(uint32_t)); + f4->setRawValue(QVariant(u)); + } +} + //----------------------------------------------------------------------------- int ESP8266ComponentController::baudIndex() diff --git a/src/AutoPilotPlugins/Common/ESP8266ComponentController.h b/src/AutoPilotPlugins/Common/ESP8266ComponentController.h index 1256f9bdb6009ec7b5d2099b57c421c855ea6922..6a525f278ea920f0ef1d107bf78689c21f16ec79 100644 --- a/src/AutoPilotPlugins/Common/ESP8266ComponentController.h +++ b/src/AutoPilotPlugins/Common/ESP8266ComponentController.h @@ -1,24 +1,24 @@ /*===================================================================== - + QGroundControl Open Source Ground Control Station - + (c) 2009, 2016 QGROUNDCONTROL PROJECT - + This file is part of the QGROUNDCONTROL project - + QGROUNDCONTROL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + QGROUNDCONTROL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with QGROUNDCONTROL. If not, see . - + ======================================================================*/ @@ -45,28 +45,34 @@ namespace Ui { class ESP8266ComponentController : public FactPanelController { Q_OBJECT - + public: ESP8266ComponentController (); ~ESP8266ComponentController (); - Q_PROPERTY(int componentID READ componentID CONSTANT) - Q_PROPERTY(QString version READ version NOTIFY versionChanged) - Q_PROPERTY(QString wifiSSID READ wifiSSID WRITE setWifiSSID NOTIFY wifiSSIDChanged) - Q_PROPERTY(QString wifiPassword READ wifiPassword WRITE setWifiPassword NOTIFY wifiPasswordChanged) - Q_PROPERTY(QStringList wifiChannels READ wifiChannels CONSTANT) - Q_PROPERTY(QStringList baudRates READ baudRates CONSTANT) - Q_PROPERTY(int baudIndex READ baudIndex WRITE setBaudIndex NOTIFY baudIndexChanged) - Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) - Q_PROPERTY(Vehicle* vehicle READ vehicle CONSTANT) + Q_PROPERTY(int componentID READ componentID CONSTANT) + Q_PROPERTY(QString version READ version NOTIFY versionChanged) + Q_PROPERTY(QString wifiIPAddress READ wifiIPAddress CONSTANT) + Q_PROPERTY(QString wifiSSID READ wifiSSID WRITE setWifiSSID NOTIFY wifiSSIDChanged) + Q_PROPERTY(QString wifiPassword READ wifiPassword WRITE setWifiPassword NOTIFY wifiPasswordChanged) + Q_PROPERTY(QString wifiSSIDSta READ wifiSSIDSta WRITE setWifiSSIDSta NOTIFY wifiSSIDStaChanged) + Q_PROPERTY(QString wifiPasswordSta READ wifiPasswordSta WRITE setWifiPasswordSta NOTIFY wifiPasswordStaChanged) + Q_PROPERTY(QStringList wifiChannels READ wifiChannels CONSTANT) + Q_PROPERTY(QStringList baudRates READ baudRates CONSTANT) + Q_PROPERTY(int baudIndex READ baudIndex WRITE setBaudIndex NOTIFY baudIndexChanged) + Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) + Q_PROPERTY(Vehicle* vehicle READ vehicle CONSTANT) Q_INVOKABLE void restoreDefaults(); Q_INVOKABLE void reboot (); int componentID () { return MAV_COMP_ID_UDP_BRIDGE; } QString version (); + QString wifiIPAddress (); QString wifiSSID (); QString wifiPassword (); + QString wifiSSIDSta (); + QString wifiPasswordSta (); QStringList wifiChannels () { return _channels; } QStringList baudRates () { return _baudRates; } int baudIndex (); @@ -75,14 +81,18 @@ public: void setWifiSSID (QString id); void setWifiPassword (QString pwd); + void setWifiSSIDSta (QString id); + void setWifiPasswordSta (QString pwd); void setBaudIndex (int idx); signals: - void versionChanged (); - void wifiSSIDChanged (); - void wifiPasswordChanged (); - void baudIndexChanged (); - void busyChanged (); + void versionChanged (); + void wifiSSIDChanged (); + void wifiPasswordChanged (); + void wifiSSIDStaChanged (); + void wifiPasswordStaChanged (); + void baudIndexChanged (); + void busyChanged (); private slots: void _processTimeout (); @@ -100,6 +110,7 @@ private: QTimer _timer; QStringList _channels; QStringList _baudRates; + QString _ipAddress; enum { WAIT_FOR_NOTHING, diff --git a/src/AutoPilotPlugins/Common/ESP8266ComponentSummary.qml b/src/AutoPilotPlugins/Common/ESP8266ComponentSummary.qml index bce51e41dd5b558422af9df641a17c027f85157a..cc58f948fad5dca63f37f4965068dbebf2958e8f 100644 --- a/src/AutoPilotPlugins/Common/ESP8266ComponentSummary.qml +++ b/src/AutoPilotPlugins/Common/ESP8266ComponentSummary.qml @@ -25,6 +25,7 @@ FactPanel { property Fact wifiHostPort: controller.getParameterFact(esp8266.componentID, "WIFI_UDP_HPORT") property Fact wifiClientPort: controller.getParameterFact(esp8266.componentID, "WIFI_UDP_CPORT") property Fact uartBaud: controller.getParameterFact(esp8266.componentID, "UART_BAUDRATE") + property Fact wifiMode: controller.getParameterFact(esp8266.componentID, "WIFI_MODE", false) //-- Don't bitch if missing Column { anchors.fill: parent @@ -33,18 +34,30 @@ FactPanel { labelText: qsTr("Firmware Version:") valueText: esp8266.version } + VehicleSummaryRow { + labelText: qsTr("WiFi Mode:") + valueText: wifiMode ? (wifiMode.value === 0 ? "AP Mode" : "Station Mode") : "AP Mode" + } VehicleSummaryRow { labelText: qsTr("WiFi Channel:") valueText: wifiChannel ? wifiChannel.valueString : "" } VehicleSummaryRow { - labelText: qsTr("WiFi SSID:") + labelText: qsTr("WiFi AP SSID:") valueText: esp8266.wifiSSID } VehicleSummaryRow { - labelText: qsTr("WiFi Password:") + labelText: qsTr("WiFi AP Password:") valueText: esp8266.wifiPassword } + VehicleSummaryRow { + labelText: qsTr("WiFi STA SSID:") + valueText: esp8266.wifiSSIDSta + } + VehicleSummaryRow { + labelText: qsTr("WiFi STA Password:") + valueText: esp8266.wifiPasswordSta + } VehicleSummaryRow { labelText: qsTr("UART Baud Rate:") valueText: uartBaud ? uartBaud.valueString : "" diff --git a/src/AutoPilotPlugins/Common/Images/APMode.svg b/src/AutoPilotPlugins/Common/Images/APMode.svg new file mode 100644 index 0000000000000000000000000000000000000000..4de7b3ecbdf841b338be608313d5adea6b03d498 --- /dev/null +++ b/src/AutoPilotPlugins/Common/Images/APMode.svg @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/AutoPilotPlugins/Common/Images/StationMode.svg b/src/AutoPilotPlugins/Common/Images/StationMode.svg new file mode 100644 index 0000000000000000000000000000000000000000..1322d7edc1e1c39b2fff6878d694bc9d2ac261a4 --- /dev/null +++ b/src/AutoPilotPlugins/Common/Images/StationMode.svg @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +