From 6256bc21e220622a16002bd3866f2892e90256a3 Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Tue, 4 Aug 2020 12:20:46 -0700 Subject: [PATCH] Support null for FactMetaData default --- src/FactSystem/FactMetaData.cc | 41 ++--- src/Vehicle/EstimatorStatusFactGroup.json | 180 +++++++++++----------- 2 files changed, 113 insertions(+), 108 deletions(-) diff --git a/src/FactSystem/FactMetaData.cc b/src/FactSystem/FactMetaData.cc index 92c05b17c..a9ed0ce19 100644 --- a/src/FactSystem/FactMetaData.cc +++ b/src/FactSystem/FactMetaData.cc @@ -321,9 +321,9 @@ bool FactMetaData::isInRawMinLimit(const QVariant& variantValue) const case valueTypeInt64: return _rawMin.value() <= variantValue.value(); case valueTypeFloat: - return _rawMin.value() <= variantValue.value(); + return qIsNaN(variantValue.toFloat()) || _rawMin.value() <= variantValue.value(); case valueTypeDouble: - return _rawMin.value() <= variantValue.value(); + return qIsNaN(variantValue.toDouble()) || _rawMin.value() <= variantValue.value(); default: return true; } @@ -351,9 +351,9 @@ bool FactMetaData::isInRawMaxLimit(const QVariant& variantValue) const case valueTypeInt64: return _rawMax.value() >= variantValue.value(); case valueTypeFloat: - return _rawMax.value() >= variantValue.value(); + return qIsNaN(variantValue.toFloat()) || _rawMax.value() >= variantValue.value(); case valueTypeDouble: - return _rawMax.value() >= variantValue.value(); + return qIsNaN(variantValue.toDouble()) || _rawMax.value() >= variantValue.value(); default: return true; } @@ -1294,26 +1294,31 @@ FactMetaData* FactMetaData::createFromJsonObject(const QJsonObject& json, QMapsetRawUnits(json[_unitsJsonKey].toString()); } - QString defaultValueJsonKey; + QString defaultValueJsonKey = _defaultValueJsonKey; #ifdef __mobile__ if (json.contains(_mobileDefaultValueJsonKey)) { defaultValueJsonKey = _mobileDefaultValueJsonKey; } #endif - if (defaultValueJsonKey.isEmpty() && json.contains(_defaultValueJsonKey)) { - defaultValueJsonKey = _defaultValueJsonKey; - } - if (!defaultValueJsonKey.isEmpty()) { - QVariant typedValue; - QString errorString; - QVariant initialValue = json[defaultValueJsonKey].toVariant(); - if (metaData->convertAndValidateRaw(initialValue, true /* convertOnly */, typedValue, errorString)) { - metaData->setRawDefaultValue(typedValue); + + if (json.contains(defaultValueJsonKey)) { + const QJsonValue jsonValue = json[defaultValueJsonKey]; + + if (jsonValue.type() == QJsonValue::Null && (type == valueTypeFloat || type == valueTypeDouble)) { + metaData->setRawDefaultValue(type == valueTypeFloat ? std::numeric_limits::quiet_NaN() : std::numeric_limits::quiet_NaN()); } else { - qWarning() << "Invalid default value, name:" << metaData->name() - << " type:" << metaData->type() - << " value:" << initialValue - << " error:" << errorString; + QVariant typedValue; + QString errorString; + QVariant initialValue = jsonValue.toVariant(); + + if (metaData->convertAndValidateRaw(initialValue, true /* convertOnly */, typedValue, errorString)) { + metaData->setRawDefaultValue(typedValue); + } else { + qWarning() << "Invalid default value, name:" << metaData->name() + << " type:" << metaData->type() + << " value:" << initialValue + << " error:" << errorString; + } } } diff --git a/src/Vehicle/EstimatorStatusFactGroup.json b/src/Vehicle/EstimatorStatusFactGroup.json index 9aa55165e..f04cc4150 100644 --- a/src/Vehicle/EstimatorStatusFactGroup.json +++ b/src/Vehicle/EstimatorStatusFactGroup.json @@ -1,135 +1,135 @@ { - "version": 1, - "fileType": "FactMetaData", + "version": 1, + "fileType": "FactMetaData", "QGC.MetaData.Facts": [ { - "name": "goodAttitudeEsimate", - "shortDesc": "Good Attitude Esimate", - "type": "bool", - "default": false + "name": "goodAttitudeEsimate", + "shortDesc": "Good Attitude Esimate", + "type": "bool", + "default": false }, { - "name": "goodHorizVelEstimate", - "shortDesc": "Good Horiz Vel Estimate", - "type": "bool", - "default": false + "name": "goodHorizVelEstimate", + "shortDesc": "Good Horiz Vel Estimate", + "type": "bool", + "default": false }, { - "name": "goodVertVelEstimate", - "shortDesc": "Good Vert Vel Estimate", - "type": "bool", - "default": false + "name": "goodVertVelEstimate", + "shortDesc": "Good Vert Vel Estimate", + "type": "bool", + "default": false }, { - "name": "goodHorizPosRelEstimate", - "shortDesc": "Good Horiz Pos Rel Estimate", - "type": "bool", - "default": false + "name": "goodHorizPosRelEstimate", + "shortDesc": "Good Horiz Pos Rel Estimate", + "type": "bool", + "default": false }, { - "name": "goodHorizPosAbsEstimate", - "shortDesc": "Good Horiz Pos Abs Estimate", - "type": "bool", - "default": false + "name": "goodHorizPosAbsEstimate", + "shortDesc": "Good Horiz Pos Abs Estimate", + "type": "bool", + "default": false }, { - "name": "goodVertPosAbsEstimate", - "shortDesc": "Good Vert Pos Abs Estimate", - "type": "bool", - "default": false + "name": "goodVertPosAbsEstimate", + "shortDesc": "Good Vert Pos Abs Estimate", + "type": "bool", + "default": false }, { - "name": "goodVertPosAGLEstimate", - "shortDesc": "Good Vert Pos AGL Estimate", - "type": "bool", - "default": false + "name": "goodVertPosAGLEstimate", + "shortDesc": "Good Vert Pos AGL Estimate", + "type": "bool", + "default": false }, { - "name": "goodConstPosModeEstimate", - "shortDesc": "Good Const Pos Mode Estimate", - "type": "bool", - "default": false + "name": "goodConstPosModeEstimate", + "shortDesc": "Good Const Pos Mode Estimate", + "type": "bool", + "default": false }, { - "name": "goodPredHorizPosRelEstimate", - "shortDesc": "Good Pred Horiz Pos Rel Estimate", - "type": "bool", - "default": false + "name": "goodPredHorizPosRelEstimate", + "shortDesc": "Good Pred Horiz Pos Rel Estimate", + "type": "bool", + "default": false }, { - "name": "goodPredHorizPosAbsEstimate", - "shortDesc": "Good Pred Horiz Pos Abs Estimate", - "type": "bool", - "default": false + "name": "goodPredHorizPosAbsEstimate", + "shortDesc": "Good Pred Horiz Pos Abs Estimate", + "type": "bool", + "default": false }, { - "name": "gpsGlitch", - "shortDesc": "Gps Glitch", - "type": "bool", - "default": false + "name": "gpsGlitch", + "shortDesc": "Gps Glitch", + "type": "bool", + "default": false }, { - "name": "accelError", - "shortDesc": "Accel Error", - "type": "bool", - "default": false + "name": "accelError", + "shortDesc": "Accel Error", + "type": "bool", + "default": false }, { - "name": "velRatio", - "shortDesc": "Vel Ratio", - "type": "float", - "decimalPlaces": 2, - "default": null + "name": "velRatio", + "shortDesc": "Vel Ratio", + "type": "float", + "decimalPlaces": 2, + "default": null }, { - "name": "horizPosRatio", - "shortDesc": "Horiz Pos Ratio", - "type": "float", - "decimalPlaces": 2, - "default": null + "name": "horizPosRatio", + "shortDesc": "Horiz Pos Ratio", + "type": "float", + "decimalPlaces": 2, + "default": null }, { - "name": "vertPosRatio", - "shortDesc": "Vert Pos Ratio", - "type": "float", - "decimalPlaces": 2, - "default": null + "name": "vertPosRatio", + "shortDesc": "Vert Pos Ratio", + "type": "float", + "decimalPlaces": 2, + "default": null }, { - "name": "magRatio", - "shortDesc": "Mag Ratio", - "type": "float", - "decimalPlaces": 2, - "default": null + "name": "magRatio", + "shortDesc": "Mag Ratio", + "type": "float", + "decimalPlaces": 2, + "default": null }, { - "name": "haglRatio", - "shortDesc": "HAGL Ratio", - "type": "float", - "decimalPlaces": 2, - "default": null + "name": "haglRatio", + "shortDesc": "HAGL Ratio", + "type": "float", + "decimalPlaces": 2, + "default": null }, { - "name": "tasRatio", - "shortDesc": "TAS Ratio", - "type": "float", - "decimalPlaces": 2, - "default": null + "name": "tasRatio", + "shortDesc": "TAS Ratio", + "type": "float", + "decimalPlaces": 2, + "default": null }, { - "name": "horizPosAccuracy", - "shortDesc": "Horiz Pos Accuracy", - "type": "float", - "decimalPlaces": 2, - "default": null + "name": "horizPosAccuracy", + "shortDesc": "Horiz Pos Accuracy", + "type": "float", + "decimalPlaces": 2, + "default": null }, { - "name": "vertPosAccuracy", - "shortDesc": "Vert Pos Accuracy", - "type": "float", - "decimalPlaces": 2, - "default": null + "name": "vertPosAccuracy", + "shortDesc": "Vert Pos Accuracy", + "type": "float", + "decimalPlaces": 2, + "default": null } ] } -- 2.22.0