AutoPilotPlugin.h 5.44 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60


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

    #ifndef AUTOPILOTPLUGIN_H
    #define AUTOPILOTPLUGIN_H

    #include <QObject>
    #include <QList>
    #include <QString>
    #include <QQmlContext>

    #include "VehicleComponent.h"
    #include "FactSystem.h"
    #include "Vehicle.h"

    class ParameterLoader;
    class Vehicle;
    class FirmwarePlugin;

    /// 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.

    class AutoPilotPlugin : public QObject
    {
        Q_OBJECT

    public:
        AutoPilotPlugin(Vehicle* vehicle, QObject* parent);
        ~AutoPilotPlugin();

        /// 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)

        /// List of VehicleComponent objects
        Q_PROPERTY(QVariantList vehicleComponents READ vehicleComponents CONSTANT)

        /// false: One or more vehicle components require setup
        Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged)

        /// Reset all parameters to their default values
        Q_INVOKABLE void resetAllParametersToDefaults(void);

        /// Re-request the full set of parameters from the autopilot
dogmaphobic's avatar
dogmaphobic committed
61
        Q_INVOKABLE void refreshAllParameters(unsigned char componentID = MAV_COMP_ID_ALL);
62 63 64 65 66 67 68 69 70 71 72 73 74 75

        /// Request a refresh on the specific parameter
        Q_INVOKABLE void refreshParameter(int componentId, const QString& name);

        /// Request a refresh on all parameters that begin with the specified prefix
        Q_INVOKABLE void refreshParametersPrefix(int componentId, const QString& namePrefix);

        /// Returns true if the specifed parameter exists from the default component
        Q_INVOKABLE bool parameterExists(int componentId, const QString& name);

        /// Returns all parameter names
        QStringList parameterNames(int componentId);

        /// Returns the specified parameter Fact from the default component
nopeppermint's avatar
nopeppermint committed
76
        /// WARNING: Returns a default Fact if parameter does not exists. If that possibility exists, check for existence first with
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
        /// parameterExists.
        Fact* getParameterFact(int componentId, const QString& name);

        /// Writes the parameter facts to the specified stream
        void writeParametersToStream(QTextStream &stream);

        /// Reads the parameters from the stream and updates values
        /// @return Errors during load. Empty string for no errors
        QString readParametersFromStream(QTextStream &stream);

        /// 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

        /// Returns the specified Fact.
nopeppermint's avatar
nopeppermint committed
93
        /// WARNING: Will assert if fact does not exists. If that possibility exists, check for existence first with
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
        /// factExists.
        Fact* getFact(FactSystem::Provider_t    provider,       ///< fact provider
                      int                       componentId,    ///< fact component, -1=default component
                      const QString&            name);          ///< fact name

        const QMap<int, QMap<QString, QStringList> >& getGroupMap(void);

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

        // Property accessors
        bool parametersReady(void) { return _parametersReady; }
        bool missingParameters(void) { return _missingParameters; }
        bool setupComplete(void);

        Vehicle* vehicle(void) { return _vehicle; }
110
        virtual void _parametersReadyPreChecks(bool parametersReady) = 0;
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

    signals:
        void parametersReadyChanged(bool parametersReady);
        void missingParametersChanged(bool missingParameters);
        void setupCompleteChanged(bool setupComplete);
        void parameterListProgress(float value);

    protected:
        /// All access to AutoPilotPugin objects is through getInstanceForAutoPilotPlugin
        AutoPilotPlugin(QObject* parent = NULL) : QObject(parent) { }

        Vehicle*        _vehicle;
        FirmwarePlugin* _firmwarePlugin;
        bool            _parametersReady;
        bool            _missingParameters;
        bool            _setupComplete;

128

129 130 131 132 133 134 135 136 137
    private slots:
        void _uasDisconnected(void);
        void _parametersReadyChanged(bool parametersReady);

    private:
        void _recalcSetupComplete(void);
    };

    #endif