From c1768f51b71ab51c0442e16032b97fe5dc530d5a Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Thu, 12 Nov 2015 19:24:18 -0800 Subject: [PATCH] MockLink Start/Stop to Preferences Preparation for auto-connect having no connect/disconnect buttons. --- qgroundcontrol.qrc | 1 + src/QmlControls/QGroundControlQmlGlobal.cc | 80 ++++++++++++++++++++++ src/QmlControls/QGroundControlQmlGlobal.h | 14 ++++ src/ui/MainWindowLeftPanel.qml | 14 ++++ src/ui/preferences/MockLink.qml | 67 ++++++++++++++++++ 5 files changed, 176 insertions(+) create mode 100644 src/ui/preferences/MockLink.qml diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index 3ce5ad56c..176c47811 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -24,6 +24,7 @@ src/ui/preferences/MavlinkSettings.qml src/MissionEditor/MissionEditor.qml src/MissionEditor/MissionEditorHelp.qml + src/ui/preferences/MockLink.qml src/AutoPilotPlugins/PX4/PowerComponent.qml src/AutoPilotPlugins/PX4/PowerComponentSummary.qml src/VehicleSetup/PX4FlowSensor.qml diff --git a/src/QmlControls/QGroundControlQmlGlobal.cc b/src/QmlControls/QGroundControlQmlGlobal.cc index 53dd03924..efec03aea 100644 --- a/src/QmlControls/QGroundControlQmlGlobal.cc +++ b/src/QmlControls/QGroundControlQmlGlobal.cc @@ -66,3 +66,83 @@ bool QGroundControlQmlGlobal::loadBoolGlobalSetting (const QString& key, bool de settings.beginGroup(kQmlGlobalKeyName); return settings.value(key, defaultValue).toBool(); } + +#ifdef QT_DEBUG +void QGroundControlQmlGlobal::_startMockLink(MockConfiguration* mockConfig) +{ + MockLink* mockLink = new MockLink(mockConfig); + + LinkManager* linkManager = qgcApp()->toolbox()->linkManager(); + + linkManager->_addLink(mockLink); + linkManager->connectLink(mockLink); +} +#endif + +void QGroundControlQmlGlobal::startPX4MockLink(bool sendStatusText) +{ +#ifdef QT_DEBUG + MockConfiguration mockConfig("PX4 MockLink"); + + mockConfig.setFirmwareType(MAV_AUTOPILOT_PX4); + mockConfig.setVehicleType(MAV_TYPE_QUADROTOR); + mockConfig.setSendStatusText(sendStatusText); + + _startMockLink(&mockConfig); +#endif +} + +void QGroundControlQmlGlobal::startGenericMockLink(bool sendStatusText) +{ +#ifdef QT_DEBUG + MockConfiguration mockConfig("Generic MockLink"); + + mockConfig.setFirmwareType(MAV_AUTOPILOT_GENERIC); + mockConfig.setVehicleType(MAV_TYPE_QUADROTOR); + mockConfig.setSendStatusText(sendStatusText); + + _startMockLink(&mockConfig); +#endif +} + +void QGroundControlQmlGlobal::startAPMArduCopterMockLink(bool sendStatusText) +{ +#ifdef QT_DEBUG + MockConfiguration mockConfig("APM ArduCopter MockLink"); + + mockConfig.setFirmwareType(MAV_AUTOPILOT_ARDUPILOTMEGA); + mockConfig.setVehicleType(MAV_TYPE_QUADROTOR); + mockConfig.setSendStatusText(sendStatusText); + + _startMockLink(&mockConfig); +#endif +} + +void QGroundControlQmlGlobal::startAPMArduPlaneMockLink(bool sendStatusText) +{ +#ifdef QT_DEBUG + MockConfiguration mockConfig("APM ArduPlane MockLink"); + + mockConfig.setFirmwareType(MAV_AUTOPILOT_ARDUPILOTMEGA); + mockConfig.setVehicleType(MAV_TYPE_FIXED_WING); + mockConfig.setSendStatusText(sendStatusText); + + _startMockLink(&mockConfig); +#endif +} + +void QGroundControlQmlGlobal::stopAllMockLinks(void) +{ +#ifdef QT_DEBUG + LinkManager* linkManager = qgcApp()->toolbox()->linkManager(); + + QList links = linkManager->getLinks(); + for (int i=0; i(link); + if (mockLink) { + linkManager->disconnectLink(mockLink); + } + } +#endif +} diff --git a/src/QmlControls/QGroundControlQmlGlobal.h b/src/QmlControls/QGroundControlQmlGlobal.h index 8f3ad3c0b..302439196 100644 --- a/src/QmlControls/QGroundControlQmlGlobal.h +++ b/src/QmlControls/QGroundControlQmlGlobal.h @@ -34,6 +34,10 @@ #include "HomePositionManager.h" #include "FlightMapSettings.h" +#ifdef QT_DEBUG +#include "MockLink.h" +#endif + class QGCToolbox; class QGroundControlQmlGlobal : public QObject @@ -58,6 +62,12 @@ public: Q_INVOKABLE void saveBoolGlobalSetting (const QString& key, bool value); Q_INVOKABLE bool loadBoolGlobalSetting (const QString& key, bool defaultValue); + Q_INVOKABLE void startPX4MockLink (bool sendStatusText); + Q_INVOKABLE void startGenericMockLink (bool sendStatusText); + Q_INVOKABLE void startAPMArduCopterMockLink (bool sendStatusText); + Q_INVOKABLE void startAPMArduPlaneMockLink (bool sendStatusText); + Q_INVOKABLE void stopAllMockLinks (void); + // Property accesors HomePositionManager* homePositionManager () { return _homePositionManager; } @@ -123,6 +133,10 @@ signals: void isVersionCheckEnabledChanged (bool enabled); private: +#ifdef QT_DEBUG + void _startMockLink(MockConfiguration* mockConfig); +#endif + HomePositionManager* _homePositionManager; FlightMapSettings* _flightMapSettings; }; diff --git a/src/ui/MainWindowLeftPanel.qml b/src/ui/MainWindowLeftPanel.qml index b831c8f02..668c236d8 100644 --- a/src/ui/MainWindowLeftPanel.qml +++ b/src/ui/MainWindowLeftPanel.qml @@ -169,6 +169,20 @@ Item { checked = true } } + QGCButton { + width: parent.width * 0.8 + height: ScreenTools.defaultFontPixelHeight * 2.5 + text: "Mock Link" + visible: ScreenTools.isDebug + exclusiveGroup: panelActionGroup + anchors.horizontalCenter: parent.horizontalCenter + onClicked: { + if(__rightPanel.source != "MockLink.qml") { + __rightPanel.source = "MockLink.qml" + } + checked = true + } + } QGCButton { width: parent.width * 0.8 height: ScreenTools.defaultFontPixelHeight * 2.5 diff --git a/src/ui/preferences/MockLink.qml b/src/ui/preferences/MockLink.qml new file mode 100644 index 000000000..7398aa59d --- /dev/null +++ b/src/ui/preferences/MockLink.qml @@ -0,0 +1,67 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 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 . + + ======================================================================*/ + +import QtQuick 2.3 + +import QGroundControl 1.0 +import QGroundControl.Controls 1.0 +import QGroundControl.Palette 1.0 +import QGroundControl.ScreenTools 1.0 + +Rectangle { + color: qgcPal.window + + QGCPalette { id: qgcPal; colorGroupEnabled: true } + + Column { + anchors.margins: ScreenTools.defaultFontPixelHeight + anchors.left: parent.left + anchors.top: parent.top + spacing: ScreenTools.defaultFontPixelHeight + + QGCButton { + text: "PX4 Vehicle" + onClicked: QGroundControl.startPX4MockLink(sendStatusText.checked) + } + QGCButton { + text: "APM ArduCopter Vehicle" + onClicked: QGroundControl.startAPMArduCopterMockLink(sendStatusText.checked) + } + QGCButton { + text: "APM ArduPlane Vehicle" + onClicked: QGroundControl.startAPMArduPlaneMockLink(sendStatusText.checked) + } + QGCButton { + text: "Generic Vehicle" + onClicked: QGroundControl.startGenericMockLink(sendStatusText.checked) + } + QGCCheckBox { + id: sendStatusText + text: "Send status text + voice" + } + QGCButton { + text: "Stop All MockLinks" + onClicked: QGroundControl.stopAllMockLinks() + } + } +} -- 2.22.0