From ad9227d7a419579e3c63444878373997506267ac Mon Sep 17 00:00:00 2001 From: vassilis Date: Sat, 10 Apr 2010 05:09:56 +0000 Subject: [PATCH] GCS/UAVObjectBrowser: Implemented settings save/load actions and created the SettingsPersistence object git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@469 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../libs/uavobjgenerator/uavobjectparser.cpp | 2 +- .../uavobjectbrowser/uavobjectbrowser.ui | 310 +++++++++--------- .../uavobjectbrowserwidget.cpp | 27 ++ .../uavobjectbrowser/uavobjectbrowserwidget.h | 5 + .../src/plugins/uavobjects/exampleobject1.h | 6 +- .../src/plugins/uavobjects/exampleobject2.h | 4 +- .../src/plugins/uavobjects/examplesettings.h | 6 +- .../uavobjects/settingspersistence.cpp | 82 +++++ .../plugins/uavobjects/settingspersistence.h | 71 ++++ .../plugins/uavobjects/uavobjectmanager.cpp | 12 +- .../src/plugins/uavobjects/uavobjectmanager.h | 12 +- ground/src/plugins/uavobjects/uavobjects.pro | 6 +- .../src/plugins/uavobjects/uavobjectsinit.cpp | 2 + .../plugins/uavobjects/uavobjecttemplate.h | 4 +- .../settingspersistence.xml | 8 + 15 files changed, 381 insertions(+), 176 deletions(-) create mode 100644 ground/src/plugins/uavobjects/settingspersistence.cpp create mode 100644 ground/src/plugins/uavobjects/settingspersistence.h create mode 100644 ground/src/shared/uavobjectdefinition/settingspersistence.xml diff --git a/ground/src/libs/uavobjgenerator/uavobjectparser.cpp b/ground/src/libs/uavobjgenerator/uavobjectparser.cpp index b5643481b..366c4d706 100644 --- a/ground/src/libs/uavobjgenerator/uavobjectparser.cpp +++ b/ground/src/libs/uavobjgenerator/uavobjectparser.cpp @@ -673,7 +673,7 @@ bool UAVObjectParser::generateGCSObject(int objIndex, const QString& templateInc } enums.append( QString(" } %1Enum;\n") - .arg( info->fields[n]->name.toUpper() ) ); + .arg( info->fields[n]->name ) ); } } outInclude.replace(QString("$(DATAENUM)"), enums); diff --git a/ground/src/plugins/uavobjectbrowser/uavobjectbrowser.ui b/ground/src/plugins/uavobjectbrowser/uavobjectbrowser.ui index dc5cfa28b..d843f4618 100644 --- a/ground/src/plugins/uavobjectbrowser/uavobjectbrowser.ui +++ b/ground/src/plugins/uavobjectbrowser/uavobjectbrowser.ui @@ -1,155 +1,155 @@ - - - UAVObjectBrowser - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - - - - Request update - - - Request - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 10 - 20 - - - - - - - - Send update - - - Send - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 10 - 20 - - - - - - - - Save to SD Card - - - Save - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 10 - 20 - - - - - - - - Read from SD Card - - - Read - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 10 - 20 - - - - - - - - Show Meta Data - - - Show Meta Data - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - + + + UAVObjectBrowser + + + + 0 + 0 + 476 + 300 + + + + Form + + + + + + + + Request update + + + Request + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 10 + 20 + + + + + + + + Send update + + + Send + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 10 + 20 + + + + + + + + Save to SD Card + + + Save + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 10 + 20 + + + + + + + + Read from SD Card + + + Read + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 10 + 20 + + + + + + + + Show Meta Data + + + Show Meta Data + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/ground/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp b/ground/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp index 65d80f363..b0a83541e 100644 --- a/ground/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp +++ b/ground/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp @@ -28,6 +28,7 @@ #include "uavobjecttreemodel.h" #include "browseritemdelegate.h" #include "ui_uavobjectbrowser.h" +#include "uavobjects/uavobjectmanager.h" #include #include #include @@ -35,6 +36,7 @@ #include #include #include +#include "extensionsystem/pluginmanager.h" UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent) { @@ -50,6 +52,8 @@ UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent m_browser->treeView->setEditTriggers(QAbstractItemView::AllEditTriggers); connect(m_browser->metaCheckBox, SIGNAL(toggled(bool)), this, SLOT(showMetaData(bool))); showMetaData(m_browser->metaCheckBox->isChecked()); + connect(m_browser->saveSDButton, SIGNAL(clicked()), this, SLOT(saveSettings())); + connect(m_browser->readSDButton, SIGNAL(clicked()), this, SLOT(readSettings())); } UAVObjectBrowserWidget::~UAVObjectBrowserWidget() @@ -79,4 +83,27 @@ void UAVObjectBrowserWidget::requestUpdate() } +void UAVObjectBrowserWidget::saveSettings() +{ + updateSettings(SettingsPersistence::OPERATION_SAVE); +} + +void UAVObjectBrowserWidget::readSettings() +{ + updateSettings(SettingsPersistence::OPERATION_LOAD); +} + +void UAVObjectBrowserWidget::updateSettings(SettingsPersistence::OperationEnum op) +{ + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager *objManager = pm->getObject(); + SettingsPersistence* obj = dynamic_cast( objManager->getObject(SettingsPersistence::NAME) ); + if (obj != NULL) + { + SettingsPersistence::DataFields data; + data.Operation = op; + obj->setData(data); + obj->updated(); + } +} diff --git a/ground/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h b/ground/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h index 9345ff191..2501697f8 100644 --- a/ground/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h +++ b/ground/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h @@ -30,6 +30,7 @@ #include #include +#include "uavobjects/settingspersistence.h" class QPushButton; class Ui_UAVObjectBrowser; @@ -47,6 +48,8 @@ private slots: void sendUpdate(); void requestUpdate(); void showMetaData(bool show); + void saveSettings(); + void readSettings(); private: @@ -54,6 +57,8 @@ private: QPushButton *m_sendUpdate; Ui_UAVObjectBrowser *m_browser; QAbstractItemModel *m_model; + + void updateSettings(SettingsPersistence::OperationEnum op); }; #endif /* UAVOBJECTBROWSERWIDGET_H_ */ diff --git a/ground/src/plugins/uavobjects/exampleobject1.h b/ground/src/plugins/uavobjects/exampleobject1.h index 2b08c02d0..c22f65bf6 100644 --- a/ground/src/plugins/uavobjects/exampleobject1.h +++ b/ground/src/plugins/uavobjects/exampleobject1.h @@ -33,8 +33,10 @@ #include "uavdataobject.h" -class ExampleObject1: public UAVDataObject +class UAVOBJECTS_EXPORT ExampleObject1: public UAVDataObject { + Q_OBJECT + public: // Field structure typedef struct { @@ -50,7 +52,7 @@ public: } __attribute__((packed)) DataFields; // Enumeration types - typedef enum { FIELD8_OPTION1=0, FIELD8_OPTION2=1, } FIELD8Enum; + typedef enum { FIELD8_OPTION1=0, FIELD8_OPTION2=1, } Field8Enum; // Constants diff --git a/ground/src/plugins/uavobjects/exampleobject2.h b/ground/src/plugins/uavobjects/exampleobject2.h index cac748493..e7c1d7940 100644 --- a/ground/src/plugins/uavobjects/exampleobject2.h +++ b/ground/src/plugins/uavobjects/exampleobject2.h @@ -33,8 +33,10 @@ #include "uavdataobject.h" -class ExampleObject2: public UAVDataObject +class UAVOBJECTS_EXPORT ExampleObject2: public UAVDataObject { + Q_OBJECT + public: // Field structure typedef struct { diff --git a/ground/src/plugins/uavobjects/examplesettings.h b/ground/src/plugins/uavobjects/examplesettings.h index b1e3219d1..b58bd00fc 100644 --- a/ground/src/plugins/uavobjects/examplesettings.h +++ b/ground/src/plugins/uavobjects/examplesettings.h @@ -33,8 +33,10 @@ #include "uavdataobject.h" -class ExampleSettings: public UAVDataObject +class UAVOBJECTS_EXPORT ExampleSettings: public UAVDataObject { + Q_OBJECT + public: // Field structure typedef struct { @@ -45,7 +47,7 @@ public: } __attribute__((packed)) DataFields; // Enumeration types - typedef enum { STEPDIRECTION_UP=0, STEPDIRECTION_DOWN=1, } STEPDIRECTIONEnum; + typedef enum { STEPDIRECTION_UP=0, STEPDIRECTION_DOWN=1, } StepDirectionEnum; // Constants diff --git a/ground/src/plugins/uavobjects/settingspersistence.cpp b/ground/src/plugins/uavobjects/settingspersistence.cpp new file mode 100644 index 000000000..d47f395f4 --- /dev/null +++ b/ground/src/plugins/uavobjects/settingspersistence.cpp @@ -0,0 +1,82 @@ +/** + ****************************************************************************** + * + * @file settingspersistence.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the SettingsPersistence object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: settingspersistence.xml. + * This is an automatically generated file. + * DO NOT modify manually. + * + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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 "settingspersistence.h" +#include "uavobjectfields.h" + +const QString SettingsPersistence::NAME = QString("SettingsPersistence"); + +SettingsPersistence::SettingsPersistence(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME) +{ + // Create fields + QList fields; + QStringList OperationEnumOptions; + OperationEnumOptions.append("Load"); + OperationEnumOptions.append("Save"); + fields.append(new UAVObjectFieldEnum(QString("Operation"), QString(""), 1, OperationEnumOptions)); + + // Initialize object + initializeFields(fields, (quint8*)&data, NUMBYTES); +} + +UAVObject::Metadata SettingsPersistence::getDefaultMetadata() +{ + UAVObject::Metadata metadata; + metadata.gcsTelemetryAcked = 1; + metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_MANUAL; + metadata.gcsTelemetryUpdatePeriod = 0; + metadata.flightTelemetryAcked = 1; + metadata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_MANUAL; + metadata.flightTelemetryUpdatePeriod = 0; + metadata.loggingUpdateMode = UAVObject::UPDATEMODE_NEVER; + metadata.loggingUpdatePeriod = 0; + return metadata; +} + +SettingsPersistence::DataFields SettingsPersistence::getData() +{ + QMutexLocker locker(mutex); + return data; +} + +void SettingsPersistence::setData(DataFields& data) +{ + QMutexLocker locker(mutex); + this->data = data; + emit objectUpdatedAuto(this); // trigger object updated event + emit objectUpdated(this); +} + +UAVDataObject* SettingsPersistence::clone(quint32 instID) +{ + SettingsPersistence* obj = new SettingsPersistence(); + obj->initialize(instID, this->getMetaObject()); + return obj; +} diff --git a/ground/src/plugins/uavobjects/settingspersistence.h b/ground/src/plugins/uavobjects/settingspersistence.h new file mode 100644 index 000000000..5c51ca9ba --- /dev/null +++ b/ground/src/plugins/uavobjects/settingspersistence.h @@ -0,0 +1,71 @@ +/** + ****************************************************************************** + * + * @file settingspersistence.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Implementation of the SettingsPersistence object. This file has been + * automatically generated by the UAVObjectGenerator. + * + * @note Object definition file: settingspersistence.xml. + * This is an automatically generated file. + * DO NOT modify manually. + * + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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 SETTINGSPERSISTENCE_H +#define SETTINGSPERSISTENCE_H + +#include "uavdataobject.h" + +class UAVOBJECTS_EXPORT SettingsPersistence: public UAVDataObject +{ + Q_OBJECT + +public: + // Field structure + typedef struct { + quint8 Operation; + + } __attribute__((packed)) DataFields; + + // Enumeration types + typedef enum { OPERATION_LOAD=0, OPERATION_SAVE=1, } OperationEnum; + + + // Constants + static const quint32 OBJID = 3652432370U; + static const QString NAME; + static const bool ISSINGLEINST = 1; + static const bool ISSETTINGS = 0; + static const quint32 NUMBYTES = sizeof(DataFields); + + // Functions + SettingsPersistence(); + + DataFields getData(); + void setData(DataFields& data); + Metadata getDefaultMetadata(); + UAVDataObject* clone(quint32 instID); + +private: + DataFields data; + +}; + +#endif // SETTINGSPERSISTENCE_H diff --git a/ground/src/plugins/uavobjects/uavobjectmanager.cpp b/ground/src/plugins/uavobjects/uavobjectmanager.cpp index 92de988f6..85246d95c 100644 --- a/ground/src/plugins/uavobjects/uavobjectmanager.cpp +++ b/ground/src/plugins/uavobjects/uavobjectmanager.cpp @@ -220,7 +220,7 @@ QList > UAVObjectManager::getMetaObjects() * Get a specific object given its name and instance ID * @returns The object is found or NULL if not */ -UAVObject* UAVObjectManager::getObject(QString& name, quint32 instId) +UAVObject* UAVObjectManager::getObject(const QString& name, quint32 instId) { return getObject(&name, 0, instId); } @@ -237,7 +237,7 @@ UAVObject* UAVObjectManager::getObject(quint32 objId, quint32 instId) /** * Helper function for the public getObject() functions. */ -UAVObject* UAVObjectManager::getObject(QString* name, quint32 objId, quint32 instId) +UAVObject* UAVObjectManager::getObject(const QString* name, quint32 objId, quint32 instId) { QMutexLocker locker(mutex); // Check if this object type is already in the list @@ -266,7 +266,7 @@ UAVObject* UAVObjectManager::getObject(QString* name, quint32 objId, quint32 ins /** * Get all the instances of the object specified by name */ -QList UAVObjectManager::getObjectInstances(QString& name) +QList UAVObjectManager::getObjectInstances(const QString& name) { return getObjectInstances(&name, 0); } @@ -282,7 +282,7 @@ QList UAVObjectManager::getObjectInstances(quint32 objId) /** * Helper function for the public getObjectInstances() */ -QList UAVObjectManager::getObjectInstances(QString* name, quint32 objId) +QList UAVObjectManager::getObjectInstances(const QString* name, quint32 objId) { QMutexLocker locker(mutex); // Check if this object type is already in the list @@ -304,7 +304,7 @@ QList UAVObjectManager::getObjectInstances(QString* name, quint32 ob /** * Get the number of instances for an object given its name */ -qint32 UAVObjectManager::getNumInstances(QString& name) +qint32 UAVObjectManager::getNumInstances(const QString& name) { return getNumInstances(&name, 0); } @@ -320,7 +320,7 @@ qint32 UAVObjectManager::getNumInstances(quint32 objId) /** * Helper function for public getNumInstances */ -qint32 UAVObjectManager::getNumInstances(QString* name, quint32 objId) +qint32 UAVObjectManager::getNumInstances(const QString* name, quint32 objId) { QMutexLocker locker(mutex); // Check if this object type is already in the list diff --git a/ground/src/plugins/uavobjects/uavobjectmanager.h b/ground/src/plugins/uavobjects/uavobjectmanager.h index e32a56964..30b1a1352 100644 --- a/ground/src/plugins/uavobjects/uavobjectmanager.h +++ b/ground/src/plugins/uavobjects/uavobjectmanager.h @@ -48,11 +48,11 @@ public: QList< QList > getObjects(); QList< QList > getDataObjects(); QList< QList > getMetaObjects(); - UAVObject* getObject(QString& name, quint32 instId = 0); + UAVObject* getObject(const QString& name, quint32 instId = 0); UAVObject* getObject(quint32 objId, quint32 instId = 0); - QList getObjectInstances(QString& name); + QList getObjectInstances(const QString& name); QList getObjectInstances(quint32 objId); - qint32 getNumInstances(QString& name); + qint32 getNumInstances(const QString& name); qint32 getNumInstances(quint32 objId); signals: @@ -66,9 +66,9 @@ private: QMutex* mutex; void addObject(UAVObject* obj); - UAVObject* getObject(QString* name, quint32 objId, quint32 instId); - QList getObjectInstances(QString* name, quint32 objId); - qint32 getNumInstances(QString* name, quint32 objId); + UAVObject* getObject(const QString* name, quint32 objId, quint32 instId); + QList getObjectInstances(const QString* name, quint32 objId); + qint32 getNumInstances(const QString* name, quint32 objId); }; diff --git a/ground/src/plugins/uavobjects/uavobjects.pro b/ground/src/plugins/uavobjects/uavobjects.pro index ac000cc2b..6d537a10a 100644 --- a/ground/src/plugins/uavobjects/uavobjects.pro +++ b/ground/src/plugins/uavobjects/uavobjects.pro @@ -22,7 +22,8 @@ HEADERS += uavobjects_global.h \ uavobjectfielduint8.h \ uavobjectfielduint16.h \ uavobjectfielduint32.h \ - uavobjectfields.h + uavobjectfields.h \ + settingspersistence.h SOURCES += uavobject.cpp \ uavmetaobject.cpp \ uavobjectmanager.cpp \ @@ -41,6 +42,7 @@ SOURCES += uavobject.cpp \ uavobjectfieldfloat.cpp \ uavobjectfielduint8.cpp \ uavobjectfielduint16.cpp \ - uavobjectfielduint32.cpp + uavobjectfielduint32.cpp \ + settingspersistence.cpp DEFINES += UAVOBJECTS_LIBRARY OTHER_FILES += UAVObjects.pluginspec diff --git a/ground/src/plugins/uavobjects/uavobjectsinit.cpp b/ground/src/plugins/uavobjects/uavobjectsinit.cpp index 885246b3d..9b8399215 100644 --- a/ground/src/plugins/uavobjects/uavobjectsinit.cpp +++ b/ground/src/plugins/uavobjects/uavobjectsinit.cpp @@ -33,6 +33,7 @@ #include "exampleobject1.h" #include "exampleobject2.h" #include "examplesettings.h" +#include "settingspersistence.h" /** @@ -44,5 +45,6 @@ void UAVObjectsInitialize(UAVObjectManager* objMngr) objMngr->registerObject( new ExampleObject1() ); objMngr->registerObject( new ExampleObject2() ); objMngr->registerObject( new ExampleSettings() ); + objMngr->registerObject( new SettingsPersistence() ); } diff --git a/ground/src/plugins/uavobjects/uavobjecttemplate.h b/ground/src/plugins/uavobjects/uavobjecttemplate.h index c8c1f8d3b..cda5978c8 100644 --- a/ground/src/plugins/uavobjects/uavobjecttemplate.h +++ b/ground/src/plugins/uavobjects/uavobjecttemplate.h @@ -33,8 +33,10 @@ #include "uavdataobject.h" -class $(NAME): public UAVDataObject +class UAVOBJECTS_EXPORT $(NAME): public UAVDataObject { + Q_OBJECT + public: // Field structure typedef struct { diff --git a/ground/src/shared/uavobjectdefinition/settingspersistence.xml b/ground/src/shared/uavobjectdefinition/settingspersistence.xml new file mode 100644 index 000000000..7131fbdd3 --- /dev/null +++ b/ground/src/shared/uavobjectdefinition/settingspersistence.xml @@ -0,0 +1,8 @@ + + + + + + + +