QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
LinkManager.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QList>
4#include <QtCore/QMutex>
5#include <QtCore/QMutexLocker>
6#include <QtCore/QStringList>
7#include <QtQmlIntegration/QtQmlIntegration>
8
9#include <limits>
10
11#include "LinkConfiguration.h"
12#include "LinkInterface.h"
13#ifndef QGC_NO_SERIAL_LINK
14 #include "QGCSerialPortInfo.h"
15#endif
16
18class LogReplayLink;
19class MAVLinkProtocol;
21class QTimer;
22class SerialLink;
24class UdpIODevice;
25
31class LinkManager : public QObject
32{
33 Q_OBJECT
34 QML_ELEMENT
35 QML_UNCREATABLE("")
36 Q_MOC_INCLUDE("QmlObjectListModel.h")
37 Q_MOC_INCLUDE("LogReplayLink.h")
39 Q_PROPERTY(QmlObjectListModel *linkConfigurations READ _qmlLinkConfigurations CONSTANT)
40 Q_PROPERTY(QStringList linkTypeStrings READ linkTypeStrings CONSTANT)
42
43public:
44 explicit LinkManager(QObject *parent = nullptr);
46
47 static LinkManager *instance();
48
49 void init();
50
52 Q_INVOKABLE LinkConfiguration *createConfiguration(int type, const QString &name);
54 Q_INVOKABLE void cancelConfigurationEditing(LinkConfiguration *config) const { delete config; }
55 Q_INVOKABLE void endConfigurationEditing(LinkConfiguration *config, LinkConfiguration *editedConfig);
56 Q_INVOKABLE void endCreateConfiguration(LinkConfiguration *config);
57 Q_INVOKABLE void removeConfiguration(LinkConfiguration *config);
59 Q_INVOKABLE void createConnectedLink(const LinkConfiguration *config);
60 Q_INVOKABLE void createMavlinkForwardingSupportLink();
62 Q_INVOKABLE void shutdown();
63 Q_INVOKABLE LogReplayLink *startLogReplay(const QString &logFile);
64
65 QList<SharedLinkInterfacePtr> links();
66 QStringList linkTypeStrings() const;
67 bool mavlinkSupportForwardingEnabled() const { return _mavlinkSupportForwardingEnabled; }
68
71
74 void setConnectionsSuspended(const QString &reason) { _connectionsSuspended = true; _connectionsSuspendedReason = reason; }
75
77 void setConnectionsAllowed() { _connectionsSuspended = false; }
78
81
84
87
88 void disconnectAll();
89
92 uint8_t allocateMavlinkChannel();
93 void freeMavlinkChannel(uint8_t channel);
94
98
99 bool containsLink(const LinkInterface *link);
100
102
104
105 static bool isBluetoothAvailable();
106
107 static bool isLinkUSBDirect(const LinkInterface *link);
108
109 static constexpr uint8_t invalidMavlinkChannel() { return std::numeric_limits<uint8_t>::max(); }
110
111signals:
114
115private slots:
116 void _linkDisconnected();
117 void _communicationError(const QString &title, const QString &error);
118
119private:
120 QmlObjectListModel *_qmlLinkConfigurations();
122 bool _connectionsSuspendedMsg() const;
123 void _updateAutoConnectLinks();
124 void _removeConfiguration(const LinkConfiguration *config);
125 void _addUDPAutoConnectLink();
126 void _addMAVLinkForwardingLink();
127 void _createDynamicForwardLink(const char *linkName, const QString &hostName);
128
129 QTimer *_portListTimer = nullptr;
130 QmlObjectListModel *_qmlConfigurations = nullptr;
131 AutoConnectSettings *_autoConnectSettings = nullptr;
132
133 bool _configUpdateSuspended = false;
134 bool _configurationsLoaded = false;
135 bool _connectionsSuspended = false;
136 bool _mavlinkSupportForwardingEnabled = false;
137 uint32_t _mavlinkChannelsUsedBitMask = 1;
138 QString _connectionsSuspendedReason;
139
140 QMutex _linksMutex;
141 QList<SharedLinkInterfacePtr> _rgLinks;
142 QList<SharedLinkConfigurationPtr> _rgLinkConfigs;
143
144 static constexpr const char *_defaultUDPLinkName = "UDP Link (AutoConnect)";
145 static constexpr const char *_mavlinkForwardingLinkName = "MAVLink Forwarding Link";
146 static constexpr const char *_mavlinkForwardingSupportLinkName = "MAVLink Support Forwarding Link";
147
148 static constexpr int _autoconnectUpdateTimerMSecs = 1000;
149#ifdef Q_OS_WIN
150 // Have to manually let the bootloader go by on Windows to get a working connect
151 static constexpr int _autoconnectConnectDelayMSecs = 6000;
152#else
153 static constexpr int _autoconnectConnectDelayMSecs = 1000;
154#endif
155
156#ifndef QGC_NO_SERIAL_LINK
157private:
158 Q_PROPERTY(QStringList serialBaudRates READ serialBaudRates CONSTANT)
159 Q_PROPERTY(QStringList serialPortStrings READ serialPortStrings NOTIFY commPortStringsChanged)
160 Q_PROPERTY(QStringList serialPorts READ serialPorts NOTIFY commPortsChanged)
161
162public:
163 static QStringList serialBaudRates();
164 QStringList serialPortStrings();
165 QStringList serialPorts();
166
167signals:
170
171private:
172 bool _isSerialPortConnected();
173 void _updateSerialPorts();
174 bool _allowAutoConnectToBoard(QGCSerialPortInfo::BoardType_t boardType) const;
175 void _addSerialAutoConnectLink();
176 bool _portAlreadyConnected(const QString &portName);
177 void _filterCompositePorts(QList<QGCSerialPortInfo> &portList);
178
179 QMap<QString, int> _autoconnectPortWaitList;
180 QList<SerialLink*> _activeLinkCheckList;
181 QStringList _commPortList;
182 QStringList _commPortDisplayList;
183 QString _autoConnectRTKPort;
184 QString _nmeaDeviceName;
185 uint32_t _nmeaBaud = 0;
186 QSerialPort *_nmeaPort = nullptr;
187#endif // QGC_NO_SERIAL_LINK
188
189 // NMEA UDP is network-only; available regardless of QGC_NO_SERIAL_LINK.
190 UdpIODevice *_nmeaSocket = nullptr;
191};
std::shared_ptr< LinkConfiguration > SharedLinkConfigurationPtr
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
Error error
Auto connect settings.
Interface holding link specific settings.
The link interface defines the interface for all links used to communicate with the ground station ap...
Manage communication links The Link Manager organizes the physical Links. It can manage arbitrary lin...
Definition LinkManager.h:32
void commPortStringsChanged()
Q_INVOKABLE void createConnectedLink(const LinkConfiguration *config)
This should only be used by Qml code.
SharedLinkInterfacePtr sharedLinkInterfacePointerForLink(const LinkInterface *link)
QStringList serialPorts()
Q_INVOKABLE void endConfigurationEditing(LinkConfiguration *config, LinkConfiguration *editedConfig)
Q_INVOKABLE void cancelConfigurationEditing(LinkConfiguration *config) const
Definition LinkManager.h:54
SharedLinkConfigurationPtr addConfiguration(LinkConfiguration *config)
QStringList linkTypeStrings() const
void isBluetoothAvailableChanged()
void loadLinkConfigurationList()
static bool isLinkUSBDirect(const LinkInterface *link)
uint8_t allocateMavlinkChannel()
Q_INVOKABLE void createMavlinkForwardingSupportLink()
Q_INVOKABLE LinkConfiguration * createConfiguration(int type, const QString &name)
Create/Edit Link Configuration.
void startAutoConnectedLinks()
Q_INVOKABLE void endCreateConfiguration(LinkConfiguration *config)
void setConnectionsAllowed()
Sets the flag to allow new connections to be made.
Definition LinkManager.h:77
Q_INVOKABLE void shutdown()
Called to signal app shutdown. Disconnects all links while turning off auto-connect.
static LinkManager * instance()
void freeMavlinkChannel(uint8_t channel)
Q_INVOKABLE void removeConfiguration(LinkConfiguration *config)
QList< SharedLinkInterfacePtr > links()
static constexpr uint8_t invalidMavlinkChannel()
void setConnectionsSuspended(const QString &reason)
Definition LinkManager.h:74
void disconnectAll()
Q_INVOKABLE LogReplayLink * startLogReplay(const QString &logFile)
void commPortsChanged()
QStringList serialPortStrings()
static QStringList serialBaudRates()
SharedLinkInterfacePtr mavlinkForwardingSupportLink()
Returns pointer to the mavlink support forwarding link, or nullptr if it does not exist.
Q_INVOKABLE LinkConfiguration * startConfigurationEditing(LinkConfiguration *config)
bool containsLink(const LinkInterface *link)
SharedLinkInterfacePtr mavlinkForwardingLink()
Returns pointer to the mavlink forwarding link, or nullptr if it does not exist.
static bool isBluetoothAvailable()
void saveLinkConfigurationList()
void mavlinkSupportForwardingEnabledChanged()
bool mavlinkSupportForwardingEnabled() const
Definition LinkManager.h:67
MAVLink micro air vehicle protocol reference implementation.
Provides functions to access serial ports.
Definition qserialport.h:17
UdpIODevice provides a QIODevice interface over a QUdpSocket in server mode.
Definition UdpIODevice.h:11