Browse Source

component information: rework to reflect changed MAVLink API

QGC4.4
Beat Küng 4 years ago committed by Don Gagne
parent
commit
dba07c9227
  1. 4
      custom-example/qgroundcontrol.qrc
  2. 2
      libs/mavlink/include/mavlink/v2.0
  3. 4
      qgroundcontrol.pro
  4. 4
      qgroundcontrol.qrc
  5. 3
      src/Camera/QGCCameraControl.cc
  6. 3
      src/Camera/QGCCameraIO.cc
  7. 4
      src/Vehicle/CMakeLists.txt
  8. 14
      src/Vehicle/CompInfo.cc
  9. 47
      src/Vehicle/CompInfo.h
  10. 93
      src/Vehicle/CompInfoGeneral.cc
  11. 13
      src/Vehicle/CompInfoGeneral.h
  12. 2
      src/Vehicle/CompInfoParam.cc
  13. 1
      src/Vehicle/CompInfoParam.h
  14. 65
      src/Vehicle/CompInfoVersion.cc
  15. 69
      src/Vehicle/ComponentInformationManager.cc
  16. 8
      src/Vehicle/ComponentInformationManager.h
  17. 2
      src/Vehicle/FTPManagerTest.cc
  18. 6
      src/comm/MockLink.General.MetaData.json
  19. BIN
      src/comm/MockLink.General.MetaData.json.xz
  20. 3
      src/comm/MockLink.Parameter.MetaData.json
  21. BIN
      src/comm/MockLink.Parameter.MetaData.json.xz
  22. BIN
      src/comm/MockLink.Version.MetaData.json.xz
  23. 46
      src/comm/MockLink.cc
  24. 1
      src/comm/MockLink.h
  25. 8
      src/comm/MockLinkFTP.cc

4
custom-example/qgroundcontrol.qrc

@ -334,8 +334,8 @@ @@ -334,8 +334,8 @@
<qresource prefix="/MockLink">
<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.xz">src/comm/MockLink.Version.MetaData.json.xz</file>
<file alias="General.MetaData.json">../src/comm/MockLink.General.MetaData.json</file>
<file alias="General.MetaData.json.xz">src/comm/MockLink.General.MetaData.json.xz</file>
<file alias="Parameter.MetaData.json">../src/comm/MockLink.Parameter.MetaData.json</file>
<file alias="Parameter.MetaData.json.xz">src/comm/MockLink.Parameter.MetaData.json.xz</file>
</qresource>

2
libs/mavlink/include/mavlink/v2.0

@ -1 +1 @@ @@ -1 +1 @@
Subproject commit 5637057af5ab8ec5667e3f8e5f8c73d3bc60eed8
Subproject commit 9e07c7d0b6eb91f0fd84f911dc91e68e865ba7ed

4
qgroundcontrol.pro

@ -681,7 +681,7 @@ HEADERS += \ @@ -681,7 +681,7 @@ HEADERS += \
src/TerrainTile.h \
src/Vehicle/CompInfo.h \
src/Vehicle/CompInfoParam.h \
src/Vehicle/CompInfoVersion.h \
src/Vehicle/CompInfoGeneral.h \
src/Vehicle/ComponentInformationManager.h \
src/Vehicle/FTPManager.h \
src/Vehicle/GPSRTKFactGroup.h \
@ -915,7 +915,7 @@ SOURCES += \ @@ -915,7 +915,7 @@ SOURCES += \
src/TerrainTile.cc\
src/Vehicle/CompInfo.cc \
src/Vehicle/CompInfoParam.cc \
src/Vehicle/CompInfoVersion.cc \
src/Vehicle/CompInfoGeneral.cc \
src/Vehicle/ComponentInformationManager.cc \
src/Vehicle/FTPManager.cc \
src/Vehicle/GPSRTKFactGroup.cc \

4
qgroundcontrol.qrc

@ -337,8 +337,8 @@ @@ -337,8 +337,8 @@
<qresource prefix="/MockLink">
<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.xz">src/comm/MockLink.Version.MetaData.json.xz</file>
<file alias="General.MetaData.json">src/comm/MockLink.General.MetaData.json</file>
<file alias="General.MetaData.json.xz">src/comm/MockLink.General.MetaData.json.xz</file>
<file alias="Parameter.MetaData.json.xz">src/comm/MockLink.Parameter.MetaData.json.xz</file>
<file alias="Parameter.MetaData.json">src/comm/MockLink.Parameter.MetaData.json</file>
</qresource>

3
src/Camera/QGCCameraControl.cc

@ -1183,8 +1183,7 @@ QGCCameraControl::_requestAllParameters() @@ -1183,8 +1183,7 @@ QGCCameraControl::_requestAllParameters()
sharedLink->mavlinkChannel(),
&msg,
static_cast<uint8_t>(_vehicle->id()),
static_cast<uint8_t>(compID()),
0); // trimmed messages = false
static_cast<uint8_t>(compID()));
_vehicle->sendMessageOnLinkThreadSafe(sharedLink.get(), msg);
}
qCDebug(CameraControlVerboseLog) << "Request all parameters";

