Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comms: Update AIRLink Threading #12203

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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
199 changes: 98 additions & 101 deletions src/Comms/AirLink/AirLinkLink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,96 @@

QGC_LOGGING_CATEGORY(AirLinkLinkLog, "qgc.AirLink.AirLinklink");

/*===========================================================================*/

AirLinkConfiguration::AirLinkConfiguration(const QString &name, QObject *parent)
: UDPConfiguration(name)
{
// qCDebug(AirLinkLinkLog) << Q_FUNC_INFO << this;
}

AirLinkConfiguration::AirLinkConfiguration(const AirLinkConfiguration *copy, QObject *parent)
: UDPConfiguration(copy)
{
// qCDebug(AirLinkLinkLog) << Q_FUNC_INFO << this;

AirLinkConfiguration::copyFrom(copy);
}

AirLinkConfiguration::~AirLinkConfiguration()
{
// qCDebug(AirLinkLinkLog) << Q_FUNC_INFO << this;
}

void AirLinkConfiguration::copyFrom(const LinkConfiguration *source)
{
Q_ASSERT(source);

const UDPConfiguration *const udpSource = qobject_cast<const UDPConfiguration*>(source);
Q_ASSERT(udpSource);
UDPConfiguration::copyFrom(udpSource);

const AirLinkConfiguration *const airLinkSource = qobject_cast<const AirLinkConfiguration*>(source);
Q_ASSERT(airLinkSource);

setUsername(airLinkSource->username());
setPassword(airLinkSource->password());
setModemName(airLinkSource->modemName());
}

void AirLinkConfiguration::loadSettings(QSettings &settings, const QString &root)
{
AppSettings *const appSettings = SettingsManager::instance()->appSettings();

settings.beginGroup(root);

setUsername(settings.value(_usernameSettingsKey, appSettings->loginAirLink()->rawValueString()).toString());
setPassword(settings.value(_passwordSettingsKey, appSettings->passAirLink()->rawValueString()).toString());
setModemName(settings.value(_modemNameSettingsKey).toString());

settings.endGroup();
}

void AirLinkConfiguration::saveSettings(QSettings &settings, const QString &root)
{
settings.beginGroup(root);

settings.setValue(_usernameSettingsKey, _username);
settings.setValue(_passwordSettingsKey, _password);
settings.setValue(_modemNameSettingsKey, _modemName);

settings.endGroup();
}

void AirLinkConfiguration::setUsername(const QString &username)
{
if (username != _username) {
_username = username;
emit usernameChanged();
}
}

void AirLinkConfiguration::setPassword(const QString &password)
{
if (password != _password) {
_password = password;
emit passwordChanged();
}
}

void AirLinkConfiguration::setModemName(const QString &modemName)
{
if (modemName != _modemName) {
_modemName = modemName;
emit modemNameChanged();
}
}

/*===========================================================================*/

AirLinkLink::AirLinkLink(SharedLinkConfigurationPtr &config, QObject *parent)
: UDPLink(config)
, _AirLinkConfig(qobject_cast<const AirLinkConfiguration*>(config.get()))
, _airLinkConfig(qobject_cast<const AirLinkConfiguration*>(config.get()))
{
// qCDebug(AirLinkLinkLog) << Q_FUNC_INFO << this;

Expand Down Expand Up @@ -51,12 +138,6 @@ AirLinkLink::~AirLinkLink()
// qCDebug(AirLinkLinkLog) << Q_FUNC_INFO << this;
}

void AirLinkLink::disconnect()
{
_setConnectFlag(false);
(void) UDPLink::disconnect();
}

bool AirLinkLink::_connect()
{
std::shared_ptr<QMetaObject::Connection> conn = std::make_shared<QMetaObject::Connection>();
Expand All @@ -65,7 +146,7 @@ bool AirLinkLink::_connect()
return;
}

mavlink_airlink_auth_response_t responseMsg;
mavlink_airlink_auth_response_t responseMsg{};
mavlink_msg_airlink_auth_response_decode(&message, &responseMsg);
const int answer = responseMsg.resp_type;
if (answer != AIRLINK_AUTH_RESPONSE_TYPE::AIRLINK_AUTH_OK) {
Expand All @@ -85,6 +166,12 @@ bool AirLinkLink::_connect()
return true;
}

void AirLinkLink::disconnect()
{
_setConnectFlag(false);
(void) UDPLink::disconnect();
}

