QGCMAVLinkUASFactory.cc 1.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#include "QGCMAVLinkUASFactory.h"
#include "UASManager.h"

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

UASInterface* QGCMAVLinkUASFactory::createUAS(MAVLinkProtocol* mavlink, LinkInterface* link, int sysid, mavlink_heartbeat_t* heartbeat, QObject* parent)
{
    QPointer<QObject> p;

lm's avatar
lm committed
13 14
    if (parent != NULL)
    {
15
        p = parent;
lm's avatar
lm committed
16 17 18
    }
    else
    {
19 20 21
        p = mavlink;
    }

22
    UASInterface* uasInterface;
23

24 25 26 27 28
    UAS* uasObject = new UAS(mavlink, sysid);
    Q_CHECK_PTR(uasObject);
    uasInterface = uasObject;
    
    uasObject->setSystemType((int)heartbeat->type);
29

30 31 32 33 34
    // 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);
35 36

    // Set the autopilot type
37
    uasInterface->setAutopilotType((int)heartbeat->autopilot);
38 39

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

42
    // First thing we do with a new UAS is get the parameters
43
    uasInterface->getParamManager()->requestParameterList();
44
    
45
    // Now add UAS to "official" list, which makes the whole application aware of it
46
    UASManager::instance()->addUAS(uasInterface);
47
    
48
    return uasInterface;
49
}