From 1b1e0f502778506ce4851df78ee833c3d03e43fd Mon Sep 17 00:00:00 2001 From: tstellanova Date: Thu, 15 Aug 2013 20:15:46 -0700 Subject: [PATCH] fix one-stage constructor problem --- src/uas/QGCUASParamManager.cc | 18 ++++++++++++++---- src/uas/QGCUASParamManager.h | 3 ++- src/uas/UAS.cc | 6 +++--- src/uas/UAS.h | 4 ++-- src/uas/UASParameterCommsMgr.cc | 15 +++++++++++---- src/uas/UASParameterCommsMgr.h | 4 +++- src/ui/QGCParamWidget.cc | 22 +++++++++++----------- src/ui/designer/QGCParamSlider.cc | 21 ++++++++------------- src/ui/designer/QGCParamSlider.h | 4 ++-- src/ui/designer/QGCTextLabel.h | 2 +- src/ui/designer/QGCToolWidgetItem.h | 2 +- 11 files changed, 58 insertions(+), 43 deletions(-) diff --git a/src/uas/QGCUASParamManager.cc b/src/uas/QGCUASParamManager.cc index bfb946732..beedd5c74 100644 --- a/src/uas/QGCUASParamManager.cc +++ b/src/uas/QGCUASParamManager.cc @@ -7,19 +7,29 @@ #include "UASInterface.h" #include "UASParameterCommsMgr.h" -QGCUASParamManager::QGCUASParamManager(QObject *parent, UASInterface* uas) : +QGCUASParamManager::QGCUASParamManager(QObject *parent) : QObject(parent), - mav(uas), + mav(NULL), paramDataModel(this), paramCommsMgr(NULL) { - paramCommsMgr = new UASParameterCommsMgr(this,mav); - // Load default values and tooltips + +} + +QGCUASParamManager* QGCUASParamManager::initWithUAS(UASInterface* uas) +{ + mav = uas; + + // Load default values and tooltips for data model loadParamMetaInfoCSV(); + paramCommsMgr = new UASParameterCommsMgr(this); + paramCommsMgr->initWithUAS(uas); + connectToCommsMgr(); + return this; } void QGCUASParamManager::connectToCommsMgr() diff --git a/src/uas/QGCUASParamManager.h b/src/uas/QGCUASParamManager.h index a346bbaa4..29c1150da 100644 --- a/src/uas/QGCUASParamManager.h +++ b/src/uas/QGCUASParamManager.h @@ -17,7 +17,8 @@ class QGCUASParamManager : public QObject { Q_OBJECT public: - QGCUASParamManager(QObject* parent = 0,UASInterface* uas = 0); + QGCUASParamManager(QObject* parent = 0); + QGCUASParamManager* initWithUAS(UASInterface* uas); /** @brief Get the known, confirmed value of a parameter */ virtual bool getParameterValue(int component, const QString& parameter, QVariant& value) const; diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 80c055836..457b294e0 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -115,8 +115,8 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(), nedPosGlobalOffset(0,0,0), nedAttGlobalOffset(0,0,0), - waypointManager(this), + paramMgr(this), #if defined(QGC_PROTOBUF_ENABLED) && defined(QGC_USE_PIXHAWK_MESSAGES) receivedOverlayTimestamp(0.0), @@ -131,8 +131,6 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(), lastAttitude(0), paramsOnceRequested(false), - paramManager(this,this), - simulation(0), // The protected members. @@ -217,6 +215,8 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(), connect(this, SIGNAL(systemSpecsChanged(int)), this, SLOT(writeSettings())); statusTimeout->start(500); readSettings(); + //need to init paramMgr after readSettings have been loaded, to properly set autopilot and so forth + paramMgr.initWithUAS(this); // Initial signals emit disarmed(); emit armingChanged(false); diff --git a/src/uas/UAS.h b/src/uas/UAS.h index b62a81a6d..0d89a75e3 100644 --- a/src/uas/UAS.h +++ b/src/uas/UAS.h @@ -492,7 +492,7 @@ protected: //COMMENTS FOR TEST UNIT /// PARAMETERS QMap* > parameters; ///< All parameters bool paramsOnceRequested; ///< If the parameter list has been read at least once - QGCUASParamManager paramManager; ///< Parameter manager for this UAS + QGCUASParamManager paramMgr; ///< Parameter manager for this UAS /// SIMULATION QGCHilLink* simulation; ///< Hardware in the loop simulation link @@ -520,7 +520,7 @@ public: /** @brief Get reference to the param manager **/ virtual QGCUASParamManager* getParamManager() { - return ¶mManager; + return ¶mMgr; } /** @brief Get the HIL simulation */ diff --git a/src/uas/UASParameterCommsMgr.cc b/src/uas/UASParameterCommsMgr.cc index 96d7d19ec..a5ed632ca 100644 --- a/src/uas/UASParameterCommsMgr.cc +++ b/src/uas/UASParameterCommsMgr.cc @@ -7,9 +7,9 @@ #define RC_CAL_CHAN_MAX 8 -UASParameterCommsMgr::UASParameterCommsMgr(QObject *parent, UASInterface *uas) : +UASParameterCommsMgr::UASParameterCommsMgr(QObject *parent) : QObject(parent), - mav(uas), + mav(NULL), paramDataModel(NULL), transmissionListMode(false), transmissionActive(false), @@ -18,10 +18,16 @@ UASParameterCommsMgr::UASParameterCommsMgr(QObject *parent, UASInterface *uas) : rewriteTimeout(1000), retransmissionBurstRequestSize(5) { + + +} + +UASParameterCommsMgr* UASParameterCommsMgr::initWithUAS(UASInterface* uas) +{ + mav = uas; paramDataModel = mav->getParamManager()->dataModel(); loadParamCommsSettings(); - //Requesting parameters one-by-one from mav connect(this, SIGNAL(parameterUpdateRequestedById(int,int)), mav, SLOT(requestParameter(int,int))); @@ -34,10 +40,11 @@ UASParameterCommsMgr::UASParameterCommsMgr(QObject *parent, UASInterface *uas) : connect(mav, SIGNAL(parameterChanged(int,int,int,int,QString,QVariant)), this, SLOT(receivedParameterUpdate(int,int,int,int,QString,QVariant))); - //connecto retransmissionTimer + //connect to retransmissionTimer connect(&retransmissionTimer, SIGNAL(timeout()), this, SLOT(retransmissionGuardTick())); + return this; } diff --git a/src/uas/UASParameterCommsMgr.h b/src/uas/UASParameterCommsMgr.h index acdab75a8..1320d7187 100644 --- a/src/uas/UASParameterCommsMgr.h +++ b/src/uas/UASParameterCommsMgr.h @@ -18,7 +18,9 @@ class UASParameterCommsMgr : public QObject public: - explicit UASParameterCommsMgr(QObject *parent = 0, UASInterface* uas = NULL); + explicit UASParameterCommsMgr(QObject *parent = 0); + UASParameterCommsMgr* initWithUAS(UASInterface* model);///< Two-stage constructor + ~UASParameterCommsMgr(); typedef enum ParamCommsStatusLevel { diff --git a/src/ui/QGCParamWidget.cc b/src/ui/QGCParamWidget.cc index 97b0b94ad..f01e526de 100644 --- a/src/ui/QGCParamWidget.cc +++ b/src/ui/QGCParamWidget.cc @@ -100,29 +100,29 @@ void QGCParamWidget::layoutWidget() // BUTTONS QPushButton* refreshButton = new QPushButton(tr("Get")); - refreshButton->setToolTip(tr("Load parameters currently in non-permanent memory of aircraft.")); - refreshButton->setWhatsThis(tr("Load parameters currently in non-permanent memory of aircraft.")); + refreshButton->setToolTip(tr("Fetch parameters currently in volatile memory of aircraft.")); + refreshButton->setWhatsThis(tr("Fetch parameters currently in volatile memory of aircraft.")); connect(refreshButton, SIGNAL(clicked()), this, SLOT(requestOnboardParamsUpdate())); horizontalLayout->addWidget(refreshButton, 2, 0); QPushButton* setButton = new QPushButton(tr("Set")); - setButton->setToolTip(tr("Set current parameters in non-permanent onboard memory")); - setButton->setWhatsThis(tr("Set current parameters in non-permanent onboard memory")); + setButton->setToolTip(tr("Send pending parameters to volatile onboard memory")); + setButton->setWhatsThis(tr("Send pending parameters to volatile onboard memory")); connect(setButton, SIGNAL(clicked()), - this, SLOT(sendPendingParameters())); + paramMgr, SLOT(sendPendingParameters())); horizontalLayout->addWidget(setButton, 2, 1); QPushButton* writeButton = new QPushButton(tr("Write (ROM)")); - writeButton->setToolTip(tr("Copy current parameters in non-permanent memory of the aircraft to permanent memory. Transmit your parameters first to write these.")); - writeButton->setWhatsThis(tr("Copy current parameters in non-permanent memory of the aircraft to permanent memory. Transmit your parameters first to write these.")); + writeButton->setToolTip(tr("Copy parameters in volatile memory of the aircraft to persistent memory. Transmit your parameters first to write these.")); + writeButton->setWhatsThis(tr("Copy parameters in volatile memory of the aircraft to persistent memory. Transmit your parameters first to write these.")); connect(writeButton, SIGNAL(clicked()), paramMgr, SLOT(copyVolatileParamsToPersistent())); horizontalLayout->addWidget(writeButton, 2, 2); QPushButton* loadFileButton = new QPushButton(tr("Load File")); - loadFileButton->setToolTip(tr("Load parameters from a file on this computer in the view. To write them to the aircraft, use transmit after loading them.")); - loadFileButton->setWhatsThis(tr("Load parameters from a file on this computer in the view. To write them to the aircraft, use transmit after loading them.")); + loadFileButton->setToolTip(tr("Load parameters from a file into qgroundcontrol. To write these to the aircraft, use transmit after loading them.")); + loadFileButton->setWhatsThis(tr("Load parameters from a file into qgroundcontrol. To write these to the aircraft, use transmit after loading them.")); connect(loadFileButton, SIGNAL(clicked()), this, SLOT(loadParametersFromFile())); horizontalLayout->addWidget(loadFileButton, 3, 0); @@ -135,8 +135,8 @@ void QGCParamWidget::layoutWidget() horizontalLayout->addWidget(saveFileButton, 3, 1); QPushButton* readButton = new QPushButton(tr("Read (ROM)")); - readButton->setToolTip(tr("Copy parameters from permanent memory to non-permanent current memory of aircraft. DOES NOT update the parameters in this view, click refresh after copying them to get them.")); - readButton->setWhatsThis(tr("Copy parameters from permanent memory to non-permanent current memory of aircraft. DOES NOT update the parameters in this view, click refresh after copying them to get them.")); + readButton->setToolTip(tr("Copy parameters from persistent onboard memory to volatile onboard memory of aircraft. DOES NOT update the parameters in this view: click refresh after copying them to get them.")); + readButton->setWhatsThis(tr("Copy parameters from persistent onboard memory to volatile onboard memory of aircraft. DOES NOT update the parameters in this view: click refresh after copying them to get them.")); connect(readButton, SIGNAL(clicked()), paramMgr, SLOT(copyPersistentParamsToVolatile())); horizontalLayout->addWidget(readButton, 3, 2); diff --git a/src/ui/designer/QGCParamSlider.cc b/src/ui/designer/QGCParamSlider.cc index b6b0dd358..6331ac721 100644 --- a/src/ui/designer/QGCParamSlider.cc +++ b/src/ui/designer/QGCParamSlider.cc @@ -17,7 +17,7 @@ QGCParamSlider::QGCParamSlider(QWidget *parent) : parameterScalingFactor(0.0), parameterMin(0.0f), parameterMax(0.0f), - component(0), + componentId(0), ui(new Ui::QGCParamSlider) { valueModLock = false; @@ -133,7 +133,7 @@ void QGCParamSlider::setActiveUAS(UASInterface* activeUas) void QGCParamSlider::requestParameter() { if (uas && !parameterName.isEmpty()) { - uas->getParamManager()->requestParameterUpdate(component, parameterName); + uas->getParamManager()->requestParameterUpdate(componentId, parameterName); } } @@ -177,7 +177,7 @@ void QGCParamSlider::setParamValue(int value) void QGCParamSlider::selectComponent(int componentIndex) { - this->component = ui->editSelectComponentComboBox->itemData(componentIndex).toInt(); + this->componentId = ui->editSelectComponentComboBox->itemData(componentIndex).toInt(); } void QGCParamSlider::selectParameter(int paramIndex) @@ -280,7 +280,7 @@ void QGCParamSlider::endEditMode() void QGCParamSlider::setParamPending() { if (uas) { - uas->getParamManager()->setPendingParam(component, parameterName, parameterValue); + uas->getParamManager()->setPendingParam(componentId, parameterName, parameterValue); } else { qWarning() << __FILE__ << __LINE__ << "NO UAS SET, DOING NOTHING"; @@ -380,7 +380,7 @@ void QGCParamSlider::setParameterValue(int uasId, int compId, int paramCount, in } } Q_UNUSED(uas); - if (compId == this->component && paramName == this->parameterName) { + if (compId == this->componentId && paramName == this->parameterName) { if (!visibleEnabled) { return; } @@ -487,7 +487,7 @@ void QGCParamSlider::writeSettings(QSettings& settings) settings.setValue("QGC_PARAM_SLIDER_DESCRIPTION", ui->nameLabel->text()); //settings.setValue("QGC_PARAM_SLIDER_BUTTONTEXT", ui->actionButton->text()); settings.setValue("QGC_PARAM_SLIDER_PARAMID", parameterName); - settings.setValue("QGC_PARAM_SLIDER_COMPONENTID", component); + settings.setValue("QGC_PARAM_SLIDER_COMPONENTID", componentId); settings.setValue("QGC_PARAM_SLIDER_MIN", ui->editMinSpinBox->value()); settings.setValue("QGC_PARAM_SLIDER_MAX", ui->editMaxSpinBox->value()); settings.setValue("QGC_PARAM_SLIDER_DISPLAY_INFO", ui->editInfoCheckBox->isChecked()); @@ -496,7 +496,7 @@ void QGCParamSlider::writeSettings(QSettings& settings) void QGCParamSlider::readSettings(const QString& pre,const QVariantMap& settings) { parameterName = settings.value(pre + "QGC_PARAM_SLIDER_PARAMID").toString(); - component = settings.value(pre + "QGC_PARAM_SLIDER_COMPONENTID").toInt(); + componentId = settings.value(pre + "QGC_PARAM_SLIDER_COMPONENTID").toInt(); ui->nameLabel->setText(settings.value(pre + "QGC_PARAM_SLIDER_DESCRIPTION").toString()); ui->editNameLabel->setText(settings.value(pre + "QGC_PARAM_SLIDER_DESCRIPTION").toString()); //settings.setValue("QGC_PARAM_SLIDER_BUTTONTEXT", ui->actionButton->text()); @@ -516,9 +516,6 @@ void QGCParamSlider::readSettings(const QString& pre,const QVariantMap& settings ui->editSelectComponentComboBox->setEnabled(true); setActiveUAS(UASManager::instance()->getActiveUAS()); - - // Get param value after settings have been loaded - //requestParameter(); } void QGCParamSlider::readSettings(const QSettings& settings) @@ -532,7 +529,7 @@ void QGCParamSlider::readSettings(const QSettings& settings) readSettings("",map); return; parameterName = settings.value("QGC_PARAM_SLIDER_PARAMID").toString(); - component = settings.value("QGC_PARAM_SLIDER_COMPONENTID").toInt(); + componentId = settings.value("QGC_PARAM_SLIDER_COMPONENTID").toInt(); ui->nameLabel->setText(settings.value("QGC_PARAM_SLIDER_DESCRIPTION").toString()); ui->editNameLabel->setText(settings.value("QGC_PARAM_SLIDER_DESCRIPTION").toString()); //settings.setValue("QGC_PARAM_SLIDER_BUTTONTEXT", ui->actionButton->text()); @@ -552,6 +549,4 @@ void QGCParamSlider::readSettings(const QSettings& settings) setActiveUAS(UASManager::instance()->getActiveUAS()); - // Get param value after settings have been loaded - //requestParameter(); } diff --git a/src/ui/designer/QGCParamSlider.h b/src/ui/designer/QGCParamSlider.h index 3ef78fdf7..74df0db05 100644 --- a/src/ui/designer/QGCParamSlider.h +++ b/src/ui/designer/QGCParamSlider.h @@ -28,7 +28,7 @@ public slots: /** @brief Set the slider value as parameter value */ void setSliderValue(int sliderValue); /** @brief Update the UI with the new parameter value */ - void setParameterValue(int uas, int component, int paramCount, int paramIndex, QString parameterName, const QVariant value); + void setParameterValue(int uas, int componentId, int paramCount, int paramIndex, QString parameterName, const QVariant value); void writeSettings(QSettings& settings); void readSettings(const QSettings& settings); void readSettings(const QString& pre,const QVariantMap& settings); @@ -62,7 +62,7 @@ protected: double parameterScalingFactor; ///< Factor to scale the parameter between slider and true value float parameterMin; float parameterMax; - int component; ///< ID of the MAV component to address + int componentId; ///< ID of the MAV component to address double scaledInt; void changeEvent(QEvent *e); diff --git a/src/ui/designer/QGCTextLabel.h b/src/ui/designer/QGCTextLabel.h index 67ed0ae63..3828d734f 100644 --- a/src/ui/designer/QGCTextLabel.h +++ b/src/ui/designer/QGCTextLabel.h @@ -25,7 +25,7 @@ public slots: void writeSettings(QSettings& settings); void readSettings(const QSettings& settings); void readSettings(const QString& pre,const QVariantMap& settings); - void textMessageReceived(int uasid, int component, int severity, QString message); + void textMessageReceived(int uasid, int componentId, int severity, QString message); private: int enabledNum; Ui::QGCTextLabel *ui; diff --git a/src/ui/designer/QGCToolWidgetItem.h b/src/ui/designer/QGCToolWidgetItem.h index e0a0cb0a3..ac0912348 100644 --- a/src/ui/designer/QGCToolWidgetItem.h +++ b/src/ui/designer/QGCToolWidgetItem.h @@ -14,7 +14,7 @@ public: QGCToolWidgetItem(const QString& name, QWidget *parent = 0); ~QGCToolWidgetItem(); - int component() { + int componentId() { return _component; } -- 2.22.0