Skip to content

Commit

Permalink
Comms: Update LinkInterface & LinkConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Aug 1, 2024
1 parent d48c2e6 commit 83ba7f9
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 353 deletions.
4 changes: 2 additions & 2 deletions src/AirLink/AirlinkLink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void AirlinkLink::_configureUdpSettings()
QUdpSocket udpSocket;
while (!udpSocket.bind(QHostAddress::LocalHost, availablePort))
availablePort++;
UDPConfiguration* udpConfig = dynamic_cast<UDPConfiguration*>(UDPLink::_config.get());
UDPConfiguration* udpConfig = dynamic_cast<UDPConfiguration*>(UDPLink::m_config.get());
udpConfig->addHost(AirLinkManager::airlinkHost, AirLinkManager::airlinkPort);
udpConfig->setLocalPort(availablePort);
udpConfig->setDynamic(false);
Expand All @@ -160,7 +160,7 @@ void AirlinkLink::_sendLoginMsgToAirLink()
__mavlink_airlink_auth_t auth;
uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
mavlink_message_t mavmsg;
AirlinkConfiguration* config = dynamic_cast<AirlinkConfiguration*>(_config.get());
AirlinkConfiguration* config = dynamic_cast<AirlinkConfiguration*>(m_config.get());
QString login = config->modemName(); ///< Connect not to account but to specific modem
QString pass = config->password();

Expand Down
2 changes: 1 addition & 1 deletion src/Comms/BluetoothLink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void BluetoothLink::run()

}

