QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
AutoPilotPlugin.cc
Go to the documentation of this file.
1#include "AutoPilotPlugin.h"
2#include "FirmwarePlugin.h"
3#include "AppMessages.h"
5#include "Vehicle.h"
6#include "VehicleComponent.h"
7
8QGC_LOGGING_CATEGORY(AutoPilotPluginLog, "AutoPilotPlugins.AutoPilotPlugin");
9
10AutoPilotPlugin::AutoPilotPlugin(Vehicle *vehicle, QObject *parent)
11 : QObject(parent)
12 , _vehicle(vehicle)
13 , _firmwarePlugin(vehicle->firmwarePlugin())
14{
15 qCDebug(AutoPilotPluginLog) << this;
16}
17
19{
20 qCDebug(AutoPilotPluginLog) << this;
21}
22
23void AutoPilotPlugin::_recalcSetupComplete()
24{
25 bool newSetupComplete = true;
26
27 for (const QVariant &componentVariant : vehicleComponents()) {
28 const VehicleComponent *const component = qobject_cast<const VehicleComponent*>(qvariant_cast<const QObject*>(componentVariant));
29 if (component) {
30 if (!component->setupComplete()) {
31 newSetupComplete = false;
32 break;
33 }
34 } else {
35 qCWarning(AutoPilotPluginLog) << "Incorrectly typed VehicleComponent";
36 }
37 }
38
39 if (_setupComplete != newSetupComplete) {
40 _setupComplete = newSetupComplete;
42 }
43}
44
46{
47 _recalcSetupComplete();
48
49 // Connect signals in order to keep setupComplete up to date
50 for (QVariant componentVariant : vehicleComponents()) {
51 VehicleComponent *const component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject*>(componentVariant));
52 if (component) {
53 (void) connect(component, &VehicleComponent::setupCompleteChanged, this, &AutoPilotPlugin::_recalcSetupComplete);
54 } else {
55 qCWarning(AutoPilotPluginLog) << "Incorrectly typed VehicleComponent";
56 }
57 }
58
59 if (!_setupComplete) {
60 QGC::showAppMessage(tr("Configuration tasks remain before this vehicle is ready to fly. See Vehicle Configuration for details."));
61 }
62}
63
65{
66 if (knownVehicleComponent != UnknownVehicleComponent) {
67 for (const QVariant &componentVariant: vehicleComponents()) {
68 VehicleComponent *const component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
69 if (component && (component->KnownVehicleComponent() == knownVehicleComponent)) {
70 return component;
71 }
72 }
73 }
74
75 return nullptr;
76}
#define QGC_LOGGING_CATEGORY(name, categoryStr)
virtual void parametersReadyPreChecks()
AutoPilotPlugin(Vehicle *vehicle, QObject *parent=nullptr)
< false: One or more vehicle components require setup
virtual ~AutoPilotPlugin()
void setupCompleteChanged()
Q_INVOKABLE VehicleComponent * findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent)
Returns the VehicleComponent for the knownVehicleComponent. Returns nullptr if not available.
virtual const QVariantList & vehicleComponents()=0
A vehicle component is an object which abstracts the physical portion of a vehicle into a set of conf...
void setupCompleteChanged()
virtual bool setupComplete() const =0
AutoPilotPlugin::KnownVehicleComponent KnownVehicleComponent() const
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Definition AppMessages.cc:9