Skip to content

Commit b1eaa25

Browse files
committed
Fix reconnecting
1 parent 1ece4f1 commit b1eaa25

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ Known users:
4242
* Simple to use Voice control made for Zibo's awesome 738X (most likely will work for 739 Ultimate)
4343
* https://github.com/Najsr/X-Plane-Voice-Control
4444

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

4751
ExtPlane-Transformer is an application that works as ExtPlane

clients/extplane-client-qt/dataref.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ DataRef::DataRef(QObject *parent) : QObject(parent)
1616
}
1717

1818
DataRef::~DataRef() {
19-
qDebug() << Q_FUNC_INFO << m_name << m_clientDataRef;
2019
if(m_clientDataRef) {
2120
m_clientDataRef->unsubscribe();
2221
m_clientDataRef = nullptr;

clients/extplane-client-qt/extplaneconnection.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ void ExtPlaneConnection::startConnection() {
3131
void ExtPlaneConnection::stopConnection() {
3232
DEBUG << "Stopping connection";
3333
BasicTcpClient::disconnectFromHost();
34-
qDeleteAll(dataRefs.values());
35-
dataRefs.clear();
34+
// qDeleteAll(dataRefs.values());
35+
// dataRefs.clear();
3636
emit connectionMessage("Stopped connection");
3737
}
3838

@@ -116,10 +116,14 @@ void ExtPlaneConnection::receivedLineSlot(QString & line) {
116116
if(line=="EXTPLANE 1") {
117117
server_ok = true;
118118
emit connectionMessage(QString("Connected to ExtPlane at %1:%2").arg(hostName()).arg(port()));
119+
DEBUG << "Setting update interval to " << m_updateInterval;
119120
setUpdateInterval(m_updateInterval);
120121
// Sub all refs
121-
for(ClientDataRef *ref : dataRefs)
122+
DEBUG << "REFS" << dataRefs.count();
123+
for(ClientDataRef *ref : dataRefs) {
124+
DEBUG << "Subscribing to ref" << ref->name();
122125
subRef(ref);
126+
}
123127
}
124128
return;
125129
} else { // Handle updates

util/basictcpclient.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ BasicTcpClient::BasicTcpClient(QObject *parent) : QTcpSocket(parent)
1010
connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
1111
connect(this, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
1212
this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
13-
connect(&reconnectTimer, SIGNAL(timeout()), this, SLOT(tryReconnect()));
14-
reconnectTimer.setInterval(5000);
15-
reconnectTimer.setSingleShot(false);
13+
connect(&m_reconnectTimer, SIGNAL(timeout()), this, SLOT(tryReconnect()));
14+
m_reconnectTimer.setInterval(5000);
15+
m_reconnectTimer.setSingleShot(false);
1616
}
1717

1818
void BasicTcpClient::startConnection() {
1919
close();
2020

21-
reconnectTimer.start();
21+
m_reconnectTimer.start();
2222
if(m_host.isEmpty() || !m_port) {
2323
m_networkError = QString("Host or port not set - can't connect to %1:%2").arg(m_host).arg(m_port);
2424
emit networkErrorChanged(m_networkError);
@@ -105,7 +105,7 @@ void BasicTcpClient::tryReconnect() {
105105
void BasicTcpClient::socketStateChanged(QAbstractSocket::SocketState state)
106106
{
107107
if(connected()) {
108-
reconnectTimer.stop();
108+
m_reconnectTimer.stop();
109109
m_networkError = "";
110110
emit networkErrorChanged(m_networkError);
111111
}
@@ -117,7 +117,7 @@ void BasicTcpClient::socketError(QAbstractSocket::SocketError err) {
117117
INFO << "Socket error:" << errorString();
118118
m_networkError = errorString() + " : " + m_host + ":" + QString::number(m_port);
119119
emit networkErrorChanged(m_networkError);
120-
reconnectTimer.start();
120+
m_reconnectTimer.start();
121121
}
122122

123123
void BasicTcpClient::readClient() {

util/basictcpclient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private slots:
5050
void socketStateChanged(QAbstractSocket::SocketState state);
5151

5252
private:
53-
QTimer reconnectTimer;
53+
QTimer m_reconnectTimer;
5454
QString m_lineEnding;
5555
QString m_host;
5656
QString m_networkError;

0 commit comments

Comments
 (0)