void BluetoothLink::_writeBytes(const QByteArray bytes)
void BluetoothLink::_writeBytes(const QByteArray &bytes)
{
if (_targetSocket) {
if(_targetSocket->write(bytes) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/Comms/BluetoothLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public slots:

private slots:
// LinkInterface overrides
void _writeBytes(const QByteArray bytes) override;
void _writeBytes(const QByteArray &bytes) override;

private:

Expand Down
202 changes: 114 additions & 88 deletions src/Comms/LinkConfiguration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,138 +24,164 @@
#include "AirlinkLink.h"
#endif

#define LINK_SETTING_ROOT "LinkConfigurations"

LinkConfiguration::LinkConfiguration(const QString& name)
: _name (name)
, _dynamic (false)
, _autoConnect (false)
, _highLatency (false)
LinkConfiguration::LinkConfiguration(const QString &name, QObject *parent)
: QObject(parent)
, m_name(name)
{

// qCDebug(AudioOutputLog) << Q_FUNC_INFO << this;
}

LinkConfiguration::LinkConfiguration(LinkConfiguration* copy)
LinkConfiguration::LinkConfiguration(LinkConfiguration *copy, QObject *parent)
: QObject(parent)
, m_link(copy->m_link)
, m_name(copy->name())
, m_dynamic(copy->isDynamic())
, m_autoConnect(copy->isAutoConnect())
, m_highLatency(copy->isHighLatency())
{
_link = copy->_link;
_name = copy->name();
_dynamic = copy->isDynamic();
_autoConnect= copy->isAutoConnect();
_highLatency= copy->isHighLatency();
Q_ASSERT(!_name.isEmpty());
// qCDebug(AudioOutputLog) << Q_FUNC_INFO << this;

LinkConfiguration::copyFrom(copy);

Q_ASSERT(!m_name.isEmpty());
}

void LinkConfiguration::copyFrom(LinkConfiguration* source)
LinkConfiguration::~LinkConfiguration()
{
Q_ASSERT(source != nullptr);
_link = source->_link;
_name = source->name();
_dynamic = source->isDynamic();
_autoConnect= source->isAutoConnect();
_highLatency= source->isHighLatency();
// qCDebug(AudioOutputLog) << Q_FUNC_INFO << this;
}

/*!
Where the settings are saved
@return The root path of the setting.
*/
const QString LinkConfiguration::settingsRoot()
void LinkConfiguration::copyFrom(LinkConfiguration *source)
{
return QString(LINK_SETTING_ROOT);
Q_CHECK_PTR(source);

m_link = source->m_link;
m_name = source->name();
m_dynamic = source->isDynamic();
m_autoConnect = source->isAutoConnect();
m_highLatency = source->isHighLatency();
}

/*!
Configuration Factory
@return A new instance of the given type
*/
LinkConfiguration* LinkConfiguration::createSettings(int type, const QString& name)
LinkConfiguration *LinkConfiguration::createSettings(int type, const QString &name)
{
LinkConfiguration* config = nullptr;
switch(type) {
LinkConfiguration *config = nullptr;

switch(static_cast<LinkType>(type)) {
#ifndef NO_SERIAL_LINK
case LinkConfiguration::TypeSerial:
config = new SerialConfiguration(name);
break;
case TypeSerial:
config = new SerialConfiguration(name);
break;
#endif
case LinkConfiguration::TypeUdp:
config = new UDPConfiguration(name);
break;
case LinkConfiguration::TypeTcp:
config = new TCPConfiguration(name);
break;
case TypeUdp:
config = new UDPConfiguration(name);
break;
case TypeTcp:
config = new TCPConfiguration(name);
break;
#ifdef QGC_ENABLE_BLUETOOTH
case LinkConfiguration::TypeBluetooth:
case TypeBluetooth:
config = new BluetoothConfiguration(name);
break;
#endif
case LinkConfiguration::TypeLogReplay:
config = new LogReplayLinkConfiguration(name);
break;
case TypeLogReplay:
config = new LogReplayLinkConfiguration(name);
break;
#ifdef QT_DEBUG
case LinkConfiguration::TypeMock:
config = new MockConfiguration(name);
break;
case TypeMock:
config = new MockConfiguration(name);
break;
#endif
#ifndef QGC_AIRLINK_DISABLED
case LinkConfiguration::Airlink:
config = new AirlinkConfiguration(name);
break;
case Airlink:
config = new AirlinkConfiguration(name);
break;
#endif
case TypeLast:
default:
break;
}

return config;
}

/*!
Duplicate link settings
@return A new copy of the given settings instance
*/
LinkConfiguration* LinkConfiguration::duplicateSettings(LinkConfiguration* source)
LinkConfiguration *LinkConfiguration::duplicateSettings(LinkConfiguration *source)
{
LinkConfiguration* dupe = nullptr;
LinkConfiguration *dupe = nullptr;

switch(source->type()) {
#ifndef NO_SERIAL_LINK
case TypeSerial:
dupe = new SerialConfiguration(qobject_cast<SerialConfiguration*>(source));
break;
case TypeSerial:
dupe = new SerialConfiguration(qobject_cast<SerialConfiguration*>(source));
break;
#endif
case TypeUdp:
dupe = new UDPConfiguration(qobject_cast<UDPConfiguration*>(source));
break;
case TypeTcp:
dupe = new TCPConfiguration(qobject_cast<TCPConfiguration*>(source));
break;
case TypeUdp:
dupe = new UDPConfiguration(qobject_cast<UDPConfiguration*>(source));
break;
case TypeTcp:
dupe = new TCPConfiguration(qobject_cast<TCPConfiguration*>(source));
break;
#ifdef QGC_ENABLE_BLUETOOTH
case TypeBluetooth:
dupe = new BluetoothConfiguration(qobject_cast<BluetoothConfiguration*>(source));
break;
case TypeBluetooth:
dupe = new BluetoothConfiguration(qobject_cast<BluetoothConfiguration*>(source));
break;
#endif
case TypeLogReplay:
dupe = new LogReplayLinkConfiguration(qobject_cast<LogReplayLinkConfiguration*>(source));
break;
case TypeLogReplay:
dupe = new LogReplayLinkConfiguration(qobject_cast<LogReplayLinkConfiguration*>(source));
break;
#ifdef QT_DEBUG
case TypeMock:
dupe = new MockConfiguration(qobject_cast<MockConfiguration*>(source));
break;
case TypeMock:
dupe = new MockConfiguration(qobject_cast<MockConfiguration*>(source));
break;
#endif
#ifndef QGC_AIRLINK_DISABLED
case Airlink:
dupe = new AirlinkConfiguration(qobject_cast<AirlinkConfiguration*>(source));
break;
case Airlink:
dupe = new AirlinkConfiguration(qobject_cast<AirlinkConfiguration*>(source));
break;
#endif
case TypeLast:
break;
case TypeLast:
default:
break;
}

return dupe;
}

void LinkConfiguration::setName(const QString name)
void LinkConfiguration::setName(const QString &name)
{
_name = name;
emit nameChanged(name);
if (name != m_name) {
m_name = name;
emit nameChanged(name);
}
}

void LinkConfiguration::setLink(SharedLinkInterfacePtr link)
{
_link = link;
emit linkChanged();
if (link.get() != this->link()) {
m_link = link;
emit linkChanged();
}
}

void LinkConfiguration::setDynamic(bool dynamic)
{
if (dynamic != m_dynamic) {
m_dynamic = dynamic;
emit dynamicChanged();
}
}

void LinkConfiguration::setAutoConnect(bool autoc)
{
if (autoc != m_autoConnect) {
m_autoConnect = autoc;
emit autoConnectChanged();
}
}

void LinkConfiguration::setHighLatency(bool hl)
{
if (hl != m_highLatency) {
m_highLatency = hl;
emit highLatencyChanged();
}
}
Loading

0 comments on commit 83ba7f9

Please sign in to comment.