Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
4787a4fc
Commit
4787a4fc
authored
Apr 13, 2015
by
Don Gagne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Group support to FactSystem
parent
9ef31ea9
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
160 additions
and
74 deletions
+160
-74
AutoPilotPlugin.cc
src/AutoPilotPlugins/AutoPilotPlugin.cc
+65
-2
AutoPilotPlugin.h
src/AutoPilotPlugins/AutoPilotPlugin.h
+27
-15
GenericAutoPilotPlugin.h
src/AutoPilotPlugins/Generic/GenericAutoPilotPlugin.h
+3
-1
PX4AutoPilotPlugin.cc
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc
+0
-1
PX4AutoPilotPlugin.h
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.h
+3
-1
PX4ParameterFacts.cc
src/AutoPilotPlugins/PX4/PX4ParameterFacts.cc
+2
-8
PX4ParameterFacts.h
src/AutoPilotPlugins/PX4/PX4ParameterFacts.h
+0
-1
Fact.cc
src/FactSystem/Fact.cc
+12
-3
Fact.h
src/FactSystem/Fact.h
+3
-24
FactMetaData.h
src/FactSystem/FactMetaData.h
+1
-1
ParameterLoader.cc
src/FactSystem/ParameterLoader.cc
+28
-8
ParameterLoader.h
src/FactSystem/ParameterLoader.h
+16
-9
No files found.
src/AutoPilotPlugins/AutoPilotPlugin.cc
View file @
4787a4fc
...
...
@@ -25,6 +25,7 @@
/// @author Don Gagne <don@thegagnes.com>
#include "AutoPilotPlugin.h"
#include "QGCUASParamManagerInterface.h"
AutoPilotPlugin
::
AutoPilotPlugin
(
UASInterface
*
uas
,
QObject
*
parent
)
:
QObject
(
parent
),
...
...
@@ -34,11 +35,36 @@ AutoPilotPlugin::AutoPilotPlugin(UASInterface* uas, QObject* parent) :
Q_ASSERT
(
_uas
);
}
void
AutoPilotPlugin
::
refreshAllParameters
(
void
)
{
_getParameterLoader
()
->
refreshAllParameters
();
}
void
AutoPilotPlugin
::
refreshParameter
(
int
componentId
,
const
QString
&
name
)
{
_getParameterLoader
()
->
refreshParameter
(
componentId
,
name
);
}
void
AutoPilotPlugin
::
refreshParametersPrefix
(
int
componentId
,
const
QString
&
namePrefix
)
{
_getParameterLoader
()
->
refreshParametersPrefix
(
componentId
,
namePrefix
);
}
bool
AutoPilotPlugin
::
parameterExists
(
const
QString
&
name
)
{
return
_getParameterLoader
()
->
parameterExists
(
FactSystem
::
defaultComponentId
,
name
);
}
Fact
*
AutoPilotPlugin
::
getParameterFact
(
const
QString
&
name
)
{
return
_getParameterLoader
()
->
getFact
(
FactSystem
::
defaultComponentId
,
name
);
}
bool
AutoPilotPlugin
::
factExists
(
FactSystem
::
Provider_t
provider
,
int
componentId
,
const
QString
&
name
)
{
switch
(
provider
)
{
case
FactSystem
:
:
ParameterProvider
:
return
getParameterLoader
()
->
fact
Exists
(
componentId
,
name
);
return
_getParameterLoader
()
->
parameter
Exists
(
componentId
,
name
);
// Other providers will go here once they come online
}
...
...
@@ -51,7 +77,7 @@ Fact* AutoPilotPlugin::getFact(FactSystem::Provider_t provider, int componentId,
{
switch
(
provider
)
{
case
FactSystem
:
:
ParameterProvider
:
return
getParameterLoader
()
->
getFact
(
componentId
,
name
);
return
_
getParameterLoader
()
->
getFact
(
componentId
,
name
);
// Other providers will go here once they come online
}
...
...
@@ -59,3 +85,40 @@ Fact* AutoPilotPlugin::getFact(FactSystem::Provider_t provider, int componentId,
Q_ASSERT
(
false
);
return
NULL
;
}
QStringList
AutoPilotPlugin
::
parameterNames
(
void
)
{
return
_getParameterLoader
()
->
parameterNames
();
}
const
QMap
<
int
,
QMap
<
QString
,
QStringList
>
>&
AutoPilotPlugin
::
getGroupMap
(
void
)
{
return
_getParameterLoader
()
->
getGroupMap
();
}
void
AutoPilotPlugin
::
writeParametersToStream
(
QTextStream
&
stream
)
{
Q_ASSERT
(
_uas
);
_uas
->
getParamManager
()
->
writeOnboardParamsToStream
(
stream
,
_uas
->
getUASName
());
}
void
AutoPilotPlugin
::
readParametersFromStream
(
QTextStream
&
stream
)
{
Q_ASSERT
(
_uas
);
Fact
*
autoSaveFact
=
NULL
;
int
previousAutoSave
=
0
;
if
(
parameterExists
(
"COM_AUTOS_PAR"
))
{
autoSaveFact
=
getParameterFact
(
"COM_AUTOS_PAR"
);
previousAutoSave
=
autoSaveFact
->
value
().
toInt
();
autoSaveFact
->
setValue
(
1
);
}
_uas
->
getParamManager
()
->
readPendingParamsFromStream
(
stream
);
if
(
autoSaveFact
)
{
autoSaveFact
->
setValue
(
previousAutoSave
);
}
}
src/AutoPilotPlugins/AutoPilotPlugin.h
View file @
4787a4fc
...
...
@@ -57,14 +57,32 @@ public:
Q_PROPERTY
(
QVariantList
vehicleComponents
READ
vehicleComponents
CONSTANT
)
/// Re-request the full set of parameters from the autopilot
Q_INVOKABLE
void
refreshAllParameters
(
void
)
{
getParameterLoader
()
->
refreshAllParameters
();
}
Q_INVOKABLE
void
refreshAllParameters
(
void
);
/// Request a refresh on the specific parameter
Q_INVOKABLE
void
refreshParameter
(
int
componentId
,
const
QString
&
name
)
{
getParameterLoader
()
->
refreshParameter
(
componentId
,
name
);
}
Q_INVOKABLE
void
refreshParameter
(
int
componentId
,
const
QString
&
name
);
/// Request a refresh on all parameters that begin with the specified prefix
Q_INVOKABLE
void
refreshParametersPrefix
(
int
componentId
,
const
QString
&
namePrefix
)
{
getParameterLoader
()
->
refreshParametersPrefix
(
componentId
,
namePrefix
);
}
Q_INVOKABLE
void
refreshParametersPrefix
(
int
componentId
,
const
QString
&
namePrefix
);
/// Returns true if the specifed parameter exists from the default component
Q_INVOKABLE
bool
parameterExists
(
const
QString
&
name
);
/// Returns all parameter names
/// FIXME: component id missing, generic to fact
QStringList
parameterNames
(
void
);
/// Returns the specified parameter Fact from the default component
/// WARNING: Will assert if fact does not exists. If that possibility exists, check for existince first with
/// factExists.
Fact
*
getParameterFact
(
const
QString
&
name
);
/// Writes the parameter facts to the specified stream
void
writeParametersToStream
(
QTextStream
&
stream
);
/// Reads the parameters from the stream and updates values
void
readParametersFromStream
(
QTextStream
&
stream
);
/// Returns true if the specifed fact exists
Q_INVOKABLE
bool
factExists
(
FactSystem
::
Provider_t
provider
,
///< fact provider
int
componentId
,
///< fact component, -1=default component
...
...
@@ -76,21 +94,12 @@ public:
Fact
*
getFact
(
FactSystem
::
Provider_t
provider
,
///< fact provider
int
componentId
,
///< fact component, -1=default component
const
QString
&
name
);
///< fact name
/// Returns true if the specifed parameter exists from the default component
Q_INVOKABLE
bool
parameterExists
(
const
QString
&
name
)
{
return
getParameterLoader
()
->
factExists
(
FactSystem
::
defaultComponentId
,
name
);
}
/// Returns the specified parameter Fact from the default component
/// WARNING: Will assert if fact does not exists. If that possibility exists, check for existince first with
/// factExists.
Fact
*
getParameterFact
(
const
QString
&
name
)
{
return
getParameterLoader
()
->
getFact
(
FactSystem
::
defaultComponentId
,
name
);
}
const
QMap
<
int
,
QMap
<
QString
,
QStringList
>
>&
getGroupMap
(
void
);
// Must be implemented by derived class
virtual
const
QVariantList
&
vehicleComponents
(
void
)
=
0
;
/// Returns the ParameterLoader
virtual
ParameterLoader
*
getParameterLoader
(
void
)
=
0
;
/// FIXME: Kind of hacky
static
void
clearStaticData
(
void
);
...
...
@@ -106,6 +115,9 @@ protected:
/// All access to AutoPilotPugin objects is through getInstanceForAutoPilotPlugin
AutoPilotPlugin
(
QObject
*
parent
=
NULL
)
:
QObject
(
parent
)
{
}
/// Returns the ParameterLoader
virtual
ParameterLoader
*
_getParameterLoader
(
void
)
=
0
;
UASInterface
*
_uas
;
bool
_pluginReady
;
};
...
...
src/AutoPilotPlugins/Generic/GenericAutoPilotPlugin.h
View file @
4787a4fc
...
...
@@ -42,7 +42,6 @@ public:
// Overrides from AutoPilotPlugin
virtual
const
QVariantList
&
vehicleComponents
(
void
);
virtual
ParameterLoader
*
getParameterLoader
(
void
)
{
return
_parameterFacts
;
}
static
QList
<
AutoPilotPluginManager
::
FullMode_t
>
getModes
(
void
);
static
QString
getShortModeText
(
uint8_t
baseMode
,
uint32_t
customMode
);
...
...
@@ -52,6 +51,9 @@ private slots:
void
_parametersReady
(
void
);
private:
// Overrides from AutoPilotPlugin
virtual
ParameterLoader
*
_getParameterLoader
(
void
)
{
return
_parameterFacts
;
}
GenericParameterFacts
*
_parameterFacts
;
};
...
...
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc
View file @
4787a4fc
...
...
@@ -90,7 +90,6 @@ PX4AutoPilotPlugin::PX4AutoPilotPlugin(UASInterface* uas, QObject* parent) :
PX4AutoPilotPlugin
::~
PX4AutoPilotPlugin
()
{
delete
_parameterFacts
;
PX4ParameterFacts
::
deleteParameterFactMetaData
();
}
QList
<
AutoPilotPluginManager
::
FullMode_t
>
PX4AutoPilotPlugin
::
getModes
(
void
)
...
...
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.h
View file @
4787a4fc
...
...
@@ -51,7 +51,6 @@ public:
// Overrides from AutoPilotPlugin
virtual
const
QVariantList
&
vehicleComponents
(
void
);
virtual
ParameterLoader
*
getParameterLoader
(
void
)
{
return
_parameterFacts
;
}
static
QList
<
AutoPilotPluginManager
::
FullMode_t
>
getModes
(
void
);
static
QString
getShortModeText
(
uint8_t
baseMode
,
uint32_t
customMode
);
...
...
@@ -69,6 +68,9 @@ private slots:
void
_pluginReadyPreChecks
(
void
);
private:
// Overrides from AutoPilotPlugin
virtual
ParameterLoader
*
_getParameterLoader
(
void
)
{
return
_parameterFacts
;
}
PX4ParameterFacts
*
_parameterFacts
;
QVariantList
_components
;
AirframeComponent
*
_airframeComponent
;
...
...
src/AutoPilotPlugins/PX4/PX4ParameterFacts.cc
View file @
4787a4fc
...
...
@@ -42,14 +42,6 @@ PX4ParameterFacts::PX4ParameterFacts(UASInterface* uas, QObject* parent) :
Q_ASSERT
(
uas
);
}
void
PX4ParameterFacts
::
deleteParameterFactMetaData
(
void
)
{
foreach
(
QString
param
,
_mapParameterName2FactMetaData
.
keys
())
{
delete
_mapParameterName2FactMetaData
[
param
];
}
_mapParameterName2FactMetaData
.
clear
();
}
/// Parse the Parameter element of parameter xml meta data
/// @param[in] xml stream reader
/// @param[in] group fact group associated with this Param element
...
...
@@ -69,6 +61,8 @@ FactMetaData* PX4ParameterFacts::_parseParameter(QXmlStreamReader& xml, const QS
FactMetaData
*
metaData
=
new
FactMetaData
();
Q_CHECK_PTR
(
metaData
);
metaData
->
group
=
group
;
// Convert type from string to FactMetaData::ValueType_t
struct
String2Type
{
...
...
src/AutoPilotPlugins/PX4/PX4ParameterFacts.h
View file @
4787a4fc
...
...
@@ -52,7 +52,6 @@ public:
virtual
QString
getDefaultComponentIdParam
(
void
)
const
{
return
QString
(
"SYS_AUTOSTART"
);
}
static
void
loadParameterFactMetaData
(
void
);
static
void
deleteParameterFactMetaData
(
void
);
static
void
clearStaticData
(
void
);
private:
...
...
src/FactSystem/Fact.cc
View file @
4787a4fc
...
...
@@ -107,7 +107,7 @@ QString Fact::shortDescription(void)
if
(
_metaData
)
{
return
_metaData
->
shortDescription
;
}
else
{
return
QString
();
return
QString
(
""
);
}
}
...
...
@@ -116,7 +116,7 @@ QString Fact::longDescription(void)
if
(
_metaData
)
{
return
_metaData
->
longDescription
;
}
else
{
return
QString
();
return
QString
(
""
);
}
}
...
...
@@ -125,7 +125,7 @@ QString Fact::units(void)
if
(
_metaData
)
{
return
_metaData
->
units
;
}
else
{
return
QString
();
return
QString
(
""
);
}
}
...
...
@@ -141,6 +141,15 @@ QVariant Fact::max(void)
return
_metaData
->
max
;
}
QString
Fact
::
group
(
void
)
{
if
(
_metaData
)
{
return
_metaData
->
group
;
}
else
{
return
"Default Group"
;
}
}
void
Fact
::
setMetaData
(
FactMetaData
*
metaData
)
{
_metaData
=
metaData
;
...
...
src/FactSystem/Fact.h
View file @
4787a4fc
...
...
@@ -54,6 +54,7 @@ class Fact : public QObject
Q_PROPERTY
(
QString
units
READ
units
CONSTANT
)
Q_PROPERTY
(
QVariant
min
READ
min
CONSTANT
)
Q_PROPERTY
(
QVariant
max
READ
max
CONSTANT
)
Q_PROPERTY
(
QString
group
READ
group
CONSTANT
)
Q_ENUMS
(
FactMetaData
::
ValueType_t
)
...
...
@@ -63,41 +64,19 @@ public:
// Property system methods
/// Read accessor for name property
QString
name
(
void
)
const
;
/// Read accessor for componentId property
int
componentId
(
void
)
const
;
/// Read accessor for value property
QVariant
value
(
void
)
const
;
/// Read accessor for valueString property
QString
valueString
(
void
)
const
;
/// Write accessor for value property
void
setValue
(
const
QVariant
&
value
);
/// Read accesor for defaultValue property
QVariant
defaultValue
(
void
);
/// Read accesor for type property
FactMetaData
::
ValueType_t
type
(
void
);
/// Read accesor for shortDescription property
QString
shortDescription
(
void
);
/// Read accesor for longDescription property
QString
longDescription
(
void
);
/// Read accesor for units property
QString
units
(
void
);
/// Read accesor for min property
QVariant
min
(
void
);
/// Read accesor for max property
QVariant
max
(
void
);
QVariant
max
(
void
);
QString
group
(
void
);
/// Sets the meta data associated with the Fact.
void
setMetaData
(
FactMetaData
*
metaData
);
...
...
src/FactSystem/FactMetaData.h
View file @
4787a4fc
...
...
@@ -57,7 +57,7 @@ public:
/// Initialize the meta data given only the type.
void
initFromTypeOnly
(
ValueType_t
initType
);
// FIXME: This needs to switch over to Q_PROPERTY mechanism
QString
group
;
ValueType_t
type
;
QVariant
defaultValue
;
QString
shortDescription
;
...
...
src/FactSystem/ParameterLoader.cc
View file @
4787a4fc
...
...
@@ -80,9 +80,6 @@ void ParameterLoader::_parameterUpdate(int uas, int componentId, QString paramet
}
if
(
!
_mapParameterName2Variant
.
contains
(
componentId
)
||
!
_mapParameterName2Variant
[
componentId
].
contains
(
parameterName
))
{
// These should not get our of sync
Q_ASSERT
(
_mapParameterName2Variant
.
contains
(
componentId
)
==
_mapFact2ParameterName
.
contains
(
componentId
));
qCDebug
(
ParameterLoaderLog
)
<<
"Adding new fact (component:"
<<
componentId
<<
"name:"
<<
parameterName
<<
")"
;
FactMetaData
::
ValueType_t
factType
;
...
...
@@ -121,7 +118,6 @@ void ParameterLoader::_parameterUpdate(int uas, int componentId, QString paramet
setMetaData
=
true
;
_mapParameterName2Variant
[
componentId
][
parameterName
]
=
QVariant
::
fromValue
(
fact
);
_mapFact2ParameterName
[
componentId
][
fact
]
=
parameterName
;
// We need to know when the fact changes from QML so that we can send the new value to the parameter manager
connect
(
fact
,
&
Fact
::
_containerValueChanged
,
this
,
&
ParameterLoader
::
_valueUpdated
);
...
...
@@ -151,8 +147,6 @@ void ParameterLoader::_valueUpdated(const QVariant& value)
int
componentId
=
fact
->
componentId
();
Q_ASSERT
(
_paramMgr
);
Q_ASSERT
(
_mapFact2ParameterName
.
contains
(
componentId
));
Q_ASSERT
(
_mapFact2ParameterName
[
componentId
].
contains
(
fact
));
QVariant
typedValue
;
switch
(
fact
->
type
())
{
...
...
@@ -196,6 +190,7 @@ void ParameterLoader::_paramMgrParameterListUpToDate(void)
qgcApp
()
->
processEvents
();
_determineDefaultComponentId
();
_setupGroupMap
();
// We should have all parameters now so we can signal ready
emit
parametersReady
();
...
...
@@ -254,7 +249,6 @@ void ParameterLoader::refreshParametersPrefix(int componentId, const QString& na
Q_ASSERT
(
_paramMgr
);
componentId
=
_actualComponentId
(
componentId
);
Q_ASSERT
(
_mapFact2ParameterName
.
contains
(
componentId
));
foreach
(
QString
name
,
_mapParameterName2Variant
[
componentId
].
keys
())
{
if
(
name
.
startsWith
(
namePrefix
))
{
refreshParameter
(
componentId
,
name
);
...
...
@@ -262,7 +256,7 @@ void ParameterLoader::refreshParametersPrefix(int componentId, const QString& na
}
}
bool
ParameterLoader
::
fact
Exists
(
int
componentId
,
const
QString
&
name
)
bool
ParameterLoader
::
parameter
Exists
(
int
componentId
,
const
QString
&
name
)
{
componentId
=
_actualComponentId
(
componentId
);
if
(
_mapParameterName2Variant
.
contains
(
componentId
))
{
...
...
@@ -280,3 +274,29 @@ Fact* ParameterLoader::getFact(int componentId, const QString& name)
Q_ASSERT
(
fact
);
return
fact
;
}
QStringList
ParameterLoader
::
parameterNames
(
void
)
{
QStringList
names
;
foreach
(
QString
paramName
,
_mapParameterName2Variant
[
_defaultComponentId
].
keys
())
{
names
<<
paramName
;
}
return
names
;
}
void
ParameterLoader
::
_setupGroupMap
(
void
)
{
foreach
(
int
componentId
,
_mapParameterName2Variant
.
keys
())
{
foreach
(
QString
name
,
_mapParameterName2Variant
[
componentId
].
keys
())
{
Fact
*
fact
=
_mapParameterName2Variant
[
componentId
][
name
].
value
<
Fact
*>
();
_mapGroup2ParameterName
[
componentId
][
fact
->
group
()]
+=
name
;
}
}
}
const
QMap
<
int
,
QMap
<
QString
,
QStringList
>
>&
ParameterLoader
::
getGroupMap
(
void
)
{
return
_mapGroup2ParameterName
;
}
src/FactSystem/ParameterLoader.h
View file @
4787a4fc
...
...
@@ -60,16 +60,22 @@ public:
/// Request a refresh on all parameters that begin with the specified prefix
void
refreshParametersPrefix
(
int
componentId
,
const
QString
&
namePrefix
);
/// Returns true if the specifed fact exists
bool
factExists
(
int
componentId
,
///< fact component, -1=default component
const
QString
&
name
);
///< fact name
/// Returns true if the specifed parameter exists
bool
parameterExists
(
int
componentId
,
///< fact component, -1=default component
const
QString
&
name
);
///< fact name
/// Returns all parameter names
/// FIXME: component id missing
QStringList
parameterNames
(
void
);
/// Returns the specified Fact.
/// WARNING: Will assert if
fact
does not exists. If that possibily exists, check for existince first with
///
fact
Exists.
/// WARNING: Will assert if
parameter
does not exists. If that possibily exists, check for existince first with
///
parameter
Exists.
Fact
*
getFact
(
int
componentId
,
///< fact component, -1=default component
const
QString
&
name
);
///< fact name
const
QMap
<
int
,
QMap
<
QString
,
QStringList
>
>&
getGroupMap
(
void
);
/// Return the parameter for which the default component id is derived from. Return an empty
/// string is this is not available.
virtual
QString
getDefaultComponentIdParam
(
void
)
const
=
0
;
...
...
@@ -92,11 +98,8 @@ private:
static
QVariant
_stringToTypedVariant
(
const
QString
&
string
,
FactMetaData
::
ValueType_t
type
,
bool
failOk
=
false
);
int
_actualComponentId
(
int
componentId
);
void
_determineDefaultComponentId
(
void
);
void
_setupGroupMap
(
void
);
/// First mapping is by component id
/// Second mapping is parameter name, to Fact
QMap
<
int
,
QMap
<
Fact
*
,
QString
>
>
_mapFact2ParameterName
;
int
_uasId
;
///< Id for uas which this set of Facts are associated with
QGCUASParamManagerInterface
*
_paramMgr
;
...
...
@@ -105,6 +108,10 @@ private:
/// Second mapping is parameter name, to Fact* in QVariant
QMap
<
int
,
QVariantMap
>
_mapParameterName2Variant
;
/// First mapping is by component id
/// Second mapping is group name, to Fact
QMap
<
int
,
QMap
<
QString
,
QStringList
>
>
_mapGroup2ParameterName
;
bool
_parametersReady
;
///< All params received from param mgr
int
_defaultComponentId
;
QString
_defaultComponentIdParam
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment