void ConfigPlugin::eraseFailed() { if (settingsErased) return; ObjectPersistence* objper = ObjectPersistence::GetInstance(getObjectManager()); ObjectPersistence::DataFields data = objper->getData(); if(data.Operation == ObjectPersistence::OPERATION_FULLERASE) { // First attempt via flash erase failed. Fall back on erase all settings data.Operation = ObjectPersistence::OPERATION_DELETE; data.Selection = ObjectPersistence::SELECTION_ALLSETTINGS; objper->setData(data); objper->updated(); QTimer::singleShot(FLASH_ERASE_TIMEOUT_MS,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 UAVObjectUtilManager::saveNextObject() { if (queue.isEmpty()) { return; } Q_ASSERT(saveState == IDLE); // Get next object from the queue UAVObject *obj = queue.head(); qDebug() << "Send save object request to board " << obj->getName(); ObjectPersistence *objper = dynamic_cast<ObjectPersistence *>(getObjectManager()->getObject(ObjectPersistence::NAME)); connect(objper, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(objectPersistenceTransactionCompleted(UAVObject *, bool))); connect(objper, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(objectPersistenceUpdated(UAVObject *))); saveState = AWAITING_ACK; if (obj != NULL) { ObjectPersistence::DataFields data; data.Operation = ObjectPersistence::OPERATION_SAVE; data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT; data.ObjectID = obj->getObjID(); data.InstanceID = obj->getInstID(); objper->setData(data); objper->updated(); } // Now: we are going to get two "objectUpdated" messages (one coming from GCS, one coming from Flight, which // will confirm the object was properly received by both sides) and then one "transactionCompleted" indicating // that the Flight side did not only receive the object but it did receive it without error. Last we will get // a last "objectUpdated" message coming from flight side, where we'll get the results of the objectPersistence // operation we asked for (saved, other). }
/** * Erase all settings from the board */ void ConfigPlugin::eraseAllSettings() { QMessageBox msgBox; msgBox.setText(tr("Are you sure you want to erase all board settings?.")); msgBox.setInformativeText(tr("All settings stored in your board flash will be deleted.")); msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Ok); if (msgBox.exec() != QMessageBox::Ok) return; settingsErased = false; ObjectPersistence* objper = ObjectPersistence::GetInstance(getObjectManager()); Q_ASSERT(objper); connect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *))); ObjectPersistence::DataFields data = objper->getData(); 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->updated(); QTimer::singleShot(FLASH_ERASE_TIMEOUT_MS,this,SLOT(eraseFailed())); }
void VehicleTemplateExportDialog::importTemplate() { QJsonObject *tmpl = ui->selectionWidget->selectedTemplate(); if (tmpl != NULL) { QList<UAVObject *> updatedObjects; m_uavoManager->fromJson(*tmpl, &updatedObjects); UAVObjectUpdaterHelper helper; foreach(UAVObject * object, updatedObjects) { UAVDataObject *dataObj = dynamic_cast<UAVDataObject *>(object); if (dataObj != NULL && dataObj->isKnown()) { helper.doObjectAndWait(dataObj); ObjectPersistence *objper = ObjectPersistence::GetInstance(m_uavoManager); ObjectPersistence::DataFields data; data.Operation = ObjectPersistence::OPERATION_SAVE; data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT; data.ObjectID = dataObj->getObjID(); data.InstanceID = dataObj->getInstID(); objper->setData(data); helper.doObjectAndWait(objper); } }
/** * Erase all settings from the board */ void ConfigPlugin::eraseAllSettings() { QMessageBox msgBox; msgBox.setText(tr("Are you sure you want to erase all board settings?.")); msgBox.setInformativeText(tr("All settings stored in your board flash will be deleted.")); msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Ok); if (msgBox.exec() != QMessageBox::Ok) return; settingsErased = false; //TODO: Replace the second and third [in eraseDone()] pop-up dialogs with a progress indicator, // counter, or infinite chain of `......` tied to the original dialog box msgBox.setText(tr("Settings will now erase.")); msgBox.setInformativeText(tr("Press <OK> and then please wait until a completion box appears. This can take up to 90 seconds.")); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec(); ObjectPersistence* objper = ObjectPersistence::GetInstance(getObjectManager()); Q_ASSERT(objper); connect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *))); ObjectPersistence::DataFields data = objper->getData(); 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->updated(); QTimer::singleShot(FLASH_ERASE_TIMEOUT_MS,this,SLOT(eraseFailed())); }
void ConfigStabilizationWidget::restoreStabBank(int bank) { UAVObject *stabBankObject = getStabBankObject(bank); if (stabBankObject) { ObjectPersistence *objectPersistenceObject = ObjectPersistence::GetInstance(getObjectManager()); QTimer updateTimer(this); QEventLoop eventLoop(this); connect(&updateTimer, SIGNAL(timeout()), &eventLoop, SLOT(quit())); connect(objectPersistenceObject, SIGNAL(objectUpdated(UAVObject *)), &eventLoop, SLOT(quit())); ObjectPersistence::DataFields data; data.Operation = ObjectPersistence::OPERATION_LOAD; data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT; data.ObjectID = stabBankObject->getObjID(); data.InstanceID = stabBankObject->getInstID(); objectPersistenceObject->setData(data); objectPersistenceObject->updated(); updateTimer.start(500); eventLoop.exec(); if (updateTimer.isActive()) { stabBankObject->requestUpdate(); } updateTimer.stop(); } }
void UAVObjectBrowserWidget::updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj) { ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( objManager->getObject(ObjectPersistence::NAME) ); if (obj != NULL) { ObjectPersistence::DataFields data; data.Operation = op; data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT; data.ObjectID = obj->getObjID(); data.InstanceID = obj->getInstID(); objper->setData(data); objper->updated(); } }
/** * @brief UAVObjectUtilManager::saveNextObject * * Processes the save queue. */ void UAVObjectUtilManager::saveNextObject() { if ( queue.isEmpty() ) { return; } Q_ASSERT(saveState == IDLE); // Get next object from the queue (don't dequeue yet) UAVObject* obj = queue.head(); Q_ASSERT(obj); qDebug() << "Send save object request to board " << obj->getName(); ObjectPersistence * objectPersistence = ObjectPersistence::GetInstance(getObjectManager()); Q_ASSERT(objectPersistence); // "transactionCompleted" is emitted once the objectPersistence object is sent over the telemetry link. // Since its metadata state that it should be ACK'ed on flight telemetry, the transactionCompleted signal // will be triggered once the GCS telemetry manager receives an ACK from the flight controller, or times // out. the success value will reflect success or failure. connect(objectPersistence, SIGNAL(transactionCompleted(UAVObject*,bool)), this, SLOT(objectPersistenceTransactionCompleted(UAVObject*,bool))); // After we update the objectPersistence UAVO, we need to listen to its "objectUpdated" event, which will occur // once the flight controller sends this object back to the GCS, with the "Operation" field set to "Completed" // or "Error". connect(objectPersistence, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(objectPersistenceUpdated(UAVObject *))); saveState = AWAITING_ACK; qDebug() << "[saveObjectToFlash] Moving on to AWAITING_ACK"; ObjectPersistence::DataFields data; data.Operation = ObjectPersistence::OPERATION_SAVE; data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT; data.ObjectID = obj->getObjID(); data.InstanceID = obj->getInstID(); objectPersistence->setData(data); objectPersistence->updated(); // Now: we are going to get the following: // - two "objectUpdated" messages (one coming from GCS, one coming from Flight, which will confirm the object // was properly received by both sides). This is because the metadata of objectPersistence has "FlightUpdateOnChange" // set to true. // - then one "transactionCompleted" indicating that the Flight side did not only receive the object but it did // receive it without error (that message will be triggered by reception of the ACK). // - Last we will get one last "objectUpdated" message coming from flight side, where we'll get the results of // the objectPersistence operation we asked for (saved, other). }
void ConfigPlugin::eraseDone(UAVObject * obj) { QMessageBox msgBox; ObjectPersistence* objper = ObjectPersistence::GetInstance(getObjectManager()); ObjectPersistence::DataFields data = objper->getData(); Q_ASSERT(obj->getInstID() == objper->getInstID()); if(data.Operation != ObjectPersistence::OPERATION_COMPLETED) { return; } disconnect(objper, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(eraseDone(UAVObject *))); if (data.Operation == ObjectPersistence::OPERATION_COMPLETED) { settingsErased = true; msgBox.setText(tr("Settings are now erased.")); msgBox.setInformativeText(tr("Please wait for the status LED to begin flashing regularly (up to a minute) then power-cycle your board to complete reset.")); } else { 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(); }