Commit 6872ff0b authored by Don Gagne's avatar Don Gagne

Fact type comes from mavlink parameter message

parent 04b5153b
...@@ -28,12 +28,13 @@ ...@@ -28,12 +28,13 @@
#include <QtQml> #include <QtQml>
Fact::Fact(QString name, QObject* parent) : Fact::Fact(QString name, FactMetaData::ValueType_t type, QObject* parent) :
QObject(parent), QObject(parent),
_name(name), _name(name),
_type(type),
_metaData(NULL) _metaData(NULL)
{ {
_value = ""; _value = 0;
} }
void Fact::setValue(const QVariant& value) void Fact::setValue(const QVariant& value)
...@@ -72,8 +73,7 @@ QVariant Fact::defaultValue(void) ...@@ -72,8 +73,7 @@ QVariant Fact::defaultValue(void)
FactMetaData::ValueType_t Fact::type(void) FactMetaData::ValueType_t Fact::type(void)
{ {
Q_ASSERT(_metaData); return _type;
return _metaData->type;
} }
QString Fact::shortDescription(void) QString Fact::shortDescription(void)
......
...@@ -57,7 +57,7 @@ class Fact : public QObject ...@@ -57,7 +57,7 @@ class Fact : public QObject
Q_ENUMS(FactMetaData::ValueType_t) Q_ENUMS(FactMetaData::ValueType_t)
public: public:
Fact(QString name = "", QObject* parent = NULL); Fact(QString name = "", FactMetaData::ValueType_t type = FactMetaData::valueTypeInt32, QObject* parent = NULL);
// Property system methods // Property system methods
...@@ -111,9 +111,10 @@ signals: ...@@ -111,9 +111,10 @@ signals:
void _containerValueChanged(QVariant& value); void _containerValueChanged(QVariant& value);
private: private:
QString _name; ///< Fact name QString _name;
QVariant _value; ///< Fact value QVariant _value;
FactMetaData* _metaData; ///< FactMetaData object for Fact FactMetaData::ValueType_t _type;
FactMetaData* _metaData;
}; };
#endif #endif
\ No newline at end of file
...@@ -51,9 +51,8 @@ FactLoader::FactLoader(UASInterface* uas, QObject* parent) : ...@@ -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 // We need to know when the param mgr is done sending the initial set of paramters
connect(_paramMgr, SIGNAL(parameterListUpToDate()), this, SLOT(_paramMgrParameterListUpToDate())); 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 // We track parameters changes to keep Facts up to date.
// use SIGNAL/SLOT style connect connect(uas, &UASInterface::parameterUpdate, this, &FactLoader::_parameterUpdate);
connect(uas, SIGNAL(parameterChanged(int, int, QString, QVariant)), this, SLOT(_parameterChanged(int, int, QString, QVariant)));
} }
FactLoader::~FactLoader() FactLoader::~FactLoader()
...@@ -65,10 +64,8 @@ FactLoader::~FactLoader() ...@@ -65,10 +64,8 @@ FactLoader::~FactLoader()
_mapFact2ParameterName.clear(); _mapFact2ParameterName.clear();
} }
/// Connected to QGCUASParmManager::parameterChanged /// Called whenever a parameter is updated or first seen.
/// void FactLoader::_parameterUpdate(int uas, int component, QString parameterName, int mavType, QVariant value)
/// 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)
{ {
// Is this for our uas? // Is this for our uas?
if (uas != _uasId) { if (uas != _uasId) {
...@@ -86,7 +83,39 @@ void FactLoader::_parameterChanged(int uas, int component, QString parameterName ...@@ -86,7 +83,39 @@ void FactLoader::_parameterChanged(int uas, int component, QString parameterName
if (!_mapParameterName2Variant.contains(parameterName)) { if (!_mapParameterName2Variant.contains(parameterName)) {
qCDebug(FactLoaderLog) << "Adding new fact" << 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; setMetaData = true;
_mapParameterName2Variant[parameterName] = QVariant::fromValue(fact); _mapParameterName2Variant[parameterName] = QVariant::fromValue(fact);
...@@ -169,39 +198,6 @@ void FactLoader::_paramMgrParameterListUpToDate(void) ...@@ -169,39 +198,6 @@ void FactLoader::_paramMgrParameterListUpToDate(void)
void FactLoader::_addMetaDataToFact(Fact* fact) 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); FactMetaData* metaData = new FactMetaData(this);
metaData->initFromTypeOnly(factType); metaData->initFromTypeOnly(fact->type());
} }
...@@ -72,7 +72,7 @@ protected: ...@@ -72,7 +72,7 @@ protected:
virtual void _addMetaDataToFact(Fact* fact); virtual void _addMetaDataToFact(Fact* fact);
private slots: 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 _valueUpdated(QVariant value);
void _paramMgrParameterListUpToDate(void); void _paramMgrParameterListUpToDate(void);
......
...@@ -37,6 +37,4 @@ FactMetaData::FactMetaData(QObject* parent) : ...@@ -37,6 +37,4 @@ FactMetaData::FactMetaData(QObject* parent) :
void FactMetaData::initFromTypeOnly(ValueType_t initType) void FactMetaData::initFromTypeOnly(ValueType_t initType)
{ {
type = initType; type = initType;
// FIXME: NYI
} }
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