2010-11-01 19:15:48 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file devicewidget.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
2011-01-08 14:22:15 +01:00
|
|
|
* @addtogroup Uploader Serial and USB Uploader Plugin
|
2010-11-01 19:15:48 +01:00
|
|
|
* @{
|
2011-01-08 14:22:15 +01:00
|
|
|
* @brief The USB and Serial protocol uploader plugin
|
2010-11-01 19:15:48 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
#include "devicewidget.h"
|
|
|
|
|
|
|
|
deviceWidget::deviceWidget(QWidget *parent) :
|
|
|
|
QWidget(parent)
|
|
|
|
{
|
|
|
|
myDevice = new Ui_deviceWidget();
|
|
|
|
myDevice->setupUi(this);
|
2010-11-26 23:49:50 +01:00
|
|
|
devicePic = NULL; // Initialize pointer to null
|
|
|
|
|
|
|
|
// Initialization of the Device icon display
|
|
|
|
myDevice->devicePicture->setScene(new QGraphicsScene(this));
|
2010-11-03 19:46:17 +01:00
|
|
|
|
|
|
|
connect(myDevice->verifyButton, SIGNAL(clicked()), this, SLOT(verifyFirmware()));
|
|
|
|
connect(myDevice->retrieveButton, SIGNAL(clicked()), this, SLOT(downloadFirmware()));
|
|
|
|
connect(myDevice->updateButton, SIGNAL(clicked()), this, SLOT(uploadFirmware()));
|
2010-12-28 22:27:21 +01:00
|
|
|
|
|
|
|
QPixmap pix = QPixmap(QString(":uploader/images/view-refresh.svg"));
|
|
|
|
myDevice->statusIcon->setPixmap(pix);
|
2011-05-25 21:23:22 +02:00
|
|
|
|
|
|
|
myDevice->certifiedFW->setText("");
|
2010-11-01 19:15:48 +01:00
|
|
|
}
|
2010-11-01 21:50:59 +01:00
|
|
|
|
2010-11-26 23:49:50 +01:00
|
|
|
|
|
|
|
void deviceWidget::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
// Thit fitInView method should only be called now, once the
|
|
|
|
// widget is shown, otherwise it cannot compute its values and
|
|
|
|
// the result is usually a ahrsbargraph that is way too small.
|
|
|
|
if (devicePic)
|
|
|
|
myDevice->devicePicture->fitInView(devicePic,Qt::KeepAspectRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deviceWidget::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
if (devicePic)
|
|
|
|
myDevice->devicePicture->fitInView(devicePic, Qt::KeepAspectRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-01 21:50:59 +01:00
|
|
|
void deviceWidget::setDeviceID(int devID){
|
|
|
|
deviceID = devID;
|
|
|
|
}
|
|
|
|
|
2010-11-06 15:17:21 +01:00
|
|
|
void deviceWidget::setDfu(DFUObject *dfu)
|
2010-11-01 21:50:59 +01:00
|
|
|
{
|
|
|
|
m_dfu = dfu;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Fills the various fields for the device
|
|
|
|
*/
|
|
|
|
void deviceWidget::populate()
|
|
|
|
{
|
|
|
|
int id = m_dfu->devices[deviceID].ID;
|
2011-01-30 02:49:32 +01:00
|
|
|
myDevice->deviceID->setText(QString("Device ID: ") + QString::number(id, 16));
|
2010-11-26 23:49:50 +01:00
|
|
|
// DeviceID tells us what sort of HW we have detected:
|
|
|
|
// display a nice icon:
|
|
|
|
myDevice->devicePicture->scene()->clear();
|
|
|
|
if (devicePic)
|
|
|
|
delete devicePic;
|
|
|
|
devicePic = new QGraphicsSvgItem();
|
|
|
|
devicePic->setSharedRenderer(new QSvgRenderer());
|
|
|
|
|
|
|
|
switch (id) {
|
2011-01-16 21:41:55 +01:00
|
|
|
case 0x0101:
|
|
|
|
devicePic->renderer()->load(QString(":/uploader/images/deviceID-0101.svg"));
|
2010-11-26 23:49:50 +01:00
|
|
|
break;
|
2011-01-16 21:41:55 +01:00
|
|
|
case 0x0301:
|
|
|
|
devicePic->renderer()->load(QString(":/uploader/images/deviceID-0301.svg"));
|
2011-01-15 16:54:04 +01:00
|
|
|
break;
|
2011-01-16 21:41:55 +01:00
|
|
|
case 0x0401:
|
|
|
|
devicePic->renderer()->load(QString(":/uploader/images/deviceID-0401.svg"));
|
2011-01-15 16:54:04 +01:00
|
|
|
break;
|
2011-01-16 21:41:55 +01:00
|
|
|
case 0x0201:
|
|
|
|
devicePic->renderer()->load(QString(":/uploader/images/deviceID-0201.svg"));
|
2010-11-26 23:49:50 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
devicePic->setElementId("device");
|
|
|
|
myDevice->devicePicture->scene()->addItem(devicePic);
|
|
|
|
myDevice->devicePicture->setSceneRect(devicePic->boundingRect());
|
|
|
|
myDevice->devicePicture->fitInView(devicePic,Qt::KeepAspectRatio);
|
|
|
|
|
2010-11-01 21:50:59 +01:00
|
|
|
bool r = m_dfu->devices[deviceID].Readable;
|
|
|
|
bool w = m_dfu->devices[deviceID].Writable;
|
2010-11-03 19:46:17 +01:00
|
|
|
myDevice->deviceACL->setText(QString("Access: ") + QString(r ? "R" : "-") + QString(w ? "W" : "-"));
|
|
|
|
myDevice->maxCodeSize->setText(QString("Max code size: ") +QString::number(m_dfu->devices[deviceID].SizeOfCode));
|
|
|
|
myDevice->fwCRC->setText(QString("FW CRC: ") + QString::number(m_dfu->devices[deviceID].FW_CRC));
|
2010-11-03 22:41:32 +01:00
|
|
|
myDevice->BLVersion->setText(QString("BL Version: ") + QString::number(m_dfu->devices[deviceID].BL_Version));
|
2010-11-03 19:46:17 +01:00
|
|
|
|
2010-11-01 21:50:59 +01:00
|
|
|
int size=((OP_DFU::device)m_dfu->devices[deviceID]).SizeOfDesc;
|
|
|
|
m_dfu->enterDFU(deviceID);
|
2011-05-08 11:36:55 +02:00
|
|
|
QByteArray desc = m_dfu->DownloadDescriptionAsBA(size);
|
|
|
|
if (! populateStructuredDescription(desc)) {
|
|
|
|
// desc was not a structured description
|
|
|
|
QString str = m_dfu->DownloadDescription(size);
|
|
|
|
myDevice->description->setMaxLength(size);
|
|
|
|
myDevice->description->setText(str.left(str.indexOf(QChar(255))));
|
2011-05-25 21:23:22 +02:00
|
|
|
QPixmap pix = QPixmap(QString(":uploader/images/gtk-info.svg"));
|
|
|
|
myDevice->certifiedFW->setPixmap(pix);
|
|
|
|
myDevice->certifiedFW->setToolTip(tr("Custom Firmware Build"));
|
2011-05-08 11:36:55 +02:00
|
|
|
myDevice->buildDate->setText("Warning: development firmware");
|
|
|
|
myDevice->commitTag->setText("");
|
|
|
|
}
|
|
|
|
|
2010-11-01 21:50:59 +01:00
|
|
|
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Ready...", STATUSICON_INFO);
|
2010-11-03 19:46:17 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-11-03 22:41:32 +01:00
|
|
|
/**
|
|
|
|
Freezes the contents of the widget so that a user cannot
|
|
|
|
try to modify the contents
|
|
|
|
*/
|
|
|
|
void deviceWidget::freeze()
|
|
|
|
{
|
|
|
|
myDevice->description->setEnabled(false);
|
|
|
|
myDevice->updateButton->setEnabled(false);
|
|
|
|
myDevice->verifyButton->setEnabled(false);
|
|
|
|
myDevice->retrieveButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2011-05-08 11:36:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Populates the widget field with the description in case
|
|
|
|
it is structured properly
|
|
|
|
*/
|
|
|
|
bool deviceWidget::populateStructuredDescription(QByteArray desc)
|
|
|
|
{
|
|
|
|
if (desc.startsWith("OpFw")) {
|
|
|
|
// This looks like a binary with a description at the end
|
|
|
|
/*
|
|
|
|
# 4 bytes: header: "OpFw"
|
|
|
|
# 4 bytes: GIT commit tag (short version of SHA1)
|
|
|
|
# 4 bytes: Unix timestamp of compile time
|
|
|
|
# 2 bytes: target platform. Should follow same rule as BOARD_TYPE and BOARD_REVISION in board define files.
|
|
|
|
# 26 bytes: commit tag if it is there, otherwise "Unreleased". Zero-padded
|
|
|
|
# ---- 40 bytes limit ---
|
|
|
|
# 20 bytes: SHA1 sum of the firmware.
|
|
|
|
# 40 bytes: free for now.
|
|
|
|
*/
|
|
|
|
// I don't want to use structs, ok ?
|
|
|
|
quint32 gitCommitTag = desc.at(4)&0xFF;
|
|
|
|
for (int i=1;i<4;i++) {
|
|
|
|
gitCommitTag = gitCommitTag<<8;
|
|
|
|
gitCommitTag += desc.at(4+i) & 0xFF;
|
|
|
|
}
|
|
|
|
myDevice->commitTag->setText("GIT tag 0x" + QString::number(gitCommitTag,16));
|
|
|
|
quint32 buildDate = desc.at(8)&0xFF;
|
|
|
|
for (int i=1;i<4;i++) {
|
|
|
|
buildDate = buildDate<<8;
|
|
|
|
buildDate += desc.at(8+i) & 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
myDevice->buildDate->setText(QString("Build time: ") + QDateTime::fromTime_t(buildDate).toString());
|
|
|
|
QByteArray targetPlatform = desc.mid(12,2);
|
|
|
|
// TODO: check platform compatibility
|
|
|
|
QString dscText = QString(desc.mid(14,26));
|
|
|
|
myDevice->description->setText(dscText);
|
|
|
|
|
2011-05-25 21:23:22 +02:00
|
|
|
QPixmap pix = QPixmap(QString(":uploader/images/application-certificate.svg"));
|
|
|
|
myDevice->certifiedFW->setPixmap(pix);
|
|
|
|
myDevice->certifiedFW->setToolTip(tr("Official Firmware Build"));
|
2011-05-08 11:36:55 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-12-28 22:27:21 +01:00
|
|
|
/**
|
|
|
|
Updates status message for messages coming from DFU
|
|
|
|
*/
|
|
|
|
void deviceWidget::dfuStatus(QString str)
|
|
|
|
{
|
|
|
|
status(str, STATUSICON_RUNNING);
|
|
|
|
}
|
|
|
|
|
2010-11-03 22:41:32 +01:00
|
|
|
/**
|
|
|
|
Updates status message
|
|
|
|
*/
|
2010-12-28 22:27:21 +01:00
|
|
|
void deviceWidget::status(QString str, StatusIcon ic)
|
2010-11-03 22:41:32 +01:00
|
|
|
{
|
2010-12-28 22:27:21 +01:00
|
|
|
QPixmap px;
|
2010-11-03 22:41:32 +01:00
|
|
|
myDevice->statusLabel->setText(str);
|
2010-12-28 22:27:21 +01:00
|
|
|
switch (ic) {
|
|
|
|
case STATUSICON_RUNNING:
|
|
|
|
px.load(QString(":/uploader/images/system-run.svg"));
|
|
|
|
break;
|
|
|
|
case STATUSICON_OK:
|
|
|
|
px.load(QString(":/uploader/images/dialog-apply.svg"));
|
|
|
|
break;
|
|
|
|
case STATUSICON_FAIL:
|
|
|
|
px.load(QString(":/uploader/images/process-stop.svg"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
px.load(QString(":/uploader/images/gtk-info.svg"));
|
|
|
|
}
|
|
|
|
myDevice->statusIcon->setPixmap(px);
|
2010-11-03 22:41:32 +01:00
|
|
|
}
|
|
|
|
|
2010-11-03 19:46:17 +01:00
|
|
|
/**
|
|
|
|
Verifies the firmware CRC
|
|
|
|
*/
|
|
|
|
void deviceWidget::verifyFirmware()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sends a firmware to the device
|
|
|
|
*/
|
|
|
|
void deviceWidget::uploadFirmware()
|
|
|
|
{
|
|
|
|
if (!m_dfu->devices[deviceID].Writable) {
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Device not writable!", STATUSICON_FAIL);
|
2010-11-03 19:46:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-26 11:44:05 +01:00
|
|
|
bool verify = false;
|
2010-12-14 00:44:31 +01:00
|
|
|
/* TODO: does not work properly on current Bootloader!
|
2010-11-26 11:44:05 +01:00
|
|
|
if (m_dfu->devices[deviceID].Readable)
|
|
|
|
verify = true;
|
2010-12-14 00:44:31 +01:00
|
|
|
*/
|
2010-11-26 11:44:05 +01:00
|
|
|
|
2010-11-03 22:41:32 +01:00
|
|
|
QString filename = setOpenFileName();
|
2010-11-03 19:46:17 +01:00
|
|
|
|
2010-11-03 22:41:32 +01:00
|
|
|
if (filename.isEmpty()) {
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Empty filename", STATUSICON_FAIL);
|
2010-11-03 22:41:32 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-11-03 19:46:17 +01:00
|
|
|
|
2011-05-08 00:57:59 +02:00
|
|
|
QFile file(filename);
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
|
|
|
status("Can't open file", STATUSICON_FAIL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray arr = file.readAll();
|
|
|
|
QByteArray desc = arr.right(100);
|
2011-05-08 11:36:55 +02:00
|
|
|
if (populateStructuredDescription(desc)) {
|
|
|
|
descriptionArray = desc;
|
2011-05-08 21:22:00 +02:00
|
|
|
// Now do sanity checking:
|
|
|
|
// - Check whether board type matches firmware:
|
|
|
|
int board = m_dfu->devices[deviceID].ID;
|
|
|
|
int firmwareBoard = ((desc.at(12)&0xff)<<8) + (desc.at(13)&0xff);
|
|
|
|
if (firmwareBoard != board) {
|
|
|
|
status("Error: firmware does not match board", STATUSICON_FAIL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Check the firmware embedded in the file:
|
|
|
|
QByteArray firmwareHash = desc.mid(40,20);
|
|
|
|
QByteArray fileHash = QCryptographicHash::hash(arr.left(arr.length()-100), QCryptographicHash::Sha1);
|
|
|
|
if (firmwareHash != fileHash) {
|
|
|
|
status("Error: firmware file corrupt", STATUSICON_FAIL);
|
|
|
|
return;
|
|
|
|
}
|
2011-05-08 00:57:59 +02:00
|
|
|
} else {
|
2011-05-08 21:22:00 +02:00
|
|
|
// The firmware is not packaged, just upload the text in the description field
|
|
|
|
// if it is there.
|
2011-05-08 11:36:55 +02:00
|
|
|
descriptionArray.clear();
|
2011-05-08 00:57:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Starting firmware upload", STATUSICON_RUNNING);
|
2010-11-22 23:31:59 +01:00
|
|
|
// We don't know which device was used previously, so we
|
|
|
|
// are cautious and reenter DFU for this deviceID:
|
|
|
|
if(!m_dfu->enterDFU(deviceID))
|
|
|
|
{
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Error:Could not enter DFU mode", STATUSICON_FAIL);
|
2010-11-22 23:31:59 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
OP_DFU::Status ret=m_dfu->StatusRequest();
|
|
|
|
qDebug() << m_dfu->StatusToString(ret);
|
|
|
|
m_dfu->AbortOperation(); // Necessary, otherwise I get random failures.
|
|
|
|
|
2010-11-03 22:41:32 +01:00
|
|
|
connect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
|
2010-12-28 22:27:21 +01:00
|
|
|
connect(m_dfu, SIGNAL(operationProgress(QString)), this, SLOT(dfuStatus(QString)));
|
2010-11-06 15:17:21 +01:00
|
|
|
connect(m_dfu, SIGNAL(uploadFinished(OP_DFU::Status)), this, SLOT(uploadFinished(OP_DFU::Status)));
|
|
|
|
bool retstatus = m_dfu->UploadFirmware(filename.toAscii(),verify, deviceID);
|
|
|
|
if(!retstatus ) {
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Could not start upload", STATUSICON_FAIL);
|
2010-11-03 22:41:32 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Uploading, please wait...", STATUSICON_RUNNING);
|
2010-11-03 19:46:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Retrieves the firmware from the device
|
|
|
|
*/
|
|
|
|
void deviceWidget::downloadFirmware()
|
|
|
|
{
|
|
|
|
if (!m_dfu->devices[deviceID].Readable) {
|
|
|
|
myDevice->statusLabel->setText(QString("Device not readable!"));
|
|
|
|
return;
|
|
|
|
}
|
2010-11-01 21:50:59 +01:00
|
|
|
|
2010-11-06 15:17:21 +01:00
|
|
|
myDevice->retrieveButton->setEnabled(false);
|
2011-04-29 22:50:58 +02:00
|
|
|
filename = setSaveFileName();
|
2010-11-06 15:17:21 +01:00
|
|
|
|
|
|
|
if (filename.isEmpty()) {
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Empty filename", STATUSICON_FAIL);
|
2010-11-06 15:17:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Downloading firmware from device", STATUSICON_RUNNING);
|
2010-11-06 15:17:21 +01:00
|
|
|
connect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
|
|
|
|
connect(m_dfu, SIGNAL(downloadFinished()), this, SLOT(downloadFinished()));
|
|
|
|
downloadedFirmware.clear(); // Empty the byte array
|
|
|
|
bool ret = m_dfu->DownloadFirmware(&downloadedFirmware,deviceID);
|
|
|
|
if(!ret) {
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Could not start download!", STATUSICON_FAIL);
|
2010-11-06 15:17:21 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Download started, please wait", STATUSICON_RUNNING);
|
2010-11-06 15:17:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Callback for the firmware download result
|
|
|
|
*/
|
|
|
|
void deviceWidget::downloadFinished()
|
|
|
|
{
|
|
|
|
disconnect(m_dfu, SIGNAL(downloadFinished()), this, SLOT(downloadFinished()));
|
2010-11-27 14:44:16 +01:00
|
|
|
disconnect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Download successful", STATUSICON_OK);
|
2010-11-06 15:17:21 +01:00
|
|
|
// Now save the result (use the utility function from OP_DFU)
|
|
|
|
m_dfu->SaveByteArrayToFile(filename, downloadedFirmware);
|
|
|
|
myDevice->retrieveButton->setEnabled(true);
|
2010-11-01 21:50:59 +01:00
|
|
|
}
|
2010-11-03 22:41:32 +01:00
|
|
|
|
2010-11-06 15:17:21 +01:00
|
|
|
/**
|
|
|
|
Callback for the firmware upload result
|
|
|
|
*/
|
|
|
|
void deviceWidget::uploadFinished(OP_DFU::Status retstatus)
|
|
|
|
{
|
|
|
|
disconnect(m_dfu, SIGNAL(uploadFinished(OP_DFU::Status)), this, SLOT(uploadFinished(OP_DFU::Status)));
|
2010-11-27 14:44:16 +01:00
|
|
|
disconnect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
|
2011-01-08 14:22:15 +01:00
|
|
|
disconnect(m_dfu, SIGNAL(operationProgress(QString)), this, SLOT(dfuStatus(QString)));
|
2010-11-06 15:17:21 +01:00
|
|
|
if(retstatus != OP_DFU::Last_operation_Success) {
|
2010-12-28 22:27:21 +01:00
|
|
|
status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data(), STATUSICON_FAIL);
|
2010-11-06 15:17:21 +01:00
|
|
|
return;
|
|
|
|
} else
|
2011-05-08 11:36:55 +02:00
|
|
|
if (!descriptionArray.isEmpty()) {
|
|
|
|
// We have a structured array to save
|
2010-12-28 22:27:21 +01:00
|
|
|
status(QString("Updating description"), STATUSICON_RUNNING);
|
2010-11-06 15:17:21 +01:00
|
|
|
repaint(); // Make sure the text above shows right away
|
2011-05-08 11:36:55 +02:00
|
|
|
retstatus = m_dfu->UploadDescription(descriptionArray);
|
2010-11-06 15:17:21 +01:00
|
|
|
if( retstatus != OP_DFU::Last_operation_Success) {
|
2010-12-28 22:27:21 +01:00
|
|
|
status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data(), STATUSICON_FAIL);
|
2010-11-06 15:17:21 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-05-08 11:36:55 +02:00
|
|
|
|
|
|
|
} else if (!myDevice->description->text().isEmpty()) {
|
|
|
|
// Fallback: we save the description field:
|
|
|
|
status(QString("Updating description"), STATUSICON_RUNNING);
|
|
|
|
repaint(); // Make sure the text above shows right away
|
|
|
|
retstatus = m_dfu->UploadDescription(myDevice->description->text());
|
|
|
|
if( retstatus != OP_DFU::Last_operation_Success) {
|
|
|
|
status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data(), STATUSICON_FAIL);
|
|
|
|
return;
|
|
|
|
}
|
2010-11-06 15:17:21 +01:00
|
|
|
}
|
2011-05-08 11:36:55 +02:00
|
|
|
|
2010-12-28 22:27:21 +01:00
|
|
|
status("Upload successful", STATUSICON_OK);
|
2010-11-06 15:17:21 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-11-03 22:41:32 +01:00
|
|
|
/**
|
|
|
|
Slot to update the progress bar
|
|
|
|
*/
|
|
|
|
void deviceWidget::setProgress(int percent)
|
|
|
|
{
|
|
|
|
myDevice->progressBar->setValue(percent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
Opens an open file dialog.
|
|
|
|
|
|
|
|
*/
|
|
|
|
QString deviceWidget::setOpenFileName()
|
|
|
|
{
|
|
|
|
QFileDialog::Options options;
|
|
|
|
QString selectedFilter;
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(this,
|
|
|
|
tr("Select firmware file"),
|
|
|
|
"",
|
2011-05-25 21:23:22 +02:00
|
|
|
tr("Firmware Files (*.bin *.opfw)"),
|
2010-11-03 22:41:32 +01:00
|
|
|
&selectedFilter,
|
|
|
|
options);
|
|
|
|
return fileName;
|
|
|
|
}
|
2011-04-29 22:50:58 +02:00
|
|
|
QString deviceWidget::setSaveFileName()
|
|
|
|
{
|
|
|
|
QFileDialog::Options options;
|
|
|
|
QString selectedFilter;
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this,
|
|
|
|
tr("Select firmware file"),
|
|
|
|
"",
|
|
|
|
tr("Firmware Files (*.bin)"),
|
|
|
|
&selectedFilter,
|
|
|
|
options);
|
|
|
|
return fileName;
|
|
|
|
}
|