APMFirmwarePlugin.h 7.4 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

Don Gagne's avatar
Don Gagne committed
10 11 12 13 14 15 16 17

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

#ifndef APMFirmwarePlugin_H
#define APMFirmwarePlugin_H

#include "FirmwarePlugin.h"
18
#include "QGCLoggingCategory.h"
19
#include "APMParameterMetaData.h"
Don Gagne's avatar
Don Gagne committed
20

Don Gagne's avatar
Don Gagne committed
21 22
#include <QAbstractSocket>

23
Q_DECLARE_LOGGING_CATEGORY(APMFirmwarePluginLog)
Pritam Ghanghas's avatar
Pritam Ghanghas committed
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
class APMFirmwareVersion
{
public:
    APMFirmwareVersion(const QString &versionText = "");
    bool isValid() const;
    bool isBeta() const;
    bool isDev() const;
    bool operator<(const APMFirmwareVersion& other) const;
    QString versionString() const { return _versionString; }
    QString vehicleType() const { return _vehicleType; }
    int majorNumber() const { return _major; }
    int minorNumber() const { return _minor; }
    int patchNumber() const { return _patch; }

private:
    void _parseVersion(const QString &versionText);
    QString _versionString;
    QString _vehicleType;
    int     _major;
    int     _minor;
    int     _patch;
};

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
class APMCustomMode
{
public:
    APMCustomMode(uint32_t mode, bool settable);
    uint32_t modeAsInt() const { return _mode; }
    bool canBeSet() const { return _settable; }
    QString modeString() const;

protected:
    void setEnumToStringMapping(const QMap<uint32_t,QString>& enumToString);

private:
    uint32_t               _mode;
    bool                   _settable;
    QMap<uint32_t,QString> _enumToString;
};

