mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
OP-557: Make the tools erase menu item attempt to perform a full format on the
flash chip first, then fall back to erasing settings via the EraseSettings object persistence. The later only removes UAVO instances that the firmware is current aware of, so can create issues when jumping between versions.
This commit is contained in:
parent
35eef66bfe
commit
33e61b4405
@ -30,7 +30,7 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
#include "objectpersistence.h"
|
||||||
|
|
||||||
ConfigPlugin::ConfigPlugin()
|
ConfigPlugin::ConfigPlugin()
|
||||||
{
|
{
|
||||||
@ -58,7 +58,7 @@ bool ConfigPlugin::initialize(const QStringList& args, QString *errMsg)
|
|||||||
"ConfigPlugin.EraseAll",
|
"ConfigPlugin.EraseAll",
|
||||||
QList<int>() <<
|
QList<int>() <<
|
||||||
Core::Constants::C_GLOBAL_ID);
|
Core::Constants::C_GLOBAL_ID);
|
||||||
cmd->action()->setText("Erase all settings from board...");
|
cmd->action()->setText(tr("Erase all settings from board..."));
|
||||||
|
|
||||||
ac->menu()->addSeparator();
|
ac->menu()->addSeparator();
|
||||||
ac->appendGroup("Utilities");
|
ac->appendGroup("Utilities");
|
||||||
@ -80,6 +80,17 @@ bool ConfigPlugin::initialize(const QStringList& args, QString *errMsg)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return handle to object manager
|
||||||
|
*/
|
||||||
|
UAVObjectManager * ConfigPlugin::getObjectManager()
|
||||||
|
{
|
||||||
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||||
|
UAVObjectManager * objMngr = pm->getObject<UAVObjectManager>();
|
||||||
|
Q_ASSERT(objMngr);
|
||||||
|
return objMngr;
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigPlugin::extensionsInitialized()
|
void ConfigPlugin::extensionsInitialized()
|
||||||
{
|
{
|
||||||
cmd->action()->setEnabled(false);
|
cmd->action()->setEnabled(false);
|
||||||
@ -122,18 +133,19 @@ void ConfigPlugin::eraseAllSettings()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
settingsErased = false;
|
settingsErased = false;
|
||||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
ObjectPersistence* objper = ObjectPersistence::GetInstance(getObjectManager());
|
||||||
UAVObjectManager * objMngr = pm->getObject<UAVObjectManager>();
|
|
||||||
Q_ASSERT(objMngr);
|
|
||||||
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( objMngr->getObject(ObjectPersistence::NAME) );
|
|
||||||
Q_ASSERT(objper);
|
Q_ASSERT(objper);
|
||||||
|
|
||||||
connect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *)));
|
connect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *)));
|
||||||
ObjectPersistence::DataFields data;
|
|
||||||
data.Operation = ObjectPersistence::OPERATION_DELETE;
|
ObjectPersistence::DataFields data = objper->getData();
|
||||||
data.Selection = ObjectPersistence::SELECTION_ALLSETTINGS;
|
data.Operation = ObjectPersistence::OPERATION_FULLERASE;
|
||||||
|
|
||||||
|
// No need for manual updated event, this is triggered by setData
|
||||||
|
// based on UAVO meta data
|
||||||
objper->setData(data);
|
objper->setData(data);
|
||||||
objper->updated();
|
objper->updated();
|
||||||
QTimer::singleShot(1500,this,SLOT(eraseFailed()));
|
QTimer::singleShot(6000,this,SLOT(eraseFailed()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,37 +153,47 @@ void ConfigPlugin::eraseFailed()
|
|||||||
{
|
{
|
||||||
if (settingsErased)
|
if (settingsErased)
|
||||||
return;
|
return;
|
||||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
||||||
UAVObjectManager * objMngr = pm->getObject<UAVObjectManager>();
|
ObjectPersistence* objper = ObjectPersistence::GetInstance(getObjectManager());
|
||||||
Q_ASSERT(objMngr);
|
|
||||||
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( objMngr->getObject(ObjectPersistence::NAME));
|
ObjectPersistence::DataFields data = objper->getData();
|
||||||
disconnect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *)));
|
if(data.Operation == ObjectPersistence::OPERATION_FULLERASE) {
|
||||||
QMessageBox msgBox;
|
// First attempt via flash erase failed. Fall back on erase all settings
|
||||||
msgBox.setText(tr("Error trying to erase settings."));
|
data.Operation = ObjectPersistence::OPERATION_DELETE;
|
||||||
msgBox.setInformativeText(tr("Power-cycle your board. Settings might be inconsistent."));
|
data.Selection = ObjectPersistence::SELECTION_ALLSETTINGS;
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
objper->setData(data);
|
||||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
objper->updated();
|
||||||
msgBox.exec();
|
QTimer::singleShot(1500,this,SLOT(eraseFailed()));
|
||||||
|
} else {
|
||||||
|
disconnect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *)));
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setText(tr("Error trying to erase settings."));
|
||||||
|
msgBox.setInformativeText(tr("Power-cycle your board after removing all blades. Settings might be inconsistent."));
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||||
|
msgBox.exec();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigPlugin::eraseDone(UAVObject * obj)
|
void ConfigPlugin::eraseDone(UAVObject * obj)
|
||||||
{
|
{
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>(sender());
|
ObjectPersistence* objper = ObjectPersistence::GetInstance(getObjectManager());
|
||||||
Q_ASSERT(obj->getName().compare("ObjectPersistence") == 0);
|
ObjectPersistence::DataFields data = objper->getData();
|
||||||
QString tmp = obj->getField("Operation")->getValue().toString();
|
Q_ASSERT(obj->getInstID() == objper->getInstID());
|
||||||
if (obj->getField("Operation")->getValue().toString().compare(QString("Delete")) == 0 ) {
|
|
||||||
|
if(data.Operation != ObjectPersistence::OPERATION_COMPLETED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *)));
|
disconnect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *)));
|
||||||
if (obj->getField("Operation")->getValue().toString().compare(QString("Completed")) == 0) {
|
if (data.Operation == ObjectPersistence::OPERATION_COMPLETED) {
|
||||||
settingsErased = true;
|
settingsErased = true;
|
||||||
msgBox.setText(tr("Settings are now erased."));
|
msgBox.setText(tr("Settings are now erased."));
|
||||||
msgBox.setInformativeText(tr("Please now power-cycle your board to complete reset."));
|
msgBox.setInformativeText(tr("Please now power-cycle your board to complete reset."));
|
||||||
} else {
|
} else {
|
||||||
msgBox.setText(tr("Error trying to erase settings."));
|
msgBox.setText(tr("Error trying to erase settings."));
|
||||||
msgBox.setInformativeText(tr("Power-cycle your board. Settings might be inconsistent."));
|
msgBox.setInformativeText(tr("Power-cycle your board after removing all blades. Settings might be inconsistent."));
|
||||||
}
|
}
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||||
|
@ -48,6 +48,7 @@ public:
|
|||||||
ConfigPlugin();
|
ConfigPlugin();
|
||||||
~ConfigPlugin();
|
~ConfigPlugin();
|
||||||
|
|
||||||
|
UAVObjectManager * getObjectManager();
|
||||||
void extensionsInitialized();
|
void extensionsInitialized();
|
||||||
bool initialize(const QStringList & arguments, QString * errorString);
|
bool initialize(const QStringList & arguments, QString * errorString);
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
Loading…
Reference in New Issue
Block a user