Newer
Older
/****************************************************************************
*
* (c) 2009-2020 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.
*
****************************************************************************/
#include <QDebug>
#include "SettingsManager.h"
QGC_LOGGING_CATEGORY(LinkManagerLog, "LinkManagerLog")
QGC_LOGGING_CATEGORY(LinkManagerVerboseLog, "LinkManagerVerboseLog")
const char* LinkManager::_defaultUPDLinkName = "UDP Link (AutoConnect)";
dogmaphobic
committed
const int LinkManager::_autoconnectUpdateTimerMSecs = 1000;
#ifdef Q_OS_WIN
// Have to manually let the bootloader go by on Windows to get a working connect
const int LinkManager::_autoconnectConnectDelayMSecs = 6000;
#else
const int LinkManager::_autoconnectConnectDelayMSecs = 1000;
#endif
LinkManager::LinkManager(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox)
dogmaphobic
committed
, _configUpdateSuspended(false)
, _configurationsLoaded(false)
, _connectionsSuspended(false)
, _mavlinkChannelsUsedBitMask(1) // We never use channel 0 to avoid sequence numbering problems
, _autoConnectSettings(nullptr)
, _mavlinkProtocol(nullptr)
#ifndef NO_SERIAL_LINK
qmlRegisterUncreatableType<LinkManager> ("QGroundControl", 1, 0, "LinkManager", "Reference only");
qmlRegisterUncreatableType<LinkConfiguration> ("QGroundControl", 1, 0, "LinkConfiguration", "Reference only");
qmlRegisterUncreatableType<LinkInterface> ("QGroundControl", 1, 0, "LinkInterface", "Reference only");
_activeLinkCheckTimer.setInterval(_activeLinkCheckTimeoutMSecs);
_activeLinkCheckTimer.setSingleShot(false);
connect(&_activeLinkCheckTimer, &QTimer::timeout, this, &LinkManager::_activeLinkCheck);
#ifndef NO_SERIAL_LINK
void LinkManager::setToolbox(QGCToolbox *toolbox)
{
_autoConnectSettings = toolbox->settingsManager()->autoConnectSettings();
_mavlinkProtocol = _toolbox->mavlinkProtocol();
acfloria
committed
connect(_mavlinkProtocol, &MAVLinkProtocol::messageReceived, this, &LinkManager::_mavlinkMessageReceived);
acfloria
committed
connect(&_portListTimer, &QTimer::timeout, this, &LinkManager::_updateAutoConnectLinks);
_portListTimer.start(_autoconnectUpdateTimerMSecs); // timeout must be long enough to get past bootloader on second pass
// This should only be used by Qml code
void LinkManager::createConnectedLink(LinkConfiguration* config)
{
for(int i = 0; i < _sharedConfigurations.count(); i++) {
SharedLinkConfigurationPointer& sharedConf = _sharedConfigurations[i];
if (sharedConf->name() == config->name())
createConnectedLink(sharedConf);
}
}
LinkInterface* LinkManager::createConnectedLink(SharedLinkConfigurationPointer& config, bool isPX4Flow)
dogmaphobic
committed
{
qWarning() << "LinkManager::createConnectedLink called with nullptr config";
return nullptr;
dogmaphobic
committed
switch(config->type()) {
auto* serialConfig = qobject_cast<SerialConfiguration*>(config.data());
pLink = new SerialLink(config, isPX4Flow);
_activeLinkCheckList.append(qobject_cast<SerialLink*>(pLink));
if (!_activeLinkCheckTimer.isActive()) {
_activeLinkCheckTimer.start();
case LinkConfiguration::TypeUdp:
pLink = new UDPLink(config);
break;
case LinkConfiguration::TypeTcp:
pLink = new TCPLink(config);
break;
case LinkConfiguration::TypeBluetooth:
pLink = new BluetoothLink(config);
break;
case LinkConfiguration::TypeLogReplay:
pLink = new LogReplayLink(config);
break;
case LinkConfiguration::TypeMock:
pLink = new MockLink(config);
break;
dogmaphobic
committed
}
_addLink(pLink);
connectLink(pLink);
dogmaphobic
committed
}
return pLink;
}
LinkInterface* LinkManager::createConnectedLink(const QString& name)
dogmaphobic
committed
{
if (name.isEmpty()) {
qWarning() << "Internal error";
} else {
for(int i = 0; i < _sharedConfigurations.count(); i++) {
SharedLinkConfigurationPointer& conf = _sharedConfigurations[i];
if (conf->name() == name) {
return createConnectedLink(conf);
}
}
dogmaphobic
committed
}
dogmaphobic
committed
}
void LinkManager::_addLink(LinkInterface* link)
qWarning() << "_addLink called from incorrect thread";
dogmaphobic
committed
dogmaphobic
committed
if (!containsLink(link)) {
int mavlinkChannel = _reserveMavlinkChannel();
if (mavlinkChannel != 0) {
link->_setMavlinkChannel(mavlinkChannel);
} else {
qWarning() << "Ran out of mavlink channels";
_sharedLinks.append(SharedLinkInterfacePointer(link));
emit newLink(link);
}
dogmaphobic
committed
connect(link, &LinkInterface::communicationError, _app, &QGCApplication::criticalMessageBoxOnMainThread);
Loading
Loading full blame...