APMFirmwarePlugin.h 4.89 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)
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 69 70 71
class APMFirmwarePlugin : public FirmwarePlugin
{
    Q_OBJECT
    
public:
    // Overrides from FirmwarePlugin
72 73 74 75

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

Don Gagne's avatar
Don Gagne committed
76
    bool        isCapable(FirmwareCapabilities capabilities);
77
    QStringList flightModes(Vehicle* vehicle) final;
Don Gagne's avatar
Don Gagne committed
78
    QString     flightMode(uint8_t base_mode, uint32_t custom_mode) const final;
79
    bool        setFlightMode(const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode) final;
Don Gagne's avatar
Don Gagne committed
80 81
    bool        isGuidedMode(const Vehicle* vehicle) const final;
    void        pauseVehicle(Vehicle* vehicle);
82
    int         manualControlReservedButtonCount(void) final;
83
    bool        adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_message_t* message) final;
Don Gagne's avatar
Don Gagne committed
84
    void        adjustOutgoingMavlinkMessage(Vehicle* vehicle, mavlink_message_t* message) final;
85 86 87 88 89 90 91 92 93
    void        initializeVehicle(Vehicle* vehicle) final;
    bool        sendHomePositionToVehicle(void) final;
    void        addMetaDataToFact(QObject* parameterMetaData, Fact* fact, MAV_TYPE vehicleType) final;
    QString     getDefaultComponentIdParam(void) const final { return QString("SYSID_SW_TYPE"); }
    void        missionCommandOverrides(QString& commonJsonFilename, QString& fixedWingJsonFilename, QString& multiRotorJsonFilename) const final;
    QString     getVersionParam(void) final { return QStringLiteral("SYSID_SW_MREV"); }
    QString     internalParameterMetaDataFile   (void) final { return QString(":/FirmwarePlugin/APM/APMParameterFactMetaData.xml"); }
    void        getParameterMetaDataVersionInfo (const QString& metaDataFile, int& majorVersion, int& minorVersion) final { APMParameterMetaData::getParameterMetaDataVersionInfo(metaDataFile, majorVersion, minorVersion); }
    QObject*    loadParameterMetaData           (const QString& metaDataFile);
94

95 96
    QString     getParameterMetaDataFile(Vehicle* vehicle);

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

private slots:
    void _artooSocketError(QAbstractSocket::SocketError socketError);
104 105
    
private:
106
    void _adjustSeverity(mavlink_message_t* message) const;
Don Gagne's avatar
Don Gagne committed
107
    void _adjustCalibrationMessageSeverity(mavlink_message_t* message) const;
108
    static bool _isTextSeverityAdjustmentNeeded(const APMFirmwareVersion& firmwareVersion);
109 110
    void _setInfoSeverity(mavlink_message_t* message) const;
    QString _getMessageText(mavlink_message_t* message) const;
Don Gagne's avatar
Don Gagne committed
111 112
    void _handleParamValue(Vehicle* vehicle, mavlink_message_t* message);
    void _handleParamSet(Vehicle* vehicle, mavlink_message_t* message);
113
    bool _handleStatusText(Vehicle* vehicle, mavlink_message_t* message);
Don Gagne's avatar
Don Gagne committed
114
    void _handleHeartbeat(Vehicle* vehicle, mavlink_message_t* message);
Don Gagne's avatar
Don Gagne committed
115
    void _soloVideoHandshake(Vehicle* vehicle);
116

117 118
    bool                    _textSeverityAdjustmentNeeded;
    QList<APMCustomMode>    _supportedModes;
119
    QMap<QString, QTime>    _noisyPrearmMap;
Don Gagne's avatar
Don Gagne committed
120 121 122 123

    static const char*  _artooIP;
    static const int    _artooVideoHandshakePort;

Don Gagne's avatar
Don Gagne committed
124 125 126
};

#endif