Commit a87e00e1 authored by tstellanova's avatar tstellanova

use a real component ID when we know what it is

parent a6fcb120
...@@ -11,7 +11,8 @@ QGCUASParamManager::QGCUASParamManager(QObject *parent) : ...@@ -11,7 +11,8 @@ QGCUASParamManager::QGCUASParamManager(QObject *parent) :
QObject(parent), QObject(parent),
mav(NULL), mav(NULL),
paramDataModel(this), paramDataModel(this),
paramCommsMgr(NULL) paramCommsMgr(NULL),
defaultComponentId(-1)
{ {
...@@ -57,6 +58,27 @@ void QGCUASParamManager::clearAllPendingParams() ...@@ -57,6 +58,27 @@ void QGCUASParamManager::clearAllPendingParams()
paramDataModel.clearAllPendingParams(); paramDataModel.clearAllPendingParams();
} }
int QGCUASParamManager::getDefaultComponentId()
{
int result = 0;
if (-1 != defaultComponentId)
return defaultComponentId;
QList<int> 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<int> QGCUASParamManager::getComponentForParam(const QString& parameter) const QList<int> QGCUASParamManager::getComponentForParam(const QString& parameter) const
{ {
return paramDataModel.getComponentForOnboardParam(parameter); return paramDataModel.getComponentForOnboardParam(parameter);
...@@ -95,6 +117,7 @@ void QGCUASParamManager::requestParameterListIfEmpty() ...@@ -95,6 +117,7 @@ void QGCUASParamManager::requestParameterListIfEmpty()
if (mav) { if (mav) {
int totalOnboard = paramDataModel.countOnboardParams(); int totalOnboard = paramDataModel.countOnboardParams();
if (totalOnboard < 2) { //TODO arbitrary constant, maybe 0 is OK? 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(); requestParameterList();
} }
} }
...@@ -108,6 +131,10 @@ void QGCUASParamManager::setParamDescriptions(const QMap<QString,QString>& param ...@@ -108,6 +131,10 @@ void QGCUASParamManager::setParamDescriptions(const QMap<QString,QString>& param
void QGCUASParamManager::setParameter(int compId, QString paramName, QVariant value) 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); paramDataModel.updatePendingParamWithValue(compId,paramName,value);
} }
...@@ -121,6 +148,10 @@ void QGCUASParamManager::sendPendingParameters(bool persistAfterSend) ...@@ -121,6 +148,10 @@ void QGCUASParamManager::sendPendingParameters(bool persistAfterSend)
void QGCUASParamManager::setPendingParam(int compId, const QString& paramName, const QVariant& value) 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); paramDataModel.updatePendingParamWithValue(compId,paramName,value);
} }
......
...@@ -23,6 +23,9 @@ public: ...@@ -23,6 +23,9 @@ public:
/** @brief Get the known, confirmed value of a parameter */ /** @brief Get the known, confirmed value of a parameter */
virtual bool getParameterValue(int component, const QString& parameter, QVariant& value) const; 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 * @brief Get a list of all component IDs using this parameter name
* @param parameter The string encoding the parameter name * @param parameter The string encoding the parameter name
...@@ -122,6 +125,7 @@ protected: ...@@ -122,6 +125,7 @@ protected:
UASInterface* mav; ///< The MAV this manager is controlling UASInterface* mav; ///< The MAV this manager is controlling
UASParameterDataModel paramDataModel;///< Shared data model of parameters UASParameterDataModel paramDataModel;///< Shared data model of parameters
UASParameterCommsMgr* paramCommsMgr; ///< Shared comms mgr for parameters UASParameterCommsMgr* paramCommsMgr; ///< Shared comms mgr for parameters
int defaultComponentId; ///< Cached default component ID
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment