QGC地面站二次开发(一)地面站介绍以及软件框架(2)QGC软件架构介绍

目录

QGCApplication 

QGroundControlQmlGlobal


在QGC的main函数里面我们看到

QGCApplication* app = new QGCApplication(argc, argv, runUnitTests);

QGCApplication是QGC数据交互的主体,QGC将相关的类在其中构造并将App作为一个全局的静态变量通过qgcApp()来访问。在该类的QGCApplication的_initCommon()实现名称为QGroundControlQmlGlobal的单例,也就是我们在qml文件中常常看到的QGroundControl 1.0模块了,通过该单例,我们可以在qml中访问C++的接口和一些属性信息。下面我们一起看一下它们的主要实现: 

void QGCApplication::_initCommon(void)
{
    QSettings settings;

    // Register our Qml objects

    qmlRegisterType     ("QGroundControl.Palette", 1, 0, "QGCPalette");
    qmlRegisterType  ("QGroundControl.Palette", 1, 0, "QGCMapPalette");

    qmlRegisterUncreatableType    ("QGroundControl",                      1, 0, "CoordinateVector",       "Reference only");
    qmlRegisterUncreatableType  ("QGroundControl",                      1, 0, "QmlObjectListModel",     "Reference only");
    qmlRegisterUncreatableType  ("QGroundControl",                      1, 0, "MissionCommandTree",     "Reference only");
    qmlRegisterUncreatableType          ("QGroundControl",                      1, 0, "CameraCalc",             "Reference only");

    qmlRegisterUncreatableType     ("QGroundControl.AutoPilotPlugin",      1, 0, "AutoPilotPlugin",        "Reference only");
    qmlRegisterUncreatableType    ("QGroundControl.AutoPilotPlugin",      1, 0, "VehicleComponent",       "Reference only");
    qmlRegisterUncreatableType             ("QGroundControl.Vehicle",              1, 0, "Vehicle",                "Reference only");
    qmlRegisterUncreatableType         ("QGroundControl.Vehicle",              1, 0, "MissionItem",            "Reference only");
    qmlRegisterUncreatableType      ("QGroundControl.Vehicle",              1, 0, "MissionManager",         "Reference only");
    qmlRegisterUncreatableType    ("QGroundControl.Vehicle",              1, 0, "ParameterManager",       "Reference only");
    qmlRegisterUncreatableType    ("QGroundControl.Vehicle",              1, 0, "QGCCameraManager",       "Reference only");
    qmlRegisterUncreatableType    ("QGroundControl.Vehicle",              1, 0, "QGCCameraControl",       "Reference only");
    qmlRegisterUncreatableType       ("QGroundControl.Vehicle",              1, 0, "LinkInterface",          "Reference only");
    qmlRegisterUncreatableType     ("QGroundControl.JoystickManager",      1, 0, "JoystickManager",        "Reference only");
    qmlRegisterUncreatableType            ("QGroundControl.JoystickManager",      1, 0, "Joystick",               "Reference only");
    qmlRegisterUncreatableType  ("QGroundControl.QGCPositionManager",   1, 0, "QGCPositionManager",     "Reference only");
    qmlRegisterUncreatableType       ("QGroundControl.FlightMap",            1, 0, "QGCMapPolygon",          "Reference only");
    qmlRegisterUncreatableType   ("QGroundControl.Controllers",          1, 0, "MissionController",      "Reference only");
    qmlRegisterUncreatableType  ("QGroundControl.Controllers",          1, 0, "GeoFenceController",     "Reference only");
    qmlRegisterUncreatableType("QGroundControl.Controllers",          1, 0, "RallyPointController",   "Reference only");
    qmlRegisterUncreatableType   ("QGroundControl.Controllers",          1, 0, "VisualMissionItem",      "Reference only");
    qmlRegisterUncreatableType("QGroundControl.FactControls",     1, 0, "FactValueSliderListModel","Reference only");

    qmlRegisterType      ("QGroundControl.Controllers", 1, 0, "ParameterEditorController");
    qmlRegisterType     ("QGroundControl.Controllers", 1, 0, "ESP8266ComponentController");
    qmlRegisterType          ("QGroundControl.Controllers", 1, 0, "ScreenToolsController");
    qmlRegisterType           ("QGroundControl.Controllers", 1, 0, "PlanMasterController");
    qmlRegisterType         ("QGroundControl.Controllers", 1, 0, "ValuesWidgetController");
    qmlRegisterType        ("QGroundControl.Controllers", 1, 0, "QGCFileDialogController");
    qmlRegisterType     ("QGroundControl.Controllers", 1, 0, "RCChannelMonitorController");
    qmlRegisterType       ("QGroundControl.Controllers", 1, 0, "JoystickConfigController");
    qmlRegisterType          ("QGroundControl.Controllers", 1, 0, "LogDownloadController");
    qmlRegisterType     ("QGroundControl.Controllers", 1, 0, "SyslinkComponentController");
    qmlRegisterType   ("QGroundControl.Controllers", 1, 0, "EditPositionDialogController");
    qmlRegisterType                   ("QGroundControl.FlightMap",   1, 0, "QGCMapCircle");
#ifndef __mobile__
    qmlRegisterType           ("QGroundControl.Controllers", 1, 0, "ViewWidgetController");
    qmlRegisterType  ("QGroundControl.Controllers", 1, 0, "CustomCommandWidgetController");
    qmlRegisterType      ("QGroundControl.Controllers", 1, 0, "FirmwareUpgradeController");
    qmlRegisterType               ("QGroundControl.Controllers", 1, 0, "GeoTagController");
    qmlRegisterType       ("QGroundControl.Controllers", 1, 0, "MavlinkConsoleController");
#endif

    // Register Qml Singletons
    qmlRegisterSingletonType   ("QGroundControl",                          1, 0, "QGroundControl",         qgroundcontrolQmlGlobalSingletonFactory);
    qmlRegisterSingletonType     ("QGroundControl.ScreenToolsController",    1, 0, "ScreenToolsController",  screenToolsControllerSingletonFactory);
    qmlRegisterSingletonType             ("QGroundControl.KMLFileHelper",            1, 0, "KMLFileHelper",          kmlFileHelperSingletonFactory);
}

