APMFirmwarePlugin.h 6.54 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * 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 "FollowMe.h"
Don Gagne's avatar
Don Gagne committed
21

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

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

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
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;
};

43
/// This is the base class for all stack specific APM firmware plugins
Don Gagne's avatar
Don Gagne committed
44 45 46
class APMFirmwarePlugin : public FirmwarePlugin
{
    Q_OBJECT
47

Don Gagne's avatar
Don Gagne committed
48 49
public:
    // Overrides from FirmwarePlugin
50

51
    QList<VehicleComponent*> componentsForVehicle(AutoPilotPlugin* vehicle) override;
52
    QList<MAV_CMD> supportedMissionCommands(QGCMAVLink::VehicleClass_t vehicleClass) override;
53

54
    AutoPilotPlugin*    autopilotPlugin                 (Vehicle* vehicle) override;
55
    bool                isCapable                       (const Vehicle *vehicle, FirmwareCapabilities capabilities) override;
56
    void                setGuidedMode                   (Vehicle* vehicle, bool guidedMode) override;
57
    void                guidedModeTakeoff               (Vehicle* vehicle, double altitudeRel) override;
58
    void                guidedModeGotoLocation          (Vehicle* vehicle, const QGeoCoordinate& gotoCoord) override;
59
    double              minimumTakeoffAltitude          (Vehicle* vehicle) override;
60 61 62 63 64
    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
65
    QString             gotoFlightMode                  (void) const override { return QStringLiteral("Guided"); }
66
    QString             rtlFlightMode                   (void) const override { return QString("RTL"); }
DonLakeFlyer's avatar
DonLakeFlyer committed
67
    QString             smartRTLFlightMode              (void) const override { return QString("Smart RTL"); }
68 69
    QString             missionFlightMode               (void) const override { return QString("Auto"); }
    void                pauseVehicle                    (Vehicle* vehicle) override;
DonLakeFlyer's avatar
DonLakeFlyer committed
70
    void                guidedModeRTL                   (Vehicle* vehicle, bool smartRTL) override;
71
    void                guidedModeChangeAltitude        (Vehicle* vehicle, double altitudeChange) override;
72
    bool                adjustIncomingMavlinkMessage    (Vehicle* vehicle, mavlink_message_t* message) override;
73
    void                adjustOutgoingMavlinkMessageThreadSafe(Vehicle* vehicle, LinkInterface* outgoingLink, mavlink_message_t* message) override;
74
    virtual void        initializeStreamRates           (Vehicle* vehicle);
75 76
    void                initializeVehicle               (Vehicle* vehicle) override;
    bool                sendHomePositionToVehicle       (void) override;
77
    QString             missionCommandOverrides         (QGCMAVLink::VehicleClass_t vehicleClass) const override;
78 79 80 81
    QString             _internalParameterMetaDataFile  (Vehicle* vehicle) override;
    FactMetaData*       _getMetaDataForFact             (QObject* parameterMetaData, const QString& name, FactMetaData::ValueType_t type, MAV_TYPE vehicleType) override;
    void                _getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion) override { APMParameterMetaData::getParameterMetaDataVersionInfo(metaDataFile, majorVersion, minorVersion); }
    QObject*            _loadParameterMetaData          (const QString& metaDataFile) override;
82 83
    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"); }
Don Gagne's avatar
Don Gagne committed
84

85 86
protected:
    /// All access to singleton is through stack specific implementation
87
    APMFirmwarePlugin(void);
88 89 90

    void setSupportedModes  (QList<APMCustomMode> supportedModes);
    void _sendGCSMotionReport(Vehicle* vehicle, FollowMe::GCSMotionReport& motionReport, uint8_t estimatationCapabilities);
Don Gagne's avatar
Don Gagne committed
91

92
    bool                _coaxialMotors;
Don Gagne's avatar
Don Gagne committed
93

Don Gagne's avatar
Don Gagne committed
94 95
private slots:
    void _artooSocketError(QAbstractSocket::SocketError socketError);
96

97
private:
Don Gagne's avatar
Don Gagne committed
98
    void _adjustCalibrationMessageSeverity(mavlink_message_t* message) const;
99 100
    void _setInfoSeverity(mavlink_message_t* message) const;
    QString _getMessageText(mavlink_message_t* message) const;
101
    void _handleIncomingParamValue(Vehicle* vehicle, mavlink_message_t* message);
102
    bool _handleIncomingStatusText(Vehicle* vehicle, mavlink_message_t* message);
103
    void _handleIncomingHeartbeat(Vehicle* vehicle, mavlink_message_t* message);
104
    void _handleOutgoingParamSetThreadSafe(Vehicle* vehicle, LinkInterface* outgoingLink, mavlink_message_t* message);
105
    void _soloVideoHandshake(void);
106
    bool _guidedModeTakeoff(Vehicle* vehicle, double altitudeRel);
107 108
    void _handleRCChannels(Vehicle* vehicle, mavlink_message_t* message);
    void _handleRCChannelsRaw(Vehicle* vehicle, mavlink_message_t* message);
109 110
    QString _getLatestVersionFileUrl(Vehicle* vehicle) override;
    QString _versionRegex() override;
111

112 113 114
    // Any instance data here must be global to all vehicles
    // Vehicle specific data should go into APMFirmwarePluginInstanceData

115
    QList<APMCustomMode>    _supportedModes;
116
    QMap<int /* vehicle id */, QMap<int /* componentId */, bool /* true: component is part of ArduPilot stack */>> _ardupilotComponentMap;
Don Gagne's avatar
Don Gagne committed
117

118 119
    QMutex _adjustOutgoingMavlinkMutex;

120 121
    static const char*      _artooIP;
    static const int        _artooVideoHandshakePort;
122 123
};

Don Gagne's avatar
Don Gagne committed
124
#endif