FirmwarePlugin.h 7 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/

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

#ifndef FirmwarePlugin_H
#define FirmwarePlugin_H

Don Gagne's avatar
Don Gagne committed
30
#include "QGCMAVLink.h"
Don Gagne's avatar
Don Gagne committed
31 32 33 34 35 36
#include "VehicleComponent.h"
#include "AutoPilotPlugin.h"

#include <QList>
#include <QString>

37 38
class Vehicle;

Don Gagne's avatar
Don Gagne committed
39 40
/// This is the base class for Firmware specific plugins
///
41 42 43 44
/// The FirmwarePlugin class represents the methods and objects which are specific to a certain Firmware flight stack.
/// This is the only place where flight stack specific code should reside in QGroundControl. The remainder of the
/// QGroundControl source is generic to a common mavlink implementation. The implementation in the base class supports
/// mavlink generic firmware. Override the base clase virtuals to create your own firmware specific plugin.
Don Gagne's avatar
Don Gagne committed
45

Don Gagne's avatar
Don Gagne committed
46
class FirmwarePlugin : public QObject
Don Gagne's avatar
Don Gagne committed
47 48 49 50 51 52
{
    Q_OBJECT

public:
    /// Set of optional capabilites which firmware may support
    typedef enum {
Don Gagne's avatar
Don Gagne committed
53
        SetFlightModeCapability,            ///< FirmwarePlugin::setFlightMode method is supported
54
        MavCmdPreflightStorageCapability,   ///< MAV_CMD_PREFLIGHT_STORAGE is supported        
Don Gagne's avatar
Don Gagne committed
55 56 57
    } FirmwareCapabilities;
    
    /// @return true: Firmware supports all specified capabilites
58 59
    virtual bool isCapable(FirmwareCapabilities capabilities) { Q_UNUSED(capabilities); return false; }

Don Gagne's avatar
Don Gagne committed
60 61 62 63
    /// Returns VehicleComponents for specified Vehicle
    ///     @param vehicle Vehicle  to associate with components
    /// @return List of VehicleComponents for the specified vehicle. Caller owns returned objects and must
    ///         free when no longer needed.
64
    virtual QList<VehicleComponent*> componentsForVehicle(AutoPilotPlugin* vehicle);
Don Gagne's avatar
Don Gagne committed
65 66
    
    /// Returns the list of available flight modes
67
    virtual QStringList flightModes(void) { return QStringList(); }
Don Gagne's avatar
Don Gagne committed
68 69 70 71
    
    /// Returns the name for this flight mode. Flight mode names must be human readable as well as audio speakable.
    ///     @param base_mode Base mode from mavlink HEARTBEAT message
    ///     @param custom_mode Custom mode from mavlink HEARTBEAT message
72
    virtual QString flightMode(uint8_t base_mode, uint32_t custom_mode);
Don Gagne's avatar
Don Gagne committed
73 74 75 76
    
    /// Sets base_mode and custom_mode to specified flight mode.
    ///     @param[out] base_mode Base mode for SET_MODE mavlink message
    ///     @param[out] custom_mode Custom mode for SET_MODE mavlink message
77
    virtual bool setFlightMode(const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode);
Don Gagne's avatar
Don Gagne committed
78
    
79
    /// FIXME: This isn't quite correct being here. All code for Joystick suvehicleTypepport is currently firmware specific
Don Gagne's avatar
Don Gagne committed
80
    /// not just this. I'm going to try to change that. If not, this will need to be removed.
81 82 83 84
    /// Returns the number of buttons which are reserved for firmware use in the MANUAL_CONTROL mavlink
    /// message. For example PX4 Flight Stack reserves the first 8 buttons to simulate rc switches.
    /// The remainder can be assigned to Vehicle actions.
    /// @return -1: reserver all buttons, >0 number of buttons to reserve
85
    virtual int manualControlReservedButtonCount(void);
86
    
nopeppermint's avatar
nopeppermint committed
87
    /// Called before any mavlink message is processed by Vehicle such that the firmwre plugin
Don Gagne's avatar
Don Gagne committed
88 89
    /// can adjust any message characteristics. This is handy to adjust or differences in mavlink
    /// spec implementations such that the base code can remain mavlink generic.
90
    ///     @param vehicle Vehicle message came from
Don Gagne's avatar
Don Gagne committed
91
    ///     @param message[in,out] Mavlink message to adjust if needed.
92
    virtual void adjustMavlinkMessage(Vehicle* vehicle, mavlink_message_t* message);
Don Gagne's avatar
Don Gagne committed
93
    
94
    /// Called when Vehicle is first created to send any necessary mavlink messages to the firmware.
95
    virtual void initializeVehicle(Vehicle* vehicle);
96 97 98 99 100 101 102

    /// Determines how to handle the first item of the mission item list. Internally to QGC the first item
    /// is always the home position.
    /// @return
    ///     true: Send first mission item as home position to vehicle. When vehicle has no mission items on
    ///             it, it may or may not return a home position back in position 0.
    ///     false: Do not send first item to vehicle, sequence numbers must be adjusted
103
    virtual bool sendHomePositionToVehicle(void);
104
    
105
    /// Returns the parameter that is used to identify the default component
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    virtual QString getDefaultComponentIdParam(void) const { return QString(); }

    /// Returns the parameter which is used to identify the version number of parameter set
    virtual QString getVersionParam(void) { return QString(); }

    /// Returns the parameter set version info pulled from inside the meta data file. -1 if not found.
    virtual void getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion);

    /// Returns the internal resource parameter meta date file.
    virtual QString internalParameterMetaDataFile(void) { return QString(); }

    /// Loads the specified parameter meta data file.
    /// @return Opaque parameter meta data information which must be stored with Vehicle. Vehicle is reponsible to
    ///         call deleteParameterMetaData when no longer needed.
    virtual QObject* loadParameterMetaData(const QString& metaDataFile) { Q_UNUSED(metaDataFile); return NULL; }
121 122

    /// Adds the parameter meta data to the Fact
123 124
    ///     @param opaqueParameterMetaData Opaque pointer returned from loadParameterMetaData
    virtual void addMetaDataToFact(QObject* parameterMetaData, Fact* fact, MAV_TYPE vehicleType) { Q_UNUSED(parameterMetaData); Q_UNUSED(fact); Q_UNUSED(vehicleType); return; }
Don Gagne's avatar
Don Gagne committed
125 126

    /// List of supported mission commands. Empty list for all commands supported.
127
    virtual QList<MAV_CMD> supportedMissionCommands(void);
128 129 130 131 132

    /// Returns the names for the mission command json override files. Empty string to specify no overrides.
    ///     @param[out] commonJsonFilename Filename for common overrides
    ///     @param[out] fixedWingJsonFilename Filename for fixed wing overrides
    ///     @param[out] multiRotorJsonFilename Filename for multi rotor overrides
133 134
    virtual void missionCommandOverrides(QString& commonJsonFilename, QString& fixedWingJsonFilename, QString& multiRotorJsonFilename) const;

Don Gagne's avatar
Don Gagne committed
135 136 137
};

#endif