QGCApplication 

构造了一个QGCToolbox* _toolbox,是一个主要的模块。在QGCToolBox的构造函数中,我们可以看到下面的代码

_settingsManager =          new SettingsManager(app, this);
    _audioOutput =              new AudioOutput             (app, this);    //语音播报
    _factSystem =               new FactSystem              (app, this);    
    _firmwarePluginManager =    new FirmwarePluginManager   (app, this);
#ifndef __mobile__
    _gpsManager =               new GPSManager              (app, this);
#endif
    _imageProvider =            new QGCImageProvider        (app, this);
    _joystickManager =          new JoystickManager         (app, this);    //虚拟遥感
    _linkManager =              new LinkManager             (app, this);    //连接管理,UDP、TCP、串口、MOCK
    _mavlinkProtocol =          new MAVLinkProtocol         (app, this);    //MAVLink消息处理入口 
    _missionCommandTree =       new MissionCommandTree      (app, this);    //Mission默认配置
    _multiVehicleManager =      new MultiVehicleManager     (app, this);    //飞机管理
    _mapEngineManager =         new QGCMapEngineManager     (app, this);    //地图引擎
    _uasMessageHandler =        new UASMessageHandler       (app, this);    //UAS
    _qgcPositionManager =       new QGCPositionManager      (app, this);
    _followMe =                 new FollowMe                (app, this);
    _videoManager =             new VideoManager            (app, this);
    _mavlinkLogManager =        new MAVLinkLogManager       (app, this);    //Log管理

在其中实现的类均继承于QGCTool,其状态都维护于protected的_toolbox变量,在其他模块,我们可以简单通过qgcApp()->toolbox()来访问其中的变量。接下来我重点介绍一下MAVLunk协议、飞机管理、Mission、电子围栏、Rally等关系可以通过 

QGroundControlQmlGlobal

它将需要在前端访问的C++类注册为它的属性,如下面的代码所示: 

Q_PROPERTY(LinkManager*         linkManager         READ linkManager            CONSTANT)
    Q_PROPERTY(MultiVehicleManager* multiVehicleManager READ multiVehicleManager    CONSTANT)
    Q_PROPERTY(QGCMapEngineManager* mapEngineManager    READ mapEngineManager       CONSTANT)
    Q_PROPERTY(QGCPositionManager*  qgcPositionManger   READ qgcPositionManger      CONSTANT)
    Q_PROPERTY(MissionCommandTree*  missionCommandTree  READ missionCommandTree     CONSTANT)
    Q_PROPERTY(VideoManager*        videoManager        READ videoManager           CONSTANT)
    Q_PROPERTY(MAVLinkLogManager*   mavlinkLogManager   READ mavlinkLogManager      CONSTANT)
    Q_PROPERTY(QGCCorePlugin*       corePlugin          READ corePlugin             CONSTANT)
    Q_PROPERTY(SettingsManager*     settingsManager     READ settingsManager        CONSTANT)
    Q_PROPERTY(FactGroup*           gpsRtk              READ gpsRtkFactGroup        CONSTANT)

同时将toolBox中的C++类指针指向它内部的指针,从而保证C++和qml前端访问相同的信息。 

void QGroundControlQmlGlobal::setToolbox(QGCToolbox* toolbox)
{
    QGCTool::setToolbox(toolbox);
    _linkManager            = toolbox->linkManager();
    _multiVehicleManager    = toolbox->multiVehicleManager();
    _mapEngineManager       = toolbox->mapEngineManager();
    _qgcPositionManager     = toolbox->qgcPositionManager();
    _missionCommandTree     = toolbox->missionCommandTree();
    _videoManager           = toolbox->videoManager();
    _mavlinkLogManager      = toolbox->mavlinkLogManager();
    _corePlugin             = toolbox->corePlugin();
    _firmwarePluginManager  = toolbox->firmwarePluginManager();
    _settingsManager        = toolbox->settingsManager();
                        ......
}

你可能感兴趣的:(嵌入式,物联网,qt,c++,ui)