FirmwarePluginManager.cc 1.79 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.
 *
 ****************************************************************************/
Don Gagne's avatar
Don Gagne committed
9

Don Gagne's avatar
Don Gagne committed
10 11 12 13 14

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

#include "FirmwarePluginManager.h"
15
#include "FirmwarePlugin.h"
Don Gagne's avatar
Don Gagne committed
16

Don Gagne's avatar
Don Gagne committed
17 18 19 20 21 22 23 24 25 26 27 28
FirmwarePluginManager::FirmwarePluginManager(QGCApplication* app)
    : QGCTool(app)
    , _genericFirmwarePlugin(NULL)
{

}

FirmwarePluginManager::~FirmwarePluginManager()
{
    delete _genericFirmwarePlugin;
}

29
QList<MAV_AUTOPILOT> FirmwarePluginManager::knownFirmwareTypes(void)
30
{
31 32 33 34 35 36 37 38 39 40 41
    if (_knownFirmwareTypes.isEmpty()) {
        QList<FirmwarePluginFactory*> factoryList = FirmwarePluginFactoryRegister::instance()->pluginFactories();

        for (int i=0; i<factoryList.count(); i++) {
            _knownFirmwareTypes.append(factoryList[i]->knownFirmwareTypes());
        }
    }

    _knownFirmwareTypes.append(MAV_AUTOPILOT_GENERIC);

    return _knownFirmwareTypes;
42 43
}

44
FirmwarePlugin* FirmwarePluginManager::firmwarePluginForAutopilot(MAV_AUTOPILOT autopilotType, MAV_TYPE vehicleType)
Don Gagne's avatar
Don Gagne committed
45
{
46 47 48 49 50 51 52
    FirmwarePlugin* _plugin = NULL;
    QList<FirmwarePluginFactory*> factoryList = FirmwarePluginFactoryRegister::instance()->pluginFactories();

    // Find the plugin which supports this vehicle
    for (int i=0; i<factoryList.count(); i++) {
        if ((_plugin = factoryList[i]->firmwarePluginForAutopilot(autopilotType, vehicleType))) {
            return _plugin;
Don Gagne's avatar
Don Gagne committed
53 54 55
        }
    }

56
    // Default plugin fallback
Don Gagne's avatar
Don Gagne committed
57
    if (!_genericFirmwarePlugin) {
58
        _genericFirmwarePlugin = new FirmwarePlugin;
Don Gagne's avatar
Don Gagne committed
59
    }
Don Gagne's avatar
Don Gagne committed
60
    return _genericFirmwarePlugin;
Don Gagne's avatar
Don Gagne committed
61
}