QGCMAVLinkUASFactory.cc 1 KB
Newer Older
1 2 3 4 5 6 7 8
#include "QGCMAVLinkUASFactory.h"
#include "UASManager.h"

QGCMAVLinkUASFactory::QGCMAVLinkUASFactory(QObject *parent) :
    QObject(parent)
{
}

Don Gagne's avatar
Don Gagne committed
9
UASInterface* QGCMAVLinkUASFactory::createUAS(MAVLinkProtocol* mavlink, LinkInterface* link, int sysid, MAV_AUTOPILOT autopilotType)
10
{
11
    UASInterface* uasInterface;
12

Don Gagne's avatar
Don Gagne committed
13
    UAS* uasObject = new UAS(mavlink, sysid, autopilotType);
14 15
    Q_CHECK_PTR(uasObject);
    uasInterface = uasObject;
16

17 18 19 20 21
    // Connect this robot to the UAS object
    // It is IMPORTANT here to use the right object type,
    // else the slot of the parent object is called (and thus the special
    // packets never reach their goal)
    connect(mavlink, &MAVLinkProtocol::messageReceived, uasObject, &UAS::receiveMessage);
22 23

    // Make UAS aware that this link can be used to communicate with the actual robot
24
    uasInterface->addLink(link);
25 26

    // Now add UAS to "official" list, which makes the whole application aware of it
27
    UASManager::instance()->addUAS(uasInterface);
28
    
29
    return uasInterface;
30
}