Unverified Commit 74fb1dae authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #8924 from DonLakeFlyer/FirmwareVehicleClass

Support for Vehicle and Firmware classes
parents 2a361a8b 2debdad3
......@@ -752,23 +752,23 @@ QList<MAV_CMD> APMFirmwarePlugin::supportedMissionCommands(void)
};
}
QString APMFirmwarePlugin::missionCommandOverrides(MAV_TYPE vehicleType) const
QString APMFirmwarePlugin::missionCommandOverrides(QGCMAVLink::VehicleClass_t vehicleClass) const
{
switch (vehicleType) {
case MAV_TYPE_GENERIC:
switch (vehicleClass) {
case QGCMAVLink::VehicleClassGeneric:
return QStringLiteral(":/json/APM-MavCmdInfoCommon.json");
case MAV_TYPE_FIXED_WING:
case QGCMAVLink::VehicleClassFixedWing:
return QStringLiteral(":/json/APM-MavCmdInfoFixedWing.json");
case MAV_TYPE_QUADROTOR:
case QGCMAVLink::VehicleClassMultiRotor:
return QStringLiteral(":/json/APM-MavCmdInfoMultiRotor.json");
case MAV_TYPE_VTOL_QUADROTOR:
case QGCMAVLink::VehicleClassVTOL:
return QStringLiteral(":/json/APM-MavCmdInfoVTOL.json");
case MAV_TYPE_SUBMARINE:
case QGCMAVLink::VehicleClassSub:
return QStringLiteral(":/json/APM-MavCmdInfoSub.json");
case MAV_TYPE_GROUND_ROVER:
case QGCMAVLink::VehicleClassRoverBoat:
return QStringLiteral(":/json/APM-MavCmdInfoRover.json");
default:
qWarning() << "APMFirmwarePlugin::missionCommandOverrides called with bad MAV_TYPE:" << vehicleType;
qWarning() << "APMFirmwarePlugin::missionCommandOverrides called with bad VehicleClass_t:" << vehicleClass;
return QString();
}
}
......
......@@ -97,7 +97,7 @@ public:
virtual void initializeStreamRates (Vehicle* vehicle);
void initializeVehicle (Vehicle* vehicle) override;
bool sendHomePositionToVehicle (void) override;
QString missionCommandOverrides (MAV_TYPE vehicleType) const override;
QString missionCommandOverrides (QGCMAVLink::VehicleClass_t vehicleClass) const override;
QString getVersionParam (void) override { return QStringLiteral("SYSID_SW_MREV"); }
QString _internalParameterMetaDataFile (Vehicle* vehicle) override;
FactMetaData* _getMetaDataForFact (QObject* parameterMetaData, const QString& name, FactMetaData::ValueType_t type, MAV_TYPE vehicleType) override;
......
......@@ -24,11 +24,11 @@ APMFirmwarePluginFactory::APMFirmwarePluginFactory(void)
}
QList<MAV_AUTOPILOT> APMFirmwarePluginFactory::supportedFirmwareTypes(void) const
QList<QGCMAVLink::FirmwareClass_t> APMFirmwarePluginFactory::supportedFirmwareClasses(void) const
{
QList<MAV_AUTOPILOT> list;
QList<QGCMAVLink::FirmwareClass_t> list;
list.append(MAV_AUTOPILOT_ARDUPILOTMEGA);
list.append(QGCMAVLink::FirmwareClassArduPilot);
return list;
}
......
......@@ -7,8 +7,7 @@
*
****************************************************************************/
#ifndef APMFirmwarePluginFactory_H
#define APMFirmwarePluginFactory_H
#pragma once
#include "FirmwarePlugin.h"
......@@ -24,8 +23,8 @@ class APMFirmwarePluginFactory : public FirmwarePluginFactory
public:
APMFirmwarePluginFactory(void);
QList<MAV_AUTOPILOT> supportedFirmwareTypes (void) const final;
FirmwarePlugin* firmwarePluginForAutopilot (MAV_AUTOPILOT autopilotType, MAV_TYPE vehicleType) final;
QList<QGCMAVLink::FirmwareClass_t> supportedFirmwareClasses(void) const final;
FirmwarePlugin* firmwarePluginForAutopilot (MAV_AUTOPILOT autopilotType, MAV_TYPE vehicleType) final;
private:
ArduCopterFirmwarePlugin* _arduCopterPluginInstance;
......@@ -33,5 +32,3 @@ private:
ArduRoverFirmwarePlugin* _arduRoverPluginInstance;
ArduSubFirmwarePlugin* _arduSubPluginInstance;
};
#endif
......@@ -34,11 +34,9 @@ FirmwarePluginFactory::FirmwarePluginFactory(void)
FirmwarePluginFactoryRegister::instance()->registerPluginFactory(this);
}
QList<MAV_TYPE> FirmwarePluginFactory::supportedVehicleTypes(void) const
QList<QGCMAVLink::VehicleClass_t> FirmwarePluginFactory::supportedVehicleClasses(void) const
{
QList<MAV_TYPE> vehicleTypes;
vehicleTypes << MAV_TYPE_FIXED_WING << MAV_TYPE_QUADROTOR << MAV_TYPE_VTOL_QUADROTOR << MAV_TYPE_GROUND_ROVER << MAV_TYPE_SUBMARINE;
return vehicleTypes;
return QGCMAVLink::allVehicleClasses();
}
FirmwarePluginFactoryRegister* FirmwarePluginFactoryRegister::instance(void)
......@@ -182,23 +180,23 @@ QList<MAV_CMD> FirmwarePlugin::supportedMissionCommands(void)
return QList<MAV_CMD>();
}
QString FirmwarePlugin::missionCommandOverrides(MAV_TYPE vehicleType) const
QString FirmwarePlugin::missionCommandOverrides(QGCMAVLink::VehicleClass_t vehicleClass) const
{
switch (vehicleType) {
case MAV_TYPE_GENERIC:
switch (vehicleClass) {
case QGCMAVLink::VehicleClassGeneric:
return QStringLiteral(":/json/MavCmdInfoCommon.json");
case MAV_TYPE_FIXED_WING:
case QGCMAVLink::VehicleClassFixedWing:
return QStringLiteral(":/json/MavCmdInfoFixedWing.json");
case MAV_TYPE_QUADROTOR:
case QGCMAVLink::VehicleClassMultiRotor:
return QStringLiteral(":/json/MavCmdInfoMultiRotor.json");
case MAV_TYPE_VTOL_QUADROTOR:
case QGCMAVLink::VehicleClassVTOL:
return QStringLiteral(":/json/MavCmdInfoVTOL.json");
case MAV_TYPE_SUBMARINE:
case QGCMAVLink::VehicleClassSub:
return QStringLiteral(":/json/MavCmdInfoSub.json");
case MAV_TYPE_GROUND_ROVER:
case QGCMAVLink::VehicleClassRoverBoat:
return QStringLiteral(":/json/MavCmdInfoRover.json");
default:
qWarning() << "FirmwarePlugin::missionCommandOverrides called with bad MAV_TYPE:" << vehicleType;
qWarning() << "FirmwarePlugin::missionCommandOverrides called with bad VehicleClass_t:" << vehicleClass;
return QString();
}
}
......@@ -787,22 +785,6 @@ bool FirmwarePlugin::hasGimbal(Vehicle* vehicle, bool& rollSupported, bool& pitc
return false;
}
bool FirmwarePlugin::isVtol(const Vehicle* vehicle) const
{
switch (vehicle->vehicleType()) {
case MAV_TYPE_VTOL_DUOROTOR:
case MAV_TYPE_VTOL_QUADROTOR:
case MAV_TYPE_VTOL_TILTROTOR:
case MAV_TYPE_VTOL_RESERVED2:
case MAV_TYPE_VTOL_RESERVED3:
case MAV_TYPE_VTOL_RESERVED4:
case MAV_TYPE_VTOL_RESERVED5:
return true;
default:
return false;
}
}
QGCCameraManager* FirmwarePlugin::createCameraManager(Vehicle* vehicle)
{
return new QGCCameraManager(vehicle);
......
......@@ -241,8 +241,8 @@ public:
virtual QList<MAV_CMD> supportedMissionCommands(void);
/// Returns the name of the mission command json override file for the specified vehicle type.
/// @param vehicleType Vehicle type to return file for, MAV_TYPE_GENERIC is a request for overrides for all vehicle types
virtual QString missionCommandOverrides(MAV_TYPE vehicleType) const;
/// @param vehicleClass Vehicle class to return file for, VehicleClassGeneric is a request for overrides for all vehicle types
virtual QString missionCommandOverrides(QGCMAVLink::VehicleClass_t vehicleClass) const;
/// Returns the mapping structure which is used to map from one parameter name to another based on firmware version.
virtual const remapParamNameMajorVersionMap_t& paramNameRemapMajorVersionMap(void) const;
......@@ -316,9 +316,6 @@ public:
/// @return true: vehicle has gimbal, false: gimbal support unknown
virtual bool hasGimbal(Vehicle* vehicle, bool& rollSupported, bool& pitchSupported, bool& yawSupported);
/// Returns true if the vehicle is a VTOL
virtual bool isVtol(const Vehicle* vehicle) const;
/// Convert from HIGH_LATENCY2.custom_mode value to correct 32 bit value.
virtual uint32_t highLatencyCustomModeTo32Bits(uint16_t hlCustomMode);
......@@ -383,11 +380,11 @@ public:
/// @return Singleton FirmwarePlugin instance for the specified MAV_AUTOPILOT.
virtual FirmwarePlugin* firmwarePluginForAutopilot(MAV_AUTOPILOT autopilotType, MAV_TYPE vehicleType) = 0;
/// @return List of firmware types this plugin supports.
virtual QList<MAV_AUTOPILOT> supportedFirmwareTypes(void) const = 0;
/// @return List of firmware classes this plugin supports.
virtual QList<QGCMAVLink::FirmwareClass_t> supportedFirmwareClasses(void) const = 0;
/// @return List of vehicle types this plugin supports.
virtual QList<MAV_TYPE> supportedVehicleTypes(void) const;
/// @return List of vehicle classes this plugin supports.
virtual QList<QGCMAVLink::VehicleClass_t> supportedVehicleClasses(void) const;
};
class FirmwarePluginFactoryRegister : public QObject
......
......@@ -26,33 +26,35 @@ FirmwarePluginManager::~FirmwarePluginManager()
delete _genericFirmwarePlugin;
}
QList<MAV_AUTOPILOT> FirmwarePluginManager::supportedFirmwareTypes(void)
QList<QGCMAVLink::FirmwareClass_t> FirmwarePluginManager::supportedFirmwareClasses(void)
{
if (_supportedFirmwareTypes.isEmpty()) {
if (_supportedFirmwareClasses.isEmpty()) {
QList<FirmwarePluginFactory*> factoryList = FirmwarePluginFactoryRegister::instance()->pluginFactories();
for (int i = 0; i < factoryList.count(); i++) {
_supportedFirmwareTypes.append(factoryList[i]->supportedFirmwareTypes());
_supportedFirmwareClasses.append(factoryList[i]->supportedFirmwareClasses());
}
_supportedFirmwareTypes.append(MAV_AUTOPILOT_GENERIC);
_supportedFirmwareClasses.append(QGCMAVLink::FirmwareClassGeneric);
}
return _supportedFirmwareTypes;
return _supportedFirmwareClasses;
}
QList<MAV_TYPE> FirmwarePluginManager::supportedVehicleTypes(MAV_AUTOPILOT firmwareType)
QList<QGCMAVLink::VehicleClass_t> FirmwarePluginManager::supportedVehicleClasses(QGCMAVLink::FirmwareClass_t firmwareClass)
{
QList<MAV_TYPE> vehicleTypes;
QList<QGCMAVLink::VehicleClass_t> vehicleClasses;
FirmwarePluginFactory* factory = _findPluginFactory(firmwareType);
FirmwarePluginFactory* factory = _findPluginFactory(firmwareClass);
if (factory) {
vehicleTypes = factory->supportedVehicleTypes();
} else if (firmwareType == MAV_AUTOPILOT_GENERIC) {
vehicleTypes << MAV_TYPE_FIXED_WING << MAV_TYPE_QUADROTOR << MAV_TYPE_VTOL_QUADROTOR << MAV_TYPE_GROUND_ROVER << MAV_TYPE_SUBMARINE;
vehicleClasses = factory->supportedVehicleClasses();
} else if (firmwareClass == QGCMAVLink::FirmwareClassGeneric) {
// Generic supports all specific vehicle class
vehicleClasses = QGCMAVLink::allVehicleClasses();
vehicleClasses.removeOne(QGCMAVLink::VehicleClassGeneric);
} else {
qWarning() << "Request for unknown firmware plugin factory" << firmwareType;
qWarning() << "Request for unknown firmware plugin factory" << firmwareClass;
}
return vehicleTypes;
return vehicleClasses;
}
FirmwarePlugin* FirmwarePluginManager::firmwarePluginForAutopilot(MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType)
......@@ -62,8 +64,6 @@ FirmwarePlugin* FirmwarePluginManager::firmwarePluginForAutopilot(MAV_AUTOPILOT
if (factory) {
plugin = factory->firmwarePluginForAutopilot(firmwareType, vehicleType);
} else if (firmwareType != MAV_AUTOPILOT_GENERIC) {
qWarning() << "Request for unknown firmware plugin factory" << firmwareType;
}
if (!plugin) {
......@@ -77,14 +77,14 @@ FirmwarePlugin* FirmwarePluginManager::firmwarePluginForAutopilot(MAV_AUTOPILOT
return plugin;
}
FirmwarePluginFactory* FirmwarePluginManager::_findPluginFactory(MAV_AUTOPILOT firmwareType)
FirmwarePluginFactory* FirmwarePluginManager::_findPluginFactory(QGCMAVLink::FirmwareClass_t firmwareClass)
{
QList<FirmwarePluginFactory*> factoryList = FirmwarePluginFactoryRegister::instance()->pluginFactories();
// Find the plugin which supports this vehicle
for (int i=0; i<factoryList.count(); i++) {
FirmwarePluginFactory* factory = factoryList[i];
if (factory->supportedFirmwareTypes().contains(firmwareType)) {
if (factory->supportedFirmwareClasses().contains(firmwareClass)) {
return factory;
}
}
......
......@@ -7,12 +7,7 @@
*
****************************************************************************/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#ifndef FirmwarePluginManager_H
#define FirmwarePluginManager_H
#pragma once
#include <QObject>
......@@ -33,10 +28,10 @@ public:
~FirmwarePluginManager();
/// Returns list of firmwares which are supported by the system
QList<MAV_AUTOPILOT> supportedFirmwareTypes(void);
QList<QGCMAVLink::FirmwareClass_t> supportedFirmwareClasses(void);
/// Returns the list of supported vehicle types for the specified firmware
QList<MAV_TYPE> supportedVehicleTypes(MAV_AUTOPILOT firmwareType);
QList<QGCMAVLink::VehicleClass_t> supportedVehicleClasses(QGCMAVLink::FirmwareClass_t firmwareClass);
/// Returns appropriate plugin for autopilot type.
/// @param firmwareType Type of firmwware to return plugin for.
......@@ -45,10 +40,8 @@ public:
FirmwarePlugin* firmwarePluginForAutopilot(MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType);
private:
FirmwarePluginFactory* _findPluginFactory(MAV_AUTOPILOT firmwareType);
FirmwarePluginFactory* _findPluginFactory(QGCMAVLink::FirmwareClass_t firmwareClass);
FirmwarePlugin* _genericFirmwarePlugin;
QList<MAV_AUTOPILOT> _supportedFirmwareTypes;
FirmwarePlugin* _genericFirmwarePlugin;
QList<QGCMAVLink::FirmwareClass_t> _supportedFirmwareClasses;
};
#endif
......@@ -297,23 +297,23 @@ QList<MAV_CMD> PX4FirmwarePlugin::supportedMissionCommands(void)
return cmds;
}
QString PX4FirmwarePlugin::missionCommandOverrides(MAV_TYPE vehicleType) const
QString PX4FirmwarePlugin::missionCommandOverrides(QGCMAVLink::VehicleClass_t vehicleClass) const
{
switch (vehicleType) {
case MAV_TYPE_GENERIC:
switch (vehicleClass) {
case QGCMAVLink::VehicleClassGeneric:
return QStringLiteral(":/json/PX4-MavCmdInfoCommon.json");
case MAV_TYPE_FIXED_WING:
case QGCMAVLink::VehicleClassFixedWing:
return QStringLiteral(":/json/PX4-MavCmdInfoFixedWing.json");
case MAV_TYPE_QUADROTOR:
case QGCMAVLink::VehicleClassMultiRotor:
return QStringLiteral(":/json/PX4-MavCmdInfoMultiRotor.json");
case MAV_TYPE_VTOL_QUADROTOR:
case QGCMAVLink::VehicleClassVTOL:
return QStringLiteral(":/json/PX4-MavCmdInfoVTOL.json");
case MAV_TYPE_SUBMARINE:
case QGCMAVLink::VehicleClassSub:
return QStringLiteral(":/json/PX4-MavCmdInfoSub.json");
case MAV_TYPE_GROUND_ROVER:
case QGCMAVLink::VehicleClassRoverBoat:
return QStringLiteral(":/json/PX4-MavCmdInfoRover.json");
default:
qWarning() << "PX4FirmwarePlugin::missionCommandOverrides called with bad MAV_TYPE:" << vehicleType;
qWarning() << "PX4FirmwarePlugin::missionCommandOverrides called with bad VehicleClass_t:" << vehicleClass;
return QString();
}
}
......
......@@ -55,7 +55,7 @@ public:
bool isGuidedMode (const Vehicle* vehicle) const override;
void initializeVehicle (Vehicle* vehicle) override;
bool sendHomePositionToVehicle (void) override;
QString missionCommandOverrides (MAV_TYPE vehicleType) const override;
QString missionCommandOverrides (QGCMAVLink::VehicleClass_t vehicleClass) const override;
QString getVersionParam (void) override { return QString("SYS_PARAM_VER"); }
FactMetaData* _getMetaDataForFact (QObject* parameterMetaData, const QString& name, FactMetaData::ValueType_t type, MAV_TYPE vehicleType) override;
QString _internalParameterMetaDataFile (Vehicle* vehicle) override { Q_UNUSED(vehicle); return QString(":/FirmwarePlugin/PX4/PX4ParameterFactMetaData.xml"); }
......
......@@ -7,10 +7,6 @@
*
****************************************************************************/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#include "PX4FirmwarePluginFactory.h"
#include "PX4/PX4FirmwarePlugin.h"
......@@ -22,10 +18,10 @@ PX4FirmwarePluginFactory::PX4FirmwarePluginFactory(void)
}
QList<MAV_AUTOPILOT> PX4FirmwarePluginFactory::supportedFirmwareTypes(void) const
QList<QGCMAVLink::FirmwareClass_t> PX4FirmwarePluginFactory::supportedFirmwareClasses(void) const
{
QList<MAV_AUTOPILOT> list;
list.append(MAV_AUTOPILOT_PX4);
QList<QGCMAVLink::FirmwareClass_t> list;
list.append(QGCMAVLink::FirmwareClassPX4);
return list;
}
......
......@@ -7,8 +7,7 @@
*
****************************************************************************/
#ifndef PX4FirmwarePluginFactory_H
#define PX4FirmwarePluginFactory_H
#pragma once
#include "FirmwarePlugin.h"
......@@ -21,11 +20,9 @@ class PX4FirmwarePluginFactory : public FirmwarePluginFactory
public:
PX4FirmwarePluginFactory(void);
QList<MAV_AUTOPILOT> supportedFirmwareTypes (void) const final;
FirmwarePlugin* firmwarePluginForAutopilot (MAV_AUTOPILOT autopilotType, MAV_TYPE vehicleType) final;
QList<QGCMAVLink::FirmwareClass_t> supportedFirmwareClasses(void) const final;
FirmwarePlugin* firmwarePluginForAutopilot (MAV_AUTOPILOT autopilotType, MAV_TYPE vehicleType) final;
private:
PX4FirmwarePlugin* _pluginInstance;
};
#endif
......@@ -26,8 +26,8 @@ FirstRunPrompt {
property var _offlineVehicle: QGroundControl.multiVehicleManager.offlineEditingVehicle
property bool _showCruiseSpeed: !_offlineVehicle.multiRotor
property bool _showHoverSpeed: _offlineVehicle.multiRotor || _offlineVehicle.vtol
property bool _multipleFirmware: QGroundControl.supportedFirmwareCount > 2
property bool _multipleVehicleTypes: QGroundControl.supportedVehicleCount > 1
property bool _multipleFirmware: !QGroundControl.singleFirmwareSupport
property bool _multipleVehicleTypes: !QGroundControl.singleVehicleSupport
property real _fieldWidth: ScreenTools.defaultFontPixelWidth * 16
ColumnLayout {
......@@ -61,7 +61,7 @@ FirstRunPrompt {
}
FactComboBox {
Layout.preferredWidth: _fieldWidth
fact: QGroundControl.settingsManager.appSettings.offlineEditingFirmwareType
fact: QGroundControl.settingsManager.appSettings.offlineEditingFirmwareClass
indexModel: false
visible: _multipleFirmware
}
......@@ -73,7 +73,7 @@ FirstRunPrompt {
}
FactComboBox {
Layout.preferredWidth: _fieldWidth
fact: QGroundControl.settingsManager.appSettings.offlineEditingVehicleType
fact: QGroundControl.settingsManager.appSettings.offlineEditingVehicleClass
indexModel: false
visible: _multipleVehicleTypes
}
......
......@@ -27,8 +27,7 @@ class MissionCommandList : public QObject
Q_OBJECT
public:
/// @param jsonFilename Json file which contains commands
/// @param baseCommandList true: bottomost level of mission command hierarchy (partial not allowed), false: mid-level of command hierarchy
/// @param baseCommandList true: bottomost level of mission command hierarchy (partial spec allowed), false: override level of hierarchy
MissionCommandList(const QString& jsonFilename, bool baseCommandList, QObject* parent = nullptr);
/// Returns list of categories in this list
......
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
......@@ -8,7 +7,6 @@
*
****************************************************************************/
#include "MissionCommandTree.h"
#include "FactMetaData.h"
#include "Vehicle.h"
......@@ -21,10 +19,10 @@
#include <QQmlEngine>
MissionCommandTree::MissionCommandTree(QGCApplication* app, QGCToolbox* toolbox, bool unitTest)
: QGCTool(app, toolbox)
, _allCommandsCategory(tr("All commands"))
, _settingsManager(nullptr)
, _unitTest(unitTest)
: QGCTool (app, toolbox)
, _allCommandsCategory (tr("All commands"))
, _settingsManager (nullptr)
, _unitTest (unitTest)
{
}
......@@ -37,25 +35,22 @@ void MissionCommandTree::setToolbox(QGCToolbox* toolbox)
#ifdef UNITTEST_BUILD
if (_unitTest) {
// Load unit testing tree
_staticCommandTree[MAV_AUTOPILOT_GENERIC][MAV_TYPE_GENERIC] = new MissionCommandList(":/unittest/UT-MavCmdInfoCommon.json", true, this);
_staticCommandTree[MAV_AUTOPILOT_GENERIC][MAV_TYPE_FIXED_WING] = new MissionCommandList(":/unittest/UT-MavCmdInfoFixedWing.json", false, this);
_staticCommandTree[MAV_AUTOPILOT_GENERIC][MAV_TYPE_QUADROTOR] = new MissionCommandList(":/unittest/UT-MavCmdInfoMultiRotor.json", false, this);
_staticCommandTree[MAV_AUTOPILOT_GENERIC][MAV_TYPE_VTOL_QUADROTOR] = new MissionCommandList(":/unittest/UT-MavCmdInfoVTOL.json", false, this);
_staticCommandTree[MAV_AUTOPILOT_GENERIC][MAV_TYPE_SUBMARINE] = new MissionCommandList(":/unittest/UT-MavCmdInfoSub.json", false, this);
_staticCommandTree[MAV_AUTOPILOT_GENERIC][MAV_TYPE_GROUND_ROVER] = new MissionCommandList(":/unittest/UT-MavCmdInfoRover.json", false, this);
_staticCommandTree[MAV_AUTOPILOT_GENERIC][QGCMAVLink::VehicleClassGeneric] = new MissionCommandList(":/unittest/UT-MavCmdInfoCommon.json", true, this);
_staticCommandTree[MAV_AUTOPILOT_GENERIC][QGCMAVLink::VehicleClassFixedWing] = new MissionCommandList(":/unittest/UT-MavCmdInfoFixedWing.json", false, this);
_staticCommandTree[MAV_AUTOPILOT_GENERIC][QGCMAVLink::VehicleClassMultiRotor] = new MissionCommandList(":/unittest/UT-MavCmdInfoMultiRotor.json", false, this);
_staticCommandTree[MAV_AUTOPILOT_GENERIC][QGCMAVLink::VehicleClassVTOL] = new MissionCommandList(":/unittest/UT-MavCmdInfoVTOL.json", false, this);
_staticCommandTree[MAV_AUTOPILOT_GENERIC][QGCMAVLink::VehicleClassSub] = new MissionCommandList(":/unittest/UT-MavCmdInfoSub.json", false, this);
_staticCommandTree[MAV_AUTOPILOT_GENERIC][QGCMAVLink::VehicleClassRoverBoat] = new MissionCommandList(":/unittest/UT-MavCmdInfoRover.json", false, this);
} else {
#endif
// Load all levels of hierarchy
for (MAV_AUTOPILOT firmwareType: _toolbox->firmwarePluginManager()->supportedFirmwareTypes()) {
FirmwarePlugin* plugin = _toolbox->firmwarePluginManager()->firmwarePluginForAutopilot(firmwareType, MAV_TYPE_QUADROTOR);
QList<MAV_TYPE> vehicleTypes;
vehicleTypes << MAV_TYPE_GENERIC << MAV_TYPE_FIXED_WING << MAV_TYPE_QUADROTOR << MAV_TYPE_VTOL_QUADROTOR << MAV_TYPE_GROUND_ROVER << MAV_TYPE_SUBMARINE;
for (const QGCMAVLink::FirmwareClass_t firmwareClass: _toolbox->firmwarePluginManager()->supportedFirmwareClasses()) {
FirmwarePlugin* plugin = _toolbox->firmwarePluginManager()->firmwarePluginForAutopilot(QGCMAVLink::firmwareClassToAutopilot(firmwareClass), MAV_TYPE_QUADROTOR);
for(MAV_TYPE vehicleType: vehicleTypes) {
QString overrideFile = plugin->missionCommandOverrides(vehicleType);
for (const QGCMAVLink::VehicleClass_t vehicleClass: QGCMAVLink::allVehicleClasses()) {
QString overrideFile = plugin->missionCommandOverrides(vehicleClass);
if (!overrideFile.isEmpty()) {
_staticCommandTree[firmwareType][vehicleType] = new MissionCommandList(overrideFile, firmwareType == MAV_AUTOPILOT_GENERIC && vehicleType == MAV_TYPE_GENERIC /* baseCommandList */, this);
_staticCommandTree[firmwareClass][vehicleClass] = new MissionCommandList(overrideFile, firmwareClass == QGCMAVLink::FirmwareClassGeneric && vehicleClass == QGCMAVLink::VehicleClassGeneric /* baseCommandList */, this);
}
}
}
......@@ -64,45 +59,15 @@ void MissionCommandTree::setToolbox(QGCToolbox* toolbox)
#endif
}
MAV_AUTOPILOT MissionCommandTree::_baseFirmwareType(MAV_AUTOPILOT firmwareType) const
{
if (qgcApp()->toolbox()->firmwarePluginManager()->supportedFirmwareTypes().contains(firmwareType)) {
return firmwareType;
} else {
return MAV_AUTOPILOT_GENERIC;
}
}
MAV_TYPE MissionCommandTree::_baseVehicleType(MAV_TYPE mavType) const
{
if (QGCMAVLink::isFixedWing(mavType)) {
return MAV_TYPE_FIXED_WING;
} else if (QGCMAVLink::isMultiRotor(mavType)) {
return MAV_TYPE_QUADROTOR;
} else if (QGCMAVLink::isVTOL(mavType)) {
return MAV_TYPE_VTOL_QUADROTOR;
} else if (QGCMAVLink::isRover(mavType)) {
return MAV_TYPE_GROUND_ROVER;
} else if (QGCMAVLink::isSub(mavType)) {
return MAV_TYPE_SUBMARINE;
} else {
return MAV_TYPE_GENERIC;
}
}
/// Add the next level of the hierarchy to a collapsed tree.
/// @param vehicle Collapsed tree is for this vehicle
/// @param cmdList List of mission commands to collapse into ui info
/// @param collapsedTree Tree we are collapsing into
void MissionCommandTree::_collapseHierarchy(Vehicle* vehicle,
const MissionCommandList* cmdList,
/// @param cmdList List of mission commands to collapse into ui info
/// @param collapsedTree Tree we are collapsing into
void MissionCommandTree::_collapseHierarchy(const MissionCommandList* cmdList,
QMap<MAV_CMD, MissionCommandUIInfo*>& collapsedTree)
{
MAV_AUTOPILOT baseFirmwareType;
MAV_TYPE baseVehicleType;
_baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType);
if (!cmdList) {
return;
}
for (MAV_CMD command: cmdList->commandIds()) {
MissionCommandUIInfo* uiInfo = cmdList->getUIInfo(command);
......@@ -118,34 +83,33 @@ void MissionCommandTree::_collapseHierarchy(Vehicle*
void MissionCommandTree::_buildAllCommands(Vehicle* vehicle)
{
MAV_AUTOPILOT baseFirmwareType;
MAV_TYPE baseVehicleType;
QGCMAVLink::FirmwareClass_t firmwareClass;
QGCMAVLink::VehicleClass_t vehicleClass;
_baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType);
_firmwareAndVehicleClassInfo(vehicle, firmwareClass, vehicleClass);
if (_allCommands.contains(baseFirmwareType) &&
_allCommands[baseFirmwareType].contains(baseVehicleType)) {
if (_allCommands.contains(firmwareClass) && _allCommands[firmwareClass].contains(vehicleClass)) {
// Already built
return;
}
QMap<MAV_CMD, MissionCommandUIInfo*>& collapsedTree = _allCommands[baseFirmwareType][baseVehicleType];
QMap<MAV_CMD, MissionCommandUIInfo*>& collapsedTree = _allCommands[firmwareClass][vehicleClass];
// Any Firmware, Any Vehicle
_collapseHierarchy(vehicle, _staticCommandTree[MAV_AUTOPILOT_GENERIC][MAV_TYPE_GENERIC], collapsedTree);
// Base of the tree is all commands
_collapseHierarchy(_staticCommandTree[MAV_AUTOPILOT_GENERIC][QGCMAVLink::VehicleClassGeneric], collapsedTree);
// Any Firmware, Specific Vehicle
if (baseVehicleType != MAV_TYPE_GENERIC) {
_collapseHierarchy(vehicle, _staticCommandTree[MAV_AUTOPILOT_GENERIC][baseVehicleType], collapsedTree);
// Add the overrides for specific vehicle types
if (vehicleClass != QGCMAVLink::VehicleClassGeneric) {
_collapseHierarchy(_staticCommandTree[QGCMAVLink::FirmwareClassGeneric][vehicleClass], collapsedTree);
}
// Known Firmware, Any Vehicle
if (baseFirmwareType != MAV_AUTOPILOT_GENERIC) {
_collapseHierarchy(vehicle, _staticCommandTree[baseFirmwareType][MAV_TYPE_GENERIC], collapsedTree);
// Add the overrides for specific firmware class, all vehicles
if (firmwareClass != QGCMAVLink::FirmwareClassGeneric) {
_collapseHierarchy(_staticCommandTree[firmwareClass][QGCMAVLink::VehicleClassGeneric], collapsedTree);
// Known Firmware, Specific Vehicle
if (baseVehicleType != MAV_TYPE_GENERIC) {
_collapseHierarchy(vehicle, _staticCommandTree[baseFirmwareType][baseVehicleType], collapsedTree);
// Add overrides for specific vehicle class
if (vehicleClass != QGCMAVLink::VehicleClassGeneric) {
_collapseHierarchy(_staticCommandTree[firmwareClass][vehicleClass], collapsedTree);
}
}
......@@ -154,28 +118,28 @@ void MissionCommandTree::_buildAllCommands(Vehicle* vehicle)
for (MAV_CMD cmd: collapsedTree.keys()) {
if (supportedCommands.contains(cmd)) {
QString newCategory = collapsedTree[cmd]->category();
if (!_supportedCategories[baseFirmwareType][baseVehicleType].contains(newCategory)) {
_supportedCategories[baseFirmwareType][baseVehicleType].append(newCategory);
if (!_supportedCategories[firmwareClass][vehicleClass].contains(newCategory)) {
_supportedCategories[firmwareClass][vehicleClass].append(newCategory);
}
}
}
_supportedCategories[baseFirmwareType][baseVehicleType].append(_allCommandsCategory);
_supportedCategories[firmwareClass][vehicleClass].append(_allCommandsCategory);
}
QStringList MissionCommandTree::_availableCategoriesForVehicle(Vehicle* vehicle)
{
MAV_AUTOPILOT baseFirmwareType;
MAV_TYPE baseVehicleType;
QGCMAVLink::FirmwareClass_t firmwareClass;
QGCMAVLink::VehicleClass_t vehicleClass;
_baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType);
_firmwareAndVehicleClassInfo(vehicle, firmwareClass, vehicleClass);
_buildAllCommands(vehicle);
return _supportedCategories[baseFirmwareType][baseVehicleType];
return _supportedCategories[firmwareClass][vehicleClass];
}
QString MissionCommandTree::friendlyName(MAV_CMD command)
{
MissionCommandList * commandList = _staticCommandTree[MAV_AUTOPILOT_GENERIC][MAV_TYPE_GENERIC];
MissionCommandList * commandList = _staticCommandTree[QGCMAVLink::FirmwareClassGeneric][QGCMAVLink::VehicleClassGeneric];
MissionCommandUIInfo* uiInfo = commandList->getUIInfo(command);
if (uiInfo) {
......@@ -187,7 +151,7 @@ QString MissionCommandTree::friendlyName(MAV_CMD command)
QString MissionCommandTree::rawName(MAV_CMD command)
{
MissionCommandList * commandList = _staticCommandTree[MAV_AUTOPILOT_GENERIC][MAV_TYPE_GENERIC];
MissionCommandList * commandList = _staticCommandTree[QGCMAVLink::FirmwareClassGeneric][QGCMAVLink::VehicleClassGeneric];
MissionCommandUIInfo* uiInfo = commandList->getUIInfo(command);
if (uiInfo) {
......@@ -199,18 +163,18 @@ QString MissionCommandTree::rawName(MAV_CMD command)
const QList<MAV_CMD>& MissionCommandTree::allCommandIds(void) const
{
return _staticCommandTree[MAV_AUTOPILOT_GENERIC][MAV_TYPE_GENERIC]->commandIds();
return _staticCommandTree[QGCMAVLink::FirmwareClassGeneric][QGCMAVLink::VehicleClassGeneric]->commandIds();
}
const MissionCommandUIInfo* MissionCommandTree::getUIInfo(Vehicle* vehicle, MAV_CMD command)
{
MAV_AUTOPILOT baseFirmwareType;
MAV_TYPE baseVehicleType;
QGCMAVLink::FirmwareClass_t firmwareClass;
QGCMAVLink::VehicleClass_t vehicleClass;
_baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType);
_firmwareAndVehicleClassInfo(vehicle, firmwareClass, vehicleClass);
_buildAllCommands(vehicle);
const QMap<MAV_CMD, MissionCommandUIInfo*>& infoMap = _allCommands[baseFirmwareType][baseVehicleType];
const QMap<MAV_CMD, MissionCommandUIInfo*>& infoMap = _allCommands[firmwareClass][vehicleClass];
if (infoMap.contains(command)) {
return infoMap[command];
} else {
......@@ -220,19 +184,19 @@ const MissionCommandUIInfo* MissionCommandTree::getUIInfo(Vehicle* vehicle, MAV_
QVariantList MissionCommandTree::getCommandsForCategory(Vehicle* vehicle, const QString& category, bool showFlyThroughCommands)
{
MAV_AUTOPILOT baseFirmwareType;