1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

GCS-Uploader Auto update function

Quick and dirty autoupdate function.
The uploader plugin is in need of a major refactoring to separate the
logic from the UI. This will be on my TODO list.
This commit is contained in:
PT_Dreamer 2012-10-05 19:55:43 +01:00
parent 919202875e
commit 8c2a5e9d06
3 changed files with 167 additions and 2 deletions

View File

@ -0,0 +1,36 @@
/**
******************************************************************************
*
* @file enums.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup
* @{
* @brief
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef ENUMS_H
#define ENUMS_H
#include "uploader_global.h"
namespace uploader
{
typedef UPLOADER_EXPORT enum { IAP_STATE_READY, IAP_STATE_STEP_1, IAP_STATE_STEP_2, IAP_STEP_RESET, IAP_STATE_BOOTLOADER} IAPStep;
typedef UPLOADER_EXPORT enum { WAITING_DISCONNECT, WAITING_CONNECT, JUMP_TO_BL, LOADING_FW, UPLOADING_FW, UPLOADING_DESC, BOOTING, SUCCESS, FAILURE} AutoUpdateStep;
}
#endif // ENUMS_H

View File

@ -432,6 +432,118 @@ void UploaderGadgetWidget::commonSystemBoot(bool safeboot)
delete dfu; // Frees up the USB/Serial port too
dfu = NULL;
}
bool UploaderGadgetWidget::autoUpdate()
{
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
cm->disconnectDevice();
cm->suspendPolling();
if (dfu) {
delete dfu;
dfu = NULL;
}
while(USBMonitor::instance()->availableDevices(0x20a0,-1,-1,-1).length()>0)
{
emit autoUpdateSignal(WAITING_DISCONNECT,QVariant());
if(QMessageBox::warning(this,tr("OpenPilot Uploader"),tr("Please disconnect all openpilot boards"),QMessageBox::Ok,QMessageBox::Cancel)==QMessageBox::Cancel)
{
emit autoUpdateSignal(FAILURE,QVariant());
return false;
}
}
emit autoUpdateSignal(WAITING_CONNECT,0);
autoUpdateConnectTimeout=0;
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(performAuto()));
m_timer->start(1000);
connect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)),&m_eventloop, SLOT(quit()));
m_eventloop.exec();
if(!m_timer->isActive())
{
m_timer->stop();
emit autoUpdateSignal(FAILURE,QVariant());
return false;
}
m_timer->stop();
dfu = new DFUObject(DFU_DEBUG, false, QString());
dfu->AbortOperation();
emit autoUpdateSignal(JUMP_TO_BL,QVariant());
if(!dfu->enterDFU(0))
{
delete dfu;
dfu = NULL;
cm->resumePolling();
emit autoUpdateSignal(FAILURE,QVariant());
return false;
}
if(!dfu->findDevices() || (dfu->numberOfDevices != 1))
{
delete dfu;
dfu = NULL;
cm->resumePolling();
emit autoUpdateSignal(FAILURE,QVariant());
return false;
}
if (dfu->numberOfDevices > 5) {
delete dfu;
dfu = NULL;
cm->resumePolling();
emit autoUpdateSignal(FAILURE,QVariant());
return false;
}
QString filename;
emit autoUpdateSignal(LOADING_FW,QVariant());
switch (dfu->devices[0].ID)
{
case 0x401:
filename="fw_coptercontrol.opfw";
break;
case 0x402:
filename="fw_coptercontrol.opfw";
break;
default:
emit autoUpdateSignal(FAILURE,QVariant());
return false;
break;
}
filename=":/firmware/firmware/"+filename;
QByteArray firmware;
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
emit autoUpdateSignal(FAILURE,QVariant());
return false;
}
firmware = file.readAll();
connect(dfu, SIGNAL(progressUpdated(int)), this, SLOT(autoUpdateProgress(int)));
connect(dfu, SIGNAL(uploadFinished(OP_DFU::Status)), &m_eventloop, SLOT(quit()));
emit autoUpdateSignal(UPLOADING_FW,QVariant());
if(!dfu->enterDFU(0))
{
emit autoUpdateSignal(FAILURE,QVariant());
return false;
}
dfu->AbortOperation();
if(!dfu->UploadFirmware(filename,false,0))
{
emit autoUpdateSignal(FAILURE,QVariant());
return false;
}
m_eventloop.exec();
QByteArray desc = firmware.right(100);
emit autoUpdateSignal(UPLOADING_DESC,QVariant());
if(dfu->UploadDescription(desc)!= OP_DFU::Last_operation_Success)
{
emit autoUpdateSignal(FAILURE,QVariant());
return false;
}
systemBoot();
emit autoUpdateSignal(SUCCESS,QVariant());
return true;
}
void UploaderGadgetWidget::autoUpdateProgress(int value)
{
emit autoUpdateSignal(UPLOADING_FW,value);
}
/**
Attempt a guided procedure to put both boards in BL mode when
@ -556,6 +668,17 @@ void UploaderGadgetWidget::perform()
}
m_progress->setValue(m_progress->value()+1);
}
void UploaderGadgetWidget::performAuto()
{
++autoUpdateConnectTimeout;
emit autoUpdateSignal(WAITING_CONNECT,autoUpdateConnectTimeout*5);
if(autoUpdateConnectTimeout==20)
{
m_timer->stop();
m_eventloop.exit();
}
}
void UploaderGadgetWidget::cancel()
{
m_timer->stop();

View File

@ -56,8 +56,9 @@
#include <QProgressDialog>
#include <QErrorMessage>
#include <QDesktopServices>
#include "enums.h"
using namespace OP_DFU;
using namespace uploader;
class UploaderGadgetWidget : public QWidget
@ -68,7 +69,6 @@ class UploaderGadgetWidget : public QWidget
public:
UploaderGadgetWidget(QWidget *parent = 0);
~UploaderGadgetWidget();
typedef enum { IAP_STATE_READY, IAP_STATE_STEP_1, IAP_STATE_STEP_2, IAP_STEP_RESET, IAP_STATE_BOOTLOADER} IAPStep;
void log(QString str);
public slots:
@ -76,6 +76,10 @@ public slots:
void onAutopilotDisconnect();
void populate();
void openHelp();
bool autoUpdate();
void autoUpdateProgress(int);
signals:
void autoUpdateSignal(uploader::AutoUpdateStep,QVariant);
private:
Ui_UploaderWidget *m_config;
DFUObject *dfu;
@ -89,6 +93,7 @@ private:
QEventLoop m_eventloop;
QErrorMessage * msg;
void connectSignalSlot(QWidget * widget);
int autoUpdateConnectTimeout;
private slots:
void onPhisicalHWConnect();
void versionMatchCheck();
@ -102,6 +107,7 @@ private slots:
void systemRescue();
void getSerialPorts();
void perform();
void performAuto();
void cancel();
void uploadStarted();
void uploadEnded(bool succeed);