Commit 781997b2 authored by Don Gagne's avatar Don Gagne

Merge pull request #2395 from pritamghanghas/apm_metadata

Apm metadata
parents fc853305 159bce05
...@@ -209,4 +209,7 @@ ...@@ -209,4 +209,7 @@
<file alias="ParameterFactMetaData.xml">src/AutoPilotPlugins/PX4/ParameterFactMetaData.xml</file> <file alias="ParameterFactMetaData.xml">src/AutoPilotPlugins/PX4/ParameterFactMetaData.xml</file>
</qresource> </qresource>
<qresource prefix="/FirmwarePlugin/APM">
<file alias="apm.pdef.xml">src/FirmwarePlugin/APM/apm.pdef.xml</file>
</qresource>
</RCC> </RCC>
...@@ -121,7 +121,9 @@ void FactMetaData::setMin(const QVariant& min) ...@@ -121,7 +121,9 @@ void FactMetaData::setMin(const QVariant& min)
_min = min; _min = min;
_minIsDefaultForType = false; _minIsDefaultForType = false;
} else { } else {
qWarning() << "Attempt to set min below allowable value"; qWarning() << "Attempt to set min below allowable value for fact: " << name()
<< ", value attempted: " << min
<< ", type: " << type() << ", min for type: " << _minForType();
_min = _minForType(); _min = _minForType();
} }
} }
...@@ -189,7 +191,7 @@ QVariant FactMetaData::_maxForType(void) const ...@@ -189,7 +191,7 @@ QVariant FactMetaData::_maxForType(void) const
bool FactMetaData::convertAndValidate(const QVariant& value, bool convertOnly, QVariant& typedValue, QString& errorString) bool FactMetaData::convertAndValidate(const QVariant& value, bool convertOnly, QVariant& typedValue, QString& errorString)
{ {
bool convertOk; bool convertOk = false;
errorString.clear(); errorString.clear();
...@@ -236,7 +238,7 @@ bool FactMetaData::convertAndValidate(const QVariant& value, bool convertOnly, Q ...@@ -236,7 +238,7 @@ bool FactMetaData::convertAndValidate(const QVariant& value, bool convertOnly, Q
} }
if (!convertOk) { if (!convertOk) {
errorString = "Invalid number"; errorString += "Invalid number";
} }
return convertOk && errorString.isEmpty(); return convertOk && errorString.isEmpty();
......
...@@ -254,7 +254,7 @@ void ParameterLoader::_parameterUpdate(int uasId, int componentId, QString param ...@@ -254,7 +254,7 @@ void ParameterLoader::_parameterUpdate(int uasId, int componentId, QString param
fact->_containerSetRawValue(value); fact->_containerSetRawValue(value);
if (setMetaData) { if (setMetaData) {
_vehicle->firmwarePlugin()->addMetaDataToFact(fact); _vehicle->firmwarePlugin()->addMetaDataToFact(fact, _vehicle->vehicleType());
} }
_dataMutex.unlock(); _dataMutex.unlock();
......
...@@ -405,11 +405,12 @@ bool APMFirmwarePlugin::sendHomePositionToVehicle(void) ...@@ -405,11 +405,12 @@ bool APMFirmwarePlugin::sendHomePositionToVehicle(void)
return true; return true;
} }
void APMFirmwarePlugin::addMetaDataToFact(Fact* fact) void APMFirmwarePlugin::addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType)
{ {
_parameterMetaData.addMetaDataToFact(fact); _parameterMetaData.addMetaDataToFact(fact, vehicleType);
} }
QList<MAV_CMD> APMFirmwarePlugin::supportedMissionCommands(void) QList<MAV_CMD> APMFirmwarePlugin::supportedMissionCommands(void)
{ {
QList<MAV_CMD> list; QList<MAV_CMD> list;
......
...@@ -89,7 +89,7 @@ public: ...@@ -89,7 +89,7 @@ public:
virtual void adjustMavlinkMessage(mavlink_message_t* message); virtual void adjustMavlinkMessage(mavlink_message_t* message);
virtual void initializeVehicle(Vehicle* vehicle); virtual void initializeVehicle(Vehicle* vehicle);
virtual bool sendHomePositionToVehicle(void); virtual bool sendHomePositionToVehicle(void);
virtual void addMetaDataToFact(Fact* fact); virtual void addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType);
virtual QString getDefaultComponentIdParam(void) const { return QString("SYSID_SW_TYPE"); } virtual QString getDefaultComponentIdParam(void) const { return QString("SYSID_SW_TYPE"); }
virtual QList<MAV_CMD> supportedMissionCommands(void); virtual QList<MAV_CMD> supportedMissionCommands(void);
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <QObject> #include <QObject>
#include <QMap> #include <QMap>
#include <QPointer>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QLoggingCategory> #include <QLoggingCategory>
...@@ -33,6 +34,20 @@ ...@@ -33,6 +34,20 @@
#include "AutoPilotPlugin.h" #include "AutoPilotPlugin.h"
#include "Vehicle.h" #include "Vehicle.h"
class APMFactMetaDataRaw
{
public:
QString name;
QString group;
QString shortDescription;
QString longDescription;
QString min;
QString max;
QString incrementSize;
QString units;
QList<QPair<QString, QString> > values;
};
/// @file /// @file
/// @author Don Gagne <don@thegagnes.com> /// @author Don Gagne <don@thegagnes.com>
...@@ -40,6 +55,8 @@ Q_DECLARE_LOGGING_CATEGORY(APMParameterMetaDataLog) ...@@ -40,6 +55,8 @@ Q_DECLARE_LOGGING_CATEGORY(APMParameterMetaDataLog)
/// Collection of Parameter Facts for PX4 AutoPilot /// Collection of Parameter Facts for PX4 AutoPilot
typedef QMap<QString, APMFactMetaDataRaw*> ParameterNametoFactMetaDataMap;
class APMParameterMetaData : public QObject class APMParameterMetaData : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -52,11 +69,15 @@ public: ...@@ -52,11 +69,15 @@ public:
virtual QString getDefaultComponentIdParam(void) const { return QString("SYSID_SW_TYPE"); } virtual QString getDefaultComponentIdParam(void) const { return QString("SYSID_SW_TYPE"); }
// Overrides from ParameterLoader // Overrides from ParameterLoader
static void addMetaDataToFact(Fact* fact); static void addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType);
static void addMetaDataToFacts(QVariantMap &facts, MAV_TYPE vehicleType);
private: private:
enum { enum {
XmlStateNone, XmlStateNone,
XmlstateParamFileFound,
XmlStateFoundVehicles,
XmlStateFoundLibraries,
XmlStateFoundParameters, XmlStateFoundParameters,
XmlStateFoundVersion, XmlStateFoundVersion,
XmlStateFoundGroup, XmlStateFoundGroup,
...@@ -65,11 +86,15 @@ private: ...@@ -65,11 +86,15 @@ private:
}; };
static void _loadParameterFactMetaData(void); static void _loadParameterFactMetaData();
static QVariant _stringToTypedVariant(const QString& string, FactMetaData::ValueType_t type, bool* convertOk); static QVariant _stringToTypedVariant(const QString& string, FactMetaData::ValueType_t type, bool* convertOk);
static bool skipXMLBlock(QXmlStreamReader& xml, const QString& blockName);
static bool parseParameterAttributes(QXmlStreamReader& xml, APMFactMetaDataRaw *rawMetaData);
static void correctGroupMemberships(ParameterNametoFactMetaDataMap& parameterToFactMetaDataMap, QMap<QString,QStringList>& groupMembers);
static QString mavTypeToString(MAV_TYPE vehicleTypeEnum);
static bool _parameterMetaDataLoaded; ///< true: parameter meta data already loaded static bool _parameterMetaDataLoaded; ///< true: parameter meta data already loaded
static QMap<QString, FactMetaData*> _mapParameterName2FactMetaData; ///< Maps from a parameter name to FactMetaData static QMap<QString, ParameterNametoFactMetaDataMap> _vehicleTypeToParametersMap; ///< Maps from a vehicle type to paramametertoFactMeta map>
}; };
#endif #endif
This diff is collapsed.
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
/// @param[out] custom_mode Custom mode for SET_MODE mavlink message /// @param[out] custom_mode Custom mode for SET_MODE mavlink message
virtual bool setFlightMode(const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode) = 0; virtual bool setFlightMode(const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode) = 0;
/// FIXME: This isn't quite correct being here. All code for Joystick support is currently firmware specific /// FIXME: This isn't quite correct being here. All code for Joystick suvehicleTypepport is currently firmware specific
/// not just this. I'm going to try to change that. If not, this will need to be removed. /// not just this. I'm going to try to change that. If not, this will need to be removed.
/// Returns the number of buttons which are reserved for firmware use in the MANUAL_CONTROL mavlink /// Returns the number of buttons which are reserved for firmware use in the MANUAL_CONTROL mavlink
/// message. For example PX4 Flight Stack reserves the first 8 buttons to simulate rc switches. /// message. For example PX4 Flight Stack reserves the first 8 buttons to simulate rc switches.
...@@ -108,7 +108,7 @@ public: ...@@ -108,7 +108,7 @@ public:
virtual QString getDefaultComponentIdParam(void) const = 0; virtual QString getDefaultComponentIdParam(void) const = 0;
/// Adds the parameter meta data to the Fact /// Adds the parameter meta data to the Fact
virtual void addMetaDataToFact(Fact* fact) = 0; virtual void addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType) = 0;
/// List of supported mission commands. Empty list for all commands supported. /// List of supported mission commands. Empty list for all commands supported.
virtual QList<MAV_CMD> supportedMissionCommands(void) = 0; virtual QList<MAV_CMD> supportedMissionCommands(void) = 0;
......
...@@ -112,8 +112,10 @@ bool GenericFirmwarePlugin::sendHomePositionToVehicle(void) ...@@ -112,8 +112,10 @@ bool GenericFirmwarePlugin::sendHomePositionToVehicle(void)
return false; return false;
} }
void GenericFirmwarePlugin::addMetaDataToFact(Fact* fact) void GenericFirmwarePlugin::addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType)
{ {
Q_UNUSED(vehicleType)
// Add default meta data // Add default meta data
FactMetaData* metaData = new FactMetaData(fact->type(), fact); FactMetaData* metaData = new FactMetaData(fact->type(), fact);
fact->setMetaData(metaData); fact->setMetaData(metaData);
......
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
virtual void adjustMavlinkMessage(mavlink_message_t* message); virtual void adjustMavlinkMessage(mavlink_message_t* message);
virtual void initializeVehicle(Vehicle* vehicle); virtual void initializeVehicle(Vehicle* vehicle);
virtual bool sendHomePositionToVehicle(void); virtual bool sendHomePositionToVehicle(void);
virtual void addMetaDataToFact(Fact* fact); virtual void addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType);
virtual QString getDefaultComponentIdParam(void) const { return QString(); } virtual QString getDefaultComponentIdParam(void) const { return QString(); }
virtual QList<MAV_CMD> supportedMissionCommands(void); virtual QList<MAV_CMD> supportedMissionCommands(void);
}; };
......
...@@ -203,9 +203,9 @@ bool PX4FirmwarePlugin::sendHomePositionToVehicle(void) ...@@ -203,9 +203,9 @@ bool PX4FirmwarePlugin::sendHomePositionToVehicle(void)
return false; return false;
} }
void PX4FirmwarePlugin::addMetaDataToFact(Fact* fact) void PX4FirmwarePlugin::addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType)
{ {
_parameterMetaData.addMetaDataToFact(fact); _parameterMetaData.addMetaDataToFact(fact, vehicleType);
} }
QList<MAV_CMD> PX4FirmwarePlugin::supportedMissionCommands(void) QList<MAV_CMD> PX4FirmwarePlugin::supportedMissionCommands(void)
......
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
virtual void adjustMavlinkMessage(mavlink_message_t* message); virtual void adjustMavlinkMessage(mavlink_message_t* message);
virtual void initializeVehicle(Vehicle* vehicle); virtual void initializeVehicle(Vehicle* vehicle);
virtual bool sendHomePositionToVehicle(void); virtual bool sendHomePositionToVehicle(void);
virtual void addMetaDataToFact(Fact* fact); virtual void addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType);
virtual QString getDefaultComponentIdParam(void) const { return QString("SYS_AUTOSTART"); } virtual QString getDefaultComponentIdParam(void) const { return QString("SYS_AUTOSTART"); }
virtual QList<MAV_CMD> supportedMissionCommands(void); virtual QList<MAV_CMD> supportedMissionCommands(void);
......
...@@ -188,7 +188,7 @@ void PX4ParameterMetaData::_loadParameterFactMetaData(void) ...@@ -188,7 +188,7 @@ void PX4ParameterMetaData::_loadParameterFactMetaData(void)
QString name = xml.attributes().value("name").toString(); QString name = xml.attributes().value("name").toString();
QString type = xml.attributes().value("type").toString(); QString type = xml.attributes().value("type").toString();
QString strDefault = xml.attributes().value("default").toString(); QString strDefault = xml.attributes().value("default").toString();
qCDebug(PX4ParameterMetaDataLog) << "Found parameter name:" << name << " type:" << type << " default:" << strDefault; qCDebug(PX4ParameterMetaDataLog) << "Found parameter name:" << name << " type:" << type << " default:" << strDefault;
...@@ -345,8 +345,10 @@ void PX4ParameterMetaData::_loadParameterFactMetaData(void) ...@@ -345,8 +345,10 @@ void PX4ParameterMetaData::_loadParameterFactMetaData(void)
} }
/// Override from FactLoad which connects the meta data to the fact /// Override from FactLoad which connects the meta data to the fact
void PX4ParameterMetaData::addMetaDataToFact(Fact* fact) void PX4ParameterMetaData::addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType)
{ {
Q_UNUSED(vehicleType)
_loadParameterFactMetaData(); _loadParameterFactMetaData();
if (_mapParameterName2FactMetaData.contains(fact->name())) { if (_mapParameterName2FactMetaData.contains(fact->name())) {
fact->setMetaData(_mapParameterName2FactMetaData[fact->name()]); fact->setMetaData(_mapParameterName2FactMetaData[fact->name()]);
......
...@@ -47,7 +47,7 @@ class PX4ParameterMetaData : public QObject ...@@ -47,7 +47,7 @@ class PX4ParameterMetaData : public QObject
public: public:
PX4ParameterMetaData(QObject* parent = NULL); PX4ParameterMetaData(QObject* parent = NULL);
void addMetaDataToFact(Fact* fact); void addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType);
private: private:
enum { enum {
......
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