mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-06 21:54:15 +01:00
Attempt to fix GCS crashes on USB disconnect: please confirm on other operating systems it is still working fine in all situations.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@3066 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
2e5863281c
commit
9d0ce95b37
@ -117,38 +117,32 @@ bool ConnectionManager::connectDevice()
|
|||||||
io_dev->open(QIODevice::ReadWrite);
|
io_dev->open(QIODevice::ReadWrite);
|
||||||
|
|
||||||
// check if opening the device worked
|
// check if opening the device worked
|
||||||
if (!io_dev->isOpen())
|
if (!io_dev->isOpen()) {
|
||||||
{
|
|
||||||
qDebug() << "Error: io_dev->isOpen() returned FALSE .. could not open connection to " << connection_device.devName
|
qDebug() << "Error: io_dev->isOpen() returned FALSE .. could not open connection to " << connection_device.devName
|
||||||
<< ": " << io_dev->errorString();
|
<< ": " << io_dev->errorString();
|
||||||
|
|
||||||
// close the device
|
// close the device
|
||||||
try
|
// EDOUARD: why do we close if we could not open ???
|
||||||
{
|
try {
|
||||||
connection_device.connection->closeDevice(connection_device.devName);
|
connection_device.connection->closeDevice(connection_device.devName);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...) { // handle exception
|
||||||
{ // handle exception
|
|
||||||
qDebug() << "Exception: connection_device.connection->closeDevice(" << connection_device.devName << ")";
|
qDebug() << "Exception: connection_device.connection->closeDevice(" << connection_device.devName << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we appear to have connected to the device OK
|
// we appear to have connected to the device OK
|
||||||
|
|
||||||
// remember the connection/device details
|
// remember the connection/device details
|
||||||
m_connectionDevice = connection_device;
|
m_connectionDevice = connection_device;
|
||||||
m_ioDev = io_dev;
|
m_ioDev = io_dev;
|
||||||
|
|
||||||
connect(m_connectionDevice.connection, SIGNAL(destroyed(QObject *)), this, SLOT(onConnectionDestroyed(QObject *)), Qt::QueuedConnection);
|
connect(m_connectionDevice.connection, SIGNAL(destroyed(QObject *)), this, SLOT(onConnectionDestroyed(QObject *)), Qt::QueuedConnection);
|
||||||
|
|
||||||
m_connectBtn->setText("Disconnect");
|
|
||||||
m_availableDevList->setEnabled(false);
|
|
||||||
|
|
||||||
// signal interested plugins that we connected to the device
|
// signal interested plugins that we connected to the device
|
||||||
emit deviceConnected(m_ioDev);
|
emit deviceConnected(m_ioDev);
|
||||||
|
m_connectBtn->setText("Disconnect");
|
||||||
|
m_availableDevList->setEnabled(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,28 +152,30 @@ bool ConnectionManager::connectDevice()
|
|||||||
*/
|
*/
|
||||||
bool ConnectionManager::disconnectDevice()
|
bool ConnectionManager::disconnectDevice()
|
||||||
{
|
{
|
||||||
if (!m_ioDev)
|
if (!m_ioDev) {
|
||||||
{ // apparently we are already disconnected
|
// apparently we are already disconnected: this can
|
||||||
|
// happen if a plugin tries to force a disconnect whereas
|
||||||
|
// we are not connected. Just return.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We are connected - disconnect from the device
|
||||||
|
|
||||||
|
// signal interested plugins that user is disconnecting his device
|
||||||
|
emit deviceAboutToDisconnect();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (m_connectionDevice.connection)
|
||||||
|
m_connectionDevice.connection->closeDevice(m_connectionDevice.devName);
|
||||||
|
} catch (...) { // handle exception
|
||||||
|
qDebug() << "Exception: m_connectionDevice.connection->closeDevice(" << m_connectionDevice.devName << ")";
|
||||||
|
}
|
||||||
|
|
||||||
m_connectionDevice.connection = NULL;
|
m_connectionDevice.connection = NULL;
|
||||||
m_ioDev = NULL;
|
m_ioDev = NULL;
|
||||||
|
|
||||||
return false;
|
m_connectBtn->setText("Connect");
|
||||||
}
|
m_availableDevList->setEnabled(true);
|
||||||
|
|
||||||
// we appear to be connected - disconnect from the device
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (m_connectionDevice.connection)
|
|
||||||
m_connectionDevice.connection->closeDevice(m_connectionDevice.devName);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{ // handle exception
|
|
||||||
qDebug() << "Exception: m_connectionDevice.connection->closeDevice(" << m_connectionDevice.devName << ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
onConnectionClosed(m_connectionDevice.connection);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -222,24 +218,11 @@ void ConnectionManager::aboutToRemoveObject(QObject *obj)
|
|||||||
m_connectionsList.removeAt(m_connectionsList.indexOf(connection));
|
m_connectionsList.removeAt(m_connectionsList.indexOf(connection));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionManager::onConnectionClosed(QObject *obj) // Pip
|
|
||||||
{
|
|
||||||
if (!m_connectionDevice.connection || m_connectionDevice.connection != obj)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_connectionDevice.connection = NULL;
|
|
||||||
m_ioDev = NULL;
|
|
||||||
|
|
||||||
m_connectBtn->setText("Connect");
|
|
||||||
m_availableDevList->setEnabled(true);
|
|
||||||
|
|
||||||
// signal interested plugins that user is disconnecting his device
|
|
||||||
emit deviceDisconnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionManager::onConnectionDestroyed(QObject *obj) // Pip
|
void ConnectionManager::onConnectionDestroyed(QObject *obj) // Pip
|
||||||
{
|
{
|
||||||
onConnectionClosed(obj);
|
//onConnectionClosed(obj);
|
||||||
|
disconnectDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -247,7 +230,8 @@ void ConnectionManager::onConnectionDestroyed(QObject *obj) // Pip
|
|||||||
*/
|
*/
|
||||||
void ConnectionManager::onConnectPressed()
|
void ConnectionManager::onConnectPressed()
|
||||||
{
|
{
|
||||||
if (!m_ioDev || !m_connectionDevice.connection)
|
// Check if we have a ioDev already created:
|
||||||
|
if (!m_ioDev)
|
||||||
{ // connecting
|
{ // connecting
|
||||||
connectDevice();
|
connectDevice();
|
||||||
}
|
}
|
||||||
@ -318,7 +302,8 @@ void ConnectionManager::unregisterAll(IConnection *connection)
|
|||||||
{
|
{
|
||||||
if (m_connectionDevice.connection && m_connectionDevice.connection == connection)
|
if (m_connectionDevice.connection && m_connectionDevice.connection == connection)
|
||||||
{ // we are currently using the one we are about to erase
|
{ // we are currently using the one we are about to erase
|
||||||
onConnectionClosed(m_connectionDevice.connection);
|
//onConnectionClosed(m_connectionDevice.connection);
|
||||||
|
disconnectDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
iter = m_devList.erase(iter);
|
iter = m_devList.erase(iter);
|
||||||
|
@ -81,7 +81,7 @@ protected:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deviceConnected(QIODevice *dev);
|
void deviceConnected(QIODevice *dev);
|
||||||
void deviceDisconnected();
|
void deviceAboutToDisconnect();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void objectAdded(QObject *obj);
|
void objectAdded(QObject *obj);
|
||||||
@ -90,7 +90,7 @@ private slots:
|
|||||||
void onConnectPressed();
|
void onConnectPressed();
|
||||||
void devChanged(IConnection *connection);
|
void devChanged(IConnection *connection);
|
||||||
|
|
||||||
void onConnectionClosed(QObject *obj);
|
// void onConnectionClosed(QObject *obj);
|
||||||
void onConnectionDestroyed(QObject *obj);
|
void onConnectionDestroyed(QObject *obj);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -74,7 +74,7 @@ ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent)
|
|||||||
// running the scopes if we are not connected and not replaying logs
|
// running the scopes if we are not connected and not replaying logs
|
||||||
// Also listen to disconnect actions from the user
|
// Also listen to disconnect actions from the user
|
||||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||||
connect(cm, SIGNAL(deviceDisconnected()), this, SLOT(stopPlotting()));
|
connect(cm, SIGNAL(deviceAboutToDisconnect()), this, SLOT(stopPlotting()));
|
||||||
connect(cm, SIGNAL(deviceConnected(QIODevice*)), this, SLOT(startPlotting()));
|
connect(cm, SIGNAL(deviceConnected(QIODevice*)), this, SLOT(startPlotting()));
|
||||||
|
|
||||||
m_csvLoggingStarted=0;
|
m_csvLoggingStarted=0;
|
||||||
@ -89,7 +89,7 @@ ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent)
|
|||||||
m_csvLoggingStartTime = QDateTime::currentDateTime();
|
m_csvLoggingStartTime = QDateTime::currentDateTime();
|
||||||
|
|
||||||
//Listen to autopilot connection events
|
//Listen to autopilot connection events
|
||||||
connect(cm, SIGNAL(deviceDisconnected()), this, SLOT(csvLoggingDisconnect()));
|
connect(cm, SIGNAL(deviceAboutToDisconnect()), this, SLOT(csvLoggingDisconnect()));
|
||||||
connect(cm, SIGNAL(deviceConnected(QIODevice*)), this, SLOT(csvLoggingConnect()));
|
connect(cm, SIGNAL(deviceConnected(QIODevice*)), this, SLOT(csvLoggingConnect()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ const quint8 UAVTalk::crc_table[256] = {
|
|||||||
UAVTalk::UAVTalk(QIODevice* iodev, UAVObjectManager* objMngr)
|
UAVTalk::UAVTalk(QIODevice* iodev, UAVObjectManager* objMngr)
|
||||||
{
|
{
|
||||||
io = iodev;
|
io = iodev;
|
||||||
|
|
||||||
this->objMngr = objMngr;
|
this->objMngr = objMngr;
|
||||||
|
|
||||||
rxState = STATE_SYNC;
|
rxState = STATE_SYNC;
|
||||||
@ -67,23 +68,17 @@ UAVTalk::UAVTalk(QIODevice* iodev, UAVObjectManager* objMngr)
|
|||||||
|
|
||||||
memset(&stats, 0, sizeof(ComStats));
|
memset(&stats, 0, sizeof(ComStats));
|
||||||
|
|
||||||
if (io) // Pip
|
|
||||||
connect(io, SIGNAL(readyRead()), this, SLOT(processInputStream()));
|
connect(io, SIGNAL(readyRead()), this, SLOT(processInputStream()));
|
||||||
}
|
}
|
||||||
|
|
||||||
UAVTalk::~UAVTalk()
|
UAVTalk::~UAVTalk()
|
||||||
{
|
{
|
||||||
// Pip
|
|
||||||
mutex->lock();
|
|
||||||
io = NULL;
|
|
||||||
objMngr = NULL;
|
|
||||||
mutex->unlock();
|
|
||||||
|
|
||||||
// According to Qt, it is not necessary to disconnect upon
|
// According to Qt, it is not necessary to disconnect upon
|
||||||
// object deletion.
|
// object deletion.
|
||||||
//disconnect(io, SIGNAL(readyRead()), this, SLOT(processInputStream()));
|
//disconnect(io, SIGNAL(readyRead()), this, SLOT(processInputStream()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the statistics counters
|
* Reset the statistics counters
|
||||||
*/
|
*/
|
||||||
@ -109,24 +104,9 @@ void UAVTalk::processInputStream()
|
|||||||
{
|
{
|
||||||
quint8 tmp;
|
quint8 tmp;
|
||||||
|
|
||||||
while (true)
|
while (io->bytesAvailable() > 0)
|
||||||
{
|
{
|
||||||
mutex->lock(); // Pip
|
io->read((char*)&tmp, 1);
|
||||||
if (!io)
|
|
||||||
{
|
|
||||||
mutex->unlock();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!io->isOpen() || io->bytesAvailable() <= 0)
|
|
||||||
{
|
|
||||||
mutex->unlock();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
qint64 bytes_read = io->read((char*)&tmp, sizeof(tmp));
|
|
||||||
mutex->unlock();
|
|
||||||
|
|
||||||
if (bytes_read <= 0) break; // Pip
|
|
||||||
|
|
||||||
processInputByte(tmp);
|
processInputByte(tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -216,9 +196,6 @@ bool UAVTalk::objectTransaction(UAVObject* obj, quint8 type, bool allInstances)
|
|||||||
*/
|
*/
|
||||||
bool UAVTalk::processInputByte(quint8 rxbyte)
|
bool UAVTalk::processInputByte(quint8 rxbyte)
|
||||||
{
|
{
|
||||||
if (!objMngr || !io) // Pip
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Update stats
|
// Update stats
|
||||||
stats.rxBytes++;
|
stats.rxBytes++;
|
||||||
|
|
||||||
@ -429,9 +406,6 @@ bool UAVTalk::receiveObject(quint8 type, quint32 objId, quint16 instId, quint8*
|
|||||||
{
|
{
|
||||||
Q_UNUSED(length);
|
Q_UNUSED(length);
|
||||||
|
|
||||||
if (!objMngr || !io) // Pip
|
|
||||||
return false;
|
|
||||||
|
|
||||||
UAVObject* obj = NULL;
|
UAVObject* obj = NULL;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
bool allInstances = (instId == ALL_INSTANCES? true : false);
|
bool allInstances = (instId == ALL_INSTANCES? true : false);
|
||||||
@ -531,9 +505,6 @@ bool UAVTalk::receiveObject(quint8 type, quint32 objId, quint16 instId, quint8*
|
|||||||
*/
|
*/
|
||||||
UAVObject* UAVTalk::updateObject(quint32 objId, quint16 instId, quint8* data)
|
UAVObject* UAVTalk::updateObject(quint32 objId, quint16 instId, quint8* data)
|
||||||
{
|
{
|
||||||
if (!objMngr || !io) // Pip
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
// Get object
|
// Get object
|
||||||
UAVObject* obj = objMngr->getObject(objId, instId);
|
UAVObject* obj = objMngr->getObject(objId, instId);
|
||||||
// If the instance does not exist create it
|
// If the instance does not exist create it
|
||||||
@ -589,9 +560,6 @@ void UAVTalk::updateAck(UAVObject* obj)
|
|||||||
*/
|
*/
|
||||||
bool UAVTalk::transmitObject(UAVObject* obj, quint8 type, bool allInstances)
|
bool UAVTalk::transmitObject(UAVObject* obj, quint8 type, bool allInstances)
|
||||||
{
|
{
|
||||||
if (!objMngr || !io) // Pip
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// If all instances are requested on a single instance object it is an error
|
// If all instances are requested on a single instance object it is an error
|
||||||
if (allInstances && obj->isSingleInstance())
|
if (allInstances && obj->isSingleInstance())
|
||||||
{
|
{
|
||||||
@ -654,9 +622,6 @@ bool UAVTalk::transmitSingleObject(UAVObject* obj, quint8 type, bool allInstance
|
|||||||
quint16 instId;
|
quint16 instId;
|
||||||
quint16 allInstId = ALL_INSTANCES;
|
quint16 allInstId = ALL_INSTANCES;
|
||||||
|
|
||||||
if (!objMngr || !io) // Pip
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Setup type and object id fields
|
// Setup type and object id fields
|
||||||
objId = obj->getObjID();
|
objId = obj->getObjID();
|
||||||
txBuffer[0] = SYNC_VAL;
|
txBuffer[0] = SYNC_VAL;
|
||||||
|
@ -31,27 +31,29 @@
|
|||||||
|
|
||||||
UAVTalkPlugin::UAVTalkPlugin()
|
UAVTalkPlugin::UAVTalkPlugin()
|
||||||
{
|
{
|
||||||
telMngr = NULL; // Pip
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UAVTalkPlugin::~UAVTalkPlugin()
|
UAVTalkPlugin::~UAVTalkPlugin()
|
||||||
{
|
{
|
||||||
if (telMngr) // Pip
|
|
||||||
telMngr->stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UAVTalkPlugin::extensionsInitialized()
|
void UAVTalkPlugin::extensionsInitialized()
|
||||||
{
|
{
|
||||||
|
// Get UAVObjectManager instance
|
||||||
|
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
||||||
|
objMngr = pm->getObject<UAVObjectManager>();
|
||||||
|
|
||||||
// Create TelemetryManager
|
// Create TelemetryManager
|
||||||
telMngr = new TelemetryManager();
|
telMngr = new TelemetryManager();
|
||||||
if (!telMngr) return; // Pip
|
|
||||||
addAutoReleasedObject(telMngr);
|
addAutoReleasedObject(telMngr);
|
||||||
|
|
||||||
// Connect to connection manager so we get notified when the user connect to his device
|
// Connect to connection manager so we get notified when the user connect to his device
|
||||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||||
QObject::connect(cm, SIGNAL(deviceConnected(QIODevice *)),
|
QObject::connect(cm, SIGNAL(deviceConnected(QIODevice *)),
|
||||||
this, SLOT(onDeviceConnect(QIODevice *)));
|
this, SLOT(onDeviceConnect(QIODevice *)));
|
||||||
QObject::connect(cm, SIGNAL(deviceDisconnected()),
|
QObject::connect(cm, SIGNAL(deviceAboutToDisconnect()),
|
||||||
this, SLOT(onDeviceDisconnect()));
|
this, SLOT(onDeviceDisconnect()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,17 +67,16 @@ bool UAVTalkPlugin::initialize(const QStringList & arguments, QString * errorStr
|
|||||||
|
|
||||||
void UAVTalkPlugin::shutdown()
|
void UAVTalkPlugin::shutdown()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UAVTalkPlugin::onDeviceConnect(QIODevice *dev)
|
void UAVTalkPlugin::onDeviceConnect(QIODevice *dev)
|
||||||
{
|
{
|
||||||
if (telMngr) // Pip
|
|
||||||
telMngr->start(dev);
|
telMngr->start(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UAVTalkPlugin::onDeviceDisconnect()
|
void UAVTalkPlugin::onDeviceDisconnect()
|
||||||
{
|
{
|
||||||
if (telMngr) // Pip
|
|
||||||
telMngr->stop();
|
telMngr->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,14 +43,6 @@ UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent)
|
|||||||
connect(telMngr, SIGNAL(connected()), this, SLOT(onAutopilotConnect()));
|
connect(telMngr, SIGNAL(connected()), this, SLOT(onAutopilotConnect()));
|
||||||
connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect()));
|
connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect()));
|
||||||
|
|
||||||
// Note: remove listening to the connection manager, it overlaps with
|
|
||||||
// listening to the telemetry manager, we should only listen to one, not both.
|
|
||||||
|
|
||||||
// Also listen to disconnect actions from the user:
|
|
||||||
// Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
|
||||||
// connect(cm, SIGNAL(deviceDisconnected()), this, SLOT(onAutopilotDisconnect()));
|
|
||||||
|
|
||||||
|
|
||||||
connect(m_config->haltButton, SIGNAL(clicked()), this, SLOT(goToBootloader()));
|
connect(m_config->haltButton, SIGNAL(clicked()), this, SLOT(goToBootloader()));
|
||||||
connect(m_config->resetButton, SIGNAL(clicked()), this, SLOT(systemReset()));
|
connect(m_config->resetButton, SIGNAL(clicked()), this, SLOT(systemReset()));
|
||||||
connect(m_config->bootButton, SIGNAL(clicked()), this, SLOT(systemBoot()));
|
connect(m_config->bootButton, SIGNAL(clicked()), this, SLOT(systemBoot()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user