diff --git a/ground/src/plugins/uploader/devicewidget.cpp b/ground/src/plugins/uploader/devicewidget.cpp index 9f4aae307..fe6e33379 100644 --- a/ground/src/plugins/uploader/devicewidget.cpp +++ b/ground/src/plugins/uploader/devicewidget.cpp @@ -58,6 +58,7 @@ void deviceWidget::populate() 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)); + myDevice->BLVersion->setText(QString("BL Version: ") + QString::number(m_dfu->devices[deviceID].BL_Version)); int size=((OP_DFU::device)m_dfu->devices[deviceID]).SizeOfDesc; m_dfu->enterDFU(deviceID); @@ -69,6 +70,26 @@ void deviceWidget::populate() } +/** + 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); +} + +/** + Updates status message + */ +void deviceWidget::status(QString str) +{ + myDevice->statusLabel->setText(str); +} + /** Verifies the firmware CRC */ @@ -88,27 +109,29 @@ void deviceWidget::uploadFirmware() } bool verify = true; + QString filename = setOpenFileName(); + if (filename.isEmpty()) { + status("Empty filename"); + return; + } - - /* - OP_DFU::Status retstatus=dfu.UploadFirmware(file.toAscii(),verify, device); - if(retstatus!=OP_DFU::Last_operation_Success) - { - cout<<"Upload failed with code:"<UploadFirmware(filename.toAscii(),verify, deviceID); + if(retstatus != OP_DFU::Last_operation_Success) { + status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data()); + return; + } else + if(!myDevice->description->text().isEmpty()) { + 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()); + return; + } + } + status("Uploading Succeded!"); } /** @@ -127,3 +150,29 @@ void deviceWidget::downloadFirmware() return ret; */ } + +/** + 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"), + "", + tr("All Files (*);;Firmware Files (*.bin)"), + &selectedFilter, + options); + return fileName; +} diff --git a/ground/src/plugins/uploader/devicewidget.h b/ground/src/plugins/uploader/devicewidget.h index 5e3227dca..b53ccdce6 100644 --- a/ground/src/plugins/uploader/devicewidget.h +++ b/ground/src/plugins/uploader/devicewidget.h @@ -31,6 +31,8 @@ #include "ui_devicewidget.h" #include "op_dfu.h" #include +#include + class deviceWidget : public QWidget { @@ -40,11 +42,14 @@ public: void setDeviceID(int devID); void setDfu(OP_DFU* dfu); void populate(); + void freeze(); + QString setOpenFileName(); private: Ui_deviceWidget *myDevice; int deviceID; OP_DFU *m_dfu; + void status(QString str); signals: @@ -52,6 +57,7 @@ public slots: void verifyFirmware(); void uploadFirmware(); void downloadFirmware(); + void setProgress(int); }; diff --git a/ground/src/plugins/uploader/op_dfu.cpp b/ground/src/plugins/uploader/op_dfu.cpp index b49c207e9..5b2dbed79 100644 --- a/ground/src/plugins/uploader/op_dfu.cpp +++ b/ground/src/plugins/uploader/op_dfu.cpp @@ -24,6 +24,11 @@ OP_DFU::OP_DFU(bool _debug): debug(_debug) qDebug() << numDevices << " device(s) opened"; } +OP_DFU::~OP_DFU() +{ + +} + bool OP_DFU::SaveByteArrayToFile(QString const & sfile, const QByteArray &array) { QFile file(sfile); @@ -147,7 +152,7 @@ bool OP_DFU::UploadData(qint32 const & numberOfBytes, QByteArray & data) // } // qDebug()<<" Data0="<<(int)data[0]<<" Data0="<<(int)data[1]<<" Data0="<<(int)data[2]<<" Data0="<<(int)data[3]<<" buf6="<<(int)buf[6]<<" buf7="<<(int)buf[7]<<" buf8="<<(int)buf[8]<<" buf9="<<(int)buf[9]; //delay::msleep(send_delay); - if(int ret=StatusRequest()!=OP_DFU::uploading) return false; + if(StatusRequest()!=OP_DFU::uploading) return false; int result = hidHandle.send(0,buf, BUF_LEN, 5000); // qDebug()<<"sent:"< devices; int numberOfDevices; @@ -122,14 +114,17 @@ public: OP_DFU::Status CompareFirmware(const QString &sfile, const CompareType &type,int device); quint32 CRC32WideFast(quint32 Crc, quint32 Size, quint32 *Buffer); quint32 CRCFromQBArray(QByteArray array, quint32 Size); - void test(); + int send_delay; bool use_delay; - void AbortOperation(void); + int AbortOperation(void); + +signals: + void progressUpdated(int); + private: bool debug; int RWFlags; - pjrc_rawhid hidHandle; int setStartBit(int command){return command|0x20;} }; diff --git a/ground/src/plugins/uploader/uploadergadgetwidget.cpp b/ground/src/plugins/uploader/uploadergadgetwidget.cpp index f598d0b04..c953c1e75 100755 --- a/ground/src/plugins/uploader/uploadergadgetwidget.cpp +++ b/ground/src/plugins/uploader/uploadergadgetwidget.cpp @@ -32,6 +32,7 @@ UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent) m_config->setupUi(this); currentStep = IAP_STATE_READY; resetOnly=false; + dfu = NULL; //m_config->systemElements->addTab((QWidget*)new deviceWidget(),QString("Device")); @@ -118,28 +119,28 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success) // Tell the mainboard to get into bootloader state: log("Going into Bootloader mode..."); - OP_DFU dfu(true); - dfu.AbortOperation(); - if(!dfu.enterDFU(0)) + dfu = new OP_DFU(false); + dfu->AbortOperation(); + if(!dfu->enterDFU(0)) { log("Could not enter DFU mode."); return; } m_config->boardStatus->setText("Bootloader"); currentStep = IAP_STATE_BOOTLOADER; - //OP_DFU::Status ret=dfu.StatusRequest(); - dfu.findDevices(); - log(QString("Found ") + QString::number(dfu.numberOfDevices) + QString(" device(s).")); + //dfu.StatusRequest(); + dfu->findDevices(); + log(QString("Found ") + QString::number(dfu->numberOfDevices) + QString(" device(s).")); // Delete all previous tabs: for (int i=0; i< m_config->systemElements->count(); i++) { QWidget *qw = m_config->systemElements->widget(i); m_config->systemElements->removeTab(i); delete qw; } - for(int i=0;inumberOfDevices;i++) { deviceWidget* dw = new deviceWidget(this); dw->setDeviceID(i); - dw->setDfu(&dfu); + dw->setDfu(dfu); dw->populate(); m_config->systemElements->addTab(dw, QString("Device") + QString::number(i)); } @@ -175,15 +176,16 @@ void UploaderGadgetWidget::systemBoot() { if (currentStep == IAP_STATE_BOOTLOADER) { clearLog(); - OP_DFU dfu(true); - dfu.AbortOperation(); - if(!dfu.enterDFU(0)) + if (!dfu) + dfu = new OP_DFU(true); + dfu->AbortOperation(); + if(!dfu->enterDFU(0)) { log("Could not enter DFU mode."); return; } log("Booting system..."); - dfu.JumpToApp(); + dfu->JumpToApp(); currentStep = IAP_STATE_READY; // stop the polling thread: otherwise it will mess up DFU ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); @@ -193,6 +195,14 @@ void UploaderGadgetWidget::systemBoot() m_config->haltButton->setEnabled(true); m_config->resetButton->setEnabled(true); m_config->boardStatus->setText("Running"); + // Freeze the tabs, they are not useful anymore and their buttons + // will cause segfaults or weird stuff if we use them. + for (int i=0; i< m_config->systemElements->count(); i++) { + deviceWidget *qw = (deviceWidget*)m_config->systemElements->widget(i); + qw->freeze(); + } + + delete dfu; } else { log("Not in bootloader mode!"); @@ -214,35 +224,12 @@ void UploaderGadgetWidget::clearLog() m_config->textBrowser->clear(); } -//user pressed send, send file using a new thread with qymodem library -void UploaderGadgetWidget::send() -{ - -} -//destructor !!?! do I need to delete something else? UploaderGadgetWidget::~UploaderGadgetWidget() { -} - - -/** - -Opens an open file dialog. - -*/ -void UploaderGadgetWidget::setOpenFileName() -{ - QFileDialog::Options options; - QString selectedFilter; - QString fileName = QFileDialog::getOpenFileName(this, - tr("QFileDialog::getOpenFileName()"), - openFileNameLE->text(), - tr("All Files (*);;Text Files (*.bin)"), - &selectedFilter, - options); - if (!fileName.isEmpty()) openFileNameLE->setText(fileName); } + + /** Shows a message box with an error string. diff --git a/ground/src/plugins/uploader/uploadergadgetwidget.h b/ground/src/plugins/uploader/uploadergadgetwidget.h index 551ac21c0..3eeaf79ed 100755 --- a/ground/src/plugins/uploader/uploadergadgetwidget.h +++ b/ground/src/plugins/uploader/uploadergadgetwidget.h @@ -42,7 +42,6 @@ #include #include #include -#include #include @@ -58,6 +57,7 @@ public: private: Ui_UploaderWidget *m_config; + OP_DFU *dfu; IAPStep currentStep; bool resetOnly; void log(QString str); @@ -66,8 +66,6 @@ private: QLineEdit* openFileNameLE; private slots: - void setOpenFileName(); - void send(); void error(QString errorString,int errorNumber); void info(QString infoString,int infoNumber); void goToBootloader(UAVObject* = NULL, bool = false);