From a87e00e13654c1b3bcfd367142e69cfa29ca1a5f Mon Sep 17 00:00:00 2001 From: tstellanova Date: Thu, 22 Aug 2013 14:56:01 -0700 Subject: [PATCH] use a real component ID when we know what it is --- src/uas/QGCUASParamManager.cc | 33 ++++++++++++++++++++++++++++++++- src/uas/QGCUASParamManager.h | 4 ++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/uas/QGCUASParamManager.cc b/src/uas/QGCUASParamManager.cc index 788a227c2..1a967e79d 100644 --- a/src/uas/QGCUASParamManager.cc +++ b/src/uas/QGCUASParamManager.cc @@ -11,7 +11,8 @@ QGCUASParamManager::QGCUASParamManager(QObject *parent) : QObject(parent), mav(NULL), paramDataModel(this), - paramCommsMgr(NULL) + paramCommsMgr(NULL), + defaultComponentId(-1) { @@ -57,6 +58,27 @@ void QGCUASParamManager::clearAllPendingParams() paramDataModel.clearAllPendingParams(); } + +int QGCUASParamManager::getDefaultComponentId() +{ + int result = 0; + + if (-1 != defaultComponentId) + return defaultComponentId; + + QList components = getComponentForParam("SYS_AUTOSTART");//TODO is this the best way to find the right component? + + // Guard against multiple components responding - this will never show in practice + if (1 == components.count()) { + result = components.first(); + defaultComponentId = result; + } + + qDebug() << "Default compId: " << result; + + return result; +} + QList QGCUASParamManager::getComponentForParam(const QString& parameter) const { return paramDataModel.getComponentForOnboardParam(parameter); @@ -95,6 +117,7 @@ void QGCUASParamManager::requestParameterListIfEmpty() if (mav) { int totalOnboard = paramDataModel.countOnboardParams(); if (totalOnboard < 2) { //TODO arbitrary constant, maybe 0 is OK? + defaultComponentId = -1; //reset this ...we have no idea what the default component ID is requestParameterList(); } } @@ -108,6 +131,10 @@ void QGCUASParamManager::setParamDescriptions(const QMap& param void QGCUASParamManager::setParameter(int compId, QString paramName, QVariant value) { + if ((0 == compId) || (-1 == compId)) { + //attempt to get an actual component ID + compId = getDefaultComponentId(); + } paramDataModel.updatePendingParamWithValue(compId,paramName,value); } @@ -121,6 +148,10 @@ void QGCUASParamManager::sendPendingParameters(bool persistAfterSend) void QGCUASParamManager::setPendingParam(int compId, const QString& paramName, const QVariant& value) { + if ((0 == compId) || (-1 == compId)) { + //attempt to get an actual component ID + compId = getDefaultComponentId(); + } paramDataModel.updatePendingParamWithValue(compId,paramName,value); } diff --git a/src/uas/QGCUASParamManager.h b/src/uas/QGCUASParamManager.h index 6866b2b95..2c31136e2 100644 --- a/src/uas/QGCUASParamManager.h +++ b/src/uas/QGCUASParamManager.h @@ -23,6 +23,9 @@ public: /** @brief Get the known, confirmed value of a parameter */ virtual bool getParameterValue(int component, const QString& parameter, QVariant& value) const; + /** @brief determine which component is the root component for the UAS and return its ID or 0 if unknown */ + virtual int getDefaultComponentId(); + /** * @brief Get a list of all component IDs using this parameter name * @param parameter The string encoding the parameter name @@ -122,6 +125,7 @@ protected: UASInterface* mav; ///< The MAV this manager is controlling UASParameterDataModel paramDataModel;///< Shared data model of parameters UASParameterCommsMgr* paramCommsMgr; ///< Shared comms mgr for parameters + int defaultComponentId; ///< Cached default component ID }; -- 2.22.0