65
/// This is the base class for all stack specific APM firmware plugins
Don Gagne's avatar
Don Gagne committed
66 67 68
class APMFirmwarePlugin : public FirmwarePlugin
{
    Q_OBJECT
69

Don Gagne's avatar
Don Gagne committed
70 71
public:
    // Overrides from FirmwarePlugin
72

73 74
    QList<VehicleComponent*> componentsForVehicle(AutoPilotPlugin* vehicle) override;
    QList<MAV_CMD> supportedMissionCommands(void) override;
75

76
    AutoPilotPlugin*    autopilotPlugin                 (Vehicle* vehicle) override;
77
    bool                isCapable                       (const Vehicle *vehicle, FirmwareCapabilities capabilities) override;
78
    void                setGuidedMode                   (Vehicle* vehicle, bool guidedMode) override;
79
    void                guidedModeTakeoff               (Vehicle* vehicle, double altitudeRel) override;
80
    void                guidedModeGotoLocation          (Vehicle* vehicle, const QGeoCoordinate& gotoCoord) override;
81
    double              minimumTakeoffAltitude          (Vehicle* vehicle) override;
82 83 84 85 86
    void                startMission                    (Vehicle* vehicle) override;
    QStringList         flightModes                     (Vehicle* vehicle) override;
    QString             flightMode                      (uint8_t base_mode, uint32_t custom_mode) const override;
    bool                setFlightMode                   (const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode) override;
    bool                isGuidedMode                    (const Vehicle* vehicle) const override;
Don Gagne's avatar
Don Gagne committed
87
    QString             gotoFlightMode                  (void) const override { return QStringLiteral("Guided"); }
88
    QString             rtlFlightMode                   (void) const override { return QString("RTL"); }
DonLakeFlyer's avatar
DonLakeFlyer committed
89
    QString             smartRTLFlightMode              (void) const override { return QString("Smart RTL"); }
90 91
    QString             missionFlightMode               (void) const override { return QString("Auto"); }
    void                pauseVehicle                    (Vehicle* vehicle) override;
DonLakeFlyer's avatar
DonLakeFlyer committed
92
    void                guidedModeRTL                   (Vehicle* vehicle, bool smartRTL) override;
93
    void                guidedModeChangeAltitude        (Vehicle* vehicle, double altitudeChange) override;
94
    bool                adjustIncomingMavlinkMessage    (Vehicle* vehicle, mavlink_message_t* message) override;
95
    void                adjustOutgoingMavlinkMessage    (Vehicle* vehicle, LinkInterface* outgoingLink, mavlink_message_t* message) override;
96
    virtual void        initializeStreamRates           (Vehicle* vehicle);
97 98 99
    void                initializeVehicle               (Vehicle* vehicle) override;
    bool                sendHomePositionToVehicle       (void) override;
    void                addMetaDataToFact               (QObject* parameterMetaData, Fact* fact, MAV_TYPE vehicleType) override;
100
    QString             missionCommandOverrides         (MAV_TYPE vehicleType) const override;
101 102 103 104
    QString             getVersionParam                 (void) override { return QStringLiteral("SYSID_SW_MREV"); }
    QString             internalParameterMetaDataFile   (Vehicle* vehicle) override;
    void                getParameterMetaDataVersionInfo (const QString& metaDataFile, int& majorVersion, int& minorVersion) override { APMParameterMetaData::getParameterMetaDataVersionInfo(metaDataFile, majorVersion, minorVersion); }
    QObject*            loadParameterMetaData           (const QString& metaDataFile) override;
105 106
    QString             brandImageIndoor                (const Vehicle* vehicle) const override { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/APM/BrandImage"); }
    QString             brandImageOutdoor               (const Vehicle* vehicle) const override { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/APM/BrandImage"); }
107
    bool                supportsTerrainFrame            (void) const override { return true; }
Don Gagne's avatar
Don Gagne committed
108

109 110
protected:
    /// All access to singleton is through stack specific implementation
111
    APMFirmwarePlugin(void);
112
    void setSupportedModes(QList<APMCustomMode> supportedModes);
Don Gagne's avatar
Don Gagne committed
113

114
    bool                _coaxialMotors;
Don Gagne's avatar
Don Gagne committed
115

Don Gagne's avatar
Don Gagne committed
116 117
private slots:
    void _artooSocketError(QAbstractSocket::SocketError socketError);
118

119
private:
120
    void _adjustSeverity(mavlink_message_t* message) const;
Don Gagne's avatar
Don Gagne committed
121
    void _adjustCalibrationMessageSeverity(mavlink_message_t* message) const;
Pritam Ghanghas's avatar
Pritam Ghanghas committed
122
    static bool _isTextSeverityAdjustmentNeeded(const APMFirmwareVersion& firmwareVersion);
Don Gagne's avatar
Don Gagne committed
123 124
    void _setInfoSeverity(mavlink_message_t* message, bool longVersion) const;
    QString _getMessageText(mavlink_message_t* message, bool longVersion) const;
125
    void _handleIncomingParamValue(Vehicle* vehicle, mavlink_message_t* message);
Don Gagne's avatar
Don Gagne committed
126
    bool _handleIncomingStatusText(Vehicle* vehicle, mavlink_message_t* message, bool longVersion);
127
    void _handleIncomingHeartbeat(Vehicle* vehicle, mavlink_message_t* message);
128
    void _handleOutgoingParamSet(Vehicle* vehicle, LinkInterface* outgoingLink, mavlink_message_t* message);
DonLakeFlyer's avatar
DonLakeFlyer committed
129
    void _soloVideoHandshake(Vehicle* vehicle, bool originalSoloFirmware);
130
    bool _guidedModeTakeoff(Vehicle* vehicle, double altitudeRel);
131 132
    void _handleRCChannels(Vehicle* vehicle, mavlink_message_t* message);
    void _handleRCChannelsRaw(Vehicle* vehicle, mavlink_message_t* message);
133 134
    QString _getLatestVersionFileUrl(Vehicle* vehicle) override;
    QString _versionRegex() override;
135

136 137 138
    // Any instance data here must be global to all vehicles
    // Vehicle specific data should go into APMFirmwarePluginInstanceData

139
    QList<APMCustomMode>    _supportedModes;
Don Gagne's avatar
Don Gagne committed
140

141 142
    static const char*      _artooIP;
    static const int        _artooVideoHandshakePort;
143 144 145 146 147 148 149 150
};

class APMFirmwarePluginInstanceData : public QObject
{
    Q_OBJECT

public:
    APMFirmwarePluginInstanceData(QObject* parent = NULL);
Don Gagne's avatar
Don Gagne committed
151

152
    bool                    textSeverityAdjustmentNeeded;
Don Gagne's avatar
Don Gagne committed
153 154 155
};

#endif