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
bb3679d7
Commit
bb3679d7
authored
May 05, 2017
by
DonLakeFlyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support load/save/default of NaN for param
parent
8192004c
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
11 deletions
+59
-11
JsonHelper.cc
src/JsonHelper.cc
+13
-0
JsonHelper.h
src/JsonHelper.h
+17
-5
MavCmdInfoCommon.json
src/MissionManager/MavCmdInfoCommon.json
+7
-0
MissionCommandUIInfo.cc
src/MissionManager/MissionCommandUIInfo.cc
+10
-2
MissionItem.cc
src/MissionManager/MissionItem.cc
+11
-4
SimpleMissionItem.cc
src/MissionManager/SimpleMissionItem.cc
+1
-0
No files found.
src/JsonHelper.cc
View file @
bb3679d7
...
...
@@ -102,6 +102,10 @@ bool JsonHelper::validateKeyTypes(const QJsonObject& jsonObject, const QStringLi
QString
valueKey
=
keys
[
i
];
if
(
jsonObject
.
contains
(
valueKey
))
{
const
QJsonValue
&
jsonValue
=
jsonObject
[
valueKey
];
if
(
types
[
i
]
==
QJsonValue
::
Null
&&
jsonValue
.
type
()
==
QJsonValue
::
Double
)
{
// Null type signals a NaN on a double value
continue
;
}
if
(
jsonValue
.
type
()
!=
types
[
i
])
{
errorString
=
QObject
::
tr
(
"Incorrect value type - key:type:expected %1:%2:%3"
).
arg
(
valueKey
).
arg
(
_jsonValueTypeToString
(
jsonValue
.
type
())).
arg
(
_jsonValueTypeToString
(
types
[
i
]));
return
false
;
...
...
@@ -342,3 +346,12 @@ void JsonHelper::savePolygon(QmlObjectListModel& list, QJsonArray& polygonArray)
polygonArray
.
append
(
jsonValue
);
}
}
double
JsonHelper
::
possibleNaNJsonValue
(
const
QJsonValue
&
value
)
{
if
(
value
.
type
()
==
QJsonValue
::
Null
)
{
return
std
::
numeric_limits
<
double
>::
quiet_NaN
();
}
else
{
return
value
.
toDouble
();
}
}
src/JsonHelper.h
View file @
bb3679d7
...
...
@@ -34,20 +34,30 @@ public:
/// jsonFileTypeKey - Required and checked to be equal to expectedFileType
/// jsonVersionKey - Required and checked to be below supportedMajorVersion, supportedMinorVersion
/// jsonGroundStationKey - Required and checked to be string type
/// @return false: validation failed
static
bool
validateQGCJsonFile
(
const
QJsonObject
&
jsonObject
,
///<
root json object
/// @return false: validation failed
, errorString set
static
bool
validateQGCJsonFile
(
const
QJsonObject
&
jsonObject
,
///<
json object to validate
const
QString
&
expectedFileType
,
///< correct file type for file
int
minSupportedVersion
,
///< minimum supported version
int
maxSupportedVersion
,
///< maximum supported major version
int
&
version
,
///< returned file version
QString
&
errorString
);
///< returned error string if validation fails
static
bool
validateRequiredKeys
(
const
QJsonObject
&
jsonObject
,
const
QStringList
&
keys
,
QString
&
errorString
);
static
bool
validateKeyTypes
(
const
QJsonObject
&
jsonObject
,
const
QStringList
&
keys
,
const
QList
<
QJsonValue
::
Type
>&
types
,
QString
&
errorString
);
/// Validates that the specified keys are in the object
/// @return false: validation failed, errorString set
static
bool
validateRequiredKeys
(
const
QJsonObject
&
jsonObject
,
///< json object to validate
const
QStringList
&
keys
,
///< keys which are required to be present
QString
&
errorString
);
///< returned error string if validation fails
/// Validates the types of specified keys are in the object
/// @return false: validation failed, errorString set
static
bool
validateKeyTypes
(
const
QJsonObject
&
jsonObject
,
///< json object to validate
const
QStringList
&
keys
,
///< keys to validate
const
QList
<
QJsonValue
::
Type
>&
types
,
///< required type for each key, QJsonValue::Null specifies double with possible NaN
QString
&
errorString
);
///< returned error string if validation fails
typedef
struct
{
const
char
*
key
;
///< json key name
QJsonValue
::
Type
type
;
///<
type of key
QJsonValue
::
Type
type
;
///<
required type for key, QJsonValue::Null specifies double with possible NaN
bool
required
;
///< true: key must be present
}
KeyValidateInfo
;
...
...
@@ -96,6 +106,8 @@ public:
static
bool
parseEnum
(
const
QJsonObject
&
jsonObject
,
QStringList
&
enumStrings
,
QStringList
&
enumValues
,
QString
&
errorString
);
/// Returns NaN if the value is null, or it not the double value
static
double
possibleNaNJsonValue
(
const
QJsonValue
&
value
);
static
const
char
*
jsonVersionKey
;
static
const
char
*
jsonGroundStationKey
;
...
...
src/MissionManager/MavCmdInfoCommon.json
View file @
bb3679d7
...
...
@@ -54,6 +54,7 @@
"label"
:
"Heading"
,
"units"
:
"radians"
,
"nanUnchanged"
:
true
,
"default"
:
null
,
"decimalPlaces"
:
2
}
},
...
...
@@ -75,6 +76,7 @@
"label"
:
"Heading"
,
"units"
:
"radians"
,
"nanUnchanged"
:
true
,
"default"
:
null
,
"decimalPlaces"
:
2
}
},
...
...
@@ -101,6 +103,7 @@
"label"
:
"Heading"
,
"units"
:
"radians"
,
"nanUnchanged"
:
true
,
"default"
:
null
,
"decimalPlaces"
:
2
}
},
...
...
@@ -157,6 +160,7 @@
"label"
:
"Heading"
,
"units"
:
"radians"
,
"nanUnchanged"
:
true
,
"default"
:
null
,
"decimalPlaces"
:
2
}
},
...
...
@@ -178,6 +182,7 @@
"label"
:
"Heading"
,
"units"
:
"radians"
,
"nanUnchanged"
:
true
,
"default"
:
null
,
"decimalPlaces"
:
2
}
},
...
...
@@ -316,6 +321,7 @@
"label"
:
"Heading"
,
"units"
:
"deg"
,
"nanUnchanged"
:
true
,
"default"
:
null
,
"decimalPlaces"
:
2
}
},
...
...
@@ -331,6 +337,7 @@
"label"
:
"Heading"
,
"units"
:
"deg"
,
"nanUnchanged"
:
true
,
"default"
:
null
,
"decimalPlaces"
:
2
}
},
...
...
src/MissionManager/MissionCommandUIInfo.cc
View file @
bb3679d7
...
...
@@ -334,7 +334,7 @@ bool MissionCommandUIInfo::loadJsonInfo(const QJsonObject& jsonObject, bool requ
// Validate key types
QList
<
QJsonValue
::
Type
>
types
;
types
<<
QJsonValue
::
Double
<<
QJsonValue
::
Double
<<
QJsonValue
::
String
<<
QJsonValue
::
String
<<
QJsonValue
::
String
<<
QJsonValue
::
String
<<
QJsonValue
::
Bool
;
types
<<
QJsonValue
::
Null
<<
QJsonValue
::
Double
<<
QJsonValue
::
String
<<
QJsonValue
::
String
<<
QJsonValue
::
String
<<
QJsonValue
::
String
<<
QJsonValue
::
Bool
;
if
(
!
JsonHelper
::
validateKeyTypes
(
jsonObject
,
allParamKeys
,
types
,
internalError
))
{
errorString
=
_loadErrorString
(
internalError
);
return
false
;
...
...
@@ -358,7 +358,15 @@ bool MissionCommandUIInfo::loadJsonInfo(const QJsonObject& jsonObject, bool requ
paramInfo
->
_nanUnchanged
=
paramObject
.
value
(
_nanUnchangedJsonKey
).
toBool
(
false
);
if
(
paramObject
.
contains
(
_defaultJsonKey
))
{
if
(
paramInfo
->
_nanUnchanged
)
{
paramInfo
->
_defaultValue
=
JsonHelper
::
possibleNaNJsonValue
(
paramObject
[
_defaultJsonKey
]);
}
else
{
if
(
paramObject
[
_defaultJsonKey
].
type
()
==
QJsonValue
::
Null
)
{
errorString
=
QString
(
"Param %1 default value was null/NaN but NaN is not allowed"
);
return
false
;
}
paramInfo
->
_defaultValue
=
paramObject
.
value
(
_defaultJsonKey
).
toDouble
(
0.0
);
}
}
else
{
paramInfo
->
_defaultValue
=
paramInfo
->
_nanUnchanged
?
std
::
numeric_limits
<
double
>::
quiet_NaN
()
:
0
;
}
...
...
src/MissionManager/MissionItem.cc
View file @
bb3679d7
...
...
@@ -260,6 +260,13 @@ bool MissionItem::load(const QJsonObject& json, int sequenceNumber, QString& err
return
false
;
}
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
if
(
rgParams
[
i
].
type
()
!=
QJsonValue
::
Double
&&
rgParams
[
i
].
type
()
!=
QJsonValue
::
Null
)
{
errorString
=
tr
(
"Param %1 incorrect type %2, must be double or null"
).
arg
(
i
+
1
).
arg
(
rgParams
[
i
].
type
());
return
false
;
}
}
// Make sure to set these first since they can signal other changes
setFrame
((
MAV_FRAME
)
v2Json
[
_jsonFrameKey
].
toInt
());
setCommand
((
MAV_CMD
)
v2Json
[
_jsonCommandKey
].
toInt
());
...
...
@@ -280,10 +287,10 @@ bool MissionItem::load(const QJsonObject& json, int sequenceNumber, QString& err
setSequenceNumber
(
sequenceNumber
);
setAutoContinue
(
v2Json
[
_jsonAutoContinueKey
].
toBool
());
setParam1
(
rgParams
[
0
].
toDouble
(
));
setParam2
(
rgParams
[
1
].
toDouble
(
));
setParam3
(
rgParams
[
2
].
toDouble
(
));
setParam4
(
rgParams
[
3
].
toDouble
(
));
setParam1
(
JsonHelper
::
possibleNaNJsonValue
(
rgParams
[
0
]
));
setParam2
(
JsonHelper
::
possibleNaNJsonValue
(
rgParams
[
1
]
));
setParam3
(
JsonHelper
::
possibleNaNJsonValue
(
rgParams
[
2
]
));
setParam4
(
JsonHelper
::
possibleNaNJsonValue
(
rgParams
[
3
]
));
return
true
;
}
...
...
src/MissionManager/SimpleMissionItem.cc
View file @
bb3679d7
...
...
@@ -633,6 +633,7 @@ void SimpleMissionItem::setDefaultsForCommand(void)
_missionItem
.
setParam2
(
0
);
break
;
case
MAV_CMD_NAV_VTOL_LAND
:
case
MAV_CMD_NAV_LAND
:
_missionItem
.
setParam7
(
0
);
break
;
...
...
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