AutoPilotPlugin.h 5.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/

24 25 26
/// @file
///     @author Don Gagne <don@thegagnes.com>

27 28 29 30 31 32
#ifndef AUTOPILOTPLUGIN_H
#define AUTOPILOTPLUGIN_H

#include <QObject>
#include <QList>
#include <QString>
Don Gagne's avatar
Don Gagne committed
33
#include <QQmlContext>
34 35

#include "VehicleComponent.h"
Don Gagne's avatar
Don Gagne committed
36
#include "FactSystem.h"
37
#include "Vehicle.h"
38 39

class ParameterLoader;
40
class Vehicle;
41

42 43 44 45 46 47
/// This is the base class for AutoPilot plugins
///
/// 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.
48 49 50 51 52 53

class AutoPilotPlugin : public QObject
{
    Q_OBJECT

public:
54
    AutoPilotPlugin(Vehicle* vehicle, QObject* parent);
55
    ~AutoPilotPlugin();
Don Gagne's avatar
Don Gagne committed
56
    
57 58 59 60 61
	/// true: parameters are ready for use
	Q_PROPERTY(bool parametersReady READ parametersReady NOTIFY parametersReadyChanged)
    
    /// true: parameters are missing from firmware response, false: all parameters received from firmware
    Q_PROPERTY(bool missingParameters READ missingParameters NOTIFY missingParametersChanged)
62
	
63 64
    /// List of VehicleComponent objects
    Q_PROPERTY(QVariantList vehicleComponents READ vehicleComponents CONSTANT)
65 66 67

	/// false: One or more vehicle components require setup
	Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged)
68
    
69 70
    /// Reset all parameters to their default values
    Q_INVOKABLE void resetAllParametersToDefaults(void);
71
	
Don Gagne's avatar
Don Gagne committed
72
    /// Re-request the full set of parameters from the autopilot
73
	Q_INVOKABLE void refreshAllParameters(void);
Don Gagne's avatar
Don Gagne committed
74 75
    
    /// Request a refresh on the specific parameter
76
	Q_INVOKABLE void refreshParameter(int componentId, const QString& name);
Don Gagne's avatar
Don Gagne committed
77
    
78
    /// Request a refresh on all parameters that begin with the specified prefix
79 80 81
	Q_INVOKABLE void refreshParametersPrefix(int componentId, const QString& namePrefix);
    
	/// Returns true if the specifed parameter exists from the default component
Don Gagne's avatar
Don Gagne committed
82
    Q_INVOKABLE bool parameterExists(int componentId, const QString& name);
83 84
	
	/// Returns all parameter names
Don Gagne's avatar
Don Gagne committed
85
	QStringList parameterNames(int componentId);
86 87
	
	/// Returns the specified parameter Fact from the default component
Don Gagne's avatar
Don Gagne committed
88 89 90
	/// WARNING: Returns a default Fact if parameter does not exists. If that possibility exists, check for existince first with
	/// parameterExists.
    Fact* getParameterFact(int componentId, const QString& name);
91 92 93 94 95
	
	/// Writes the parameter facts to the specified stream
	void writeParametersToStream(QTextStream &stream);
	
	/// Reads the parameters from the stream and updates values
96 97
    /// @return Errors during load. Empty string for no errors
	QString readParametersFromStream(QTextStream &stream);
98
	
99 100 101 102
    /// Returns true if the specifed fact exists
    Q_INVOKABLE bool factExists(FactSystem::Provider_t  provider,       ///< fact provider
                                int                     componentId,    ///< fact component, -1=default component
                                const QString&          name);          ///< fact name
103
    
104 105 106 107 108 109 110
    /// Returns the specified Fact.
    /// WARNING: Will assert if fact does not exists. If that possibility exists, check for existince first with
    /// factExists.
    Fact* getFact(FactSystem::Provider_t    provider,       ///< fact provider
                  int                       componentId,    ///< fact component, -1=default component
                  const QString&            name);          ///< fact name
    
111 112
    const QMap<int, QMap<QString, QStringList> >& getGroupMap(void);

113 114 115
    // Must be implemented by derived class
    virtual const QVariantList& vehicleComponents(void) = 0;
    
116
    static void clearStaticData(void);
117
	
118
	// Property accessors
119 120
	bool parametersReady(void) { return _parametersReady; }
    bool missingParameters(void) { return _missingParameters; }
121 122
	bool setupComplete(void);
	
123
    Vehicle* vehicle(void) { return _vehicle; }
Don Gagne's avatar
Don Gagne committed
124
    
125
signals:
126 127
    void parametersReadyChanged(bool parametersReady);
    void missingParametersChanged(bool missingParameters);
128
	void setupCompleteChanged(bool setupComplete);
129
    void parameterListProgress(float value);
130
	
131
protected:
132
    /// All access to AutoPilotPugin objects is through getInstanceForAutoPilotPlugin
Don Gagne's avatar
Don Gagne committed
133
    AutoPilotPlugin(QObject* parent = NULL) : QObject(parent) { }
134
    
135 136 137
	/// Returns the ParameterLoader
	virtual ParameterLoader* _getParameterLoader(void) = 0;
	
138
    Vehicle*    _vehicle;
139 140
    bool        _parametersReady;
    bool        _missingParameters;
141
	bool		_setupComplete;
142 143 144
	
private slots:
	void _uasDisconnected(void);
145
	void _parametersReadyChanged(bool parametersReady);
146 147 148
	
private:
	void _recalcSetupComplete(void);
149 150 151
};

#endif