mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-21 11:54:15 +01:00
OP-35 Cleanup of DFU object management, I think I have fixed all the potential segfaults, prove me wrong!
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2164 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
6ab6f3e84a
commit
63c3799521
@ -121,6 +121,7 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
|
|||||||
|
|
||||||
// Tell the mainboard to get into bootloader state:
|
// Tell the mainboard to get into bootloader state:
|
||||||
log("Going into Bootloader mode...");
|
log("Going into Bootloader mode...");
|
||||||
|
if (!dfu)
|
||||||
dfu = new DFUObject(false);
|
dfu = new DFUObject(false);
|
||||||
dfu->AbortOperation();
|
dfu->AbortOperation();
|
||||||
if(!dfu->enterDFU(0))
|
if(!dfu->enterDFU(0))
|
||||||
@ -149,6 +150,7 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
|
|||||||
m_config->haltButton->setEnabled(false);
|
m_config->haltButton->setEnabled(false);
|
||||||
m_config->resetButton->setEnabled(false);
|
m_config->resetButton->setEnabled(false);
|
||||||
m_config->bootButton->setEnabled(true);
|
m_config->bootButton->setEnabled(true);
|
||||||
|
m_config->rescueButton->setEnabled(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IAP_STATE_BOOTLOADER:
|
case IAP_STATE_BOOTLOADER:
|
||||||
@ -189,13 +191,14 @@ void UploaderGadgetWidget::systemBoot()
|
|||||||
log("Booting system...");
|
log("Booting system...");
|
||||||
dfu->JumpToApp();
|
dfu->JumpToApp();
|
||||||
currentStep = IAP_STATE_READY;
|
currentStep = IAP_STATE_READY;
|
||||||
// stop the polling thread: otherwise it will mess up DFU
|
// Restart the polling thread
|
||||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||||
RawHIDConnection *cnx = pm->getObject<RawHIDConnection>();
|
RawHIDConnection *cnx = pm->getObject<RawHIDConnection>();
|
||||||
cnx->resumePolling();
|
cnx->resumePolling();
|
||||||
m_config->bootButton->setEnabled(false);
|
m_config->bootButton->setEnabled(false);
|
||||||
m_config->haltButton->setEnabled(true);
|
m_config->haltButton->setEnabled(true);
|
||||||
m_config->resetButton->setEnabled(true);
|
m_config->resetButton->setEnabled(true);
|
||||||
|
m_config->rescueButton->setEnabled(true);
|
||||||
m_config->boardStatus->setText("Running");
|
m_config->boardStatus->setText("Running");
|
||||||
// Freeze the tabs, they are not useful anymore and their buttons
|
// Freeze the tabs, they are not useful anymore and their buttons
|
||||||
// will cause segfaults or weird stuff if we use them.
|
// will cause segfaults or weird stuff if we use them.
|
||||||
@ -205,6 +208,7 @@ void UploaderGadgetWidget::systemBoot()
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete dfu;
|
delete dfu;
|
||||||
|
dfu = NULL;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log("Not in bootloader mode!");
|
log("Not in bootloader mode!");
|
||||||
@ -217,14 +221,13 @@ void UploaderGadgetWidget::systemBoot()
|
|||||||
*/
|
*/
|
||||||
void UploaderGadgetWidget::systemRescue()
|
void UploaderGadgetWidget::systemRescue()
|
||||||
{
|
{
|
||||||
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||||
|
RawHIDConnection *cnx = pm->getObject<RawHIDConnection>();
|
||||||
switch (rescueStep) {
|
switch (rescueStep) {
|
||||||
case RESCUE_STEP0: {
|
case RESCUE_STEP0: {
|
||||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||||
cm->disconnectDevice();
|
cm->disconnectDevice();
|
||||||
|
|
||||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
||||||
// stop the polling thread: otherwise it will mess up DFU
|
// stop the polling thread: otherwise it will mess up DFU
|
||||||
RawHIDConnection *cnx = pm->getObject<RawHIDConnection>();
|
|
||||||
cnx->suspendPolling();
|
cnx->suspendPolling();
|
||||||
// Delete all previous tabs:
|
// Delete all previous tabs:
|
||||||
while (m_config->systemElements->count()) {
|
while (m_config->systemElements->count()) {
|
||||||
@ -232,6 +235,8 @@ void UploaderGadgetWidget::systemRescue()
|
|||||||
m_config->systemElements->removeTab(0);
|
m_config->systemElements->removeTab(0);
|
||||||
delete qw;
|
delete qw;
|
||||||
}
|
}
|
||||||
|
// Existing DFU objects will have a handle over USB and will
|
||||||
|
// disturb everything for the rescue process:
|
||||||
if (dfu) {
|
if (dfu) {
|
||||||
delete dfu;
|
delete dfu;
|
||||||
dfu = NULL;
|
dfu = NULL;
|
||||||
@ -259,17 +264,22 @@ void UploaderGadgetWidget::systemRescue()
|
|||||||
case RESCUE_STEP3:
|
case RESCUE_STEP3:
|
||||||
log("... Detecting Mainboard...");
|
log("... Detecting Mainboard...");
|
||||||
repaint();
|
repaint();
|
||||||
if (!dfu)
|
|
||||||
dfu = new DFUObject(true);
|
dfu = new DFUObject(true);
|
||||||
dfu->AbortOperation();
|
dfu->AbortOperation();
|
||||||
if(!dfu->enterDFU(0))
|
if(!dfu->enterDFU(0))
|
||||||
{
|
{
|
||||||
|
rescueStep = RESCUE_STEP0;
|
||||||
log("Could not enter DFU mode.");
|
log("Could not enter DFU mode.");
|
||||||
|
cnx->resumePolling();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!dfu->findDevices())
|
if(!dfu->findDevices() || (dfu->numberOfDevices != 1))
|
||||||
{
|
{
|
||||||
|
rescueStep = RESCUE_STEP0;
|
||||||
log("Could not detect mainboard.");
|
log("Could not detect mainboard.");
|
||||||
|
delete dfu;
|
||||||
|
dfu = NULL;
|
||||||
|
cnx->resumePolling();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rescueStep = RESCUE_POWER1;
|
rescueStep = RESCUE_POWER1;
|
||||||
@ -293,11 +303,17 @@ void UploaderGadgetWidget::systemRescue()
|
|||||||
if(!dfu->findDevices())
|
if(!dfu->findDevices())
|
||||||
{
|
{
|
||||||
log("Could not detect devices.");
|
log("Could not detect devices.");
|
||||||
|
delete dfu;
|
||||||
|
dfu = NULL;
|
||||||
|
cnx->resumePolling();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log(QString("Found ") + QString::number(dfu->numberOfDevices) + QString(" device(s)."));
|
log(QString("Found ") + QString::number(dfu->numberOfDevices) + QString(" device(s)."));
|
||||||
if (dfu->numberOfDevices > 5) {
|
if (dfu->numberOfDevices > 5) {
|
||||||
log("Inconsistent number of devices, aborting!");
|
log("Inconsistent number of devices, aborting!");
|
||||||
|
delete dfu;
|
||||||
|
dfu = NULL;
|
||||||
|
cnx->resumePolling();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(int i=0;i<dfu->numberOfDevices;i++) {
|
for(int i=0;i<dfu->numberOfDevices;i++) {
|
||||||
@ -310,10 +326,9 @@ void UploaderGadgetWidget::systemRescue()
|
|||||||
m_config->haltButton->setEnabled(false);
|
m_config->haltButton->setEnabled(false);
|
||||||
m_config->resetButton->setEnabled(false);
|
m_config->resetButton->setEnabled(false);
|
||||||
m_config->bootButton->setEnabled(true);
|
m_config->bootButton->setEnabled(true);
|
||||||
|
m_config->rescueButton->setEnabled(false);
|
||||||
currentStep = IAP_STATE_BOOTLOADER; // So that we can boot from the GUI afterwards.
|
currentStep = IAP_STATE_BOOTLOADER; // So that we can boot from the GUI afterwards.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user