From 6872ff0ba84065397fb1512f34cbba9a3d90eb7d Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Fri, 27 Feb 2015 18:41:03 -0800 Subject: [PATCH] Fact type comes from mavlink parameter message --- src/FactSystem/Fact.cc | 8 ++-- src/FactSystem/Fact.h | 9 ++-- src/FactSystem/FactLoader.cc | 80 ++++++++++++++++------------------ src/FactSystem/FactLoader.h | 2 +- src/FactSystem/FactMetaData.cc | 2 - 5 files changed, 48 insertions(+), 53 deletions(-) diff --git a/src/FactSystem/Fact.cc b/src/FactSystem/Fact.cc index b4de94768..860fd1c5e 100644 --- a/src/FactSystem/Fact.cc +++ b/src/FactSystem/Fact.cc @@ -28,12 +28,13 @@ #include -Fact::Fact(QString name, QObject* parent) : +Fact::Fact(QString name, FactMetaData::ValueType_t type, QObject* parent) : QObject(parent), _name(name), + _type(type), _metaData(NULL) { - _value = ""; + _value = 0; } void Fact::setValue(const QVariant& value) @@ -72,8 +73,7 @@ QVariant Fact::defaultValue(void) FactMetaData::ValueType_t Fact::type(void) { - Q_ASSERT(_metaData); - return _metaData->type; + return _type; } QString Fact::shortDescription(void) diff --git a/src/FactSystem/Fact.h b/src/FactSystem/Fact.h index 7d601a639..7d1f6943b 100644 --- a/src/FactSystem/Fact.h +++ b/src/FactSystem/Fact.h @@ -57,7 +57,7 @@ class Fact : public QObject Q_ENUMS(FactMetaData::ValueType_t) public: - Fact(QString name = "", QObject* parent = NULL); + Fact(QString name = "", FactMetaData::ValueType_t type = FactMetaData::valueTypeInt32, QObject* parent = NULL); // Property system methods @@ -111,9 +111,10 @@ signals: void _containerValueChanged(QVariant& value); private: - QString _name; ///< Fact name - QVariant _value; ///< Fact value - FactMetaData* _metaData; ///< FactMetaData object for Fact + QString _name; + QVariant _value; + FactMetaData::ValueType_t _type; + FactMetaData* _metaData; }; #endif \ No newline at end of file diff --git a/src/FactSystem/FactLoader.cc b/src/FactSystem/FactLoader.cc index f13156b30..903fb44a9 100644 --- a/src/FactSystem/FactLoader.cc +++ b/src/FactSystem/FactLoader.cc @@ -51,9 +51,8 @@ FactLoader::FactLoader(UASInterface* uas, QObject* parent) : // We need to know when the param mgr is done sending the initial set of paramters connect(_paramMgr, SIGNAL(parameterListUpToDate()), this, SLOT(_paramMgrParameterListUpToDate())); - // We track parameters changes to keep Facts up to date. UASInterface::parameterChanged has multiple overrides so we need to - // use SIGNAL/SLOT style connect - connect(uas, SIGNAL(parameterChanged(int, int, QString, QVariant)), this, SLOT(_parameterChanged(int, int, QString, QVariant))); + // We track parameters changes to keep Facts up to date. + connect(uas, &UASInterface::parameterUpdate, this, &FactLoader::_parameterUpdate); } FactLoader::~FactLoader() @@ -65,10 +64,8 @@ FactLoader::~FactLoader() _mapFact2ParameterName.clear(); } -/// Connected to QGCUASParmManager::parameterChanged -/// -/// When a new parameter is seen it is added to the system. If the parameter is already known it is updated. -void FactLoader::_parameterChanged(int uas, int component, QString parameterName, QVariant value) +/// Called whenever a parameter is updated or first seen. +void FactLoader::_parameterUpdate(int uas, int component, QString parameterName, int mavType, QVariant value) { // Is this for our uas? if (uas != _uasId) { @@ -86,7 +83,39 @@ void FactLoader::_parameterChanged(int uas, int component, QString parameterName if (!_mapParameterName2Variant.contains(parameterName)) { qCDebug(FactLoaderLog) << "Adding new fact" << parameterName; - Fact* fact = new Fact(parameterName, this); + FactMetaData::ValueType_t factType; + switch (mavType) { + case MAV_PARAM_TYPE_UINT8: + factType = FactMetaData::valueTypeUint8; + break; + case MAV_PARAM_TYPE_INT8: + factType = FactMetaData::valueTypeUint8; + break; + case MAV_PARAM_TYPE_UINT16: + factType = FactMetaData::valueTypeUint16; + break; + case MAV_PARAM_TYPE_INT16: + factType = FactMetaData::valueTypeInt16; + break; + case MAV_PARAM_TYPE_UINT32: + factType = FactMetaData::valueTypeUint32; + break; + case MAV_PARAM_TYPE_INT32: + factType = FactMetaData::valueTypeInt32; + break; + case MAV_PARAM_TYPE_REAL32: + factType = FactMetaData::valueTypeFloat; + break; + case MAV_PARAM_TYPE_REAL64: + factType = FactMetaData::valueTypeDouble; + break; + default: + factType = FactMetaData::valueTypeInt32; + qCritical() << "Unsupported fact type" << mavType; + break; + } + + Fact* fact = new Fact(parameterName, factType, this); setMetaData = true; _mapParameterName2Variant[parameterName] = QVariant::fromValue(fact); @@ -169,39 +198,6 @@ void FactLoader::_paramMgrParameterListUpToDate(void) void FactLoader::_addMetaDataToFact(Fact* fact) { - // Create generic meta data based on value variant type - - FactMetaData::ValueType_t factType = FactMetaData::valueTypeInt32; // init to in32 to silence compiler warning - - switch ((QMetaType::Type)fact->value().type()) { - case QMetaType::Int: - factType = FactMetaData::valueTypeInt32; - break; - - case QMetaType::UInt: - factType = FactMetaData::valueTypeUint32; - break; - - case QMetaType::Double: - factType = FactMetaData::valueTypeDouble; - - case QMetaType::Short: - factType = FactMetaData::valueTypeInt16; - break; - - case QMetaType::UShort: - factType = FactMetaData::valueTypeUint16; - break; - - case QMetaType::Float: - factType = FactMetaData::valueTypeFloat; - break; - - default: - qWarning() << fact->name() << "Invalid variant type" << fact->value().type(); - break; - } - FactMetaData* metaData = new FactMetaData(this); - metaData->initFromTypeOnly(factType); + metaData->initFromTypeOnly(fact->type()); } diff --git a/src/FactSystem/FactLoader.h b/src/FactSystem/FactLoader.h index 699a1fbe0..851035a91 100644 --- a/src/FactSystem/FactLoader.h +++ b/src/FactSystem/FactLoader.h @@ -72,7 +72,7 @@ protected: virtual void _addMetaDataToFact(Fact* fact); private slots: - void _parameterChanged(int uas, int component, QString parameterName, QVariant value); + void _parameterUpdate(int uas, int component, QString parameterName, int mavType, QVariant value); void _valueUpdated(QVariant value); void _paramMgrParameterListUpToDate(void); diff --git a/src/FactSystem/FactMetaData.cc b/src/FactSystem/FactMetaData.cc index 1b4de8954..5de76f6a6 100644 --- a/src/FactSystem/FactMetaData.cc +++ b/src/FactSystem/FactMetaData.cc @@ -37,6 +37,4 @@ FactMetaData::FactMetaData(QObject* parent) : void FactMetaData::initFromTypeOnly(ValueType_t initType) { type = initType; - - // FIXME: NYI } -- 2.22.0