Skip to content

Commit

Permalink
AutoPilotPlugins: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Feb 22, 2025
1 parent cfb8f7d commit d7c7fd0
Show file tree
Hide file tree
Showing 20 changed files with 908 additions and 1,192 deletions.
48 changes: 21 additions & 27 deletions src/AutoPilotPlugins/AutoPilotPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,43 @@
*
****************************************************************************/


/// @file
/// @author Don Gagne <[email protected]>

#include "AutoPilotPlugin.h"
#include "QGCApplication.h"
#include "FirmwarePlugin.h"
#include "QGCApplication.h"
#include "QGCLoggingCategory.h"
#include "Vehicle.h"
#include "VehicleComponent.h"

#include <QtCore/QCoreApplication>

AutoPilotPlugin::AutoPilotPlugin(Vehicle* vehicle, QObject* parent)
QGC_LOGGING_CATEGORY(AutoPilotPluginLog, "qgc.autopilotplugin.autopilotplugin");

AutoPilotPlugin::AutoPilotPlugin(Vehicle *vehicle, QObject *parent)
: QObject(parent)
, _vehicle(vehicle)
, _firmwarePlugin(vehicle->firmwarePlugin())
, _setupComplete(false)
{

// qCDebug(AutoPilotPluginLog) << Q_FUNC_INFO << this;
}

AutoPilotPlugin::~AutoPilotPlugin()
{

// qCDebug(AutoPilotPluginLog) << Q_FUNC_INFO << this;
}

void AutoPilotPlugin::_recalcSetupComplete(void)
void AutoPilotPlugin::_recalcSetupComplete()
{
bool newSetupComplete = true;

for(const QVariant& componentVariant: vehicleComponents()) {
VehicleComponent* component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
for (const QVariant &componentVariant : vehicleComponents()) {
const VehicleComponent *const component = qobject_cast<const VehicleComponent*>(qvariant_cast<const QObject*>(componentVariant));
if (component) {
if (!component->setupComplete()) {
newSetupComplete = false;
break;
}
} else {
qWarning() << "AutoPilotPlugin::_recalcSetupComplete Incorrectly typed VehicleComponent";
qCWarning(AutoPilotPluginLog) << "Incorrectly typed VehicleComponent";
}
}

Expand All @@ -54,22 +53,17 @@ void AutoPilotPlugin::_recalcSetupComplete(void)
}
}

bool AutoPilotPlugin::setupComplete(void) const
{
return _setupComplete;
}

void AutoPilotPlugin::parametersReadyPreChecks(void)
void AutoPilotPlugin::parametersReadyPreChecks()
{
_recalcSetupComplete();

// Connect signals in order to keep setupComplete up to date
for(QVariant componentVariant: vehicleComponents()) {
VehicleComponent* component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
for (QVariant componentVariant : vehicleComponents()) {
VehicleComponent *const component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject*>(componentVariant));
if (component) {
connect(component, &VehicleComponent::setupCompleteChanged, this, &AutoPilotPlugin::_recalcSetupComplete);
(void) connect(component, &VehicleComponent::setupCompleteChanged, this, &AutoPilotPlugin::_recalcSetupComplete);
} else {
qWarning() << "AutoPilotPlugin::_recalcSetupComplete Incorrectly typed VehicleComponent";
qCWarning(AutoPilotPluginLog) << "Incorrectly typed VehicleComponent";
}
}

Expand All @@ -82,12 +76,12 @@ void AutoPilotPlugin::parametersReadyPreChecks(void)
}
}

