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 "QGCApplication.h"
5#include "Vehicle.h"
6#include "VehicleComponent.h"
7
8#include <QtCore/QCoreApplication>
9
10QGC_LOGGING_CATEGORY(AutoPilotPluginLog, "AutoPilotPlugins.AutoPilotPlugin");
11
12AutoPilotPlugin::AutoPilotPlugin(Vehicle *vehicle, QObject *parent)
13 : QObject(parent)
14 , _vehicle(vehicle)
15 , _firmwarePlugin(vehicle->firmwarePlugin())
16{
17 qCDebug(AutoPilotPluginLog) << this;
18}
19
20AutoPilotPlugin::~AutoPilotPlugin()
21{
22 qCDebug(AutoPilotPluginLog) << this;
23}
24
25void AutoPilotPlugin::_recalcSetupComplete()
26{
27 bool newSetupComplete = true;
28
29 for (const QVariant &componentVariant : vehicleComponents()) {
30 const VehicleComponent *const component = qobject_cast<const VehicleComponent*>(qvariant_cast<const QObject*>(componentVariant));
31 if (component) {
32 if (!component->setupComplete()) {
33 newSetupComplete = false;
34 break;
35 }
36 } else {
37 qCWarning(AutoPilotPluginLog) << "Incorrectly typed VehicleComponent";
38 }
39 }
40
41 if (_setupComplete != newSetupComplete) {
42 _setupComplete = newSetupComplete;
44 }
45}
46
47void AutoPilotPlugin::parametersReadyPreChecks()
48{
49 _recalcSetupComplete();
50
51 // Connect signals in order to keep setupComplete up to date
52 for (QVariant componentVariant : vehicleComponents()) {
53 VehicleComponent *const component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject*>(componentVariant));
54 if (component) {
55 (void) connect(component, &VehicleComponent::setupCompleteChanged, this, &AutoPilotPlugin::_recalcSetupComplete);
56 } else {
57 qCWarning(AutoPilotPluginLog) << "Incorrectly typed VehicleComponent";
58 }
59 }
60
61 if (!_setupComplete) {
62 // Take the user to Vehicle Config Summary
63 qgcApp()->showVehicleConfig();
64 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
65 qgcApp()->showAppMessage(tr("One or more vehicle components require setup prior to flight."));
66 }
67}
68
69VehicleComponent *AutoPilotPlugin::findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent)
70{
71 if (knownVehicleComponent != UnknownVehicleComponent) {
72 for (const QVariant &componentVariant: vehicleComponents()) {
73 VehicleComponent *const component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
74 if (component && (component->KnownVehicleComponent() == knownVehicleComponent)) {
75 return component;
76 }
77 }
78 }
79
80 return nullptr;
81}
#define qgcApp()
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void setupCompleteChanged()
void setupCompleteChanged()