Skip to content

Commit

Permalink
Merge pull request mavlink#1662 from mavlink/hilfix
Browse files Browse the repository at this point in the history
XPlane HIL interface: Fix link deletion logic so no QGC reboots are r…
  • Loading branch information
DonLakeFlyer committed Jun 22, 2015
2 parents 36493ff + f528a64 commit 2c7bf3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/comm/QGCXPlaneLink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ QGCXPlaneLink::~QGCXPlaneLink()
storeSettings();
// Tell the thread to exit
_should_exit = true;
// Wait for it to exit
wait();

// if(connectState) {
// disconnectSimulation();
// }
if (socket) {
socket->close();
socket->deleteLater();
socket = NULL;
}
}

void QGCXPlaneLink::loadSettings()
Expand Down Expand Up @@ -169,11 +169,13 @@ void QGCXPlaneLink::run()

emit statusMessage("Binding socket failed!");

delete socket;
socket->deleteLater();
socket = NULL;
return;
}

emit statusMessage(tr("Waiting for XPlane.."));

QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes()));

UAS* uas = dynamic_cast<UAS*>(mav);
Expand All @@ -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);

uas->startHil();
} else {
emit statusMessage(tr("Failed to connect to drone instance"));
return;
}

#pragma pack(push, 1)
Expand Down Expand Up @@ -254,6 +259,8 @@ void QGCXPlaneLink::run()

connectState = false;

QObject::disconnect(socket, SIGNAL(readyRead()), this, SLOT(readBytes()));

socket->close();
socket->deleteLater();
socket = NULL;
Expand Down Expand Up @@ -908,7 +915,6 @@ bool QGCXPlaneLink::disconnectSimulation()
if (connectState)
{
_should_exit = true;
wait();
} else {
emit simulationDisconnected();
emit simulationConnected(false);
Expand Down
6 changes: 6 additions & 0 deletions src/uas/UAS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(),
*/
UAS::~UAS()
{
stopHil();
if (simulation) {
// wait for the simulator to exit
simulation->wait();
simulation->deleteLater();
}
writeSettings();
}

Expand Down

0 comments on commit 2c7bf3a

Please sign in to comment.