VehicleComponent* AutoPilotPlugin::findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent)
VehicleComponent *AutoPilotPlugin::findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent)
{
if (knownVehicleComponent != UnknownVehicleComponent) {
for(const QVariant& componentVariant: vehicleComponents()) {
VehicleComponent* component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
if (component && component->KnownVehicleComponent() == knownVehicleComponent) {
for (const QVariant &componentVariant: vehicleComponents()) {
VehicleComponent *const component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
if (component && (component->KnownVehicleComponent() == knownVehicleComponent)) {
return component;
}
}
Expand Down
43 changes: 20 additions & 23 deletions src/AutoPilotPlugins/AutoPilotPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@

#pragma once

#include <QtCore/QLoggingCategory>
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QVariantList>

class Vehicle;
class FirmwarePlugin;
class Vehicle;
class VehicleComponent;

/// This is the base class for AutoPilot plugins
///
Q_DECLARE_LOGGING_CATEGORY(AutoPilotPluginLog)

/// The AutoPilotPlugin class is an abstract base class which represent the methods and objects
/// which are specific to a certain AutoPilot. This is the only place where AutoPilot specific
/// code should reside in QGroundControl. The remainder of the QGroundControl source is
/// generic to a common mavlink implementation.

class AutoPilotPlugin : public QObject
{
Q_OBJECT
Q_PROPERTY(QVariantList vehicleComponents READ vehicleComponents NOTIFY vehicleComponentsChanged) ///< List of VehicleComponent objects
Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged) ///< false: One or more vehicle components require setup

public:
AutoPilotPlugin(Vehicle* vehicle, QObject* parent);
~AutoPilotPlugin();
explicit AutoPilotPlugin(Vehicle *vehicle, QObject *parent = nullptr);
virtual ~AutoPilotPlugin();

// Vehicle Components which are available for firmware types
enum KnownVehicleComponent {
Expand All @@ -43,35 +45,30 @@ class AutoPilotPlugin : public QObject
};
Q_ENUM(KnownVehicleComponent)

Q_PROPERTY(QVariantList vehicleComponents READ vehicleComponents NOTIFY vehicleComponentsChanged) ///< List of VehicleComponent objects
Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged) ///< false: One or more vehicle components require setup

/// Called when parameters are ready for the first time. Note that parameters may still be missing.
/// Overrides must call base class.
virtual void parametersReadyPreChecks(void);
virtual void parametersReadyPreChecks();

// Must be implemented by derived class
virtual const QVariantList& vehicleComponents(void) = 0;
virtual const QVariantList &vehicleComponents() = 0;

/// Returns the name of the vehicle component which must complete setup prior to this one. Empty string for none.
Q_INVOKABLE virtual QString prerequisiteSetup(VehicleComponent* component) const = 0;

Q_INVOKABLE VehicleComponent* findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent);
Q_INVOKABLE virtual QString prerequisiteSetup(VehicleComponent *component) const = 0;

Q_INVOKABLE bool knownVehicleComponentAvailable(KnownVehicleComponent knownVehicleComponent) { return findKnownVehicleComponent(knownVehicleComponent) != nullptr; }
Q_INVOKABLE VehicleComponent *findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent);
Q_INVOKABLE bool knownVehicleComponentAvailable(KnownVehicleComponent knownVehicleComponent) { return (findKnownVehicleComponent(knownVehicleComponent) != nullptr); }

// Property accessors
bool setupComplete(void) const;
bool setupComplete() const { return _setupComplete; }

signals:
void setupCompleteChanged (void);
void vehicleComponentsChanged (void);
void setupCompleteChanged();
void vehicleComponentsChanged();

protected:
Vehicle* _vehicle;
FirmwarePlugin* _firmwarePlugin;
bool _setupComplete;
Vehicle *_vehicle = nullptr;
FirmwarePlugin *_firmwarePlugin = nullptr;
bool _setupComplete = false;

private slots:
void _recalcSetupComplete(void);
void _recalcSetupComplete();
};
44 changes: 1 addition & 43 deletions src/AutoPilotPlugins/Common/ESP8266Component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,11 @@
*
****************************************************************************/


#include "ESP8266Component.h"
#include "AutoPilotPlugin.h"

ESP8266Component::ESP8266Component(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
ESP8266Component::ESP8266Component(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent)
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
, _name(tr("WiFi Bridge"))
{

}

QString ESP8266Component::name(void) const
{
return _name;
}

QString ESP8266Component::description(void) const
{
return tr("The ESP8266 WiFi Bridge Component is used to setup the WiFi link.");
}

QString ESP8266Component::iconResource(void) const
{
return "/qmlimages/wifi.svg";
}

bool ESP8266Component::requiresSetup(void) const
{
return false;
}

bool ESP8266Component::setupComplete(void) const
{
return true;
}

QStringList ESP8266Component::setupCompleteChangedTriggerList(void) const
{
return QStringList();
}

QUrl ESP8266Component::setupSource(void) const
{
return QUrl::fromUserInput("qrc:/qml/ESP8266Component.qml");
}

QUrl ESP8266Component::summaryQmlSource(void) const
{
return QUrl::fromUserInput("qrc:/qml/ESP8266ComponentSummary.qml");
}
31 changes: 14 additions & 17 deletions src/AutoPilotPlugins/Common/ESP8266Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@
*
****************************************************************************/


#pragma once

#include "VehicleComponent.h"

class ESP8266Component : public VehicleComponent
{
Q_OBJECT

public:
ESP8266Component (Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent = nullptr);

// Virtuals from VehicleComponent
QStringList setupCompleteChangedTriggerList() const;

// Virtuals from VehicleComponent
QString name () const;
QString description () const;
QString iconResource () const;
bool requiresSetup () const;
bool setupComplete () const;
QUrl setupSource () const;
QUrl summaryQmlSource () const;

explicit ESP8266Component(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent = nullptr);

QStringList setupCompleteChangedTriggerList() const final { return QStringList(); }
QString name() const final { return _name; }
QString description() const final { return tr("The ESP8266 WiFi Bridge Component is used to setup the WiFi link."); }
QString iconResource() const final { return QStringLiteral("/qmlimages/wifi.svg"); }
bool requiresSetup() const final { return false; }
bool setupComplete() const final { return true; }
QUrl setupSource() const final { return QUrl::fromUserInput("qrc:/qml/ESP8266Component.qml"); }
QUrl summaryQmlSource() const final { return QUrl::fromUserInput("qrc:/qml/ESP8266ComponentSummary.qml"); }

private:
const QString _name;
QVariantList _summaryItems;
const QString _name;
QVariantList _summaryItems;
};
Loading

0 comments on commit d7c7fd0

Please sign in to comment.