1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00
Fixed issue with GCS crashing on app closure.

This has not been tested with real hardware.

I have captured a log of the data from the other end of the TCP connection and I still have to check it against the UAVTalk spec to see if it is error free...

This has now been tested on the following platforms and compiles and runs on all:
Win XP
Windows 7
Lunix (Fedora 11)



git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@900 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
andrew 2010-06-27 04:10:01 +00:00 committed by andrew
parent 99ffd457fd
commit 0b5e089b1f

View File

@ -42,8 +42,7 @@
TCPtelemetryConnection::TCPtelemetryConnection()
{
tcpSocket = new QTcpSocket(this);
//create all our objects
m_config = new TCPtelemetryConfiguration("TCP Connection", NULL, this);
m_config->restoresettings();
@ -59,21 +58,12 @@ TCPtelemetryConnection::TCPtelemetryConnection()
TCPtelemetryConnection::~TCPtelemetryConnection()
{
/* if (tcpSocket->state()>0){
tcpSocket->disconnectFromHost ();
}*/
tcpSocket->close ();
// delete(m_optionspage);
// delete(m_config);
//tcpSocket->close ();
//delete(tcpSocket);
}
void TCPtelemetryConnection::onEnumerationChanged()
{//no change from serial plugin
emit availableDevChanged(this);
}
@ -83,6 +73,7 @@ QStringList TCPtelemetryConnection::availableDevices()
{
QStringList list;
//we only have one "device" as defined by the configuration m_config
list.append((const QString )m_config->HostName());
return list;
@ -91,71 +82,81 @@ QStringList TCPtelemetryConnection::availableDevices()
QIODevice *TCPtelemetryConnection::openDevice(const QString &deviceName)
{
const int Timeout = 5 * 1000;
//if (tcpSocket->state()>0){
// tcpSocket->close();
//}
tcpSocket->connectToHost((const QString )m_config->HostName(), m_config->Port());
if (tcpSocket->waitForConnected(Timeout)) {
return tcpSocket;
}
int state;
QString HostName;
int Port;
QMessageBox msgBox;
msgBox.setText((const QString )tcpSocket->errorString ());
msgBox.exec();
tcpSocket = new QTcpSocket(this);
//get the configuration info
HostName = m_config->HostName();
Port = m_config->Port();
//do sanity check on hostname and port...
if((HostName.length()==0)||(Port<1)){
msgBox.setText((const QString )"Please configure Host and Port options before opening the connection");
msgBox.exec();
}
else {
//try to connect...
tcpSocket->connectToHost((const QString )HostName, Port);
//in blocking mode so we wait for the connection to succeed
if (tcpSocket->waitForConnected(Timeout)) {
return tcpSocket;
}
//tell user something went wrong
msgBox.setText((const QString )tcpSocket->errorString ());
msgBox.exec();
}
return NULL;
}
void TCPtelemetryConnection::closeDevice(const QString &deviceName)
{
/* if (tcpSocket->state()>0){
tcpSocket->disconnectFromHost ();
}*/
//tcpSocket->close();
//still having problems with the app crashing when we reference the tcpsocket outside the openDevice function...
//tcpSocket->close ();
//delete(tcpSocket);
}
QString TCPtelemetryConnection::connectionName()
{//updated from serial plugin
return QString("TCP telemetry port");
}
QString TCPtelemetryConnection::shortName()
{//updated from serial plugin
return QString("TCP");
}
TCPtelemetryPlugin::TCPtelemetryPlugin()
{//no change from serial plugin
}
TCPtelemetryPlugin::~TCPtelemetryPlugin()
{//no change from serial plugin
{//manually remove the options page object
removeObject(m_connection->Optionspage());
}
void TCPtelemetryPlugin::extensionsInitialized()
{//updated from serial plugin
{
addAutoReleasedObject(m_connection);
}
bool TCPtelemetryPlugin::initialize(const QStringList &arguments, QString *errorString)
{//no change from serial plugin
{
Q_UNUSED(arguments);
Q_UNUSED(errorString);
m_connection = new TCPtelemetryConnection();
addAutoReleasedObject(m_connection->Optionspage());
//must manage this registration of child object ourselves
//if we use an autorelease here it causes the GCS to crash
//as it is deleting objects as the app closes...
addObject(m_connection->Optionspage());
return true;
}