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
1c95fb26
Commit
1c95fb26
authored
Jul 01, 2020
by
DonLakeFlyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parent
ee4d1384
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
128 additions
and
9 deletions
+128
-9
qgroundcontrol.qrc
qgroundcontrol.qrc
+2
-0
ComponentInformationManager.cc
src/Vehicle/ComponentInformationManager.cc
+103
-7
ComponentInformationManager.h
src/Vehicle/ComponentInformationManager.h
+12
-2
StateMachine.cc
src/Vehicle/StateMachine.cc
+9
-0
StateMachine.h
src/Vehicle/StateMachine.h
+2
-0
No files found.
qgroundcontrol.qrc
View file @
1c95fb26
...
...
@@ -337,5 +337,7 @@
<file alias="APMArduSubMockLink.params">src/comm/APMArduSubMockLink.params</file>
<file alias="PX4MockLink.params">src/comm/PX4MockLink.params</file>
<file alias="Version.MetaData.json">src/comm/MockLink.Version.MetaData.json</file>
<file alias="Version.MetaData.json.gz">src/comm/MockLink.Version.MetaData.json.gz</file>
<file alias="Parameter.MetaData.json">src/comm/MockLink.Parameter.MetaData.json</file>
</qresource>
</RCC>
src/Vehicle/ComponentInformationManager.cc
View file @
1c95fb26
...
...
@@ -10,14 +10,21 @@
#include "ComponentInformationManager.h"
#include "Vehicle.h"
#include "FTPManager.h"
#include "QGCZlib.h"
#include "JsonHelper.h"
#include <QStandardPaths>
#include <QJsonDocument>
#include <QJsonArray>
QGC_LOGGING_CATEGORY
(
ComponentInformationManagerLog
,
"ComponentInformationManagerLog"
)
const
char
*
ComponentInformationManager
::
_jsonVersionKey
=
"version"
;
const
char
*
ComponentInformationManager
::
_jsonSupportedCompMetadataTypesKey
=
"supportedCompMetadataTypes"
;
ComponentInformationManager
::
StateFn
ComponentInformationManager
::
_rgStates
[]
=
{
ComponentInformationManager
::
_stateRequestCompInfoVersion
,
//
ComponentInformationManager::_stateRequestCompInfoParam,
ComponentInformationManager
::
_stateRequestCompInfoParam
,
ComponentInformationManager
::
_stateRequestAllCompInfoComplete
};
...
...
@@ -27,6 +34,7 @@ RequestMetaDataTypeStateMachine::StateFn RequestMetaDataTypeStateMachine::_rgSta
RequestMetaDataTypeStateMachine
::
_stateRequestCompInfo
,
RequestMetaDataTypeStateMachine
::
_stateRequestMetaDataJson
,
RequestMetaDataTypeStateMachine
::
_stateRequestTranslationJson
,
RequestMetaDataTypeStateMachine
::
_stateRequestComplete
,
};
int
RequestMetaDataTypeStateMachine
::
_cStates
=
sizeof
(
RequestMetaDataTypeStateMachine
::
_rgStates
)
/
sizeof
(
RequestMetaDataTypeStateMachine
::
_rgStates
[
0
]);
...
...
@@ -69,7 +77,12 @@ void ComponentInformationManager::_stateRequestCompInfoComplete(void)
void
ComponentInformationManager
::
_stateRequestCompInfoParam
(
StateMachine
*
stateMachine
)
{
ComponentInformationManager
*
compMgr
=
static_cast
<
ComponentInformationManager
*>
(
stateMachine
);
compMgr
->
_requestTypeStateMachine
.
request
(
COMP_METADATA_TYPE_PARAMETER
);
if
(
compMgr
->
_isCompTypeSupported
(
COMP_METADATA_TYPE_PARAMETER
))
{
compMgr
->
_requestTypeStateMachine
.
request
(
COMP_METADATA_TYPE_PARAMETER
);
}
else
{
}
}
void
ComponentInformationManager
::
_stateRequestAllCompInfoComplete
(
StateMachine
*
stateMachine
)
...
...
@@ -80,6 +93,41 @@ void ComponentInformationManager::_stateRequestAllCompInfoComplete(StateMachine*
compMgr
->
_requestAllCompleteFnData
=
nullptr
;
}
void
ComponentInformationManager
::
_compInfoJsonAvailable
(
const
QString
&
metadataJsonFileName
,
const
QString
&
translationsJsonFileName
)
{
qCDebug
(
ComponentInformationManagerLog
)
<<
"_compInfoJsonAvailable metadata:translation"
<<
metadataJsonFileName
<<
translationsJsonFileName
;
if
(
!
metadataJsonFileName
.
isEmpty
())
{
QString
errorString
;
QJsonDocument
jsonDoc
;
if
(
!
JsonHelper
::
isJsonFile
(
metadataJsonFileName
,
jsonDoc
,
errorString
))
{
qCWarning
(
ComponentInformationManagerLog
)
<<
"Version json file read failed"
<<
errorString
;
return
;
}
QJsonObject
jsonObj
=
jsonDoc
.
object
();
if
(
currentState
()
==
_stateRequestCompInfoVersion
)
{
QList
<
JsonHelper
::
KeyValidateInfo
>
keyInfoList
=
{
{
_jsonVersionKey
,
QJsonValue
::
Double
,
true
},
{
_jsonSupportedCompMetadataTypesKey
,
QJsonValue
::
Array
,
true
},
};
if
(
!
JsonHelper
::
validateKeys
(
jsonObj
,
keyInfoList
,
errorString
))
{
qCWarning
(
ComponentInformationManagerLog
)
<<
"Version json validation failed:"
<<
errorString
;
return
;
}
for
(
const
QJsonValue
&
idValue
:
jsonObj
[
_jsonSupportedCompMetadataTypesKey
].
toArray
())
{
_supportedMetaDataTypes
.
append
(
static_cast
<
COMP_METADATA_TYPE
>
(
idValue
.
toInt
()));
}
}
}
}
bool
ComponentInformationManager
::
_isCompTypeSupported
(
COMP_METADATA_TYPE
type
)
{
return
_supportedMetaDataTypes
.
contains
(
type
);
}
RequestMetaDataTypeStateMachine
::
RequestMetaDataTypeStateMachine
(
ComponentInformationManager
*
compMgr
)
:
_compMgr
(
compMgr
)
{
...
...
@@ -91,6 +139,8 @@ void RequestMetaDataTypeStateMachine::request(COMP_METADATA_TYPE type)
_compInfoAvailable
=
false
;
_type
=
type
;
_stateIndex
=
-
1
;
_jsonMetadataFileName
.
clear
();
_jsonTranslationFileName
.
clear
();
start
();
}
...
...
@@ -171,9 +221,47 @@ void RequestMetaDataTypeStateMachine::_stateRequestCompInfo(StateMachine* stateM
}
}
void
RequestMetaDataTypeStateMachine
::
_downloadComplete
(
const
QString
&
file
,
const
QString
&
errorMsg
)
QString
RequestMetaDataTypeStateMachine
::
_downloadCompleteJsonWorker
(
const
QString
&
fileName
,
const
QString
&
inflatedFileName
)
{
qCDebug
(
ComponentInformationManagerLog
)
<<
"RequestMetaDataTypeStateMachine::_downloadComplete"
<<
file
<<
errorMsg
;
QString
outputFileName
=
fileName
;
if
(
fileName
.
endsWith
(
".gz"
,
Qt
::
CaseInsensitive
))
{
outputFileName
=
(
QDir
(
QStandardPaths
::
writableLocation
(
QStandardPaths
::
TempLocation
)).
absoluteFilePath
(
inflatedFileName
));
if
(
QGCZlib
::
inflateGzipFile
(
fileName
,
outputFileName
))
{
QFile
(
fileName
).
remove
();
}
else
{
qCWarning
(
ComponentInformationManagerLog
)
<<
"Inflate of compressed json failed"
<<
inflatedFileName
;
outputFileName
.
clear
();
}
}
else
{
outputFileName
=
fileName
;
}
return
outputFileName
;
}
void
RequestMetaDataTypeStateMachine
::
_downloadCompleteMetaDataJson
(
const
QString
&
fileName
,
const
QString
&
errorMsg
)
{
qCDebug
(
ComponentInformationManagerLog
)
<<
"RequestMetaDataTypeStateMachine::_downloadCompleteMetaDataJson fileName:errorMsg"
<<
fileName
<<
errorMsg
;
if
(
errorMsg
.
isEmpty
())
{
_jsonMetadataFileName
=
_downloadCompleteJsonWorker
(
fileName
,
"metadata.json"
);
}
advance
();
}
void
RequestMetaDataTypeStateMachine
::
_downloadCompleteTranslationJson
(
const
QString
&
fileName
,
const
QString
&
errorMsg
)
{
qCDebug
(
ComponentInformationManagerLog
)
<<
"RequestMetaDataTypeStateMachine::_downloadCompleteTranslationJson fileName:errorMsg"
<<
fileName
<<
errorMsg
;
QString
jsonTranslationFileName
;
if
(
errorMsg
.
isEmpty
())
{
jsonTranslationFileName
=
_downloadCompleteJsonWorker
(
fileName
,
"translation.json"
);
}
_compMgr
->
_compInfoJsonAvailable
(
_jsonMetadataFileName
,
jsonTranslationFileName
);
advance
();
}
...
...
@@ -186,9 +274,9 @@ void RequestMetaDataTypeStateMachine::_stateRequestMetaDataJson(StateMachine* st
if
(
requestMachine
->
_compInfoAvailable
)
{
ComponentInformation_t
&
compInfo
=
requestMachine
->
_compInfo
;
qCDebug
(
ComponentInformationManagerLog
)
<<
"Downloading metadata json"
<<
compInfo
.
translation
URI
;
qCDebug
(
ComponentInformationManagerLog
)
<<
"Downloading metadata json"
<<
compInfo
.
metadata
URI
;
if
(
_uriIsFTP
(
compInfo
.
metadataURI
))
{
connect
(
ftpManager
,
&
FTPManager
::
downloadComplete
,
requestMachine
,
&
RequestMetaDataTypeStateMachine
::
_downloadComplete
);
connect
(
ftpManager
,
&
FTPManager
::
downloadComplete
,
requestMachine
,
&
RequestMetaDataTypeStateMachine
::
_downloadComplete
MetaDataJson
);
ftpManager
->
download
(
compInfo
.
metadataURI
,
QStandardPaths
::
writableLocation
(
QStandardPaths
::
TempLocation
));
}
else
{
// FIXME: NYI
...
...
@@ -214,7 +302,7 @@ void RequestMetaDataTypeStateMachine::_stateRequestTranslationJson(StateMachine*
}
else
{
qCDebug
(
ComponentInformationManagerLog
)
<<
"Downloading translation json"
<<
compInfo
.
translationURI
;
if
(
_uriIsFTP
(
compInfo
.
translationURI
))
{
connect
(
ftpManager
,
&
FTPManager
::
downloadComplete
,
requestMachine
,
&
RequestMetaDataTypeStateMachine
::
_downloadComplete
);
connect
(
ftpManager
,
&
FTPManager
::
downloadComplete
,
requestMachine
,
&
RequestMetaDataTypeStateMachine
::
_downloadComplete
TranslationJson
);
ftpManager
->
download
(
compInfo
.
metadataURI
,
QStandardPaths
::
writableLocation
(
QStandardPaths
::
TempLocation
));
}
else
{
// FIXME: NYI
...
...
@@ -227,6 +315,14 @@ void RequestMetaDataTypeStateMachine::_stateRequestTranslationJson(StateMachine*
}
}
void
RequestMetaDataTypeStateMachine
::
_stateRequestComplete
(
StateMachine
*
stateMachine
)
{
RequestMetaDataTypeStateMachine
*
requestMachine
=
static_cast
<
RequestMetaDataTypeStateMachine
*>
(
stateMachine
);
requestMachine
->
compMgr
()
->
_compInfoJsonAvailable
(
requestMachine
->
_jsonMetadataFileName
,
requestMachine
->
_jsonTranslationFileName
);
requestMachine
->
advance
();
}
bool
RequestMetaDataTypeStateMachine
::
_uriIsFTP
(
const
QString
&
uri
)
{
return
uri
.
startsWith
(
"mavlinkftp"
,
Qt
::
CaseInsensitive
);
...
...
src/Vehicle/ComponentInformationManager.h
View file @
1c95fb26
...
...
@@ -43,12 +43,15 @@ public:
void
statesCompleted
(
void
)
const
final
;
private
slots
:
void
_downloadComplete
(
const
QString
&
file
,
const
QString
&
errorMsg
);
void
_downloadCompleteMetaDataJson
(
const
QString
&
file
,
const
QString
&
errorMsg
);
void
_downloadCompleteTranslationJson
(
const
QString
&
file
,
const
QString
&
errorMsg
);
QString
_downloadCompleteJsonWorker
(
const
QString
&
jsonFileName
,
const
QString
&
inflatedFileName
);
private:
static
void
_stateRequestCompInfo
(
StateMachine
*
stateMachine
);
static
void
_stateRequestMetaDataJson
(
StateMachine
*
stateMachine
);
static
void
_stateRequestTranslationJson
(
StateMachine
*
stateMachine
);
static
void
_stateRequestComplete
(
StateMachine
*
stateMachine
);
static
bool
_uriIsFTP
(
const
QString
&
uri
);
...
...
@@ -56,6 +59,8 @@ private:
COMP_METADATA_TYPE
_type
=
COMP_METADATA_TYPE_VERSION
;
bool
_compInfoAvailable
=
false
;
ComponentInformation_t
_compInfo
;
QString
_jsonMetadataFileName
;
QString
_jsonTranslationFileName
;
static
StateFn
_rgStates
[];
static
int
_cStates
;
...
...
@@ -78,7 +83,9 @@ public:
const
StateFn
*
rgStates
(
void
)
const
final
;
private:
void
_stateRequestCompInfoComplete
(
void
);
void
_stateRequestCompInfoComplete
(
void
);
void
_compInfoJsonAvailable
(
const
QString
&
metadataJsonFileName
,
const
QString
&
translationsJsonFileName
);
bool
_isCompTypeSupported
(
COMP_METADATA_TYPE
type
);
static
void
_stateRequestCompInfoVersion
(
StateMachine
*
stateMachine
);
static
void
_stateRequestCompInfoParam
(
StateMachine
*
stateMachine
);
...
...
@@ -97,5 +104,8 @@ private:
static
StateFn
_rgStates
[];
static
int
_cStates
;
static
const
char
*
_jsonVersionKey
;
static
const
char
*
_jsonSupportedCompMetadataTypesKey
;
friend
class
RequestMetaDataTypeStateMachine
;
};
src/Vehicle/StateMachine.cc
View file @
1c95fb26
...
...
@@ -50,3 +50,12 @@ void StateMachine::statesCompleted(void) const
{
}
StateMachine
::
StateFn
StateMachine
::
currentState
(
void
)
{
if
(
_active
)
{
return
rgStates
()[
_stateIndex
];
}
else
{
return
nullptr
;
}
}
src/Vehicle/StateMachine.h
View file @
1c95fb26
...
...
@@ -29,6 +29,8 @@ public:
/// Move the state machine to the specified state and call the state function
void
move
(
StateFn
stateFn
);
StateFn
currentState
(
void
);
/// @return The number of states in the rgStates array
virtual
int
stateCount
(
void
)
const
=
0
;
...
...
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