Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 91 additions & 89 deletions src/Comms/LinkManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,81 +461,6 @@ void LinkManager::_addMAVLinkForwardingLink()
_createDynamicForwardLink(_mavlinkForwardingLinkName, hostName);
}

#ifdef QGC_ZEROCONF_ENABLED
void LinkManager::_addZeroConfAutoConnectLink()
{
if (!_autoConnectSettings->autoConnectZeroConf()->rawValue().toBool()) {
return;
}

static QSharedPointer<QMdnsEngine::Server> server;
static QSharedPointer<QMdnsEngine::Browser> browser;
server.reset(new QMdnsEngine::Server());
browser.reset(new QMdnsEngine::Browser(server.get(), QMdnsEngine::MdnsBrowseType));

const auto checkIfConnectionLinkExist = [this](LinkConfiguration::LinkType linkType, const QString &linkName) {
QMutexLocker locker(&_linksMutex);
for (const SharedLinkInterfacePtr &link : std::as_const(_rgLinks)) {
const SharedLinkConfigurationPtr linkConfig = link->linkConfiguration();
if (linkConfig && (linkConfig->type() == linkType) && (linkConfig->name() == linkName)) {
return true;
}
}

return false;
};

(void) connect(browser.get(), &QMdnsEngine::Browser::serviceAdded, this, [checkIfConnectionLinkExist, this](const QMdnsEngine::Service &service) {
qCDebug(LinkManagerLog) << "Found Zero-Conf:" << service.type() << service.name() << service.hostname() << service.port() << service.attributes();

if (!service.type().startsWith("_mavlink")) {
qCWarning(LinkManagerLog) << "Invalid ZeroConf SericeType" << service.type();
return;
}

// Windows doesnt accept trailling dots in mdns
// http://www.dns-sd.org/trailingdotsindomainnames.html
QString hostname = service.hostname();
if (hostname.endsWith('.')) {
hostname.chop(1);
}

if (service.type().startsWith("_mavlink._udp")) {
static const QString udpName = QStringLiteral("ZeroConf UDP");
if (checkIfConnectionLinkExist(LinkConfiguration::TypeUdp, udpName)) {
qCDebug(LinkManagerLog) << "Connection already exist";
return;
}

UDPConfiguration *const link = new UDPConfiguration(udpName);
link->addHost(hostname, service.port());
link->setAutoConnect(true);
link->setDynamic(true);
SharedLinkConfigurationPtr config = addConfiguration(link);
if (!createConnectedLink(config)) {
qCWarning(LinkManagerLog) << "Failed to create" << udpName;
}
} else if (service.type().startsWith("_mavlink._tcp")) {
static QString tcpName = QStringLiteral("ZeroConf TCP");
if (checkIfConnectionLinkExist(LinkConfiguration::TypeTcp, tcpName)) {
qCDebug(LinkManagerLog) << "Connection already exist";
return;
}

TCPConfiguration *const link = new TCPConfiguration(tcpName);
link->setHost(hostname);
link->setPort(service.port());
link->setAutoConnect(true);
link->setDynamic(true);
SharedLinkConfigurationPtr config = addConfiguration(link);
if (!createConnectedLink(config)) {
qCWarning(LinkManagerLog) << "Failed to create" << tcpName;
}
}
});
}
#endif

