3#include <QtCore/QDeadlineTimer>
4#include <QtCore/QElapsedTimer>
5#include <QtCore/QSettings>
6#include <QtCore/QString>
7#include <QtQmlIntegration/QtQmlIntegration>
18 Q_MOC_INCLUDE(
"LinkInterface.h")
35 QString
name()
const {
return _name; }
39 void setLink(
const std::shared_ptr<LinkInterface>
link);
43 bool linkActive()
const {
return (
link() !=
nullptr) || (_autoConnect && _autoConnectStarted && !_suppressAutoReconnect); }
57 void setForwarding(
bool forwarding =
true) { _forwarding = forwarding; };
66 if (_suppressAutoReconnect != suppress) { _suppressAutoReconnect = suppress; emit
linkActiveChanged(); }
71 if (_autoConnectStarted != started) { _autoConnectStarted = started; emit
linkActiveChanged(); }
76 const int exp = qMin(_reconnectAttempts, 16);
77 _reconnectAttempts = qMin(_reconnectAttempts + 1, 17);
78 _nextReconnect = QDeadlineTimer(qMin(_reconnectBaseMs << exp, _reconnectMaxMs));
84 if (_connectedTimer.isValid() && (_connectedTimer.elapsed() >= _reconnectStableMs)) {
87 _connectedTimer.invalidate();
105#ifndef QGC_NO_SERIAL_LINK
126 virtual
void loadSettings(QSettings &settings, const QString &root) = 0;
131 virtual
void saveSettings(QSettings &settings, const QString &root) const = 0;
149 static QString
settingsRoot() {
return QStringLiteral(
"LinkConfigurations"); }
164 bool _dynamic =
false;
165 bool _forwarding =
false;
166 bool _autoConnect =
false;
167 bool _highLatency =
false;
168 bool _suppressAutoReconnect =
false;
169 bool _autoConnectStarted =
false;
170 int _reconnectAttempts = 0;
171 QDeadlineTimer _nextReconnect;
172 QElapsedTimer _connectedTimer;
174 static constexpr int _reconnectBaseMs = 1000;
175 static constexpr int _reconnectMaxMs = 5000;
176 static constexpr int _reconnectStableMs = 2000;
std::shared_ptr< LinkConfiguration > SharedLinkConfigurationPtr
std::weak_ptr< LinkConfiguration > WeakLinkConfigurationPtr
Interface holding link specific settings.
std::weak_ptr< LinkInterface > _link
Link currently using this configuration (if any)
@ TypeBluetooth
Bluetooth Link.
virtual void loadSettings(QSettings &settings, const QString &root)=0
virtual LinkType type() const =0
static LinkConfiguration * duplicateSettings(const LinkConfiguration *source)
virtual void copyFrom(const LinkConfiguration *source)
bool isAutoConnect() const
void setDynamic(bool dynamic=true)
Set if this is this a dynamic configuration. (decided at runtime)
virtual QString settingsURL() const =0
Settings URL, Pure virtual method providing the URL for the (QML) settings dialog.
virtual void saveSettings(QSettings &settings, const QString &root) const =0
void setAutoConnectStarted(bool started)
bool suppressAutoReconnect() const
void setHighLatency(bool hl=false)
Set if this is this an High Latency configuration.
static LinkConfiguration * createSettings(int type, const QString &name)
void setForwarding(bool forwarding=true)
Set if this is this a forwarding link configuration. (decided at runtime)
static QString settingsRoot()
void noteDisconnected()
Reset backoff only if the link stayed up long enough to count as working.
LinkInterface * link() const
void autoConnectChanged()
void highLatencyChanged()
void resetReconnectBackoff()
void nameChanged(const QString &name)
void setSuppressAutoReconnect(bool suppress)
bool autoConnectStarted() const
void setName(const QString &name)
virtual ~LinkConfiguration()
void noteReconnectAttempt()
virtual QString settingsTitle() const =0
Settings Title, Pure virtual method providing the Title for the (QML) settings dialog.
void setLink(const std::shared_ptr< LinkInterface > link)
bool isForwarding() const
bool isHighLatency() const
virtual void setAutoConnect(bool autoc=true)
Set if this is this an Auto Connect configuration.
bool reconnectReady() const
The link interface defines the interface for all links used to communicate with the ground station ap...