Commit 89285b12 authored by DonLakeFlyer's avatar DonLakeFlyer

parent 4450945e
......@@ -683,6 +683,9 @@ HEADERS += \
src/SHPFileHelper.h \
src/Terrain/TerrainQuery.h \
src/TerrainTile.h \
src/Vehicle/CompInfo.h \
src/Vehicle/CompInfoParam.h \
src/Vehicle/CompInfoVersion.h \
src/Vehicle/ComponentInformationManager.h \
src/Vehicle/FTPManager.h \
src/Vehicle/GPSRTKFactGroup.h \
......@@ -899,6 +902,9 @@ SOURCES += \
src/SHPFileHelper.cc \
src/Terrain/TerrainQuery.cc \
src/TerrainTile.cc\
src/Vehicle/CompInfo.cc \
src/Vehicle/CompInfoParam.cc \
src/Vehicle/CompInfoVersion.cc \
src/Vehicle/ComponentInformationManager.cc \
src/Vehicle/FTPManager.cc \
src/Vehicle/GPSRTKFactGroup.cc \
......
......@@ -131,6 +131,9 @@ const char* FactMetaData::_maxJsonKey = "max";
const char* FactMetaData::_incrementJsonKey = "increment";
const char* FactMetaData::_hasControlJsonKey = "control";
const char* FactMetaData::_qgcRebootRequiredJsonKey = "qgcRebootRequired";
const char* FactMetaData::_categoryJsonKey = "category";
const char* FactMetaData::_groupJsonKey = "group";
const char* FactMetaData::_volatileJsonKey = "volatile";
FactMetaData::FactMetaData(QObject* parent)
: QObject (parent)
......@@ -1233,14 +1236,6 @@ FactMetaData* FactMetaData::createFromJsonObject(const QJsonObject& json, QMap<Q
{
QString errorString;
// Make sure we have the required keys
QStringList requiredKeys;
requiredKeys << _nameJsonKey << _typeJsonKey;
if (!JsonHelper::validateRequiredKeys(json, requiredKeys, errorString)) {
qWarning() << errorString;
return new FactMetaData(valueTypeUint32, metaDataParent);
}
QList<JsonHelper::KeyValidateInfo> keyInfoList = {
{ _nameJsonKey, QJsonValue::String, true },
{ _typeJsonKey, QJsonValue::String, true },
......@@ -1252,6 +1247,9 @@ FactMetaData* FactMetaData::createFromJsonObject(const QJsonObject& json, QMap<Q
{ _maxJsonKey, QJsonValue::Double, false },
{ _hasControlJsonKey, QJsonValue::Bool, false },
{ _qgcRebootRequiredJsonKey, QJsonValue::Bool, false },
{ _categoryJsonKey, QJsonValue::String, false },
{ _groupJsonKey, QJsonValue::String, false },
{ _volatileJsonKey, QJsonValue::Bool, false },
};
if (!JsonHelper::validateKeys(json, keyInfoList, errorString)) {
qWarning() << errorString;
......@@ -1361,16 +1359,30 @@ FactMetaData* FactMetaData::createFromJsonObject(const QJsonObject& json, QMap<Q
}
}
bool hasControlJsonKey = true;
if (json.contains(_hasControlJsonKey)) {
metaData->setHasControl(json[_hasControlJsonKey].toBool());
} else {
metaData->setHasControl(true);
hasControlJsonKey = json[_hasControlJsonKey].toBool();
}
metaData->setHasControl(hasControlJsonKey);
bool qgcRebootRequired = false;
if (json.contains(_qgcRebootRequiredJsonKey)) {
metaData->setQGCRebootRequired(json[_qgcRebootRequiredJsonKey].toBool());
} else {
metaData->setQGCRebootRequired(false);
qgcRebootRequired = json[_qgcRebootRequiredJsonKey].toBool();
}
metaData->setQGCRebootRequired(qgcRebootRequired);
bool volatileValue = false;
if (json.contains(_volatileJsonKey)) {
volatileValue = json[_volatileJsonKey].toBool();
}
metaData->setVolatileValue(volatileValue);
if (json.contains(_groupJsonKey)) {
metaData->setGroup(json[_groupJsonKey].toString());
}
if (json.contains(_categoryJsonKey)) {
metaData->setCategory(json[_categoryJsonKey].toString());
}
return metaData;
......
......@@ -47,6 +47,8 @@ public:
// @return Error string for failed validation explanation to user. Empty string indicates no error.
typedef QString (*CustomCookedValidator)(const QVariant& cookedValue);
typedef QMap<QString /* param Name */, FactMetaData*> NameToMetaDataMap_t;
FactMetaData(QObject* parent = nullptr);
FactMetaData(ValueType_t type, QObject* parent = nullptr);
FactMetaData(ValueType_t type, const QString name, QObject* parent = nullptr);
......@@ -359,6 +361,9 @@ private:
static const char* _incrementJsonKey;
static const char* _hasControlJsonKey;
static const char* _qgcRebootRequiredJsonKey;
static const char* _categoryJsonKey;
static const char* _groupJsonKey;
static const char* _volatileJsonKey;
static const char* _jsonMetaDataDefinesName;
static const char* _jsonMetaDataFactsName;
......
This diff is collapsed.
......@@ -33,8 +33,7 @@ class ParameterManager : public QObject
public:
/// @param uas Uas which this set of facts is associated with
ParameterManager (Vehicle* vehicle);
~ParameterManager ();
ParameterManager(Vehicle* vehicle);
Q_PROPERTY(bool parametersReady READ parametersReady NOTIFY parametersReadyChanged) ///< true: Parameters are ready for use
Q_PROPERTY(bool missingParameters READ missingParameters NOTIFY missingParametersChanged) ///< true: Parameters are missing from firmware response, false: all parameters received from firmware
......@@ -91,29 +90,6 @@ public:
/// Returns the version number for the parameter set, -1 if not known
int parameterSetVersion(void) { return _parameterSetMajorVersion; }
/// Returns the newest available parameter meta data file (from cache or internal) for the specified information.
/// @param wantedMajorVersion Major version you are looking for
/// @param[out] majorVersion Major version for found meta data
/// @param[out] minorVersion Minor version for found meta data
/// @return Meta data file name of best match, emptyString is none found
static QString parameterMetaDataFile(Vehicle* vehicle, MAV_AUTOPILOT firmwareType, int wantedMajorVersion, int& majorVersion, int& minorVersion);
/// If this file is newer than anything in the cache, cache it as the latest version
static void cacheMetaDataFile(const QString& metaDataFile, MAV_AUTOPILOT firmwareType);
/// Saves the specified param set to the json object.
/// @param componentId Component id which contains params, MAV_COMP_ID_ALL to save all components
/// @param paramsToSave List of params names to save, empty to save all for component
/// @param saveObject Json object to save to
void saveToJson(int componentId, const QStringList& paramsToSave, QJsonObject& saveObject);
/// Load a parameter set from json
/// @param json Json object to load from
/// @param required true: no parameters in object will generate error
/// @param errorString Error string if return is false
/// @return true: success, false: failure (errorString set)
bool loadFromJson(const QJsonObject& json, bool required, QString& errorString);
bool pendingWrites(void);
Vehicle* vehicle(void) { return _vehicle; }
......@@ -128,32 +104,31 @@ protected:
Vehicle* _vehicle;
MAVLinkProtocol* _mavlink;
void _parameterUpdate(int vehicleId, int componentId, QString parameterName, int parameterCount, int parameterId, int mavType, QVariant value);
void _valueUpdated(const QVariant& value);
void _waitingParamTimeout(void);
void _tryCacheLookup(void);
void _initialRequestTimeout(void);
void _parameterUpdate (int vehicleId, int componentId, QString parameterName, int parameterCount, int parameterId, int mavType, QVariant value);
void _valueUpdated (const QVariant& value);
void _waitingParamTimeout (void);
void _tryCacheLookup (void);
void _initialRequestTimeout (void);
private:
static QVariant _stringToTypedVariant(const QString& string, FactMetaData::ValueType_t type, bool failOk = false);
static FirmwarePlugin* _anyVehicleTypeFirmwarePlugin(MAV_AUTOPILOT firmwareType);
int _actualComponentId(int componentId);
void _setupComponentCategoryMap(int componentId);
void _setupDefaultComponentCategoryMap(void);
void _readParameterRaw(int componentId, const QString& paramName, int paramIndex);
void _writeParameterRaw(int componentId, const QString& paramName, const QVariant& value);
void _writeLocalParamCache(int vehicleId, int componentId);
void _tryCacheHashLoad(int vehicleId, int componentId, QVariant hash_value);
void _loadMetaData(void);
void _clearMetaData(void);
void _addMetaDataToDefaultComponent(void);
QString _remapParamNameToVersion(const QString& paramName);
void _loadOfflineEditingParams(void);
QString _logVehiclePrefix(int componentId);
void _setLoadProgress(double loadProgress);
bool _fillIndexBatchQueue(bool waitingParamTimeout);
void _updateProgressBar(void);
int _actualComponentId (int componentId);
void _setupComponentCategoryMap (int componentId);
void _setupDefaultComponentCategoryMap (void);
void _readParameterRaw (int componentId, const QString& paramName, int paramIndex);
void _writeParameterRaw (int componentId, const QString& paramName, const QVariant& value);
void _writeLocalParamCache (int vehicleId, int componentId);
void _tryCacheHashLoad (int vehicleId, int componentId, QVariant hash_value);
void _loadMetaData (void);
void _clearMetaData (void);
void _addMetaDataToDefaultComponent (void);
QString _remapParamNameToVersion (const QString& paramName);
void _loadOfflineEditingParams (void);
QString _logVehiclePrefix (int componentId);
void _setLoadProgress (double loadProgress);
bool _fillIndexBatchQueue (bool waitingParamTimeout);
void _updateProgressBar (void);
MAV_PARAM_TYPE _factTypeToMavType(FactMetaData::ValueType_t factType);
FactMetaData::ValueType_t _mavTypeToFactType(MAV_PARAM_TYPE mavType);
......@@ -178,7 +153,6 @@ private:
bool _logReplay; ///< true: running with log replay link
QString _versionParam; ///< Parameter which contains parameter set version
int _parameterSetMajorVersion; ///< Version for parameter set, -1 if not known
QObject* _parameterMetaData; ///< Opaque data from FirmwarePlugin::loadParameterMetaDataCall
typedef QPair<int /* FactMetaData::ValueType_t */, QVariant /* Fact::rawValue */> ParamTypeVal;
typedef QMap<QString /* parameter name */, ParamTypeVal> CacheMapName2ParamTypeVal;
......@@ -222,7 +196,6 @@ private:
Fact _defaultFact; ///< Used to return default fact, when parameter not found
static const char* _cachedMetaDataFilePrefix;
static const char* _jsonParametersKey;
static const char* _jsonCompIdKey;
static const char* _jsonParamNameKey;
......
......@@ -702,15 +702,17 @@ bool APMFirmwarePlugin::sendHomePositionToVehicle(void)
return true;
}
void APMFirmwarePlugin::addMetaDataToFact(QObject* parameterMetaData, Fact* fact, MAV_TYPE vehicleType)
FactMetaData* APMFirmwarePlugin::_getMetaDataForFact(QObject* parameterMetaData, const QString& name, FactMetaData::ValueType_t type, MAV_TYPE vehicleType)
{
APMParameterMetaData* apmMetaData = qobject_cast<APMParameterMetaData*>(parameterMetaData);
if (apmMetaData) {
apmMetaData->addMetaDataToFact(fact, vehicleType);
return apmMetaData->getMetaDataForFact(name, vehicleType, type);
} else {
qWarning() << "Internal error: pointer passed to APMFirmwarePlugin::addMetaDataToFact not APMParameterMetaData";
}
return nullptr;
}
QList<MAV_CMD> APMFirmwarePlugin::supportedMissionCommands(void)
......@@ -771,7 +773,7 @@ QString APMFirmwarePlugin::missionCommandOverrides(MAV_TYPE vehicleType) const
}
}
QObject* APMFirmwarePlugin::loadParameterMetaData(const QString& metaDataFile)
QObject* APMFirmwarePlugin::_loadParameterMetaData(const QString& metaDataFile)
{
Q_UNUSED(metaDataFile);
......@@ -806,7 +808,7 @@ void APMFirmwarePlugin::_artooSocketError(QAbstractSocket::SocketError socketErr
qgcApp()->showAppMessage(tr("Error during Solo video link setup: %1").arg(socketError));
}
QString APMFirmwarePlugin::internalParameterMetaDataFile(Vehicle* vehicle)
QString APMFirmwarePlugin::_internalParameterMetaDataFile(Vehicle* vehicle)
{
switch (vehicle->vehicleType()) {
case MAV_TYPE_QUADROTOR:
......
......@@ -97,12 +97,12 @@ public:
virtual void initializeStreamRates (Vehicle* vehicle);
void initializeVehicle (Vehicle* vehicle) override;
bool sendHomePositionToVehicle (void) override;
void addMetaDataToFact (QObject* parameterMetaData, Fact* fact, MAV_TYPE vehicleType) override;
QString missionCommandOverrides (MAV_TYPE vehicleType) const override;
QString getVersionParam (void) override { return QStringLiteral("SYSID_SW_MREV"); }
QString internalParameterMetaDataFile (Vehicle* vehicle) override;
void getParameterMetaDataVersionInfo (const QString& metaDataFile, int& majorVersion, int& minorVersion) override { APMParameterMetaData::getParameterMetaDataVersionInfo(metaDataFile, majorVersion, minorVersion); }
QObject* loadParameterMetaData (const QString& metaDataFile) override;
QString _internalParameterMetaDataFile (Vehicle* vehicle) override;
FactMetaData* _getMetaDataForFact (QObject* parameterMetaData, const QString& name, FactMetaData::ValueType_t type, MAV_TYPE vehicleType) override;
void _getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion) override { APMParameterMetaData::getParameterMetaDataVersionInfo(metaDataFile, majorVersion, minorVersion); }
QObject* _loadParameterMetaData (const QString& metaDataFile) override;
QString brandImageIndoor (const Vehicle* vehicle) const override { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/APM/BrandImage"); }
QString brandImageOutdoor (const Vehicle* vehicle) const override { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/APM/BrandImage"); }
......
......@@ -425,27 +425,26 @@ bool APMParameterMetaData::parseParameterAttributes(QXmlStreamReader& xml, APMFa
return true;
}
void APMParameterMetaData::addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType)
FactMetaData* APMParameterMetaData::getMetaDataForFact(const QString& name, MAV_TYPE vehicleType, FactMetaData::ValueType_t type)
{
const QString mavTypeString = mavTypeToString(vehicleType);
APMFactMetaDataRaw* rawMetaData = nullptr;
// check if we have metadata for fact, use generic otherwise
if (_vehicleTypeToParametersMap[mavTypeString].contains(fact->name())) {
rawMetaData = _vehicleTypeToParametersMap[mavTypeString][fact->name()];
} else if (_vehicleTypeToParametersMap["libraries"].contains(fact->name())) {
rawMetaData = _vehicleTypeToParametersMap["libraries"][fact->name()];
if (_vehicleTypeToParametersMap[mavTypeString].contains(name)) {
rawMetaData = _vehicleTypeToParametersMap[mavTypeString][name];
} else if (_vehicleTypeToParametersMap["libraries"].contains(name)) {
rawMetaData = _vehicleTypeToParametersMap["libraries"][name];
}
FactMetaData *metaData = new FactMetaData(fact->type(), fact);
FactMetaData *metaData = new FactMetaData(type, this);
// we don't have data for this fact
if (!rawMetaData) {
metaData->setCategory(QStringLiteral("Advanced"));
metaData->setGroup(_groupFromParameterName(fact->name()));
fact->setMetaData(metaData);
qCDebug(APMParameterMetaDataLog) << "No metaData for " << fact->name() << "using generic metadata";
return;
metaData->setGroup(_groupFromParameterName(name));
qCDebug(APMParameterMetaDataLog) << "No metaData for " << name << "using generic metadata";
return metaData;
}
metaData->setName(rawMetaData->name);
......@@ -531,7 +530,7 @@ void APMParameterMetaData::addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType)
QVariant typedBitSet;
switch (fact->type()) {
switch (type) {
case FactMetaData::valueTypeInt8:
typedBitSet = QVariant((signed char)bitSet);
break;
......@@ -599,15 +598,15 @@ void APMParameterMetaData::addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType)
}
// ArduPilot does not yet support decimal places meta data. So for P/I/D parameters we force to 6 places
if ((fact->name().endsWith(QStringLiteral("_P")) ||
fact->name().endsWith(QStringLiteral("_I")) ||
fact->name().endsWith(QStringLiteral("_D"))) &&
(fact->type() == FactMetaData::valueTypeFloat ||
fact->type() == FactMetaData::valueTypeDouble)) {
if ((name.endsWith(QStringLiteral("_P")) ||
name.endsWith(QStringLiteral("_I")) ||
name.endsWith(QStringLiteral("_D"))) &&
(type == FactMetaData::valueTypeFloat ||
type == FactMetaData::valueTypeDouble)) {
metaData->setDecimalPlaces(6);
}
fact->setMetaData(metaData);
return metaData;
}
void APMParameterMetaData::getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion)
......
......@@ -58,7 +58,7 @@ class APMParameterMetaData : public QObject
public:
APMParameterMetaData(void);
void addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType);
FactMetaData* getMetaDataForFact(const QString& name, MAV_TYPE vehicleType, FactMetaData::ValueType_t type);
void loadParameterFactMetaDataFile(const QString& metaDataFile);
static void getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion);
......@@ -83,8 +83,9 @@ private:
QString mavTypeToString(MAV_TYPE vehicleTypeEnum);
QString _groupFromParameterName(const QString& name);
bool _parameterMetaDataLoaded; ///< true: parameter meta data already loaded
QMap<QString, ParameterNametoFactMetaDataMap> _vehicleTypeToParametersMap; ///< Maps from a vehicle type to paramametertoFactMeta map>
bool _parameterMetaDataLoaded = false; ///< true: parameter meta data already loaded
// FIXME: metadata is vehicle type specific now
QMap<QString, ParameterNametoFactMetaDataMap> _vehicleTypeToParametersMap; ///< Maps from a vehicle type to paramametertoFactMeta map>
};
#endif
......@@ -203,7 +203,7 @@ QString FirmwarePlugin::missionCommandOverrides(MAV_TYPE vehicleType) const
}
}
void FirmwarePlugin::getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion)
void FirmwarePlugin::_getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion)
{
Q_UNUSED(metaDataFile);
majorVersion = -1;
......
......@@ -214,24 +214,28 @@ public:
/// Returns the parameter set version info pulled from inside the meta data file. -1 if not found.
/// Note: The implementation for this must not vary by vehicle type.
virtual void getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion);
/// Important: Only CompInfoParam code should use this method
virtual void _getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion);
/// Returns the internal resource parameter meta date file.
virtual QString internalParameterMetaDataFile(Vehicle* /*vehicle*/) { return QString(); }
/// Important: Only CompInfoParam code should use this method
virtual QString _internalParameterMetaDataFile(Vehicle* /*vehicle*/) { return QString(); }
/// Loads the specified parameter meta data file.
/// @return Opaque parameter meta data information which must be stored with Vehicle. Vehicle is responsible to
/// call deleteParameterMetaData when no longer needed.
virtual QObject* loadParameterMetaData(const QString& /*metaDataFile*/) { return nullptr; }
/// Important: Only CompInfoParam code should use this method
virtual QObject* _loadParameterMetaData(const QString& /*metaDataFile*/) { return nullptr; }
/// Returns the FactMetaData associated with the parameter name
/// @param opaqueParameterMetaData Opaque pointer returned from loadParameterMetaData
/// @param name Parameter name
virtual FactMetaData* getMetaDataForFact(QObject* /*parameterMetaData*/, const QString& /*name*/, MAV_TYPE /*vehicleType*/) { return nullptr; }
/// Important: Only CompInfoParam code should use this method
virtual FactMetaData* _getMetaDataForFact(QObject* /*parameterMetaData*/, const QString& /*name*/, FactMetaData::ValueType_t /* type */, MAV_TYPE /*vehicleType*/) { return nullptr; }
/// Adds the parameter meta data to the Fact
/// Returns the FactMetaData associated with the parameter name
/// @param opaqueParameterMetaData Opaque pointer returned from loadParameterMetaData
virtual void addMetaDataToFact(QObject* /*parameterMetaData*/, Fact* /*fact*/, MAV_TYPE /*vehicleType*/) { return; }
/// Important: Only CompInfoParam code should use this method
virtual bool _isParameterVolatile(QObject* /*parameterMetaData*/, const QString& /*name*/, MAV_TYPE /*vehicleType*/) { return false; }
/// List of supported mission commands. Empty list for all commands supported.
virtual QList<MAV_CMD> supportedMissionCommands(void);
......
......@@ -250,12 +250,12 @@ bool PX4FirmwarePlugin::sendHomePositionToVehicle(void)
return false;
}
FactMetaData* PX4FirmwarePlugin::getMetaDataForFact(QObject* parameterMetaData, const QString& name, MAV_TYPE vehicleType)
FactMetaData* PX4FirmwarePlugin::_getMetaDataForFact(QObject* parameterMetaData, const QString& name, FactMetaData::ValueType_t type, MAV_TYPE vehicleType)
{
PX4ParameterMetaData* px4MetaData = qobject_cast<PX4ParameterMetaData*>(parameterMetaData);
if (px4MetaData) {
return px4MetaData->getMetaDataForFact(name, vehicleType);
return px4MetaData->getMetaDataForFact(name, vehicleType, type);
} else {
qWarning() << "Internal error: pointer passed to PX4FirmwarePlugin::getMetaDataForFact not PX4ParameterMetaData";
}
......@@ -263,18 +263,7 @@ FactMetaData* PX4FirmwarePlugin::getMetaDataForFact(QObject* parameterMetaData,
return nullptr;
}
void PX4FirmwarePlugin::addMetaDataToFact(QObject* parameterMetaData, Fact* fact, MAV_TYPE vehicleType)
{
PX4ParameterMetaData* px4MetaData = qobject_cast<PX4ParameterMetaData*>(parameterMetaData);
if (px4MetaData) {
px4MetaData->addMetaDataToFact(fact, vehicleType);
} else {
qWarning() << "Internal error: pointer passed to PX4FirmwarePlugin::addMetaDataToFact not PX4ParameterMetaData";
}
}
void PX4FirmwarePlugin::getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion)
void PX4FirmwarePlugin::_getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion)
{
return PX4ParameterMetaData::getParameterMetaDataVersionInfo(metaDataFile, majorVersion, minorVersion);
}
......@@ -329,7 +318,7 @@ QString PX4FirmwarePlugin::missionCommandOverrides(MAV_TYPE vehicleType) const
}
}
QObject* PX4FirmwarePlugin::loadParameterMetaData(const QString& metaDataFile)
QObject* PX4FirmwarePlugin::_loadParameterMetaData(const QString& metaDataFile)
{
PX4ParameterMetaData* metaData = new PX4ParameterMetaData;
if (!metaDataFile.isEmpty()) {
......
......@@ -55,15 +55,14 @@ public:
bool isGuidedMode (const Vehicle* vehicle) const override;
void initializeVehicle (Vehicle* vehicle) override;
bool sendHomePositionToVehicle (void) override;
void addMetaDataToFact (QObject* parameterMetaData, Fact* fact, MAV_TYPE vehicleType) override;
FactMetaData* getMetaDataForFact (QObject* parameterMetaData, const QString& name, MAV_TYPE vehicleType) override;
QString missionCommandOverrides (MAV_TYPE vehicleType) const override;
QString getVersionParam (void) override { return QString("SYS_PARAM_VER"); }
QString internalParameterMetaDataFile (Vehicle* vehicle) override { Q_UNUSED(vehicle); return QString(":/FirmwarePlugin/PX4/PX4ParameterFactMetaData.xml"); }
void getParameterMetaDataVersionInfo (const QString& metaDataFile, int& majorVersion, int& minorVersion) override;
QObject* loadParameterMetaData (const QString& metaDataFile) final;
FactMetaData* _getMetaDataForFact (QObject* parameterMetaData, const QString& name, FactMetaData::ValueType_t type, MAV_TYPE vehicleType) override;
QString _internalParameterMetaDataFile (Vehicle* vehicle) override { Q_UNUSED(vehicle); return QString(":/FirmwarePlugin/PX4/PX4ParameterFactMetaData.xml"); }
void _getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion) override;
QObject* _loadParameterMetaData (const QString& metaDataFile) final;
bool adjustIncomingMavlinkMessage (Vehicle* vehicle, mavlink_message_t* message) override;
QString offlineEditingParamFile(Vehicle* vehicle) override { Q_UNUSED(vehicle); return QStringLiteral(":/FirmwarePlugin/PX4/PX4.OfflineEditing.params"); }
QString offlineEditingParamFile (Vehicle* vehicle) override { Q_UNUSED(vehicle); return QStringLiteral(":/FirmwarePlugin/PX4/PX4.OfflineEditing.params"); }
QString brandImageIndoor (const Vehicle* vehicle) const override { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/PX4/BrandImage"); }
QString brandImageOutdoor (const Vehicle* vehicle) const override { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/PX4/BrandImage"); }
QString autoDisarmParameter (Vehicle* vehicle) override { Q_UNUSED(vehicle); return QStringLiteral("COM_DISARM_LAND"); }
......
......@@ -25,7 +25,6 @@ static const char* kInvalidConverstion = "Internal Error: No support for string
QGC_LOGGING_CATEGORY(PX4ParameterMetaDataLog, "PX4ParameterMetaDataLog")
PX4ParameterMetaData::PX4ParameterMetaData(void)
: _parameterMetaDataLoaded(false)
{
}
......@@ -480,7 +479,7 @@ void PX4ParameterMetaData::_generateParameterJson()
if (metaData->volatileValue()) {
_jsonWriteLine(jsonFile, indentLevel, "\"volatile\": true,");
}
_jsonWriteLine(jsonFile, indentLevel, QStringLiteral("\"decimalPlaces\": \"%1\",").arg(metaData->decimalPlaces()));
_jsonWriteLine(jsonFile, indentLevel, QStringLiteral("\"decimalPlaces\": %1,").arg(metaData->decimalPlaces()));
_jsonWriteLine(jsonFile, indentLevel, QStringLiteral("\"minValue\": %1,").arg(metaData->rawMin().toDouble()));
_jsonWriteLine(jsonFile, indentLevel, QStringLiteral("\"maxValue\": %1").arg(metaData->rawMax().toDouble()));
_jsonWriteLine(jsonFile, --indentLevel, QStringLiteral("}%1").arg(++keyIndex == _mapParameterName2FactMetaData.keys().count() ? "" : ","));
......@@ -491,24 +490,17 @@ void PX4ParameterMetaData::_generateParameterJson()
}
#endif
FactMetaData* PX4ParameterMetaData::getMetaDataForFact(const QString& name, MAV_TYPE vehicleType)
FactMetaData* PX4ParameterMetaData::getMetaDataForFact(const QString& name, MAV_TYPE vehicleType, FactMetaData::ValueType_t type)
{
Q_UNUSED(vehicleType)
if (_mapParameterName2FactMetaData.contains(name)) {
return _mapParameterName2FactMetaData[name];
} else {
return nullptr;
if (!_mapParameterName2FactMetaData.contains(name)) {
qCDebug(PX4ParameterMetaDataLog) << "No metaData for " << name << "using generic metadata";
FactMetaData* metaData = new FactMetaData(type, this);
_mapParameterName2FactMetaData[name] = metaData;
}
}
void PX4ParameterMetaData::addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType)
{
Q_UNUSED(vehicleType)
if (_mapParameterName2FactMetaData.contains(fact->name())) {
fact->setMetaData(_mapParameterName2FactMetaData[fact->name()]);
}
return _mapParameterName2FactMetaData[name];
}
void PX4ParameterMetaData::getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion)
......
......@@ -36,8 +36,7 @@ public:
PX4ParameterMetaData(void);
void loadParameterFactMetaDataFile (const QString& metaDataFile);
FactMetaData* getMetaDataForFact (const QString& name, MAV_TYPE vehicleType);
void addMetaDataToFact (Fact* fact, MAV_TYPE vehicleType);
FactMetaData* getMetaDataForFact (const QString& name, MAV_TYPE vehicleType, FactMetaData::ValueType_t type);
static void getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion);
......@@ -58,8 +57,8 @@ private:
void _generateParameterJson();
#endif
bool _parameterMetaDataLoaded; ///< true: parameter meta data already loaded
QMap<QString, FactMetaData*> _mapParameterName2FactMetaData; ///< Maps from a parameter name to FactMetaData
bool _parameterMetaDataLoaded = false; ///< true: parameter meta data already loaded
FactMetaData::NameToMetaDataMap_t _mapParameterName2FactMetaData; ///< Maps from a parameter name to FactMetaData
};
#endif
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#include "CompInfo.h"
CompInfo::CompInfo(COMP_METADATA_TYPE type, uint8_t compId, Vehicle* vehicle, QObject* parent)
: QObject (parent)
, type (type)
, vehicle (vehicle)
, compId (compId)
{
}
void CompInfo::setMessage(const mavlink_message_t& message)
{
mavlink_component_information_t componentInformation;
mavlink_msg_component_information_decode(&message, &componentInformation);
available = true;
uidMetaData = componentInformation.metadata_uid;
uidTranslation = componentInformation.translation_uid;
uriMetaData = componentInformation.metadata_uri;
uriTranslation = componentInformation.translation_uri;
}
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#pragma once
#include "QGCMAVLink.h"
#include "QGCLoggingCategory.h"
#include "FactMetaData.h"
#include <QObject>
class FactMetaData;
class Vehicle;
class FirmwarePlugin;
/// Base class for all CompInfo types
class CompInfo : public QObject
{
Q_OBJECT
public:
CompInfo(COMP_METADATA_TYPE type, uint8_t compId, Vehicle* vehicle, QObject* parent = nullptr);
/// Called to pass the COMPONENT_INFORMATION message in
void setMessage(const mavlink_message_t& message);
virtual void setJson(const QString& metaDataJsonFileName, const QString& translationJsonFileName) = 0;
COMP_METADATA_TYPE type;
Vehicle* vehicle = nullptr;
uint8_t compId = MAV_COMP_ID_ALL;
bool available = false;
uint32_t uidMetaData = 0;
uint32_t uidTranslation = 0;
QString uriMetaData;
QString uriTranslation;
};
This diff is collapsed.
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#pragma once
#include "CompInfo.h"
#include "QGCMAVLink.h"
#include "QGCLoggingCategory.h"
#include "FactMetaData.h"
#include <QObject>
class FactMetaData;
class Vehicle;
class FirmwarePlugin;
Q_DECLARE_LOGGING_CATEGORY(CompInfoParamLog)
class CompInfoParam : public CompInfo
{
Q_OBJECT
public:
CompInfoParam(uint8_t compId, Vehicle* vehicle, QObject* parent = nullptr);
FactMetaData* factMetaDataForName(const QString& name, FactMetaData::ValueType_t type);
// Overrides from CompInfo
void setJson(const QString& metadataJsonFileName, const QString& translationJsonFileName) override;
// The following methods are used to support the old non-COMPONENT_INFORMATION based mechanism to get parameter meta data
bool _isParameterVolatile (const QString& name);
void _parameterMajorVersionKnown(int wantedMajorVersion);
void _clearPX4ParameterMetaData (void);
static void _cachePX4MetaDataFile(const QString& metaDataFile);
private:
static FirmwarePlugin* _anyVehicleTypeFirmwarePlugin (MAV_AUTOPILOT firmwareType);
static QString _parameterMetaDataFile (Vehicle* vehicle, MAV_AUTOPILOT firmwareType, int wantedMajorVersion, int& majorVersion, int& minorVersion);
bool _noJsonMetadata = true;
FactMetaData::NameToMetaDataMap_t _nameToMetaDataMap;
QObject* _opaqueParameterMetaData = nullptr;
static const char* _cachedMetaDataFilePrefix;
static const char* _jsonScopeKey;
static const char* _jsonParametersKey;
};
/****************************************************************************