QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
LinkConfiguration.cc
Go to the documentation of this file.
1#include "LinkConfiguration.h"
3#ifndef QGC_NO_SERIAL_LINK
4#include "SerialLink.h"
5#endif
6#include "UDPLink.h"
7#include "TCPLink.h"
8#include "LogReplayLink.h"
9#include "BluetoothLink.h"
10#ifdef QT_DEBUG
11#include "MockLink.h"
12#endif
13
14QGC_LOGGING_CATEGORY(LinkConfigurationLog, "Comms.LinkConfiguration")
15
16LinkConfiguration::LinkConfiguration(const QString &name, QObject *parent)
17 : QObject(parent)
18 , _name(name)
19{
20 qCDebug(LinkConfigurationLog) << this;
21}
22
24 : QObject(parent)
25 , _link(copy->_link)
26 , _name(copy->name())
27 , _dynamic(copy->isDynamic())
28 , _forwarding(copy->isForwarding())
29 , _autoConnect(copy->isAutoConnect())
30 , _highLatency(copy->isHighLatency())
31{
32 qCDebug(LinkConfigurationLog) << this;
33
34 if (_name.isEmpty()) {
35 qCWarning(LinkConfigurationLog) << "Copied configuration has no name";
36 }
37}
38
40{
41 qCDebug(LinkConfigurationLog) << this;
42}
43
45{
46 if (!source) {
47 qCWarning(LinkConfigurationLog) << "copyFrom called with null source";
48 return;
49 }
50
51 setLink(source->_link.lock());
52 setName(source->name());
53 setDynamic(source->isDynamic());
56 setForwarding(source->isForwarding());
57}
58
60{
61 LinkConfiguration *config = nullptr;
62
63 switch (static_cast<LinkType>(type)) {
64#ifndef QGC_NO_SERIAL_LINK
65 case TypeSerial:
67 break;
68#endif
69 case TypeUdp:
71 break;
72 case TypeTcp:
74 break;
75 case TypeBluetooth:
77 break;
78 case TypeLogReplay:
80 break;
81#ifdef QT_DEBUG
82 case TypeMock:
84 break;
85#endif
86 case TypeLast:
87 default:
88 break;
89 }
90
91 return config;
92}
93
95{
96 LinkConfiguration *dupe = nullptr;
97
98 switch(source->type()) {
99#ifndef QGC_NO_SERIAL_LINK
100 case TypeSerial:
101 dupe = new SerialConfiguration(qobject_cast<const SerialConfiguration*>(source));
102 break;
103#endif
104 case TypeUdp:
105 dupe = new UDPConfiguration(qobject_cast<const UDPConfiguration*>(source));
106 break;
107 case TypeTcp:
108 dupe = new TCPConfiguration(qobject_cast<const TCPConfiguration*>(source));
109 break;
110 case TypeBluetooth:
111 dupe = new BluetoothConfiguration(qobject_cast<const BluetoothConfiguration*>(source));
112 break;
113 case TypeLogReplay:
114 dupe = new LogReplayConfiguration(qobject_cast<const LogReplayConfiguration*>(source));
115 break;
116#ifdef QT_DEBUG
117 case TypeMock:
118 dupe = new MockConfiguration(qobject_cast<const MockConfiguration*>(source));
119 break;
120#endif
121 case TypeLast:
122 default:
123 break;
124 }
125
126 return dupe;
127}
128
129void LinkConfiguration::setName(const QString &name)
130{
131 if (name != _name) {
132 _name = name;
133 emit nameChanged(name);
134 }
135}
136
138{
139 if (link.get() != this->link()) {
140 _link = link;
141 emit linkChanged();
142 emit linkActiveChanged();
143
144 if (link.get()) {
145 (void) connect(link.get(), &LinkInterface::disconnected, this, &LinkConfiguration::linkChanged, Qt::QueuedConnection);
146 }
147 }
148}
149
151{
152 if (dynamic != _dynamic) {
153 _dynamic = dynamic;
154 emit dynamicChanged();
155 }
156}
157
159{
160 if (autoc != _autoConnect) {
161 _autoConnect = autoc;
162 emit autoConnectChanged();
163 emit linkActiveChanged();
164 }
165}
166
168{
169 if (hl != _highLatency) {
170 _highLatency = hl;
171 emit highLatencyChanged();
172 }
173}
Config config
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Interface holding link specific settings.
std::weak_ptr< LinkInterface > _link
Link currently using this configuration (if any)
@ TypeSerial
Serial Link.
@ TypeBluetooth
Bluetooth Link.
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)
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)
LinkInterface * link() const
void autoConnectChanged()
void highLatencyChanged()
void nameChanged(const QString &name)
void setName(const QString &name)
QString name() const
void setLink(const std::shared_ptr< LinkInterface > link)
bool isForwarding() const
bool isHighLatency() const
LinkConfiguration(const QString &name, QObject *parent=nullptr)
void linkActiveChanged()
void setAutoConnect(bool autoc=true)
Set if this is this an Auto Connect configuration.
void disconnected()