AutoPilotPlugin.h 4.98 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 36

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

class ParameterLoader;
40

41 42 43 44 45 46
/// 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.
47 48 49 50 51 52

class AutoPilotPlugin : public QObject
{
    Q_OBJECT

public:
Don Gagne's avatar
Don Gagne committed
53 54
    AutoPilotPlugin(UASInterface* uas, QObject* parent);
    
55 56 57
	/// true: plugin is ready for use, plugin should no longer be used
	Q_PROPERTY(bool pluginReady READ pluginReady NOTIFY pluginReadyChanged)
	
58 59
    /// List of VehicleComponent objects
    Q_PROPERTY(QVariantList vehicleComponents READ vehicleComponents CONSTANT)
60 61 62 63

	/// false: One or more vehicle components require setup
	Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged)
	
Don Gagne's avatar
Don Gagne committed
64
    /// Re-request the full set of parameters from the autopilot
65
	Q_INVOKABLE void refreshAllParameters(void);
Don Gagne's avatar
Don Gagne committed
66 67
    
    /// Request a refresh on the specific parameter
68
	Q_INVOKABLE void refreshParameter(int componentId, const QString& name);
Don Gagne's avatar
Don Gagne committed
69
    
70
    /// Request a refresh on all parameters that begin with the specified prefix
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
	Q_INVOKABLE void refreshParametersPrefix(int componentId, const QString& namePrefix);
    
	/// Returns true if the specifed parameter exists from the default component
	Q_INVOKABLE bool parameterExists(const QString& name);
	
	/// Returns all parameter names
	/// FIXME: component id missing, generic to fact
	QStringList parameterNames(void);
	
	/// Returns the specified parameter Fact from the default component
	/// WARNING: Will assert if fact does not exists. If that possibility exists, check for existince first with
	/// factExists.
	Fact* getParameterFact(const QString& name);
	
	/// Writes the parameter facts to the specified stream
	void writeParametersToStream(QTextStream &stream);
	
	/// Reads the parameters from the stream and updates values
	void readParametersFromStream(QTextStream &stream);
	
91 92 93 94
    /// 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
95
    
96 97 98 99 100 101 102
    /// 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
    
103 104
    const QMap<int, QMap<QString, QStringList> >& getGroupMap(void);

105 106 107
    // Must be implemented by derived class
    virtual const QVariantList& vehicleComponents(void) = 0;
    
108
    static void clearStaticData(void);
109
	
110
	// Property accessors
111
	bool pluginReady(void) { return _pluginReady; }
112 113
	bool setupComplete(void);
	
Don Gagne's avatar
Don Gagne committed
114 115
    UASInterface* uas(void) { return _uas; }
    
116
signals:
117
    void pluginReadyChanged(bool pluginReady);
118
	void setupCompleteChanged(bool setupComplete);
119
    void parameterListProgress(float value);
120
	
121
protected:
122
    /// All access to AutoPilotPugin objects is through getInstanceForAutoPilotPlugin
Don Gagne's avatar
Don Gagne committed
123
    AutoPilotPlugin(QObject* parent = NULL) : QObject(parent) { }
124
    
125 126 127
	/// Returns the ParameterLoader
	virtual ParameterLoader* _getParameterLoader(void) = 0;
	
128 129
    UASInterface*   _uas;
    bool            _pluginReady;
130
	bool			_setupComplete;
131 132 133
	
private slots:
	void _uasDisconnected(void);
134 135 136 137
	void _pluginReadyChanged(bool pluginReady);
	
private:
	void _recalcSetupComplete(void);
138 139 140
};

#endif