FirmwarePlugin.cc 8.44 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/
9

10
#include "FirmwarePlugin.h"
Don Gagne's avatar
Don Gagne committed
11
#include "QGCApplication.h"
12
#include "Generic/GenericAutoPilotPlugin.h"
Don Gagne's avatar
Don Gagne committed
13 14 15

#include <QDebug>

16 17
static FirmwarePluginFactoryRegister* _instance = NULL;

18 19
const char* guided_mode_not_supported_by_vehicle = "Guided mode not supported by Vehicle.";

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
const char* FirmwarePlugin::px4FollowMeFlightMode = "Follow Me";

FirmwarePluginFactory::FirmwarePluginFactory(void)
{
    FirmwarePluginFactoryRegister::instance()->registerPluginFactory(this);
}

FirmwarePluginFactoryRegister* FirmwarePluginFactoryRegister::instance(void)
{
    if (!_instance) {
        _instance = new FirmwarePluginFactoryRegister;
    }

    return _instance;
}

AutoPilotPlugin* FirmwarePlugin::autopilotPlugin(Vehicle* vehicle)
{
    return new GenericAutoPilotPlugin(vehicle, vehicle);
}

41
bool FirmwarePlugin::isCapable(const Vehicle *vehicle, FirmwareCapabilities capabilities)
Don Gagne's avatar
Don Gagne committed
42
{
43
    Q_UNUSED(vehicle);
Don Gagne's avatar
Don Gagne committed
44 45 46 47
    Q_UNUSED(capabilities);
    return false;
}

48
QList<VehicleComponent*> FirmwarePlugin::componentsForVehicle(AutoPilotPlugin* vehicle)
Don Gagne's avatar
Don Gagne committed
49 50
{
    Q_UNUSED(vehicle);
51

Don Gagne's avatar
Don Gagne committed
52 53 54
    return QList<VehicleComponent*>();
}

Don Gagne's avatar
Don Gagne committed
55
QString FirmwarePlugin::flightMode(uint8_t base_mode, uint32_t custom_mode) const
Don Gagne's avatar
Don Gagne committed
56 57
{
    QString flightMode;
58

Don Gagne's avatar
Don Gagne committed
59 60 61 62 63
    struct Bit2Name {
        uint8_t     baseModeBit;
        const char* name;
    };
    static const struct Bit2Name rgBit2Name[] = {
64 65 66 67 68 69
    { MAV_MODE_FLAG_MANUAL_INPUT_ENABLED,   "Manual" },
    { MAV_MODE_FLAG_STABILIZE_ENABLED,      "Stabilize" },
    { MAV_MODE_FLAG_GUIDED_ENABLED,         "Guided" },
    { MAV_MODE_FLAG_AUTO_ENABLED,           "Auto" },
    { MAV_MODE_FLAG_TEST_ENABLED,           "Test" },
};
70

Don Gagne's avatar
Don Gagne committed
71
    Q_UNUSED(custom_mode);
72

Don Gagne's avatar
Don Gagne committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86
    if (base_mode == 0) {
        flightMode = "PreFlight";
    } else if (base_mode & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED) {
        flightMode = QString("Custom:0x%1").arg(custom_mode, 0, 16);
    } else {
        for (size_t i=0; i<sizeof(rgBit2Name)/sizeof(rgBit2Name[0]); i++) {
            if (base_mode & rgBit2Name[i].baseModeBit) {
                if (i != 0) {
                    flightMode += " ";
                }
                flightMode += rgBit2Name[i].name;
            }
        }
    }
87

Don Gagne's avatar
Don Gagne committed
88 89 90
    return flightMode;
}

91
bool FirmwarePlugin::setFlightMode(const QString& flightMode, uint8_t* base_mode, uint32_t* custom_mode)
Don Gagne's avatar
Don Gagne committed
92 93 94 95
{
    Q_UNUSED(flightMode);
    Q_UNUSED(base_mode);
    Q_UNUSED(custom_mode);
96

97
    qWarning() << "FirmwarePlugin::setFlightMode called on base class, not supported";
98

Don Gagne's avatar
Don Gagne committed
99 100
    return false;
}
101

102
int FirmwarePlugin::manualControlReservedButtonCount(void)
103 104 105 106 107
{
    // We don't know whether the firmware is going to used any of these buttons.
    // So reserve them all.
    return -1;
}
Don Gagne's avatar
Don Gagne committed
108

109 110 111 112 113
int FirmwarePlugin::defaultJoystickTXMode(void)
{
    return 2;
}

114 115 116 117 118 119
bool FirmwarePlugin::supportsThrottleModeCenterZero(void)
{
    // By default, this is supported
    return true;
}

120 121 122 123 124
bool FirmwarePlugin::supportsManualControl(void)
{
    return false;
}

125 126 127 128 129
bool FirmwarePlugin::supportsRadio(void)
{
    return true;
}

130 131 132 133 134
bool FirmwarePlugin::supportsJSButton(void)
{
    return false;
}

135
bool FirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_message_t* message)
Don Gagne's avatar
Don Gagne committed
136 137
{
    Q_UNUSED(vehicle);
138
    Q_UNUSED(message);
Don Gagne's avatar
Don Gagne committed
139
    // Generic plugin does no message adjustment
140
    return true;
Don Gagne's avatar
Don Gagne committed
141 142
}

143
void FirmwarePlugin::adjustOutgoingMavlinkMessage(Vehicle* vehicle, LinkInterface* outgoingLink, mavlink_message_t* message)
Don Gagne's avatar
Don Gagne committed
144
{
145
    Q_UNUSED(vehicle);
146
    Q_UNUSED(outgoingLink);
Don Gagne's avatar
Don Gagne committed
147 148 149
    Q_UNUSED(message);
    // Generic plugin does no message adjustment
}
150