void LinkManager::_updateAutoConnectLinks()
{
if (_connectionsSuspended) {
Expand Down Expand Up @@ -798,6 +723,97 @@ void LinkManager::_createDynamicForwardLink(const char *linkName, const QString
qCDebug(LinkManagerLog) << "New dynamic MAVLink forwarding port added:" << linkName << " hostname:" << hostName;
}

void LinkManager::resetMavlinkSigning()
{
// Make a copy under mutex protection to avoid holding lock during signing initialization
QList<SharedLinkInterfacePtr> links;
{
QMutexLocker locker(&_linksMutex);
links = _rgLinks;
}

for (const SharedLinkInterfacePtr &sharedLink: links) {
sharedLink->initMavlinkSigning();
}
}

#ifdef QGC_ZEROCONF_ENABLED

void LinkManager::_addZeroConfAutoConnectLink()
{
if (!_autoConnectSettings->autoConnectZeroConf()->rawValue().toBool()) {
return;
}

static QSharedPointer<QMdnsEngine::Server> server;
static QSharedPointer<QMdnsEngine::Browser> browser;
server.reset(new QMdnsEngine::Server());
browser.reset(new QMdnsEngine::Browser(server.get(), QMdnsEngine::MdnsBrowseType));

const auto checkIfConnectionLinkExist = [this](LinkConfiguration::LinkType linkType, const QString &linkName) {
QMutexLocker locker(&_linksMutex);
for (const SharedLinkInterfacePtr &link : std::as_const(_rgLinks)) {
const SharedLinkConfigurationPtr linkConfig = link->linkConfiguration();
if (linkConfig && (linkConfig->type() == linkType) && (linkConfig->name() == linkName)) {
return true;
}
}

return false;
};

(void) connect(browser.get(), &QMdnsEngine::Browser::serviceAdded, this, [checkIfConnectionLinkExist, this](const QMdnsEngine::Service &service) {
qCDebug(LinkManagerLog) << "Found Zero-Conf:" << service.type() << service.name() << service.hostname() << service.port() << service.attributes();

if (!service.type().startsWith("_mavlink")) {
qCWarning(LinkManagerLog) << "Invalid ZeroConf SericeType" << service.type();
return;
}

// Windows doesnt accept trailling dots in mdns
// http://www.dns-sd.org/trailingdotsindomainnames.html
QString hostname = service.hostname();
if (hostname.endsWith('.')) {
hostname.chop(1);
}

if (service.type().startsWith("_mavlink._udp")) {
static const QString udpName = QStringLiteral("ZeroConf UDP");
if (checkIfConnectionLinkExist(LinkConfiguration::TypeUdp, udpName)) {
qCDebug(LinkManagerLog) << "Connection already exist";
return;
}

UDPConfiguration *const link = new UDPConfiguration(udpName);
link->addHost(hostname, service.port());
link->setAutoConnect(true);
link->setDynamic(true);
SharedLinkConfigurationPtr config = addConfiguration(link);
if (!createConnectedLink(config)) {
qCWarning(LinkManagerLog) << "Failed to create" << udpName;
}
} else if (service.type().startsWith("_mavlink._tcp")) {
static QString tcpName = QStringLiteral("ZeroConf TCP");
if (checkIfConnectionLinkExist(LinkConfiguration::TypeTcp, tcpName)) {
qCDebug(LinkManagerLog) << "Connection already exist";
return;
}

TCPConfiguration *const link = new TCPConfiguration(tcpName);
link->setHost(hostname);
link->setPort(service.port());
link->setAutoConnect(true);
link->setDynamic(true);
SharedLinkConfigurationPtr config = addConfiguration(link);
if (!createConnectedLink(config)) {
qCWarning(LinkManagerLog) << "Failed to create" << tcpName;
}
}
});
}

#endif // QGC_ZEROCONF_ENABLED

bool LinkManager::isLinkUSBDirect(const LinkInterface *link)
{
#ifndef QGC_NO_SERIAL_LINK
Expand All @@ -820,20 +836,6 @@ bool LinkManager::isLinkUSBDirect(const LinkInterface *link)
return false;
}

void LinkManager::resetMavlinkSigning()
{
// Make a copy under mutex protection to avoid holding lock during signing initialization
QList<SharedLinkInterfacePtr> links;
{
QMutexLocker locker(&_linksMutex);
links = _rgLinks;
}

for (const SharedLinkInterfacePtr &sharedLink: links) {
sharedLink->initMavlinkSigning();
}
}

#ifndef QGC_NO_SERIAL_LINK // Serial Only Functions

void LinkManager::_filterCompositePorts(QList<QGCSerialPortInfo> &portList)
Expand Down
10 changes: 5 additions & 5 deletions src/Comms/LinkManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class SerialLink;
class UDPConfiguration;
class UdpIODevice;

/// @brief Manage communication links
/// The Link Manager organizes the physical Links. It can manage arbitrary
/// links and takes care of connecting them as well assigning the correct
/// protocol instance to transport the link data into the application.
/// Manage communication links
/// The Link Manager organizes the physical Links. It can manage arbitrary
/// links and takes care of connecting them as well assigning the correct
/// protocol instance to transport the link data into the application.
class LinkManager : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -178,9 +178,9 @@ private slots:
Q_PROPERTY(QStringList serialPorts READ serialPorts NOTIFY commPortsChanged)

public:
static QStringList serialBaudRates();
QStringList serialPortStrings();
QStringList serialPorts();
static QStringList serialBaudRates();

signals:
void commPortStringsChanged();
Expand Down
3 changes: 2 additions & 1 deletion src/FactSystem/ParameterManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,8 @@ void ParameterManager::_writeLocalParamCache(int vehicleId, int componentId)
QDir ParameterManager::parameterCacheDir()
{
const QString spath(QFileInfo(QSettings().fileName()).dir().absolutePath());
return (spath + QDir::separator() + QStringLiteral("ParamCache"));
const QDir cacheDir(spath + QDir::separator() + QStringLiteral("ParamCache"));
return cacheDir;
}

QString ParameterManager::parameterCacheFile(int vehicleId, int componentId)
Expand Down
Loading
Loading