3
src/Camera/QGCCameraIO.cc

@ -372,8 +372,7 @@ QGCCameraParamIO::paramRequest(bool reset) @@ -372,8 +372,7 @@ QGCCameraParamIO::paramRequest(bool reset)
static_cast<uint8_t>(_vehicle->id()),
static_cast<uint8_t>(_control->compID()),
param_id,
-1,
0); // trimmed messages = false
-1);
_vehicle->sendMessageOnLinkThreadSafe(sharedLink.get(), msg);
}
_paramRequestTimer.start();

4
src/Vehicle/CMakeLists.txt

@ -20,8 +20,8 @@ add_library(Vehicle @@ -20,8 +20,8 @@ add_library(Vehicle
CompInfo.h
CompInfoParam.cc
CompInfoParam.h
CompInfoVersion.cc
CompInfoVersion.h
CompInfoGeneral.cc
CompInfoGeneral.h
ComponentInformationManager.cc
ComponentInformationManager.h
FTPManager.cc

14
src/Vehicle/CompInfo.cc

@ -18,15 +18,9 @@ CompInfo::CompInfo(COMP_METADATA_TYPE type, uint8_t compId, Vehicle* vehicle, QO @@ -18,15 +18,9 @@ CompInfo::CompInfo(COMP_METADATA_TYPE type, uint8_t compId, Vehicle* vehicle, QO
}
void CompInfo::setMessage(const mavlink_message_t& message)
void CompInfo::setUriMetaData(const QString &uri, uint32_t crc)
{
mavlink_component_information_t componentInformation;
mavlink_msg_component_information_decode(&message, &componentInformation);
available = true;
uidMetaData = componentInformation.metadata_uid;
uidTranslation = componentInformation.translation_uid;
uriMetaData = componentInformation.metadata_uri;
uriTranslation = componentInformation.translation_uri;
_uris.uriMetaData = uri;
_uris.crcMetaData = crc;
_uris.crcMetaDataValid = true;
}

47
src/Vehicle/CompInfo.h

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
class FactMetaData;
class Vehicle;
class FirmwarePlugin;
class CompInfoGeneral;
/// Base class for all CompInfo types
class CompInfo : public QObject
@ -27,17 +28,43 @@ class CompInfo : public QObject @@ -27,17 +28,43 @@ class CompInfo : public QObject
public:
CompInfo(COMP_METADATA_TYPE type, uint8_t compId, Vehicle* vehicle, QObject* parent = nullptr);
/// Called to pass the COMPONENT_INFORMATION message in
void setMessage(const mavlink_message_t& message);
const QString& uriMetaData() const { return _uris.uriMetaData; }
const QString& uriTranslation() const { return _uris.uriTranslation; }
uint32_t crcMetaData() const { return _uris.crcMetaData; }
bool crcMetaDataValid() const { return _uris.crcMetaDataValid; }
uint32_t crcTranslation() const { return _uris.crcTranslation; }
bool crcTranslationValid() const { return _uris.crcTranslationValid; }
void setUriMetaData(const QString& uri, uint32_t crc);
virtual void setJson(const QString& metaDataJsonFileName, const QString& translationJsonFileName) = 0;
COMP_METADATA_TYPE type;
Vehicle* vehicle = nullptr;
uint8_t compId = MAV_COMP_ID_ALL;
bool available = false;
uint32_t uidMetaData = 0;
uint32_t uidTranslation = 0;
QString uriMetaData;
QString uriTranslation;
bool available() const { return !_uris.uriMetaData.isEmpty(); }
const COMP_METADATA_TYPE type;
Vehicle* const vehicle = nullptr;
const uint8_t compId = MAV_COMP_ID_ALL;
private:
friend class CompInfoGeneral;
struct Uris {
bool crcMetaDataValid = false;
bool crcMetaDataFallbackValid = false;
bool crcTranslationValid = false;
bool crcTranslationFallbackValid = false;
uint32_t crcMetaData = 0;
uint32_t crcMetaDataFallback = 0;
uint32_t crcTranslation = 0;
uint32_t crcTranslationFallback = 0;
QString uriMetaData;
QString uriMetaDataFallback;
QString uriTranslation;
QString uriTranslationFallback;
};
Uris _uris;
};

93
src/Vehicle/CompInfoGeneral.cc

@ -0,0 +1,93 @@ @@ -0,0 +1,93 @@
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#include "CompInfoGeneral.h"
#include "JsonHelper.h"
#include "FactMetaData.h"
#include "FirmwarePlugin.h"
#include "FirmwarePluginManager.h"
#include "QGCApplication.h"
#include <QStandardPaths>
#include <QJsonDocument>
#include <QJsonArray>
QGC_LOGGING_CATEGORY(CompInfoGeneralLog, "CompInfoGeneralLog")
const char* CompInfoGeneral::_jsonMetadataTypesKey = "metadataTypes";
CompInfoGeneral::CompInfoGeneral(uint8_t compId, Vehicle* vehicle, QObject* parent)
: CompInfo(COMP_METADATA_TYPE_GENERAL, compId, vehicle, parent)
{
}
void CompInfoGeneral::setUris(CompInfo &compInfo) const
{
const auto& metadataTypeIter = _supportedTypes.constFind(compInfo.type);
if (metadataTypeIter == _supportedTypes.constEnd()) {
compInfo._uris = {}; // reset
} else {
compInfo._uris = *metadataTypeIter;
}
}
void CompInfoGeneral::setJson(const QString& metadataJsonFileName, const QString& /*translationJsonFileName*/)
{
if (metadataJsonFileName.isEmpty()) {
return;
}
QString errorString;
QJsonDocument jsonDoc;
if (!JsonHelper::isJsonFile(metadataJsonFileName, jsonDoc, errorString)) {
qCWarning(CompInfoGeneralLog) << "Metadata json file open failed: compid:" << compId << errorString;
return;
}
QJsonObject jsonObj = jsonDoc.object();
QList<JsonHelper::KeyValidateInfo> keyInfoList = {
{ JsonHelper::jsonVersionKey, QJsonValue::Double, true },
{ _jsonMetadataTypesKey, QJsonValue::Array, true },
};
if (!JsonHelper::validateKeys(jsonObj, keyInfoList, errorString)) {
qCWarning(CompInfoGeneralLog) << "Metadata json validation failed: compid:" << compId << errorString;
return;
}
int version = jsonObj[JsonHelper::jsonVersionKey].toInt();
if (version != 1) {
qCWarning(CompInfoGeneralLog) << "Metadata json unsupported version" << version;
return;
}
QJsonArray rgSupportedTypes = jsonObj[_jsonMetadataTypesKey].toArray();
for (QJsonValue typeValue : rgSupportedTypes) {
int type = typeValue["type"].toInt(-1);
if (type == -1)
continue;
Uris uris;
uris.uriMetaData = typeValue["uri"].toString();
uris.crcMetaData = typeValue["fileCrc"].toVariant().toLongLong(); // Note: can't use toInt()
uris.crcMetaDataValid = typeValue.toObject().contains("fileCrc");
uris.uriMetaDataFallback = typeValue["uriFallback"].toString();
uris.crcMetaDataFallback = typeValue["fileCrcFallback"].toVariant().toLongLong();
uris.crcMetaDataFallbackValid = typeValue.toObject().contains("fileCrcFallback");
uris.uriTranslation = typeValue["translationUri"].toString();
uris.crcTranslation = typeValue["translationFileCrc"].toVariant().toLongLong();
uris.crcTranslationValid = typeValue.toObject().contains("translationFileCrc");
uris.uriTranslationFallback = typeValue["translationUriFallback"].toString();
uris.crcTranslationFallback = typeValue["translationFileCrcFallback"].toVariant().toLongLong();
uris.crcTranslationFallbackValid = typeValue.toObject().contains("translationFileCrcFallback");
_supportedTypes[(COMP_METADATA_TYPE)type] = uris;
qCDebug(CompInfoGeneralLog) << "Metadata type : uri : crc" << type << uris.uriMetaData << uris.crcMetaData;
}
}

13
src/Vehicle/CompInfoVersion.h → src/Vehicle/CompInfoGeneral.h

@ -15,27 +15,30 @@ @@ -15,27 +15,30 @@
#include "FactMetaData.h"
#include <QObject>
#include <QMap>
class FactMetaData;
class Vehicle;
class FirmwarePlugin;
Q_DECLARE_LOGGING_CATEGORY(CompInfoVersionLog)
Q_DECLARE_LOGGING_CATEGORY(CompInfoGeneralLog)
class CompInfoVersion : public CompInfo
class CompInfoGeneral : public CompInfo
{
Q_OBJECT
public:
CompInfoVersion(uint8_t compId, Vehicle* vehicle, QObject* parent = nullptr);
CompInfoGeneral(uint8_t compId, Vehicle* vehicle, QObject* parent = nullptr);
bool isMetaDataTypeSupported(COMP_METADATA_TYPE type) { return _supportedTypes.contains(type); }
void setUris(CompInfo& compInfo) const;
// Overrides from CompInfo
void setJson(const QString& metadataJsonFileName, const QString& translationJsonFileName) override;
private:
QList<COMP_METADATA_TYPE> _supportedTypes;
QMap<COMP_METADATA_TYPE, Uris> _supportedTypes;
static const char* _jsonSupportedCompMetadataTypesKey;
static const char* _jsonMetadataTypesKey;
};

2
src/Vehicle/CompInfoParam.cc

@ -20,7 +20,6 @@ @@ -20,7 +20,6 @@
QGC_LOGGING_CATEGORY(CompInfoParamLog, "CompInfoParamLog")
const char* CompInfoParam::_jsonScopeKey = "scope";
const char* CompInfoParam::_jsonParametersKey = "parameters";
const char* CompInfoParam::_cachedMetaDataFilePrefix = "ParameterFactMetaData";
const char* CompInfoParam::_indexedNameTag = "{n}";
@ -54,7 +53,6 @@ void CompInfoParam::setJson(const QString& metadataJsonFileName, const QString& @@ -54,7 +53,6 @@ void CompInfoParam::setJson(const QString& metadataJsonFileName, const QString&
QList<JsonHelper::KeyValidateInfo> keyInfoList = {
{ JsonHelper::jsonVersionKey, QJsonValue::Double, true },
{ _jsonScopeKey, QJsonValue::String, true },
{ _jsonParametersKey, QJsonValue::Array, true },
};
if (!JsonHelper::validateKeys(jsonObj, keyInfoList, errorString)) {

1
src/Vehicle/CompInfoParam.h

@ -50,7 +50,6 @@ private: @@ -50,7 +50,6 @@ private:
QObject* _opaqueParameterMetaData = nullptr;
static const char* _cachedMetaDataFilePrefix;
static const char* _jsonScopeKey;
static const char* _jsonParametersKey;
static const char* _indexedNameTag;
};

65
src/Vehicle/CompInfoVersion.cc

@ -1,65 +0,0 @@ @@ -1,65 +0,0 @@
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#include "CompInfoVersion.h"
#include "JsonHelper.h"
#include "FactMetaData.h"
#include "FirmwarePlugin.h"
#include "FirmwarePluginManager.h"
#include "QGCApplication.h"
#include <QStandardPaths>
#include <QJsonDocument>
#include <QJsonArray>
QGC_LOGGING_CATEGORY(CompInfoVersionLog, "CompInfoVersionLog")
const char* CompInfoVersion::_jsonSupportedCompMetadataTypesKey = "supportedCompMetadataTypes";
CompInfoVersion::CompInfoVersion(uint8_t compId, Vehicle* vehicle, QObject* parent)
: CompInfo (COMP_METADATA_TYPE_VERSION, compId, vehicle, parent)
{
}
void CompInfoVersion::setJson(const QString& metadataJsonFileName, const QString& /*translationJsonFileName*/)
{
if (metadataJsonFileName.isEmpty()) {
return;
}
QString errorString;
QJsonDocument jsonDoc;
if (!JsonHelper::isJsonFile(metadataJsonFileName, jsonDoc, errorString)) {
qCWarning(CompInfoVersionLog) << "Metadata json file open failed: compid:" << compId << errorString;
return;
}
QJsonObject jsonObj = jsonDoc.object();
QList<JsonHelper::KeyValidateInfo> keyInfoList = {
{ JsonHelper::jsonVersionKey, QJsonValue::Double, true },
{ _jsonSupportedCompMetadataTypesKey, QJsonValue::Array, true },
};
if (!JsonHelper::validateKeys(jsonObj, keyInfoList, errorString)) {
qCWarning(CompInfoVersionLog) << "Metadata json validation failed: compid:" << compId << errorString;
return;
}
int version = jsonObj[JsonHelper::jsonVersionKey].toInt();
if (version != 1) {
qCWarning(CompInfoVersionLog) << "Metadata json unsupported version" << version;
return;
}
QJsonArray rgSupportedTypes = jsonObj[_jsonSupportedCompMetadataTypesKey].toArray();
for (QJsonValue typeValue: rgSupportedTypes) {
_supportedTypes.append(static_cast<COMP_METADATA_TYPE>(typeValue.toInt()));
}
}

69
src/Vehicle/ComponentInformationManager.cc

@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
#include "FTPManager.h"
#include "QGCLZMA.h"
#include "JsonHelper.h"
#include "CompInfoVersion.h"
#include "CompInfoGeneral.h"
#include "CompInfoParam.h"
#include "QGCFileDownload.h"
#include "QGCApplication.h"
@ -26,7 +26,8 @@ @@ -26,7 +26,8 @@
QGC_LOGGING_CATEGORY(ComponentInformationManagerLog, "ComponentInformationManagerLog")
ComponentInformationManager::StateFn ComponentInformationManager::_rgStates[]= {
ComponentInformationManager::_stateRequestCompInfoVersion,
ComponentInformationManager::_stateRequestCompInfoGeneral,
ComponentInformationManager::_stateRequestCompInfoGeneralComplete,
ComponentInformationManager::_stateRequestCompInfoParam,
ComponentInformationManager::_stateRequestAllCompInfoComplete
};
@ -46,7 +47,7 @@ ComponentInformationManager::ComponentInformationManager(Vehicle* vehicle) @@ -46,7 +47,7 @@ ComponentInformationManager::ComponentInformationManager(Vehicle* vehicle)
: _vehicle (vehicle)
, _requestTypeStateMachine (this)
{
_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_VERSION] = new CompInfoVersion (MAV_COMP_ID_AUTOPILOT1, vehicle, this);
_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_GENERAL] = new CompInfoGeneral (MAV_COMP_ID_AUTOPILOT1, vehicle, this);
_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_PARAMETER] = new CompInfoParam (MAV_COMP_ID_AUTOPILOT1, vehicle, this);
}
@ -67,10 +68,25 @@ void ComponentInformationManager::requestAllComponentInformation(RequestAllCompl @@ -67,10 +68,25 @@ void ComponentInformationManager::requestAllComponentInformation(RequestAllCompl
start();
}
void ComponentInformationManager::_stateRequestCompInfoVersion(StateMachine* stateMachine)
void ComponentInformationManager::_stateRequestCompInfoGeneral(StateMachine* stateMachine)
{
ComponentInformationManager* compMgr = static_cast<ComponentInformationManager*>(stateMachine);
compMgr->_requestTypeStateMachine.request(compMgr->_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_VERSION]);
compMgr->_requestTypeStateMachine.request(compMgr->_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_GENERAL]);
}
void ComponentInformationManager::_stateRequestCompInfoGeneralComplete(StateMachine* stateMachine)
{
ComponentInformationManager* compMgr = static_cast<ComponentInformationManager*>(stateMachine);
compMgr->_updateAllUri();
compMgr->advance();
}
void ComponentInformationManager::_updateAllUri()
{
CompInfoGeneral* general = qobject_cast<CompInfoGeneral*>(_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_GENERAL]);
for (auto& compInfo : _compInfoMap[MAV_COMP_ID_AUTOPILOT1]) {
general->setUris(*compInfo);
}
}
void ComponentInformationManager::_stateRequestCompInfoComplete(void)
@ -100,7 +116,7 @@ void ComponentInformationManager::_stateRequestAllCompInfoComplete(StateMachine* @@ -100,7 +116,7 @@ void ComponentInformationManager::_stateRequestAllCompInfoComplete(StateMachine*
bool ComponentInformationManager::_isCompTypeSupported(COMP_METADATA_TYPE type)
{
return qobject_cast<CompInfoVersion*>(_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_VERSION])->isMetaDataTypeSupported(type);
return qobject_cast<CompInfoGeneral*>(_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_GENERAL])->isMetaDataTypeSupported(type);
}
CompInfoParam* ComponentInformationManager::compInfoParam(uint8_t compId)
@ -112,9 +128,9 @@ CompInfoParam* ComponentInformationManager::compInfoParam(uint8_t compId) @@ -112,9 +128,9 @@ CompInfoParam* ComponentInformationManager::compInfoParam(uint8_t compId)
return qobject_cast<CompInfoParam*>(_compInfoMap[compId][COMP_METADATA_TYPE_PARAMETER]);
}
CompInfoVersion* ComponentInformationManager::compInfoVersion(uint8_t compId)
CompInfoGeneral* ComponentInformationManager::compInfoGeneral(uint8_t compId)
{
return _compInfoMap.contains(compId) && _compInfoMap[compId].contains(COMP_METADATA_TYPE_VERSION) ? qobject_cast<CompInfoVersion*>(_compInfoMap[compId][COMP_METADATA_TYPE_VERSION]) : nullptr;
return _compInfoMap.contains(compId) && _compInfoMap[compId].contains(COMP_METADATA_TYPE_GENERAL) ? qobject_cast<CompInfoGeneral*>(_compInfoMap[compId][COMP_METADATA_TYPE_GENERAL]) : nullptr;
}
RequestMetaDataTypeStateMachine::RequestMetaDataTypeStateMachine(ComponentInformationManager* compMgr)
@ -150,7 +166,7 @@ void RequestMetaDataTypeStateMachine::statesCompleted(void) const @@ -150,7 +166,7 @@ void RequestMetaDataTypeStateMachine::statesCompleted(void) const
QString RequestMetaDataTypeStateMachine::typeToString(void)
{
return _compInfo->type == COMP_METADATA_TYPE_VERSION ? "COMP_METADATA_TYPE_VERSION" : "COMP_METADATA_TYPE_PARAM";
return _compInfo->type == COMP_METADATA_TYPE_GENERAL ? "COMP_METADATA_TYPE_GENERAL" : "COMP_METADATA_TYPE_PARAM";
}
static void _requestMessageResultHandler(void* resultHandlerData, MAV_RESULT result, Vehicle::RequestMessageResultHandlerFailureCode_t failureCode, const mavlink_message_t &message)
@ -158,7 +174,10 @@ static void _requestMessageResultHandler(void* resultHandlerData, MAV_RESULT res @@ -158,7 +174,10 @@ static void _requestMessageResultHandler(void* resultHandlerData, MAV_RESULT res
RequestMetaDataTypeStateMachine* requestMachine = static_cast<RequestMetaDataTypeStateMachine*>(resultHandlerData);
if (result == MAV_RESULT_ACCEPTED) {
requestMachine->compInfo()->setMessage(message);
mavlink_component_information_t componentInformation;
mavlink_msg_component_information_decode(&message, &componentInformation);
requestMachine->compInfo()->setUriMetaData(componentInformation.general_metadata_uri, componentInformation.general_metadata_file_crc);
// TODO: handle peripherals
} else {
switch (failureCode) {
case Vehicle::RequestMessageFailureCommandError:
@ -183,6 +202,11 @@ void RequestMetaDataTypeStateMachine::_stateRequestCompInfo(StateMachine* stateM @@ -183,6 +202,11 @@ void RequestMetaDataTypeStateMachine::_stateRequestCompInfo(StateMachine* stateM
Vehicle* vehicle = requestMachine->_compMgr->vehicle();
WeakLinkInterfacePtr weakLink = vehicle->vehicleLinkManager()->primaryLink();
if (requestMachine->_compInfo->type != COMP_METADATA_TYPE_GENERAL) {
requestMachine->advance();
return;
}
if (weakLink.expired()) {
qCDebug(ComponentInformationManagerLog) << QStringLiteral("_stateRequestCompInfo Skipping component information %1 request due to no primary link").arg(requestMachine->typeToString());
stateMachine->advance();
@ -200,8 +224,7 @@ void RequestMetaDataTypeStateMachine::_stateRequestCompInfo(StateMachine* stateM @@ -200,8 +224,7 @@ void RequestMetaDataTypeStateMachine::_stateRequestCompInfo(StateMachine* stateM
_requestMessageResultHandler,
stateMachine,
MAV_COMP_ID_AUTOPILOT1,
MAVLINK_MSG_ID_COMPONENT_INFORMATION,
requestMachine->_compInfo->type);
MAVLINK_MSG_ID_COMPONENT_INFORMATION);
}
}
}
@ -295,11 +318,11 @@ void RequestMetaDataTypeStateMachine::_stateRequestMetaDataJson(StateMachine* st @@ -295,11 +318,11 @@ void RequestMetaDataTypeStateMachine::_stateRequestMetaDataJson(StateMachine* st
CompInfo* compInfo = requestMachine->compInfo();
FTPManager* ftpManager = compInfo->vehicle->ftpManager();
if (compInfo->available) {
qCDebug(ComponentInformationManagerLog) << "Downloading metadata json" << compInfo->uriMetaData;
if (_uriIsMAVLinkFTP(compInfo->uriMetaData)) {
if (compInfo->available()) {
qCDebug(ComponentInformationManagerLog) << "Downloading metadata json" << compInfo->uriMetaData();
if (_uriIsMAVLinkFTP(compInfo->uriMetaData())) {
connect(ftpManager, &FTPManager::downloadComplete, requestMachine, &RequestMetaDataTypeStateMachine::_ftpDownloadCompleteMetaDataJson);
if (!ftpManager->download(compInfo->uriMetaData, QStandardPaths::writableLocation(QStandardPaths::TempLocation))) {
if (!ftpManager->download(compInfo->uriMetaData(), QStandardPaths::writableLocation(QStandardPaths::TempLocation))) {
qCWarning(ComponentInformationManagerLog) << "RequestMetaDataTypeStateMachine::_stateRequestMetaDataJson FTPManager::download returned failure";
disconnect(ftpManager, &FTPManager::downloadComplete, requestMachine, &RequestMetaDataTypeStateMachine::_ftpDownloadCompleteMetaDataJson);
requestMachine->advance();
@ -307,7 +330,7 @@ void RequestMetaDataTypeStateMachine::_stateRequestMetaDataJson(StateMachine* st @@ -307,7 +330,7 @@ void RequestMetaDataTypeStateMachine::_stateRequestMetaDataJson(StateMachine* st
} else {
QGCFileDownload* download = new QGCFileDownload(requestMachine);
connect(download, &QGCFileDownload::downloadComplete, requestMachine, &RequestMetaDataTypeStateMachine::_httpDownloadCompleteMetaDataJson);
if (!download->download(compInfo->uriMetaData)) {
if (!download->download(compInfo->uriMetaData())) {
qCWarning(ComponentInformationManagerLog) << "RequestMetaDataTypeStateMachine::_stateRequestMetaDataJson QGCFileDownload::download returned failure";
disconnect(download, &QGCFileDownload::downloadComplete, requestMachine, &RequestMetaDataTypeStateMachine::_httpDownloadCompleteMetaDataJson);
requestMachine->advance();
@ -325,15 +348,15 @@ void RequestMetaDataTypeStateMachine::_stateRequestTranslationJson(StateMachine* @@ -325,15 +348,15 @@ void RequestMetaDataTypeStateMachine::_stateRequestTranslationJson(StateMachine*
CompInfo* compInfo = requestMachine->compInfo();
FTPManager* ftpManager = compInfo->vehicle->ftpManager();
if (compInfo->available) {
if (compInfo->uriTranslation.isEmpty()) {
if (compInfo->available()) {
if (compInfo->uriTranslation().isEmpty()) {
qCDebug(ComponentInformationManagerLog) << "Skipping translation json download. No translation json specified";
requestMachine->advance();
} else {
qCDebug(ComponentInformationManagerLog) << "Downloading translation json" << compInfo->uriTranslation;
if (_uriIsMAVLinkFTP(compInfo->uriTranslation)) {
qCDebug(ComponentInformationManagerLog) << "Downloading translation json" << compInfo->uriTranslation();
if (_uriIsMAVLinkFTP(compInfo->uriTranslation())) {
connect(ftpManager, &FTPManager::downloadComplete, requestMachine, &RequestMetaDataTypeStateMachine::_ftpDownloadCompleteTranslationJson);
if (!ftpManager->download(compInfo->uriTranslation, QStandardPaths::writableLocation(QStandardPaths::TempLocation))) {
if (!ftpManager->download(compInfo->uriTranslation(), QStandardPaths::writableLocation(QStandardPaths::TempLocation))) {
qCWarning(ComponentInformationManagerLog) << "_stateRequestTranslationJson::_stateRequestMetaDataJson FTPManager::download returned failure";
connect(ftpManager, &FTPManager::downloadComplete, requestMachine, &RequestMetaDataTypeStateMachine::_ftpDownloadCompleteTranslationJson);
requestMachine->advance();
@ -341,7 +364,7 @@ void RequestMetaDataTypeStateMachine::_stateRequestTranslationJson(StateMachine* @@ -341,7 +364,7 @@ void RequestMetaDataTypeStateMachine::_stateRequestTranslationJson(StateMachine*
} else {
QGCFileDownload* download = new QGCFileDownload(requestMachine);
connect(download, &QGCFileDownload::downloadComplete, requestMachine, &RequestMetaDataTypeStateMachine::_httpDownloadCompleteTranslationJson);
if (!download->download(compInfo->uriTranslation)) {
if (!download->download(compInfo->uriTranslation())) {
qCWarning(ComponentInformationManagerLog) << "_stateRequestTranslationJson::_stateRequestMetaDataJson QGCFileDownload::download returned failure";
disconnect(download, &QGCFileDownload::downloadComplete, requestMachine, &RequestMetaDataTypeStateMachine::_httpDownloadCompleteTranslationJson);
requestMachine->advance();

8
src/Vehicle/ComponentInformationManager.h

@ -19,7 +19,7 @@ class Vehicle; @@ -19,7 +19,7 @@ class Vehicle;
class ComponentInformationManager;
class CompInfo;
class CompInfoParam;
class CompInfoVersion;
class CompInfoGeneral;
class RequestMetaDataTypeStateMachine : public StateMachine
{
@ -73,7 +73,7 @@ public: @@ -73,7 +73,7 @@ public:
void requestAllComponentInformation (RequestAllCompleteFn requestAllCompletFn, void * requestAllCompleteFnData);
Vehicle* vehicle (void) { return _vehicle; }
CompInfoParam* compInfoParam (uint8_t compId);
CompInfoVersion* compInfoVersion (uint8_t compId);
CompInfoGeneral* compInfoGeneral (uint8_t compId);
// Overrides from StateMachine
int stateCount (void) const final;
@ -82,8 +82,10 @@ public: @@ -82,8 +82,10 @@ public:
private:
void _stateRequestCompInfoComplete (void);
bool _isCompTypeSupported (COMP_METADATA_TYPE type);
void _updateAllUri ();
static void _stateRequestCompInfoVersion (StateMachine* stateMachine);
static void _stateRequestCompInfoGeneral (StateMachine* stateMachine);
static void _stateRequestCompInfoGeneralComplete(StateMachine* stateMachine);
static void _stateRequestCompInfoParam (StateMachine* stateMachine);
static void _stateRequestAllCompInfoComplete (StateMachine* stateMachine);

2
src/Vehicle/FTPManagerTest.cc

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
#include "FTPManager.h"
const FTPManagerTest::TestCase_t FTPManagerTest::_rgTestCases[] = {
{ "/version.json" },
{ "/general.json" },
};
void FTPManagerTest::cleanup(void)

6
src/comm/MockLink.Version.MetaData.json → src/comm/MockLink.General.MetaData.json

@ -4,5 +4,7 @@ @@ -4,5 +4,7 @@
"modelName": "QGC MockLink Model",
"firmwareVersion": "1.0.0",
"hardwareVersion": "1.0.0",
"supportedCompMetadataTypes": [ 0, 1 ]
}
"metadataTypes": [
{"type": 1, "uri": "mftp://[;comp=1]parameter.json.xz", "fileCrc": 1}
]
}

BIN
src/comm/MockLink.General.MetaData.json.xz

Binary file not shown.

3
src/comm/MockLink.Parameter.MetaData.json

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
{
"version": 1,
"scope": "Firmware",
"parameters": [
{
"name": "ctl_bw",
@ -20633,4 +20632,4 @@ @@ -20633,4 +20632,4 @@
"shortDesc": "RV_YAW_P"
}
]
}
}

BIN
src/comm/MockLink.Parameter.MetaData.json.xz

Binary file not shown.

BIN
src/comm/MockLink.Version.MetaData.json.xz

Binary file not shown.

46
src/comm/MockLink.cc

@ -1576,14 +1576,8 @@ bool MockLink::_handleRequestMessage(const mavlink_command_long_t& request, bool @@ -1576,14 +1576,8 @@ bool MockLink::_handleRequestMessage(const mavlink_command_long_t& request, bool
switch ((int)request.param1) {
case MAVLINK_MSG_ID_COMPONENT_INFORMATION:
if (_firmwareType == MAV_AUTOPILOT_PX4) {
switch (static_cast<int>(request.param2)) {
case COMP_METADATA_TYPE_VERSION:
_sendVersionMetaData();
return true;
case COMP_METADATA_TYPE_PARAMETER:
_sendParameterMetaData();
return true;
}
_sendVersionMetaData();
return true;
}
break;
case MAVLINK_MSG_ID_DEBUG:
@ -1619,45 +1613,21 @@ void MockLink::_sendVersionMetaData(void) @@ -1619,45 +1613,21 @@ void MockLink::_sendVersionMetaData(void)
{
mavlink_message_t responseMsg;
#if 1
char metaDataURI[MAVLINK_MSG_COMPONENT_INFORMATION_FIELD_METADATA_URI_LEN] = "mftp://[;comp=1]version.json";
char metaDataURI[MAVLINK_MSG_COMPONENT_INFORMATION_FIELD_GENERAL_METADATA_URI_LEN] = "mftp://[;comp=1]general.json";
#else
char metaDataURI[MAVLINK_MSG_COMPONENT_INFORMATION_FIELD_METADATA_URI_LEN] = "https://bit.ly/31nm0fs";
char metaDataURI[MAVLINK_MSG_COMPONENT_INFORMATION_FIELD_GENERAL_METADATA_URI_LEN] = "https://bit.ly/31nm0fs";
#endif
char translationURI[MAVLINK_MSG_COMPONENT_INFORMATION_FIELD_TRANSLATION_URI_LEN] = "";
char peripheralsMetaDataURI[MAVLINK_MSG_COMPONENT_INFORMATION_FIELD_PERIPHERALS_METADATA_URI_LEN] = "https://bit.ly/31nm0fs";
mavlink_msg_component_information_pack_chan(_vehicleSystemId,
_vehicleComponentId,
_mavlinkChannel,
&responseMsg,
0, // time_boot_ms
COMP_METADATA_TYPE_VERSION,
1, // comp_metadata_uid
metaDataURI,
0, // comp_translation_uid
translationURI);
respondWithMavlinkMessage(responseMsg);
}
void MockLink::_sendParameterMetaData(void)
{
mavlink_message_t responseMsg;
#if 1
char metaDataURI[MAVLINK_MSG_COMPONENT_INFORMATION_FIELD_METADATA_URI_LEN] = "mftp://[;comp=1]parameter.json.xz";
#else
char metaDataURI[MAVLINK_MSG_COMPONENT_INFORMATION_FIELD_METADATA_URI_LEN] = "https://bit.ly/2ZKRIRE";
#endif
char translationURI[MAVLINK_MSG_COMPONENT_INFORMATION_FIELD_TRANSLATION_URI_LEN] = "";
mavlink_msg_component_information_pack_chan(_vehicleSystemId,
_vehicleComponentId,
_mavlinkChannel,
&responseMsg,
0, // time_boot_ms
COMP_METADATA_TYPE_PARAMETER,
1, // comp_metadata_uid
100, // general_metadata_file_crc
metaDataURI,
0, // comp_translation_uid
translationURI);
0, // peripherals_metadata_file_crc
peripheralsMetaDataURI);
respondWithMavlinkMessage(responseMsg);
}

1
src/comm/MockLink.h

@ -228,7 +228,6 @@ private: @@ -228,7 +228,6 @@ private:
void _sendADSBVehicles (void);
void _moveADSBVehicle (void);
void _sendVersionMetaData (void);
void _sendParameterMetaData (void);
static MockLink* _startMockLinkWorker(QString configName, MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType, bool sendStatusText, MockConfiguration::FailureMode_t failureMode);
static MockLink* _startMockLink(MockConfiguration* mockConfig);

8
src/comm/MockLinkFTP.cc

@ -117,10 +117,10 @@ void MockLinkFTP::_openCommand(uint8_t senderSystemId, uint8_t senderComponentId @@ -117,10 +117,10 @@ void MockLinkFTP::_openCommand(uint8_t senderSystemId, uint8_t senderComponentId
if (path.startsWith(sizePrefix)) {
QString sizeString = path.right(path.length() - sizePrefix.length());
tmpFilename = _createTestTempFile(sizeString.toInt());
} else if (path == "/version.json") {
tmpFilename = ":MockLink/Version.MetaData.json";
} else if (path == "/version.json.xz") {
tmpFilename = ":MockLink/Version.MetaData.json.xz";
} else if (path == "/general.json") {
tmpFilename = ":MockLink/General.MetaData.json";
} else if (path == "/general.json.xz") {
tmpFilename = ":MockLink/General.MetaData.json.xz";
} else if (path == "/parameter.json") {
tmpFilename = ":MockLink/Parameter.MetaData.json";
} else if (path == "/parameter.json.xz") {

Loading…
Cancel
Save