Commit 63a393b2 authored by Lorenz Meier's avatar Lorenz Meier

XPlane HIL interface: Fix link deletion logic so no QGC reboots are required between runs

parent 21d48a5b
...@@ -80,12 +80,12 @@ QGCXPlaneLink::~QGCXPlaneLink() ...@@ -80,12 +80,12 @@ QGCXPlaneLink::~QGCXPlaneLink()
storeSettings(); storeSettings();
// Tell the thread to exit // Tell the thread to exit
_should_exit = true; _should_exit = true;
// Wait for it to exit
wait();
// if(connectState) { if (socket) {
// disconnectSimulation(); socket->close();
// } socket->deleteLater();
socket = NULL;
}
} }
void QGCXPlaneLink::loadSettings() void QGCXPlaneLink::loadSettings()
...@@ -169,11 +169,13 @@ void QGCXPlaneLink::run() ...@@ -169,11 +169,13 @@ void QGCXPlaneLink::run()
emit statusMessage("Binding socket failed!"); emit statusMessage("Binding socket failed!");
delete socket; socket->deleteLater();
socket = NULL; socket = NULL;
return; return;
} }
emit statusMessage(tr("Waiting for XPlane.."));
QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes())); QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes()));
UAS* uas = dynamic_cast<UAS*>(mav); UAS* uas = dynamic_cast<UAS*>(mav);
...@@ -188,6 +190,9 @@ void QGCXPlaneLink::run() ...@@ -188,6 +190,9 @@ void QGCXPlaneLink::run()
connect(this, SIGNAL(sensorHilRawImuChanged(quint64,float,float,float,float,float,float,float,float,float,float,float,float,float,quint32)), uas, SLOT(sendHilSensors(quint64,float,float,float,float,float,float,float,float,float,float,float,float,float,quint32)), Qt::QueuedConnection); connect(this, SIGNAL(sensorHilRawImuChanged(quint64,float,float,float,float,float,float,float,float,float,float,float,float,float,quint32)), uas, SLOT(sendHilSensors(quint64,float,float,float,float,float,float,float,float,float,float,float,float,float,quint32)), Qt::QueuedConnection);
uas->startHil(); uas->startHil();
} else {
emit statusMessage(tr("Failed to connect to drone instance"));
return;
} }
#pragma pack(push, 1) #pragma pack(push, 1)
...@@ -254,12 +259,16 @@ void QGCXPlaneLink::run() ...@@ -254,12 +259,16 @@ void QGCXPlaneLink::run()
connectState = false; connectState = false;
QObject::disconnect(socket, SIGNAL(readyRead()), this, SLOT(readBytes()));
socket->close(); socket->close();
socket->deleteLater(); socket->deleteLater();
socket = NULL; socket = NULL;
emit simulationDisconnected(); emit simulationDisconnected();
emit simulationConnected(false); emit simulationConnected(false);
this->deleteLater();
} }
void QGCXPlaneLink::setPort(int localPort) void QGCXPlaneLink::setPort(int localPort)
...@@ -908,7 +917,6 @@ bool QGCXPlaneLink::disconnectSimulation() ...@@ -908,7 +917,6 @@ bool QGCXPlaneLink::disconnectSimulation()
if (connectState) if (connectState)
{ {
_should_exit = true; _should_exit = true;
wait();
} else { } else {
emit simulationDisconnected(); emit simulationDisconnected();
emit simulationConnected(false); emit simulationConnected(false);
......
...@@ -242,6 +242,8 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(), ...@@ -242,6 +242,8 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(),
*/ */
UAS::~UAS() UAS::~UAS()
{ {
stopHil();
simulation->deleteLater();
writeSettings(); writeSettings();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment