Skip to content

Commit

Permalink
Fix reconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
vranki committed Nov 26, 2019
1 parent 1ece4f1 commit b1eaa25
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Known users:
* Simple to use Voice control made for Zibo's awesome 738X (most likely will work for 739 Ultimate)
* https://github.com/Najsr/X-Plane-Voice-Control

Note: X-Plane has UDP interface that can be used to do lot of things ExtPlane normally
would do. See https://github.com/dotsha747/libXPlane-UDP-Client for a c++ client
for the UDP interface.

## Transformer ##

ExtPlane-Transformer is an application that works as ExtPlane
Expand Down
1 change: 0 additions & 1 deletion clients/extplane-client-qt/dataref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ DataRef::DataRef(QObject *parent) : QObject(parent)
}

DataRef::~DataRef() {
qDebug() << Q_FUNC_INFO << m_name << m_clientDataRef;
if(m_clientDataRef) {
m_clientDataRef->unsubscribe();
m_clientDataRef = nullptr;
Expand Down
10 changes: 7 additions & 3 deletions clients/extplane-client-qt/extplaneconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ void ExtPlaneConnection::startConnection() {
void ExtPlaneConnection::stopConnection() {
DEBUG << "Stopping connection";
BasicTcpClient::disconnectFromHost();
qDeleteAll(dataRefs.values());
dataRefs.clear();
// qDeleteAll(dataRefs.values());
// dataRefs.clear();
emit connectionMessage("Stopped connection");
}

Expand Down Expand Up @@ -116,10 +116,14 @@ void ExtPlaneConnection::receivedLineSlot(QString & line) {
if(line=="EXTPLANE 1") {
server_ok = true;
emit connectionMessage(QString("Connected to ExtPlane at %1:%2").arg(hostName()).arg(port()));
DEBUG << "Setting update interval to " << m_updateInterval;
setUpdateInterval(m_updateInterval);
// Sub all refs
for(ClientDataRef *ref : dataRefs)
DEBUG << "REFS" << dataRefs.count();
for(ClientDataRef *ref : dataRefs) {
DEBUG << "Subscribing to ref" << ref->name();
subRef(ref);
}
}
return;
} else { // Handle updates
Expand Down
12 changes: 6 additions & 6 deletions util/basictcpclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ BasicTcpClient::BasicTcpClient(QObject *parent) : QTcpSocket(parent)
connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
connect(this, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
connect(&reconnectTimer, SIGNAL(timeout()), this, SLOT(tryReconnect()));
reconnectTimer.setInterval(5000);
reconnectTimer.setSingleShot(false);
connect(&m_reconnectTimer, SIGNAL(timeout()), this, SLOT(tryReconnect()));
m_reconnectTimer.setInterval(5000);
m_reconnectTimer.setSingleShot(false);
}

void BasicTcpClient::startConnection() {
close();

reconnectTimer.start();
m_reconnectTimer.start();
if(m_host.isEmpty() || !m_port) {
m_networkError = QString("Host or port not set - can't connect to %1:%2").arg(m_host).arg(m_port);
emit networkErrorChanged(m_networkError);
Expand Down Expand Up @@ -105,7 +105,7 @@ void BasicTcpClient::tryReconnect() {
void BasicTcpClient::socketStateChanged(QAbstractSocket::SocketState state)
{
if(connected()) {
reconnectTimer.stop();
m_reconnectTimer.stop();
m_networkError = "";
emit networkErrorChanged(m_networkError);
}
Expand All @@ -117,7 +117,7 @@ void BasicTcpClient::socketError(QAbstractSocket::SocketError err) {
INFO << "Socket error:" << errorString();
m_networkError = errorString() + " : " + m_host + ":" + QString::number(m_port);
emit networkErrorChanged(m_networkError);
reconnectTimer.start();
m_reconnectTimer.start();
}

void BasicTcpClient::readClient() {
Expand Down
2 changes: 1 addition & 1 deletion util/basictcpclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private slots:
void socketStateChanged(QAbstractSocket::SocketState state);

private:
QTimer reconnectTimer;
QTimer m_reconnectTimer;
QString m_lineEnding;
QString m_host;
QString m_networkError;
Expand Down

0 comments on commit b1eaa25

Please sign in to comment.