void AirLinkLink::_configureUdpSettings()
{
quint16 availablePort = 14550;
Expand All @@ -103,12 +190,12 @@ void AirLinkLink::_sendLoginMsgToAirLink()
{
mavlink_airlink_auth_t auth{};

const QString login = _AirLinkConfig->modemName(); ///< Connect not to account but to specific modem
const QString pass = _AirLinkConfig->password();
const QString login = _airLinkConfig->modemName(); ///< Connect not to account but to specific modem
const QString pass = _airLinkConfig->password();
(void) strcpy(auth.login, login.toUtf8().constData());
(void) strcpy(auth.password, pass.toUtf8().constData());

mavlink_message_t mavmsg;
mavlink_message_t mavmsg{};
(void) mavlink_msg_airlink_auth_pack(0, 0, &mavmsg, auth.login, auth.password);

uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
Expand All @@ -132,93 +219,3 @@ void AirLinkLink::_setConnectFlag(bool connect)
QMutexLocker locker(&_mutex);
_needToConnect = connect;
}

/*===========================================================================*/

AirLinkConfiguration::AirLinkConfiguration(const QString &name, QObject *parent)
: UDPConfiguration(name)
{
// qCDebug(AirLinkLinkLog) << Q_FUNC_INFO << this;
}

AirLinkConfiguration::AirLinkConfiguration(const AirLinkConfiguration *copy, QObject *parent)
: UDPConfiguration(copy)
{
// qCDebug(AirLinkLinkLog) << Q_FUNC_INFO << this;

Q_CHECK_PTR(copy);

copyFrom(copy);
}

AirLinkConfiguration::~AirLinkConfiguration()
{
// qCDebug(AirLinkLinkLog) << Q_FUNC_INFO << this;
}

void AirLinkConfiguration::setUsername(const QString &username)
{
if (username != _username) {
_username = username;
emit usernameChanged();
}
}

void AirLinkConfiguration::setPassword(const QString &password)
{
if (password != _password) {
_password = password;
emit passwordChanged();
}
}

void AirLinkConfiguration::setModemName(const QString &modemName)
{
if (modemName != _modemName) {
_modemName = modemName;
emit modemNameChanged();
}
}

void AirLinkConfiguration::loadSettings(QSettings &settings, const QString &root)
{
AppSettings *const appSettings = SettingsManager::instance()->appSettings();

settings.beginGroup(root);

setUsername(settings.value(_usernameSettingsKey, appSettings->loginAirLink()->rawValueString()).toString());
setPassword(settings.value(_passwordSettingsKey, appSettings->passAirLink()->rawValueString()).toString());
setModemName(settings.value(_modemNameSettingsKey).toString());

settings.endGroup();
}

void AirLinkConfiguration::saveSettings(QSettings &settings, const QString &root)
{
settings.beginGroup(root);

settings.setValue(_usernameSettingsKey, _username);
settings.setValue(_passwordSettingsKey, _password);
settings.setValue(_modemNameSettingsKey, _modemName);

settings.endGroup();
}

void AirLinkConfiguration::copyFrom(const LinkConfiguration *source)
{
Q_CHECK_PTR(source);

const AirLinkConfiguration *const AirLinkSource = qobject_cast<const AirLinkConfiguration*>(source);
if (AirLinkSource) {
setUsername(AirLinkSource->username());
setPassword(AirLinkSource->password());
setModemName(AirLinkSource->modemName());
} else {
qCWarning(AirLinkLinkLog) << "Internal error: cannot read AirLinkConfiguration from given source";
}

const UDPConfiguration *const udpSource = qobject_cast<const UDPConfiguration*>(source);
if (udpSource) {
UDPConfiguration::copyFrom(udpSource);
}
}
27 changes: 13 additions & 14 deletions src/Comms/AirLink/AirLinkLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,25 @@ class AirLinkConfiguration : public UDPConfiguration
Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
Q_PROPERTY(QString modemName READ modemName WRITE setModemName NOTIFY modemNameChanged)
public:
AirLinkConfiguration(const QString &name, QObject *parent = nullptr);
AirLinkConfiguration(const AirLinkConfiguration *copy, QObject *parent = nullptr);
explicit AirLinkConfiguration(const QString &name, QObject *parent = nullptr);
explicit AirLinkConfiguration(const AirLinkConfiguration *copy, QObject *parent = nullptr);
~AirLinkConfiguration();

QString username() const { return _username; }
QString password() const { return _password; }
QString modemName() const { return _modemName; }

void setUsername(const QString &username);
void setPassword(const QString &password);
void setModemName(const QString &modemName);

LinkType type() const final { return LinkConfiguration::AirLink; }
void copyFrom(const LinkConfiguration *source) final;

void loadSettings(QSettings &settings, const QString &root) final;
void saveSettings(QSettings &settings, const QString &root) final;
QString settingsURL() final { return "AirLinkSettings.qml"; }
QString settingsURL() final { return QStringLiteral("AirLinkSettings.qml"); }
QString settingsTitle() final { return tr("AirLink Link Settings"); }

QString username() const { return _username; }
void setUsername(const QString &username);

QString password() const { return _password; }
void setPassword(const QString &password);

QString modemName() const { return _modemName; }
void setModemName(const QString &modemName);

signals:
void usernameChanged();
Expand All @@ -67,7 +66,7 @@ class AirLinkLink : public UDPLink
Q_OBJECT

public:
AirLinkLink(SharedLinkConfigurationPtr &config, QObject *parent = nullptr);
explicit AirLinkLink(SharedLinkConfigurationPtr &config, QObject *parent = nullptr);
~AirLinkLink();

void disconnect() final;
Expand All @@ -81,7 +80,7 @@ private slots:
bool _stillConnecting();
void _setConnectFlag(bool connect);

const AirLinkConfiguration *_AirLinkConfig = nullptr;
const AirLinkConfiguration *_airLinkConfig = nullptr;
QMutex _mutex;
bool _needToConnect = false;

Expand Down
2 changes: 1 addition & 1 deletion src/Comms/AirLink/AirLinkManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void AirLinkManager::updateCredentials(const QString &login, const QString &pass

void AirLinkManager::_connectToAirLinkServer(const QString &login, const QString &pass)
{
const QUrl url("https://air-link.space/api/gs/getModems");
const QUrl url(QStringLiteral("https://air-link.space/api/gs/getModems"));
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");

Expand Down
Loading