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
78115454
Commit
78115454
authored
Jun 25, 2017
by
Don Gagne
Committed by
GitHub
Jun 25, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5339 from DonLakeFlyer/V3MissionItemFormat
New V3 format for mission items
parents
988ffbee
4a36f9d5
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
213 additions
and
100 deletions
+213
-100
MissionItem.cc
src/MissionManager/MissionItem.cc
+53
-27
MissionItem.h
src/MissionManager/MissionItem.h
+4
-1
MissionItemTest.cc
src/MissionManager/MissionItemTest.cc
+150
-71
MissionItemTest.h
src/MissionManager/MissionItemTest.h
+6
-1
No files found.
src/MissionManager/MissionItem.cc
View file @
78115454
...
...
@@ -162,12 +162,8 @@ void MissionItem::save(QJsonObject& json) const
json
[
_jsonAutoContinueKey
]
=
autoContinue
();
json
[
_jsonDoJumpIdKey
]
=
_sequenceNumber
;
QJsonArray
rgParams
=
{
param1
(),
param2
(),
param3
(),
param4
()
};
QJsonArray
rgParams
=
{
param1
(),
param2
(),
param3
(),
param4
()
,
param5
(),
param6
(),
param7
()
};
json
[
_jsonParamsKey
]
=
rgParams
;
QJsonValue
coordinateValue
;
JsonHelper
::
saveGeoCoordinate
(
QGeoCoordinate
(
param5
(),
param6
(),
param7
()),
true
/* writeAltitude */
,
coordinateValue
);
json
[
_jsonCoordinateKey
]
=
coordinateValue
;
}
bool
MissionItem
::
load
(
QTextStream
&
loadStream
)
...
...
@@ -229,10 +225,46 @@ bool MissionItem::_convertJsonV1ToV2(const QJsonObject& json, QJsonObject& v2Jso
return
true
;
}
bool
MissionItem
::
_convertJsonV2ToV3
(
QJsonObject
&
json
,
QString
&
errorString
)
{
// V2 format: param 5/6/7 stored in GeoCoordinate
// V3 format: param 5/6/7 stored in params array
if
(
!
json
.
contains
(
_jsonCoordinateKey
))
{
// Already V3 format
return
true
;
}
QList
<
JsonHelper
::
KeyValidateInfo
>
keyInfoList
=
{
{
_jsonCoordinateKey
,
QJsonValue
::
Array
,
true
},
};
if
(
!
JsonHelper
::
validateKeys
(
json
,
keyInfoList
,
errorString
))
{
return
false
;
}
QGeoCoordinate
coordinate
;
if
(
!
JsonHelper
::
loadGeoCoordinate
(
json
[
_jsonCoordinateKey
],
true
/* altitudeRequired */
,
coordinate
,
errorString
))
{
return
false
;
}
QJsonArray
rgParam
=
json
[
_jsonParamsKey
].
toArray
();
rgParam
.
append
(
coordinate
.
latitude
());
rgParam
.
append
(
coordinate
.
longitude
());
rgParam
.
append
(
coordinate
.
altitude
());
json
[
_jsonParamsKey
]
=
rgParam
;
json
.
remove
(
_jsonCoordinateKey
);
return
true
;
}
bool
MissionItem
::
load
(
const
QJsonObject
&
json
,
int
sequenceNumber
,
QString
&
errorString
)
{
QJsonObject
v2Json
;
if
(
!
_convertJsonV1ToV2
(
json
,
v2Json
,
errorString
))
{
QJsonObject
convertedJson
;
if
(
!
_convertJsonV1ToV2
(
json
,
convertedJson
,
errorString
))
{
return
false
;
}
if
(
!
_convertJsonV2ToV3
(
convertedJson
,
errorString
))
{
return
false
;
}
...
...
@@ -242,21 +274,20 @@ bool MissionItem::load(const QJsonObject& json, int sequenceNumber, QString& err
{
_jsonCommandKey
,
QJsonValue
::
Double
,
true
},
{
_jsonParamsKey
,
QJsonValue
::
Array
,
true
},
{
_jsonAutoContinueKey
,
QJsonValue
::
Bool
,
true
},
{
_jsonCoordinateKey
,
QJsonValue
::
Array
,
true
},
{
_jsonDoJumpIdKey
,
QJsonValue
::
Double
,
false
},
};
if
(
!
JsonHelper
::
validateKeys
(
v2
Json
,
keyInfoList
,
errorString
))
{
if
(
!
JsonHelper
::
validateKeys
(
converted
Json
,
keyInfoList
,
errorString
))
{
return
false
;
}
if
(
v2
Json
[
VisualMissionItem
::
jsonTypeKey
]
!=
VisualMissionItem
::
jsonTypeSimpleItemValue
)
{
errorString
=
tr
(
"Type found: %1 must be: %2"
).
arg
(
v2
Json
[
VisualMissionItem
::
jsonTypeKey
].
toString
()).
arg
(
VisualMissionItem
::
jsonTypeSimpleItemValue
);
if
(
converted
Json
[
VisualMissionItem
::
jsonTypeKey
]
!=
VisualMissionItem
::
jsonTypeSimpleItemValue
)
{
errorString
=
tr
(
"Type found: %1 must be: %2"
).
arg
(
converted
Json
[
VisualMissionItem
::
jsonTypeKey
].
toString
()).
arg
(
VisualMissionItem
::
jsonTypeSimpleItemValue
);
return
false
;
}
QJsonArray
rgParams
=
v2
Json
[
_jsonParamsKey
].
toArray
();
if
(
rgParams
.
count
()
!=
4
)
{
errorString
=
tr
(
"%1 key must contains
4
values"
).
arg
(
_jsonParamsKey
);
QJsonArray
rgParams
=
converted
Json
[
_jsonParamsKey
].
toArray
();
if
(
rgParams
.
count
()
!=
7
)
{
errorString
=
tr
(
"%1 key must contains
7
values"
).
arg
(
_jsonParamsKey
);
return
false
;
}
...
...
@@ -268,29 +299,24 @@ bool MissionItem::load(const QJsonObject& json, int sequenceNumber, QString& err
}
// Make sure to set these first since they can signal other changes
setFrame
((
MAV_FRAME
)
v2Json
[
_jsonFrameKey
].
toInt
());
setCommand
((
MAV_CMD
)
v2Json
[
_jsonCommandKey
].
toInt
());
QGeoCoordinate
coordinate
;
if
(
!
JsonHelper
::
loadGeoCoordinate
(
v2Json
[
_jsonCoordinateKey
],
true
/* altitudeRequired */
,
coordinate
,
errorString
))
{
return
false
;
}
setParam5
(
coordinate
.
latitude
());
setParam6
(
coordinate
.
longitude
());
setParam7
(
coordinate
.
altitude
());
setFrame
((
MAV_FRAME
)
convertedJson
[
_jsonFrameKey
].
toInt
());
setCommand
((
MAV_CMD
)
convertedJson
[
_jsonCommandKey
].
toInt
());
_doJumpId
=
-
1
;
if
(
v2
Json
.
contains
(
_jsonDoJumpIdKey
))
{
_doJumpId
=
v2
Json
[
_jsonDoJumpIdKey
].
toInt
();
if
(
converted
Json
.
contains
(
_jsonDoJumpIdKey
))
{
_doJumpId
=
converted
Json
[
_jsonDoJumpIdKey
].
toInt
();
}
setIsCurrentItem
(
false
);
setSequenceNumber
(
sequenceNumber
);
setAutoContinue
(
v2
Json
[
_jsonAutoContinueKey
].
toBool
());
setAutoContinue
(
converted
Json
[
_jsonAutoContinueKey
].
toBool
());
setParam1
(
JsonHelper
::
possibleNaNJsonValue
(
rgParams
[
0
]));
setParam2
(
JsonHelper
::
possibleNaNJsonValue
(
rgParams
[
1
]));
setParam3
(
JsonHelper
::
possibleNaNJsonValue
(
rgParams
[
2
]));
setParam4
(
JsonHelper
::
possibleNaNJsonValue
(
rgParams
[
3
]));
setParam5
(
JsonHelper
::
possibleNaNJsonValue
(
rgParams
[
4
]));
setParam6
(
JsonHelper
::
possibleNaNJsonValue
(
rgParams
[
5
]));
setParam7
(
JsonHelper
::
possibleNaNJsonValue
(
rgParams
[
6
]));
return
true
;
}
...
...
src/MissionManager/MissionItem.h
View file @
78115454
...
...
@@ -114,6 +114,7 @@ private slots:
private:
bool
_convertJsonV1ToV2
(
const
QJsonObject
&
json
,
QJsonObject
&
v2Json
,
QString
&
errorString
);
bool
_convertJsonV2ToV3
(
QJsonObject
&
json
,
QString
&
errorString
);
int
_sequenceNumber
;
int
_doJumpId
;
...
...
@@ -134,10 +135,12 @@ private:
static
const
char
*
_jsonFrameKey
;
static
const
char
*
_jsonCommandKey
;
static
const
char
*
_jsonAutoContinueKey
;
static
const
char
*
_jsonCoordinateKey
;
static
const
char
*
_jsonParamsKey
;
static
const
char
*
_jsonDoJumpIdKey
;
// Deprecated V2 format keys
static
const
char
*
_jsonCoordinateKey
;
// Deprecated V1 format keys
static
const
char
*
_jsonParam1Key
;
static
const
char
*
_jsonParam2Key
;
...
...
src/MissionManager/MissionItemTest.cc
View file @
78115454
This diff is collapsed.
Click to expand it.
src/MissionManager/MissionItemTest.h
View file @
78115454
...
...
@@ -35,11 +35,16 @@ private slots:
void
_testSimpleLoadFromStream
(
void
);
void
_testLoadFromJsonV1
(
void
);
void
_testLoadFromJsonV2
(
void
);
void
_testLoadFromJsonV3
(
void
);
void
_testLoadFromJsonV3NaN
(
void
);
void
_testSimpleLoadFromJson
(
void
);
void
_testSaveToJson
(
void
);
private:
void
_checkExpectedMissionItem
(
const
MissionItem
&
missionItem
);
void
_checkExpectedMissionItem
(
const
MissionItem
&
missionItem
,
bool
allNaNs
=
false
);
QJsonObject
_createV1Json
(
void
);
QJsonObject
_createV2Json
(
void
);
QJsonObject
_createV3Json
(
bool
allNaNs
=
false
);
int
_seq
=
10
;
Vehicle
*
_offlineVehicle
;
...
...
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