diff --git a/src/uas/QGCUASParamManager.cc b/src/uas/QGCUASParamManager.cc index 788a227c291c33d3a0ecfb03e32f39f173bbc807..1a967e79d3ba239c8fa8cbbbe9521b377043e19a 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 6866b2b9514016c03ed501ca77b7e101eeb00c3a..2c31136e26b69b6bf6af7ba11ceb739c7fa09a55 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 };