From f4b19fe65aeac71aff0592064a3f5eaed565acc0 Mon Sep 17 00:00:00 2001 From: elafargue Date: Thu, 2 Jun 2011 16:08:19 +0200 Subject: [PATCH] OP-369 Settings Import/Export for the Airframe. Also sanitized UAV Object saving in flash in one central location in the uavobjectutils library. --- .../src/plugins/config/configahrswidget.cpp | 3 +- .../plugins/config/configairframewidget.cpp | 17 +- .../src/plugins/config/configccpmwidget.cpp | 9 +- .../src/plugins/config/configinputwidget.cpp | 6 +- .../src/plugins/config/configoutputwidget.cpp | 6 +- .../config/configstabilizationwidget.cpp | 6 +- .../src/plugins/config/configtaskwidget.cpp | 99 +------- .../src/plugins/config/configtaskwidget.h | 10 +- .../plugins/config/configtelemetrywidget.cpp | 10 +- .../src/plugins/importexport/importexport.pro | 11 +- .../importexport/importexportdialog.cpp | 3 +- .../plugins/importexport/importexportdialog.h | 3 +- .../importexport/importexportdialog.ui | 2 +- .../importexportgadgetconfiguration.cpp | 76 ------ .../importexportgadgetconfiguration.h | 65 ------ .../importexportgadgetfactory.cpp | 67 ------ .../importexport/importexportgadgetfactory.h | 61 ----- .../importexportgadgetoptionspage.cpp | 81 ------- .../importexportgadgetoptionspage.h | 74 ------ .../importexportgadgetoptionspage.ui | 103 --------- .../importexport/importexportgadgetwidget.cpp | 49 ++-- .../importexport/importexportgadgetwidget.h | 4 +- .../importexport/importexportgadgetwidget.ui | 85 ++++--- .../importexport/importexportplugin.cpp | 7 +- .../plugins/importexport/importexportplugin.h | 3 - .../uavobjectutil/uavobjectutilmanager.cpp | 121 ++++++---- .../uavobjectutil/uavobjectutilmanager.h | 12 +- .../uavsettingsimportexport.cpp | 218 +++++++++++------- .../uavsettingsimportexport.h | 4 +- .../uavsettingsimportexport.pluginspec | 1 + .../uavsettingsimportexport_dependencies.pri | 1 + 31 files changed, 322 insertions(+), 895 deletions(-) delete mode 100644 ground/openpilotgcs/src/plugins/importexport/importexportgadgetconfiguration.cpp delete mode 100644 ground/openpilotgcs/src/plugins/importexport/importexportgadgetconfiguration.h delete mode 100644 ground/openpilotgcs/src/plugins/importexport/importexportgadgetfactory.cpp delete mode 100644 ground/openpilotgcs/src/plugins/importexport/importexportgadgetfactory.h delete mode 100644 ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.cpp delete mode 100644 ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.h delete mode 100644 ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.ui diff --git a/ground/openpilotgcs/src/plugins/config/configahrswidget.cpp b/ground/openpilotgcs/src/plugins/config/configahrswidget.cpp index 9d81392e4..228e7157e 100644 --- a/ground/openpilotgcs/src/plugins/config/configahrswidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configahrswidget.cpp @@ -568,8 +568,7 @@ void ConfigAHRSWidget::saveAHRSCalibration() UAVObjectField *field = obj->getField(QString("measure_var")); field->setValue("SET"); obj->updated(); - updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj); - + saveObjectToSD(obj); } FORCE_ALIGN_FUNC diff --git a/ground/openpilotgcs/src/plugins/config/configairframewidget.cpp b/ground/openpilotgcs/src/plugins/config/configairframewidget.cpp index da6dc6afb..4e23de86e 100644 --- a/ground/openpilotgcs/src/plugins/config/configairframewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configairframewidget.cpp @@ -1524,7 +1524,7 @@ bool ConfigAirframeWidget::setupMixer(double mixerFactors[8][3]) setupQuadMotor(channel, mixerFactors[i][0]*pFactor, rFactor*mixerFactors[i][1], yFactor*mixerFactors[i][2]); } - obj->updated(); +// obj->updated(); return true; } @@ -1568,7 +1568,7 @@ void ConfigAirframeWidget::setupMotors(QList motorList) field = obj->getField(motor); field->setValue(mmList.takeFirst()->currentText()); } - obj->updated(); // Save... + //obj->updated(); // Save... } @@ -2026,14 +2026,12 @@ void ConfigAirframeWidget::sendAircraftUpdate() m_aircraft->mrStatusLabel->setText("Error: Assign a Yaw channel"); return; } + motorList << "VTOLMotorNW" << "VTOLMotorNE" << "VTOLMotorS"; + setupMotors(motorList); obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); Q_ASSERT(obj); field = obj->getField("FixedWingYaw1"); field->setValue(m_aircraft->triYawChannel->currentText()); - // No need to send a obj->updated() here because setupMotors - // will do it. - motorList << "VTOLMotorNW" << "VTOLMotorNE" << "VTOLMotorS"; - setupMotors(motorList); // Motor 1 to 6, Y6 Layout: // pitch roll yaw @@ -2112,10 +2110,13 @@ void ConfigAirframeWidget::sendAircraftUpdate() field->setValue(m_aircraft->customMixerTable->item(5,i)->text(),ti); } - obj->updated(); } - UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("SystemSettings"))); + UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); + obj->updated(); + obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); + obj->updated(); + obj = dynamic_cast(getObjectManager()->getObject(QString("SystemSettings"))); UAVObjectField* field = obj->getField(QString("AirframeType")); field->setValue(airframeType); obj->updated(); diff --git a/ground/openpilotgcs/src/plugins/config/configccpmwidget.cpp b/ground/openpilotgcs/src/plugins/config/configccpmwidget.cpp index ea4078b52..74e38b803 100644 --- a/ground/openpilotgcs/src/plugins/config/configccpmwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configccpmwidget.cpp @@ -1195,11 +1195,9 @@ void ConfigccpmWidget::saveccpmUpdate() ShowDisclaimer(0); // Send update so that the latest value is saved sendccpmUpdate(); - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objManager = pm->getObject(); - UAVDataObject* obj = dynamic_cast(objManager->getObject(QString("MixerSettings"))); + UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(obj); - updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj); + saveObjectToSD(obj); } void ConfigccpmWidget::resizeEvent(QResizeEvent* event) @@ -1506,8 +1504,7 @@ void ConfigccpmWidget::SwashLvlFinishButtonPressed() } obj->updated(); - - updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj); + saveObjectToSD(obj); //restore Flight control of ActuatorCommand enableSwashplateLevellingControl(false); diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp index 9ee8f6bb7..84f29705b 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp @@ -508,11 +508,9 @@ void ConfigInputWidget::saveRCInputObject() { // Send update so that the latest value is saved sendRCInputUpdate(); - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objManager = pm->getObject(); - UAVDataObject* obj = dynamic_cast(objManager->getObject(QString("ManualControlSettings"))); + UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("ManualControlSettings"))); Q_ASSERT(obj); - updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj); + saveObjectToSD(obj); } diff --git a/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp index 27858e111..8a38ce80f 100644 --- a/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp @@ -534,11 +534,9 @@ void ConfigOutputWidget::saveRCOutputObject() { // Send update so that the latest value is saved sendRCOutputUpdate(); - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objManager = pm->getObject(); - UAVDataObject* obj = dynamic_cast(objManager->getObject(QString("ActuatorSettings"))); + UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); Q_ASSERT(obj); - updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj); + saveObjectToSD(obj); } diff --git a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp index dd172a599..c78db94bd 100644 --- a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp @@ -262,11 +262,9 @@ void ConfigStabilizationWidget::saveStabilizationUpdate() { // Send update so that the latest value is saved sendStabilizationUpdate(); - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objManager = pm->getObject(); - UAVDataObject* obj = dynamic_cast(objManager->getObject(QString("StabilizationSettings"))); + UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("StabilizationSettings"))); Q_ASSERT(obj); - updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj); + saveObjectToSD(obj); } diff --git a/ground/openpilotgcs/src/plugins/config/configtaskwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtaskwidget.cpp index 8fb743ef0..9ddf04aa6 100644 --- a/ground/openpilotgcs/src/plugins/config/configtaskwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtaskwidget.cpp @@ -30,8 +30,6 @@ ConfigTaskWidget::ConfigTaskWidget(QWidget *parent) : QWidget(parent) { - saveState = IDLE; - queue.clear(); } ConfigTaskWidget::~ConfigTaskWidget() @@ -41,100 +39,13 @@ ConfigTaskWidget::~ConfigTaskWidget() void ConfigTaskWidget::saveObjectToSD(UAVObject *obj) { - // Add to queue - queue.enqueue(obj); - // If queue length is one, then start sending (call sendNextObject) - // Otherwise, do nothing, it's sending anyway - if (queue.length()==1) - saveNextObject(); - + // saveObjectToSD is now handled by the UAVUtils plugin in one + // central place (and one central queue) + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + UAVObjectUtilManager* utilMngr = pm->getObject(); + utilMngr->saveObjectToSD(obj); } -void ConfigTaskWidget::saveNextObject() -{ - if ( queue.isEmpty() ) - { - return; - } - - Q_ASSERT(saveState == IDLE); - - // Get next object from the queue - UAVObject* obj = queue.head(); - ObjectPersistence* objper = dynamic_cast( getObjectManager()->getObject(ObjectPersistence::NAME) ); - connect(objper, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(objectPersistenceTransactionCompleted(UAVObject*,bool))); - connect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(objectPersistenceUpdated(UAVObject *))); - saveState = AWAITING_ACK; - if (obj != NULL) - { - ObjectPersistence::DataFields data; - data.Operation = ObjectPersistence::OPERATION_SAVE; - data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT; - data.ObjectID = obj->getObjID(); - data.InstanceID = obj->getInstID(); - objper->setData(data); - objper->updated(); - } -} - -/** - * @brief Process the transactionCompleted message from Telemetry indicating request sent successfully - * @param[in] The object just transsacted. Must be ObjectPersistance - * @param[in] success Indicates that the transaction did not time out - * - * After a failed transaction (usually timeout) resends the save request. After a succesful - * transaction will then wait for a save completed update from the autopilot. - */ -void ConfigTaskWidget::objectPersistenceTransactionCompleted(UAVObject* obj, bool success) -{ - if(success) { - Q_ASSERT(obj->getName().compare("ObjectPersistence") == 0); - Q_ASSERT(saveState == AWAITING_ACK); - saveState = AWAITING_COMPLETED; - disconnect(obj, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(objectPersistenceTransactionCompleted(UAVObject*,bool))); - } else if (!success) { - // Can be caused by timeout errors on sending. Send again. - saveNextObject(); - } -} - -/** - * @brief Process the ObjectPersistence updated message to confirm the right object saved - * then requests next object be saved. - * @param[in] The object just received. Must be ObjectPersistance - */ -void ConfigTaskWidget::objectPersistenceUpdated(UAVObject * obj) -{ - Q_ASSERT(obj->getName().compare("ObjectPersistence") == 0); - if(saveState == AWAITING_COMPLETED) { - // Check flight is saying it completed. This is the only thing flight should do to trigger an update. - Q_ASSERT( obj->getField("Operation")->getValue().toString().compare(QString("Completed")) == 0 ); - - // Check right object saved - UAVObject* savingObj = queue.head(); - Q_ASSERT( obj->getField("ObjectID")->getValue() == savingObj->getObjID() ); - - obj->disconnect(this); - queue.dequeue(); // We can now remove the object, it's done. - saveState = IDLE; - saveNextObject(); - } -} - -void ConfigTaskWidget::updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj) -{ - ObjectPersistence* objper = dynamic_cast( getObjectManager()->getObject(ObjectPersistence::NAME) ); - if (obj != NULL) - { - ObjectPersistence::DataFields data; - data.Operation = op; - data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT; - data.ObjectID = obj->getObjID(); - data.InstanceID = obj->getInstID(); - objper->setData(data); - objper->updated(); - } -} UAVObjectManager* ConfigTaskWidget::getObjectManager() { ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); diff --git a/ground/openpilotgcs/src/plugins/config/configtaskwidget.h b/ground/openpilotgcs/src/plugins/config/configtaskwidget.h index 0650ddb25..5c467b918 100644 --- a/ground/openpilotgcs/src/plugins/config/configtaskwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configtaskwidget.h @@ -31,7 +31,7 @@ #include "extensionsystem/pluginmanager.h" #include "uavobjectmanager.h" #include "uavobject.h" -#include "objectpersistence.h" +#include "uavobjectutilmanager.h" #include #include #include @@ -45,20 +45,12 @@ public: ConfigTaskWidget(QWidget *parent = 0); ~ConfigTaskWidget(); void saveObjectToSD(UAVObject *obj); - void updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj); UAVObjectManager* getObjectManager(); - static double listMean(QList list); private slots: - void objectPersistenceTransactionCompleted(UAVObject* obj, bool success); - void objectPersistenceUpdated(UAVObject * obj); private: - QQueue queue; - void saveNextObject(); - enum {IDLE, AWAITING_ACK, AWAITING_COMPLETED} saveState; - }; diff --git a/ground/openpilotgcs/src/plugins/config/configtelemetrywidget.cpp b/ground/openpilotgcs/src/plugins/config/configtelemetrywidget.cpp index 843f94ffb..8e8ce5fbc 100644 --- a/ground/openpilotgcs/src/plugins/config/configtelemetrywidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtelemetrywidget.cpp @@ -84,9 +84,7 @@ void ConfigTelemetryWidget::requestTelemetryUpdate() */ void ConfigTelemetryWidget::sendTelemetryUpdate() { - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objManager = pm->getObject(); - UAVDataObject* obj = dynamic_cast(objManager->getObject(QString("TelemetrySettings"))); + UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("TelemetrySettings"))); Q_ASSERT(obj); UAVObjectField* field = obj->getField(QString("Speed")); field->setValue(m_telemetry->telemetrySpeed->currentText()); @@ -100,11 +98,9 @@ void ConfigTelemetryWidget::saveTelemetryUpdate() { // Send update so that the latest value is saved sendTelemetryUpdate(); - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objManager = pm->getObject(); - UAVDataObject* obj = dynamic_cast(objManager->getObject(QString("TelemetrySettings"))); + UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("TelemetrySettings"))); Q_ASSERT(obj); - updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj); + saveObjectToSD(obj); } diff --git a/ground/openpilotgcs/src/plugins/importexport/importexport.pro b/ground/openpilotgcs/src/plugins/importexport/importexport.pro index 0d5d2778d..3c9b6ba13 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexport.pro +++ b/ground/openpilotgcs/src/plugins/importexport/importexport.pro @@ -7,18 +7,9 @@ include(importexport_dependencies.pri) HEADERS += importexportplugin.h \ importexportgadgetwidget.h \ importexportdialog.h -HEADERS += importexportgadget.h -HEADERS += importexportgadgetfactory.h -HEADERS += importexportgadgetconfiguration.h -HEADERS += importexportgadgetoptionspage.h SOURCES += importexportplugin.cpp \ importexportgadgetwidget.cpp \ importexportdialog.cpp -SOURCES += importexportgadget.cpp -SOURCES += importexportgadgetfactory.cpp -SOURCES += importexportgadgetconfiguration.cpp -SOURCES += importexportgadgetoptionspage.cpp OTHER_FILES += ImportExportGadget.pluginspec -FORMS += importexportgadgetoptionspage.ui \ - importexportgadgetwidget.ui \ +FORMS += importexportgadgetwidget.ui \ importexportdialog.ui diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportdialog.cpp b/ground/openpilotgcs/src/plugins/importexport/importexportdialog.cpp index 74efb81e1..df38653f8 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportdialog.cpp +++ b/ground/openpilotgcs/src/plugins/importexport/importexportdialog.cpp @@ -1,12 +1,11 @@ #include "importexportdialog.h" #include "ui_importexportdialog.h" -ImportExportDialog::ImportExportDialog( ImportExportGadgetConfiguration *config, QWidget *parent) : +ImportExportDialog::ImportExportDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ImportExportDialog) { ui->setupUi(this); - ui->widget->loadConfiguration(config); setWindowTitle(tr("Import Export Settings")); connect( ui->widget, SIGNAL(done()), this, SLOT(close())); diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportdialog.h b/ground/openpilotgcs/src/plugins/importexport/importexportdialog.h index e93addd77..008d588d1 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportdialog.h +++ b/ground/openpilotgcs/src/plugins/importexport/importexportdialog.h @@ -27,7 +27,6 @@ #define IMPORTEXPORTDIALOG_H #include -#include "importexportgadgetconfiguration.h" namespace Ui { class ImportExportDialog; @@ -38,7 +37,7 @@ class ImportExportDialog : public QDialog Q_OBJECT public: - explicit ImportExportDialog( ImportExportGadgetConfiguration *config, QWidget *parent = 0); + explicit ImportExportDialog(QWidget *parent = 0); ~ImportExportDialog(); protected: diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportdialog.ui b/ground/openpilotgcs/src/plugins/importexport/importexportdialog.ui index eca016fc4..3c0fca682 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportdialog.ui +++ b/ground/openpilotgcs/src/plugins/importexport/importexportdialog.ui @@ -23,7 +23,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel + QDialogButtonBox::Close diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetconfiguration.cpp b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetconfiguration.cpp deleted file mode 100644 index 8e97c9bec..000000000 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetconfiguration.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/** - ****************************************************************************** - * - * @file importexportgadgetconfiguration.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @see The GNU Public License (GPL) Version 3 - * @brief Configuration for Import/Export Plugin - * @addtogroup GCSPlugins GCS Plugins - * @{ - * @addtogroup importexportplugin - * @{ - * - *****************************************************************************/ -/* - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "importexportgadgetconfiguration.h" - -static const QString VERSION = "1.0.1"; - -/** - * Loads a saved configuration or defaults if non exist. - * - */ -ImportExportGadgetConfiguration::ImportExportGadgetConfiguration(QString classId, QSettings* qSettings, UAVConfigInfo *configInfo, QObject *parent) : - IUAVGadgetConfiguration(classId, parent) -{ - if ( ! qSettings ) - return; - - if ( configInfo->version() == UAVConfigVersion() ) - configInfo->setVersion("1.0.0"); - - if ( !configInfo->standardVersionHandlingOK(VERSION)) - return; - - iniFile = qSettings->value("iniFile", "gcs.xml").toString(); -} - -/** - * Clones a configuration. - * - */ -IUAVGadgetConfiguration *ImportExportGadgetConfiguration::clone() -{ - ImportExportGadgetConfiguration *m = new ImportExportGadgetConfiguration(this->classId()); - m->iniFile = iniFile; - return m; -} - -/** - * Saves a configuration. - * - */ -void ImportExportGadgetConfiguration::saveConfig(QSettings* qSettings, Core::UAVConfigInfo *configInfo) const { - configInfo->setVersion(VERSION); - qSettings->setValue("iniFile", iniFile); -} - -/** - * @} - * @} - */ diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetconfiguration.h b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetconfiguration.h deleted file mode 100644 index 21a87ff27..000000000 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetconfiguration.h +++ /dev/null @@ -1,65 +0,0 @@ -/** - ****************************************************************************** - * @file - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @see The GNU Public License (GPL) Version 3 - * @addtogroup GCSPlugins GCS Plugins - * @{ - * @addtogroup importexportplugin - * @{ - *****************************************************************************/ -/* - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef IMPORTEXPORTGADGETCONFIGURATION_H -#define IMPORTEXPORTGADGETCONFIGURATION_H - -#include -#include "importexport_global.h" - -using namespace Core; - -/* This is a generic bargraph dial - supporting one indicator. - */ -class IMPORTEXPORT_EXPORT ImportExportGadgetConfiguration : public IUAVGadgetConfiguration -{ - Q_OBJECT -public: - ImportExportGadgetConfiguration(QString classId, QSettings* qSettings = 0, UAVConfigInfo *configInfo = 0, QObject *parent = 0); - - //set dial configuration functions - void setIniFile(QString filename) { - iniFile = filename; - } - - //get dial configuration functions - QString getIniFile() const{ - return iniFile; - } - - void saveConfig(QSettings* settings, Core::UAVConfigInfo *configInfo) const; - IUAVGadgetConfiguration *clone(); - -private: - QString iniFile; -}; - -#endif // IMPORTEXPORTGADGETCONFIGURATION_H -/** - * @} - * @} - */ diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetfactory.cpp b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetfactory.cpp deleted file mode 100644 index b9d93fde3..000000000 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetfactory.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/** - ****************************************************************************** - * - * @file importexportgadgetfactory.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @see The GNU Public License (GPL) Version 3 - * @brief Factory for Import/Export Plugin - * @addtogroup GCSPlugins GCS Plugins - * @{ - * @addtogroup importexportplugin - * @{ - * - *****************************************************************************/ -/* - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include "importexportgadgetfactory.h" -#include "importexportgadgetwidget.h" -#include "importexportgadget.h" -#include "importexportgadgetconfiguration.h" -#include "importexportgadgetoptionspage.h" -#include - -ImportExportGadgetFactory::ImportExportGadgetFactory(QObject *parent) : - IUAVGadgetFactory(QString("ImportExportGadget"), - tr("Import/Export GCS Config"), - parent) -{ -} - -ImportExportGadgetFactory::~ImportExportGadgetFactory() -{ -} - -Core::IUAVGadget* ImportExportGadgetFactory::createGadget(QWidget *parent) -{ - ImportExportGadgetWidget* gadgetWidget = new ImportExportGadgetWidget(parent); - return new ImportExportGadget(QString("ImportExportGadget"), gadgetWidget, parent); -} - -IUAVGadgetConfiguration *ImportExportGadgetFactory::createConfiguration(QSettings* qSettings, UAVConfigInfo *configInfo) -{ - lastConfig = new ImportExportGadgetConfiguration(QString("ImportExportGadget"), qSettings, configInfo); - return lastConfig; -} - -IOptionsPage *ImportExportGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) -{ - return new ImportExportGadgetOptionsPage(qobject_cast(config)); -} - -/** - * @} - * @} - */ diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetfactory.h b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetfactory.h deleted file mode 100644 index ac1b56494..000000000 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetfactory.h +++ /dev/null @@ -1,61 +0,0 @@ -/** - ****************************************************************************** - * @file - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @see The GNU Public License (GPL) Version 3 - * @addtogroup GCSPlugins GCS Plugins - * @{ - * @addtogroup importexportplugin - * @{ - *****************************************************************************/ -/* - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef IMPORTEXPORTGADGETFACTORY_H_ -#define IMPORTEXPORTGADGETFACTORY_H_ - -#include -#include "importexportgadgetconfiguration.h" - -namespace Core -{ -class IUAVGadget; -class IUAVGadgetFactory; -} - -using namespace Core; - -class IMPORTEXPORT_EXPORT ImportExportGadgetFactory : public IUAVGadgetFactory -{ - Q_OBJECT -public: - ImportExportGadgetFactory(QObject *parent = 0); - ~ImportExportGadgetFactory(); - ImportExportGadgetConfiguration *getLastConfig(){ return lastConfig;} - - Core::IUAVGadget *createGadget(QWidget *parent); - IUAVGadgetConfiguration *createConfiguration(QSettings *qSettings, UAVConfigInfo *configInfo); - IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); - -private: - ImportExportGadgetConfiguration *lastConfig; -}; - -#endif // IMPORTEXPORTGADGETFACTORY_H_ -/** - * @} - * @} - */ diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.cpp b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.cpp deleted file mode 100644 index ade45bb5f..000000000 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/** - ****************************************************************************** - * - * @file importexportgadgetoptionspage.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @see The GNU Public License (GPL) Version 3 - * @brief Option page for Import/Export Plugin - * @addtogroup GCSPlugins GCS Plugins - * @{ - * @addtogroup importexportplugin - * @{ - * - *****************************************************************************/ -/* - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "importexportgadgetoptionspage.h" -#include "importexportgadgetconfiguration.h" -#include "ui_importexportgadgetoptionspage.h" - -#include -#include - -ImportExportGadgetOptionsPage::ImportExportGadgetOptionsPage(ImportExportGadgetConfiguration *config, QObject *parent) : - IOptionsPage(parent), - m_config(config) -{ -} - -//creates options page widget (uses the UI file) -QWidget *ImportExportGadgetOptionsPage::createPage(QWidget *parent) -{ - - options_page = new Ui::ImportExportGadgetOptionsPage(); - //main widget - QWidget *optionsPageWidget = new QWidget; - //main layout - options_page->setupUi(optionsPageWidget); - - // Restore the contents from the settings: - options_page->iniFile->setExpectedKind(Utils::PathChooser::File); - options_page->iniFile->setPromptDialogFilter(tr("INI file (*.ini);; XML file (*.xml)")); - options_page->iniFile->setPromptDialogTitle(tr("Choose configuration file")); - options_page->iniFile->setPath(m_config->getIniFile()); - - return optionsPageWidget; -} - -/** - * Called when the user presses apply or OK. - * - * Saves the current values - * - */ -void ImportExportGadgetOptionsPage::apply() -{ - m_config->setIniFile(options_page->iniFile->path()); -} - - -void ImportExportGadgetOptionsPage::finish() -{ - -} -/** - * @} - * @} - */ diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.h b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.h deleted file mode 100644 index 41415dde4..000000000 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - ****************************************************************************** - * @file - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @see The GNU Public License (GPL) Version 3 - * @addtogroup GCSPlugins GCS Plugins - * @{ - * @addtogroup importexportplugin - * @{ - *****************************************************************************/ -/* - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef IMPORTEXPORTGADGETOPTIONSPAGE_H -#define IMPORTEXPORTGADGETOPTIONSPAGE_H - -#include "importexport_global.h" -#include "coreplugin/dialogs/ioptionspage.h" -#include -#include -#include -#include - -namespace Core -{ -class IUAVGadgetConfiguration; -} - -class ImportExportGadgetConfiguration; - -namespace Ui -{ -class ImportExportGadgetOptionsPage; -} - -using namespace Core; - -class IMPORTEXPORT_EXPORT ImportExportGadgetOptionsPage : public IOptionsPage -{ - Q_OBJECT -public: - explicit ImportExportGadgetOptionsPage(ImportExportGadgetConfiguration *config, QObject *parent = 0); - - QWidget *createPage(QWidget *parent); - void apply(); - void finish(); - -private: - Ui::ImportExportGadgetOptionsPage *options_page; - ImportExportGadgetConfiguration *m_config; - QFont font; - -private slots: - -}; - -#endif // IMPORTEXPORTGADGETOPTIONSPAGE_H -/** - * @} - * @} - */ diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.ui b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.ui deleted file mode 100644 index 176d5dd6c..000000000 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.ui +++ /dev/null @@ -1,103 +0,0 @@ - - - ImportExportGadgetOptionsPage - - - - 0 - 0 - 486 - 300 - - - - - 0 - 0 - - - - Form - - - - - -1 - -1 - 485 - 339 - - - - - QLayout::SetMinimumSize - - - 10 - - - 5 - - - 10 - - - 10 - - - - - 10 - - - QLayout::SetMaximumSize - - - 10 - - - - - Default Config File - - - - - - - - 0 - 0 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Utils::PathChooser - QWidget -
utils/pathchooser.h
- 1 -
-
- - -
diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.cpp b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.cpp index eda567bde..350e1a3ff 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.cpp @@ -48,10 +48,9 @@ ImportExportGadgetWidget::ImportExportGadgetWidget(QWidget *parent) : setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); ui->setupUi(this); ui->configFile->setExpectedKind(Utils::PathChooser::File); - ui->configFile->setPromptDialogFilter(tr("INI file (*.ini);; XML file (*.xml)")); + ui->configFile->setPromptDialogFilter(tr("XML file (*.xml)")); ui->configFile->setPromptDialogTitle(tr("Choose configuration file")); - } ImportExportGadgetWidget::~ImportExportGadgetWidget() @@ -70,17 +69,22 @@ void ImportExportGadgetWidget::changeEvent(QEvent *e) break; } } -void ImportExportGadgetWidget::loadConfiguration(const ImportExportGadgetConfiguration* config) -{ - if ( !config ) - return; - - ui->configFile->setPath(config->getIniFile()); -} void ImportExportGadgetWidget::on_exportButton_clicked() { QString file = ui->configFile->path(); + if (file.isEmpty()) { + QMessageBox msgBox; + msgBox.setText(tr("Empty File name.")); + msgBox.setInformativeText(tr("Please choose an export file name.")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); + return; + } + // Add a "XML" extension to the file in case it does not exist: + if (!file.endsWith(".xml")) + file.append(".xml"); + qDebug() << "Export pressed! Write to file " << QFileInfo(file).absoluteFilePath(); if ( QFileInfo(file).exists() ){ @@ -133,18 +137,7 @@ void ImportExportGadgetWidget::exportConfiguration(const QString& fileName) bool doAllGadgets = ui->checkBoxAllGadgets->isChecked(); bool doPlugins = ui->checkBoxPlugins->isChecked(); - QSettings::Format format; - if ( ui->radioButtonIniFormat->isChecked() ){ - format = QSettings::IniFormat; - } - else if ( ui->radioButtonXmlFormat->isChecked() ){ - format = XmlConfig::XmlSettingsFormat; - } - else { - qWarning() << "Program Error in ImportExportGadgetWidget::exportConfiguration: unknown format. Assume XML!"; - format = XmlConfig::XmlSettingsFormat; - } - + QSettings::Format format = XmlConfig::XmlSettingsFormat; QSettings qs(fileName, format); if (doGeneral) { @@ -193,19 +186,7 @@ void ImportExportGadgetWidget::importConfiguration(const QString& fileName) bool doAllGadgets = ui->checkBoxAllGadgets->isChecked(); bool doPlugins = ui->checkBoxPlugins->isChecked(); - QSettings::Format format; - if ( ui->radioButtonIniFormat->isChecked() ){ - format = QSettings::IniFormat; - } - else if ( ui->radioButtonXmlFormat->isChecked() ){ - format = XmlConfig::XmlSettingsFormat; - } - else { - qWarning() << "Program Error in ImportExportGadgetWidget::exportConfiguration: unknown format. Assume XML!"; - format = XmlConfig::XmlSettingsFormat; - } - - QSettings qs(fileName, format); + QSettings qs(fileName, XmlConfig::XmlSettingsFormat); if ( doAllGadgets ) { Core::ICore::instance()->uavGadgetInstanceManager()->readSettings(&qs); diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.h b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.h index 37393678c..ced46a059 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.h @@ -13,8 +13,8 @@ #include #include +#include "importexport_global.h" #include -#include "importexportgadgetconfiguration.h" namespace Ui { @@ -28,8 +28,6 @@ public: ImportExportGadgetWidget(QWidget *parent = 0); ~ImportExportGadgetWidget(); - void loadConfiguration(const ImportExportGadgetConfiguration* config); - signals: void done(); diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.ui b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.ui index 2aba80711..c29461d5c 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.ui +++ b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.ui @@ -82,8 +82,50 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 32 + 32 + + + + + + + + :/core/images/helpicon.svg:/core/images/helpicon.svg + + + + 32 + 32 + + + + true + + + + + Export the GCS settings selected in the checkboxes above. + Export @@ -91,6 +133,9 @@ + + Import settings from the config file, only for the items checked above. + Import @@ -98,46 +143,16 @@ + + Resets your GCS configuration to its default configuration. + Reset Config - - - - Help - - - - - - - Format - - - - - - XML Format - - - true - - - - - - - INI Format - - - - - - @@ -148,6 +163,8 @@ 1 - + + + diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportplugin.cpp b/ground/openpilotgcs/src/plugins/importexport/importexportplugin.cpp index 44d2b82a1..32f783593 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportplugin.cpp +++ b/ground/openpilotgcs/src/plugins/importexport/importexportplugin.cpp @@ -4,7 +4,7 @@ * @file importexportplugin.cpp * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @see The GNU Public License (GPL) Version 3 - * @brief Import/Export Plugin + * @brief Import/Export Plugin for GCS Settings * @addtogroup GCSPlugins GCS Plugins * @{ * @defgroup importexportplugin @@ -28,7 +28,6 @@ */ #include "importexportplugin.h" -#include "importexportgadgetfactory.h" #include "importexportdialog.h" #include #include @@ -55,8 +54,6 @@ bool ImportExportPlugin::initialize(const QStringList& args, QString *errMsg) { Q_UNUSED(args); Q_UNUSED(errMsg); - mf = new ImportExportGadgetFactory(this); - addAutoReleasedObject(mf); // Add Menu entry Core::ActionManager* am = Core::ICore::instance()->actionManager(); @@ -82,7 +79,7 @@ bool ImportExportPlugin::initialize(const QStringList& args, QString *errMsg) void ImportExportPlugin::importExport() { - ImportExportDialog(mf->getLastConfig()).exec(); + ImportExportDialog().exec(); } void ImportExportPlugin::extensionsInitialized() diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportplugin.h b/ground/openpilotgcs/src/plugins/importexport/importexportplugin.h index 91b3ed901..7070ce56c 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportplugin.h +++ b/ground/openpilotgcs/src/plugins/importexport/importexportplugin.h @@ -30,8 +30,6 @@ #include #include "importexport_global.h" -class ImportExportGadgetFactory; - class IMPORTEXPORT_EXPORT ImportExportPlugin : public ExtensionSystem::IPlugin { Q_OBJECT @@ -44,7 +42,6 @@ public: bool initialize(const QStringList & arguments, QString * errorString); void shutdown(); private: - ImportExportGadgetFactory *mf; private slots: void importExport(); diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp index 9bfa9f24e..a4cde6428 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.cpp @@ -58,64 +58,101 @@ UAVObjectUtilManager::~UAVObjectUtilManager() } } + +UAVObjectManager* UAVObjectUtilManager::getObjectManager() { + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager * objMngr = pm->getObject(); + Q_ASSERT(objMngr); + return objMngr; +} + + // ****************************** // SD card saving - +// void UAVObjectUtilManager::saveObjectToSD(UAVObject *obj) { - QMutexLocker locker(mutex); + // Add to queue + queue.enqueue(obj); + // If queue length is one, then start sending (call sendNextObject) + // Otherwise, do nothing, it's sending anyway + if (queue.length()==1) + saveNextObject(); - if (!obj) return; - - // Add to queue - queue.enqueue(obj); - - // If queue length is one, then start sending (call sendNextObject) - // Otherwise, do nothing, it's sending anyway - if (queue.length() <= 1) - saveNextObject(); } void UAVObjectUtilManager::saveNextObject() { - if (queue.isEmpty()) return; + if ( queue.isEmpty() ) + { + return; + } - // Get next object from the queue - UAVObject *obj = queue.head(); - if (!obj) return; + Q_ASSERT(saveState == IDLE); - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - if (!pm) return; - - UAVObjectManager *om = pm->getObject(); - if (!om) return; - - ObjectPersistence *objper = dynamic_cast(om->getObject(ObjectPersistence::NAME)); - connect(objper, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(transactionCompleted(UAVObject *, bool))); - - ObjectPersistence::DataFields data; - data.Operation = ObjectPersistence::OPERATION_SAVE; - data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT; - data.ObjectID = obj->getObjID(); - data.InstanceID = obj->getInstID(); - objper->setData(data); - objper->updated(); + // Get next object from the queue + UAVObject* obj = queue.head(); + ObjectPersistence* objper = dynamic_cast( getObjectManager()->getObject(ObjectPersistence::NAME) ); + connect(objper, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(objectPersistenceTransactionCompleted(UAVObject*,bool))); + connect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(objectPersistenceUpdated(UAVObject *))); + saveState = AWAITING_ACK; + if (obj != NULL) + { + ObjectPersistence::DataFields data; + data.Operation = ObjectPersistence::OPERATION_SAVE; + data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT; + data.ObjectID = obj->getObjID(); + data.InstanceID = obj->getInstID(); + objper->setData(data); + objper->updated(); + } } -void UAVObjectUtilManager::transactionCompleted(UAVObject *obj, bool success) +/** + * @brief Process the transactionCompleted message from Telemetry indicating request sent successfully + * @param[in] The object just transsacted. Must be ObjectPersistance + * @param[in] success Indicates that the transaction did not time out + * + * After a failed transaction (usually timeout) resends the save request. After a succesful + * transaction will then wait for a save completed update from the autopilot. + */ +void UAVObjectUtilManager::objectPersistenceTransactionCompleted(UAVObject* obj, bool success) { - Q_UNUSED(success); - - QMutexLocker locker(mutex); - - if (!obj) return; - - // Disconnect from sending object - obj->disconnect(this); - queue.dequeue(); // We can now remove the object, it's done. - saveNextObject(); + if(success) { + Q_ASSERT(obj->getName().compare("ObjectPersistence") == 0); + Q_ASSERT(saveState == AWAITING_ACK); + saveState = AWAITING_COMPLETED; + disconnect(obj, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(objectPersistenceTransactionCompleted(UAVObject*,bool))); + } else if (!success) { + // Can be caused by timeout errors on sending. Send again. + saveNextObject(); + } } +/** + * @brief Process the ObjectPersistence updated message to confirm the right object saved + * then requests next object be saved. + * @param[in] The object just received. Must be ObjectPersistance + */ +void UAVObjectUtilManager::objectPersistenceUpdated(UAVObject * obj) +{ + Q_ASSERT(obj->getName().compare("ObjectPersistence") == 0); + if(saveState == AWAITING_COMPLETED) { + // Check flight is saying it completed. This is the only thing flight should do to trigger an update. + Q_ASSERT( obj->getField("Operation")->getValue().toString().compare(QString("Completed")) == 0 ); + + // Check right object saved + UAVObject* savingObj = queue.head(); + Q_ASSERT( obj->getField("ObjectID")->getValue() == savingObj->getObjID() ); + + obj->disconnect(this); + queue.dequeue(); // We can now remove the object, it's done. + saveState = IDLE; + saveNextObject(); + } +} + + /** * Get the UAV Board model, for anyone interested. Return format is: * (Board Type << 8) + BoardRevision. diff --git a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h index 5d6afbfa2..80ca9e900 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h +++ b/ground/openpilotgcs/src/plugins/uavobjectutil/uavobjectutilmanager.h @@ -63,17 +63,21 @@ public: int getBoardModel(); QByteArray getBoardCPUSerial(); QString getBoardDescription(); + UAVObjectManager* getObjectManager(); + void saveObjectToSD(UAVObject *obj); + private: QMutex *mutex; - QQueue queue; - + enum {IDLE, AWAITING_ACK, AWAITING_COMPLETED} saveState; void saveNextObject(); - void saveObjectToSD(UAVObject *obj); private slots: - void transactionCompleted(UAVObject *obj, bool success); + //void transactionCompleted(UAVObject *obj, bool success); + void objectPersistenceTransactionCompleted(UAVObject* obj, bool success); + void objectPersistenceUpdated(UAVObject * obj); + }; diff --git a/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport.cpp b/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport.cpp index 7bd6b3e5b..e1b9ea1d1 100644 --- a/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport.cpp +++ b/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport.cpp @@ -36,6 +36,7 @@ #include #include +#include // for menu item #include @@ -74,20 +75,21 @@ bool UAVSettingsImportExportPlugin::initialize(const QStringList& args, QString Core::ActionManager* am = Core::ICore::instance()->actionManager(); Core::ActionContainer* ac = am->actionContainer(Core::Constants::M_FILE); Core::Command* cmd = am->registerAction(new QAction(this), - "UAVSettingsImportExportPlugin.UAVSettingsImportExport", + "UAVSettingsImportExportPlugin.UAVSettingsExport", QList() << Core::Constants::C_GLOBAL_ID); - cmd->setDefaultKeySequence(QKeySequence("Ctrl+E")); + cmd->setDefaultKeySequence(QKeySequence("Ctrl+E")); + cmd->action()->setText(tr("Export UAV Settings...")); + ac->addAction(cmd, Core::Constants::G_FILE_SAVE); + connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(exportUAVSettings())); -// cmd->action()->setText(tr("UAV Settings Import/Export...")); - cmd->action()->setText(tr("UAV Settings Export...")); - -// ac->menu()->addSeparator(); -// ac->appendGroup("ImportExport"); -// ac->addAction(cmd, "ImportExport"); - ac->addAction(cmd, Core::Constants::G_FILE_SAVE); - - connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(importExport())); + cmd = am->registerAction(new QAction(this), + "UAVSettingsImportExportPlugin.UAVSettingsImport", + QList() << + Core::Constants::C_GLOBAL_ID); + cmd->action()->setText(tr("Import UAV Settings...")); + ac->addAction(cmd, Core::Constants::G_FILE_SAVE); + connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(importUAVSettings())); return true; } @@ -97,39 +99,106 @@ void UAVSettingsImportExportPlugin::extensionsInitialized() // Do nothing } + // Slot called by the menu manager on user action -// TODO: import function is not implemented yet -void UAVSettingsImportExportPlugin::importExport() +void UAVSettingsImportExportPlugin::importUAVSettings() { - // available formats - enum { UNDEF, UAV, XML, INI } fileFormat = UNDEF; - - // ask for file name and export format + // ask for file name QString fileName; - QString filters = tr("UAV Settings files (*.uav)") - + ";;" + tr("Simple XML files (*.xml)") - + ";;" + tr("INI files (*.ini)"); - - fileName = QFileDialog::getSaveFileName(0, tr("Save UAV Settings File As"), "", filters); + QString filters = tr("UAVSettings XML files (*.xml)"); + fileName = QFileDialog::getOpenFileName(0, tr("Import UAV Settings"), "", filters); if (fileName.isEmpty()) { return; } - // check export file format - QFileInfo fileInfo(fileName); - QString fileType = fileInfo.suffix().toLower(); + // Now open the file + QFile file(fileName); + QDomDocument doc("UAVSettings"); + file.open(QFile::ReadOnly|QFile::Text); + if (!doc.setContent(file.readAll())) { + QMessageBox msgBox; + msgBox.setText(tr("File Parsing Failed.")); + msgBox.setInformativeText(tr("This file is not a correct XML file")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); + return; + } + file.close(); - if (fileType == "uav") { - fileFormat = UAV; - } else if (fileType == "xml") { - fileFormat = XML; - } else if (fileType == "ini") { - fileFormat = INI; - } else { - QMessageBox::critical(0, - tr("UAV Settings Export"), - tr("Unsupported export file format: ") + fileType, - QMessageBox::Ok); + QDomElement root = doc.documentElement(); + if (root.tagName() != "settings") { + QMessageBox msgBox; + msgBox.setText(tr("Wrong file contents.")); + msgBox.setInformativeText(tr("This file is not a correct UAVSettings file")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); + return; + } + + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager *objManager = pm->getObject(); + UAVObjectUtilManager *utilManager = pm->getObject(); + QDomNode node = root.firstChild(); + while (!node.isNull()) { + QDomElement e = node.toElement(); + if (e.tagName() == "object") { + // - Read each object + QString uavObjectName = e.attribute("name"); + uint uavObjectID = e.attribute("id").toUInt(NULL,16); + // Sanity Check: + UAVObject* obj = objManager->getObject(uavObjectName); + if (uavObjectID != obj->getObjID()) { + qDebug() << "Mismatch for Object " << uavObjectName << uavObjectID << " - " << obj->getObjID(); + QMessageBox msgBox; + msgBox.setText(tr("File Object Mismatch: aborting.")); + msgBox.setInformativeText(tr("Found a mismatch between file object definition and current object definition.")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); + return; + + } else { + // - Update each field + // - Issue and "updated" command + QDomNode field = node.firstChild(); + while(!field.isNull()) { + QDomElement f = field.toElement(); + if (f.tagName() == "field") { + UAVObjectField *uavfield = obj->getField(f.attribute("name")); + if (f.attribute("elements").toInt() == 1) { + uavfield->setValue(f.attribute("values")); + } else { + // This is an enum: + int i=0; + QStringList list = f.attribute("values").split(","); + foreach (QString element, list) { + uavfield->setValue(element,i++); + } + } + } + field = field.nextSibling(); + } + obj->updated(); + utilManager->saveObjectToSD(obj); + } + } + node = node.nextSibling(); + } + QMessageBox msgBox; + msgBox.setText(tr("Settings restored.")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); + +} + +// Slot called by the menu manager on user action +void UAVSettingsImportExportPlugin::exportUAVSettings() +{ + // ask for file name + QString fileName; + QString filters = tr("UAVSettings XML files (*.xml)"); + + fileName = QFileDialog::getSaveFileName(0, tr("Save UAV Settings File As"), "", filters); + if (fileName.isEmpty()) { return; } @@ -152,12 +221,10 @@ void UAVSettingsImportExportPlugin::importExport() QDomElement o = doc.createElement("object"); o.setAttribute("name", obj->getName()); o.setAttribute("id", QString("0x")+ QString().setNum(obj->getObjID(),16).toUpper()); - if (fileFormat == UAV) { - QDomElement d = doc.createElement("description"); - QDomText t = doc.createTextNode(obj->getDescription().remove("@Ref ", Qt::CaseInsensitive)); - d.appendChild(t); - o.appendChild(d); - } + QDomElement d = doc.createElement("description"); + QDomText t = doc.createTextNode(obj->getDescription().remove("@Ref ", Qt::CaseInsensitive)); + d.appendChild(t); + o.appendChild(d); // iterate over fields QList fieldList = obj->getFields(); @@ -175,13 +242,11 @@ void UAVSettingsImportExportPlugin::importExport() f.setAttribute("name", field->getName()); f.setAttribute("values", vals); - if (fileFormat == UAV) { - f.setAttribute("type", field->getTypeAsString()); - f.setAttribute("units", field->getUnits()); - f.setAttribute("elements", nelem); - if (field->getType() == UAVObjectField::ENUM) { - f.setAttribute("options", field->getOptions().join(",")); - } + f.setAttribute("type", field->getTypeAsString()); + f.setAttribute("units", field->getUnits()); + f.setAttribute("elements", nelem); + if (field->getType() == UAVObjectField::ENUM) { + f.setAttribute("options", field->getOptions().join(",")); } o.appendChild(f); } @@ -189,48 +254,23 @@ void UAVSettingsImportExportPlugin::importExport() } } } - // save file - if ((fileFormat == UAV) || (fileFormat == XML)) { - QFile file(fileName); - if (file.open(QIODevice::WriteOnly) && - (file.write(doc.toString(4).toAscii()) != -1)) { - file.close(); - } else { - QMessageBox::critical(0, - tr("UAV Settings Export"), - tr("Unable to save settings: ") + fileName, - QMessageBox::Ok); - return; - } - } else if (fileFormat == INI) { - if (QFile::exists(fileName) && !QFile::remove(fileName)) { - QMessageBox::critical(0, - tr("UAV Settings Export"), - tr("Unable to remove existing file: ") + fileName, - QMessageBox::Ok); - return; - } - - QSettings ini(fileName, QSettings::IniFormat); - QDomElement docElem = doc.documentElement(); - QDomNodeList nodeList = docElem.elementsByTagName("object"); - for (int i = 0; i < nodeList.count(); i++) { - QDomElement e = nodeList.at(i).toElement(); - if (!e.isNull()) { - ini.beginGroup(e.attribute("name", "undefined")); - ini.setValue("id", e.attribute("id")); - QDomNodeList n = e.elementsByTagName("field"); - for (int j = 0; j < n.count(); j++) { - QDomElement f = n.at(j).toElement(); - if (!f.isNull()) { - ini.setValue(f.attribute("name", "unknown"), f.attribute("values")); - } - } - ini.endGroup(); - } - } + QFile file(fileName); + if (file.open(QIODevice::WriteOnly) && + (file.write(doc.toString(4).toAscii()) != -1)) { + file.close(); + } else { + QMessageBox::critical(0, + tr("UAV Settings Export"), + tr("Unable to save settings: ") + fileName, + QMessageBox::Ok); + return; } + + QMessageBox msgBox; + msgBox.setText(tr("Settings saved.")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); } void UAVSettingsImportExportPlugin::shutdown() diff --git a/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport.h b/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport.h index 60b0efd6a..696103ba4 100644 --- a/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport.h +++ b/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport.h @@ -28,6 +28,7 @@ #define UAVSETTINGSIMPORTEXPORT_H #include +#include "uavobjectutil/uavobjectutilmanager.h" class UAVSettingsImportExportPlugin : public ExtensionSystem::IPlugin { @@ -42,7 +43,8 @@ public: void shutdown(); private slots: - void importExport(); + void importUAVSettings(); + void exportUAVSettings(); }; diff --git a/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport.pluginspec b/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport.pluginspec index 7b64a8e60..b40dc5b60 100644 --- a/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport.pluginspec +++ b/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport.pluginspec @@ -7,5 +7,6 @@ + diff --git a/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport_dependencies.pri b/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport_dependencies.pri index 4bb362f98..2bf87c3be 100644 --- a/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport_dependencies.pri +++ b/ground/openpilotgcs/src/plugins/uavsettingsimportexport/uavsettingsimportexport_dependencies.pri @@ -1,2 +1,3 @@ include(../../plugins/coreplugin/coreplugin.pri) include(../../plugins/uavobjects/uavobjects.pri) +include(../../plugins/uavobjectutil/uavobjectutil.pri)