151
void FirmwarePlugin::initializeVehicle(Vehicle* vehicle)
152 153
{
    Q_UNUSED(vehicle);
154

155 156
    // Generic Flight Stack is by definition "generic", so no extra work
}
157

158
bool FirmwarePlugin::sendHomePositionToVehicle(void)
159 160 161 162 163 164
{
    // Generic stack does not want home position sent in the first position.
    // Subsequent sequence numbers must be adjusted.
    // This is the mavlink spec default.
    return false;
}
165

166
QList<MAV_CMD> FirmwarePlugin::supportedMissionCommands(void)
Don Gagne's avatar
Don Gagne committed
167 168 169 170
{
    // Generic supports all commands
    return QList<MAV_CMD>();
}
171

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
QString FirmwarePlugin::missionCommandOverrides(MAV_TYPE vehicleType) const
{
    switch (vehicleType) {
    case MAV_TYPE_GENERIC:
        return QStringLiteral(":/json/MavCmdInfoCommon.json");
        break;
    case MAV_TYPE_FIXED_WING:
        return QStringLiteral(":/json/MavCmdInfoFixedWing.json");
        break;
    case MAV_TYPE_QUADROTOR:
        return QStringLiteral(":/json/MavCmdInfoMultiRotor.json");
        break;
    case MAV_TYPE_VTOL_QUADROTOR:
        return QStringLiteral(":/json/MavCmdInfoVTOL.json");
        break;
    case MAV_TYPE_SUBMARINE:
        return QStringLiteral(":/json/MavCmdInfoSub.json");
        break;
    case MAV_TYPE_GROUND_ROVER:
        return QStringLiteral(":/json/MavCmdInfoRover.json");
        break;
    default:
        qWarning() << "FirmwarePlugin::missionCommandOverrides called with bad MAV_TYPE:" << vehicleType;
        return QString();
    }
197
}
198 199 200 201 202 203 204

void FirmwarePlugin::getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion)
{
    Q_UNUSED(metaDataFile);
    majorVersion = -1;
    minorVersion = -1;
}
Don Gagne's avatar
Don Gagne committed
205 206 207 208 209 210 211 212 213 214 215 216

bool FirmwarePlugin::isGuidedMode(const Vehicle* vehicle) const
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
    return false;
}

void FirmwarePlugin::setGuidedMode(Vehicle* vehicle, bool guidedMode)
{
    Q_UNUSED(vehicle);
    Q_UNUSED(guidedMode);
217
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
218 219 220 221 222 223 224 225 226 227 228 229 230
}

bool FirmwarePlugin::isPaused(const Vehicle* vehicle) const
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
    return false;
}

void FirmwarePlugin::pauseVehicle(Vehicle* vehicle)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
231
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
232 233 234 235 236 237
}

void FirmwarePlugin::guidedModeRTL(Vehicle* vehicle)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
238
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
239 240 241 242 243 244
}

void FirmwarePlugin::guidedModeLand(Vehicle* vehicle)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
245
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
246 247 248 249 250 251 252
}

void FirmwarePlugin::guidedModeTakeoff(Vehicle* vehicle, double altitudeRel)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
    Q_UNUSED(altitudeRel);
253
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
254 255
}

256 257 258 259 260 261
void FirmwarePlugin::guidedModeOrbit(Vehicle* /*vehicle*/, const QGeoCoordinate& /*centerCoord*/, double /*radius*/, double /*velocity*/, double /*altitude*/)
{
    // Not supported by generic vehicle
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
}

Don Gagne's avatar
Don Gagne committed
262 263 264 265 266
void FirmwarePlugin::guidedModeGotoLocation(Vehicle* vehicle, const QGeoCoordinate& gotoCoord)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
    Q_UNUSED(gotoCoord);
267
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
268 269 270 271 272 273 274
}

void FirmwarePlugin::guidedModeChangeAltitude(Vehicle* vehicle, double altitudeRel)
{
    // Not supported by generic vehicle
    Q_UNUSED(vehicle);
    Q_UNUSED(altitudeRel);
275
    qgcApp()->showMessage(guided_mode_not_supported_by_vehicle);
Don Gagne's avatar
Don Gagne committed
276
}
277 278 279

const FirmwarePlugin::remapParamNameMajorVersionMap_t& FirmwarePlugin::paramNameRemapMajorVersionMap(void) const
{
Don Gagne's avatar
Don Gagne committed
280 281 282
    static const remapParamNameMajorVersionMap_t remap;

    return remap;
283 284 285 286 287 288 289
}

int FirmwarePlugin::remapParamNameHigestMinorVersionNumber(int majorVersionNumber) const
{
    Q_UNUSED(majorVersionNumber);
    return 0;
}
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304

QString FirmwarePlugin::missionFlightMode(void)
{
    return QString();
}

QString FirmwarePlugin::rtlFlightMode(void)
{
    return QString();
}

QString FirmwarePlugin::takeControlFlightMode(void)
{
    return QString();
}
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322

QString FirmwarePlugin::vehicleImageOpaque(const Vehicle* vehicle) const
{
    Q_UNUSED(vehicle);
    return QStringLiteral("/qmlimages/vehicleArrowOpaque.svg");
}

QString FirmwarePlugin::vehicleImageOutline(const Vehicle* vehicle) const
{
    Q_UNUSED(vehicle);
    return QStringLiteral("/qmlimages/vehicleArrowOutline.svg");
}

QString FirmwarePlugin::vehicleImageCompass(const Vehicle* vehicle) const
{
    Q_UNUSED(vehicle);
    return QStringLiteral("/qmlimages/compassInstrumentArrow.svg");
}