APMFirmwarePlugin.h 5.77 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"
20
#include "APMGeoFenceManager.h"
21
#include "APMRallyPointManager.h"
Don Gagne's avatar
Don Gagne committed
22

Don Gagne's avatar
Don Gagne committed
23 24
#include <QAbstractSocket>

25
Q_DECLARE_LOGGING_CATEGORY(APMFirmwarePluginLog)
Pritam Ghanghas's avatar
Pritam Ghanghas committed
26

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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;
};

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
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;
};

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

Don Gagne's avatar
Don Gagne committed
72 73
public:
    // Overrides from FirmwarePlugin
74 75 76 77

    QList<VehicleComponent*> componentsForVehicle(AutoPilotPlugin* vehicle) final;
    QList<MAV_CMD> supportedMissionCommands(void) final;

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    AutoPilotPlugin*    autopilotPlugin                 (Vehicle* vehicle) final;
    bool                isCapable                       (const Vehicle *vehicle, FirmwareCapabilities capabilities);
    QStringList         flightModes                     (Vehicle* vehicle) final;
    QString             flightMode                      (uint8_t base_mode, uint32_t custom_mode) const final;
    bool                setFlightMode                   (const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode) final;
    bool                isGuidedMode                    (const Vehicle* vehicle) const final;
    void                pauseVehicle                    (Vehicle* vehicle);
    int                 manualControlReservedButtonCount(void);
    bool                adjustIncomingMavlinkMessage    (Vehicle* vehicle, mavlink_message_t* message) final;
    void                adjustOutgoingMavlinkMessage    (Vehicle* vehicle, LinkInterface* outgoingLink, mavlink_message_t* message) final;
    void                initializeVehicle               (Vehicle* vehicle) final;
    bool                sendHomePositionToVehicle       (void) final;
    void                addMetaDataToFact               (QObject* parameterMetaData, Fact* fact, MAV_TYPE vehicleType) final;
    QString             missionCommandOverrides         (MAV_TYPE vehicleType) const;
    QString             getVersionParam                 (void) final { return QStringLiteral("SYSID_SW_MREV"); }
    QString             internalParameterMetaDataFile   (Vehicle* vehicle) final;
    void                getParameterMetaDataVersionInfo (const QString& metaDataFile, int& majorVersion, int& minorVersion) final { APMParameterMetaData::getParameterMetaDataVersionInfo(metaDataFile, majorVersion, minorVersion); }
    QObject*            loadParameterMetaData           (const QString& metaDataFile);
    GeoFenceManager*    newGeoFenceManager              (Vehicle* vehicle) { return new APMGeoFenceManager(vehicle); }
    RallyPointManager*  newRallyPointManager            (Vehicle* vehicle) { return new APMRallyPointManager(vehicle); }
98 99
    QString             brandImageIndoor                (const Vehicle* vehicle) const { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/APM/BrandImage"); }
    QString             brandImageOutdoor               (const Vehicle* vehicle) const { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/APM/BrandImage"); }
Don Gagne's avatar
Don Gagne committed
100

101 102
protected:
    /// All access to singleton is through stack specific implementation
103
    APMFirmwarePlugin(void);
104
    void setSupportedModes(QList<APMCustomMode> supportedModes);
Don Gagne's avatar
Don Gagne committed
105

106
    bool                _coaxialMotors;
Don Gagne's avatar
Don Gagne committed
107

Don Gagne's avatar
Don Gagne committed
108 109
private slots:
    void _artooSocketError(QAbstractSocket::SocketError socketError);
110

111
private:
112
    void _adjustSeverity(mavlink_message_t* message) const;
Don Gagne's avatar
Don Gagne committed
113
    void _adjustCalibrationMessageSeverity(mavlink_message_t* message) const;
Pritam Ghanghas's avatar
Pritam Ghanghas committed
114
    static bool _isTextSeverityAdjustmentNeeded(const APMFirmwareVersion& firmwareVersion);
115 116
    void _setInfoSeverity(mavlink_message_t* message) const;
    QString _getMessageText(mavlink_message_t* message) const;
117 118 119
    void _handleIncomingParamValue(Vehicle* vehicle, mavlink_message_t* message);
    bool _handleIncomingStatusText(Vehicle* vehicle, mavlink_message_t* message);
    void _handleIncomingHeartbeat(Vehicle* vehicle, mavlink_message_t* message);
120
    void _handleOutgoingParamSet(Vehicle* vehicle, LinkInterface* outgoingLink, mavlink_message_t* message);
Don Gagne's avatar
Don Gagne committed
121
    void _soloVideoHandshake(Vehicle* vehicle);
122

123 124
    bool                    _textSeverityAdjustmentNeeded;
    QList<APMCustomMode>    _supportedModes;
125
    QMap<QString, QTime>    _noisyPrearmMap;
Don Gagne's avatar
Don Gagne committed
126

127 128
    static const char*      _artooIP;
    static const int        _artooVideoHandshakePort;
Don Gagne's avatar
Don Gagne committed
129

Don Gagne's avatar
Don Gagne committed
130 131 132
};

#endif