From 8d2c9c37fbc4809769a0c38a1c77d0471352ede7 Mon Sep 17 00:00:00 2001 From: edouard Date: Mon, 1 Nov 2010 18:15:48 +0000 Subject: [PATCH] OP-35 Fix complile issue on Win7 (please confirm), Halt button now puts the mainboard into bootloader mode. Nothing more... git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2055 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/rawhid/pjrc_rawhid.h | 3 +- ground/src/plugins/rawhid/rawhidplugin.cpp | 2 +- ground/src/plugins/uploader/devicewidget.cpp | 35 ++++++ ground/src/plugins/uploader/devicewidget.h | 49 ++++++++ ground/src/plugins/uploader/devicewidget.ui | 114 ++++++++++++++++++ ground/src/plugins/uploader/op_dfu.cpp | 21 ++-- ground/src/plugins/uploader/uploader.pro | 9 +- .../plugins/uploader/uploadergadgetwidget.cpp | 32 ++++- .../plugins/uploader/uploadergadgetwidget.h | 2 + 9 files changed, 248 insertions(+), 19 deletions(-) create mode 100644 ground/src/plugins/uploader/devicewidget.cpp create mode 100644 ground/src/plugins/uploader/devicewidget.h create mode 100644 ground/src/plugins/uploader/devicewidget.ui diff --git a/ground/src/plugins/rawhid/pjrc_rawhid.h b/ground/src/plugins/rawhid/pjrc_rawhid.h index 683cf81d7..3c94aa64e 100644 --- a/ground/src/plugins/rawhid/pjrc_rawhid.h +++ b/ground/src/plugins/rawhid/pjrc_rawhid.h @@ -33,8 +33,9 @@ #include #include #include +#include "rawhid_global.h" -class pjrc_rawhid +class RAWHID_EXPORT pjrc_rawhid { public: pjrc_rawhid(); diff --git a/ground/src/plugins/rawhid/rawhidplugin.cpp b/ground/src/plugins/rawhid/rawhidplugin.cpp index 8b112eb94..82f48125e 100644 --- a/ground/src/plugins/rawhid/rawhidplugin.cpp +++ b/ground/src/plugins/rawhid/rawhidplugin.cpp @@ -98,9 +98,9 @@ QStringList RawHIDConnection::availableDevices() QMutexLocker locker(&m_enumMutex); QStringList devices; - pjrc_rawhid dev; if (enablePolling) { + pjrc_rawhid dev; //open all device we can int opened = dev.open(MAX_DEVICES, VID, PID, USAGE_PAGE, USAGE); diff --git a/ground/src/plugins/uploader/devicewidget.cpp b/ground/src/plugins/uploader/devicewidget.cpp new file mode 100644 index 000000000..a0e79353a --- /dev/null +++ b/ground/src/plugins/uploader/devicewidget.cpp @@ -0,0 +1,35 @@ +/** + ****************************************************************************** + * + * @file devicewidget.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup YModemUploader YModem Serial Uploader Plugin + * @{ + * @brief The YModem protocol serial uploader plugin + *****************************************************************************/ +/* + * 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); +} diff --git a/ground/src/plugins/uploader/devicewidget.h b/ground/src/plugins/uploader/devicewidget.h new file mode 100644 index 000000000..766340657 --- /dev/null +++ b/ground/src/plugins/uploader/devicewidget.h @@ -0,0 +1,49 @@ +/** + ****************************************************************************** + * + * @file devicewidget.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup YModemUploader YModem Serial Uploader Plugin + * @{ + * @brief The YModem protocol serial uploader plugin + *****************************************************************************/ +/* + * 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 DEVICEWIDGET_H +#define DEVICEWIDGET_H + +#include "ui_devicewidget.h" +#include + +class deviceWidget : public QWidget +{ + Q_OBJECT +public: + explicit deviceWidget(QWidget *parent = 0); + +private: + Ui_deviceWidget *myDevice; + +signals: + +public slots: + +}; + +#endif // DEVICEWIDGET_H diff --git a/ground/src/plugins/uploader/devicewidget.ui b/ground/src/plugins/uploader/devicewidget.ui new file mode 100644 index 000000000..3409cdead --- /dev/null +++ b/ground/src/plugins/uploader/devicewidget.ui @@ -0,0 +1,114 @@ + + + deviceWidget + + + + 0 + 0 + 516 + 236 + + + + Form + + + + + + + + + + + DeviceID + + + + + + + 24 + + + + + + + ReadWrite + + + + + + + MaxCodeSize + + + + + + + fwCRC + + + + + + + BootLoaderVersion + + + + + + + Retrieve... + + + + + + + + 160 + 160 + + + + + + + + Update... + + + + + + + Verify... + + + + + + + + 75 + true + + + + Status + + + + + + + + + + diff --git a/ground/src/plugins/uploader/op_dfu.cpp b/ground/src/plugins/uploader/op_dfu.cpp index 90c416c8b..b49c207e9 100644 --- a/ground/src/plugins/uploader/op_dfu.cpp +++ b/ground/src/plugins/uploader/op_dfu.cpp @@ -8,32 +8,29 @@ OP_DFU::OP_DFU(bool _debug): debug(_debug) send_delay=10; use_delay=true; int numDevices=0; - cout<<"Please connect device now\n"; int count=0; while(numDevices==0) { - cout<<"."; + if (debug) + qDebug() << "."; delay::msleep(500); numDevices = hidHandle.open(1,0x20a0,0x4117,0,0); //0xff9c,0x0001); if(++count==10) { - cout<<"\r"; - cout<<" "; - cout<<"\r"; count=0; } } if(debug) qDebug() << numDevices << " device(s) opened"; } + bool OP_DFU::SaveByteArrayToFile(QString const & sfile, const QByteArray &array) { QFile file(sfile); - //QFile file("in.txt"); if (!file.open(QIODevice::WriteOnly)) { if(debug) - qDebug()<<"Cant open file"; + qDebug()<<"Can't open file"; return false; } file.write(array); @@ -59,7 +56,7 @@ bool OP_DFU::enterDFU(int const &devNumber) if(result<1) return false; if(debug) - qDebug() << result << " bytes sent"; + qDebug() << "EnterDFU: " << result << " bytes sent"; return true; } bool OP_DFU::StartUpload(qint32 const & numberOfBytes, TransferTypes const & type,quint32 crc) @@ -324,6 +321,7 @@ void OP_DFU::JumpToApp() int result = hidHandle.send(0,buf, BUF_LEN, 500); } + OP_DFU::Status OP_DFU::StatusRequest() { char buf[BUF_LEN]; @@ -340,19 +338,18 @@ OP_DFU::Status OP_DFU::StatusRequest() int result = hidHandle.send(0,buf, BUF_LEN, 10000); if(debug) - qDebug() << result << " bytes sent"; + qDebug() << "StatusRequest: " << result << " bytes sent"; result = hidHandle.receive(0,buf,BUF_LEN,10000); if(debug) - qDebug() << result << " bytes received"; + qDebug() << "StatusRequest: " << result << " bytes received"; if(buf[1]==OP_DFU::Status_Rep) { return (OP_DFU::Status)buf[6]; } else return OP_DFU::abort; - - } + bool OP_DFU::findDevices() { devices.clear(); diff --git a/ground/src/plugins/uploader/uploader.pro b/ground/src/plugins/uploader/uploader.pro index c7cf1dd8a..6a261760a 100755 --- a/ground/src/plugins/uploader/uploader.pro +++ b/ground/src/plugins/uploader/uploader.pro @@ -13,7 +13,8 @@ HEADERS += uploadergadget.h \ uploadergadgetwidget.h \ uploaderplugin.h \ op_dfu.h \ - delay.h + delay.h \ + devicewidget.h SOURCES += uploadergadget.cpp \ uploadergadgetconfiguration.cpp \ uploadergadgetfactory.cpp \ @@ -21,8 +22,10 @@ SOURCES += uploadergadget.cpp \ uploadergadgetwidget.cpp \ uploaderplugin.cpp \ op_dfu.cpp \ - delay.cpp + delay.cpp \ + devicewidget.cpp OTHER_FILES += Uploader.pluginspec FORMS += \ - uploader.ui + uploader.ui \ + devicewidget.ui diff --git a/ground/src/plugins/uploader/uploadergadgetwidget.cpp b/ground/src/plugins/uploader/uploadergadgetwidget.cpp index 807735d16..d969dee92 100755 --- a/ground/src/plugins/uploader/uploadergadgetwidget.cpp +++ b/ground/src/plugins/uploader/uploadergadgetwidget.cpp @@ -33,6 +33,8 @@ UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent) currentStep = IAP_STATE_READY; resetOnly=false; + //m_config->systemElements->addTab((QWidget*)new deviceWidget(),QString("Device")); + connect(m_config->haltButton, SIGNAL(clicked()), this, SLOT(goToBootloader())); connect(m_config->resetButton, SIGNAL(clicked()), this, SLOT(systemReset())); @@ -62,7 +64,9 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success) case IAP_STATE_STEP_1: if (!success) { log(QString("Oops, failure step 1")); + log("Reset did NOT happen"); currentStep == IAP_STATE_READY; + disconnect(fwIAP, SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToBootloader(UAVObject*, bool))); break; } delay::msleep(600); @@ -74,7 +78,9 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success) case IAP_STATE_STEP_2: if (!success) { log(QString("Oops, failure step 2")); + log("Reset did NOT happen"); currentStep == IAP_STATE_READY; + disconnect(fwIAP, SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToBootloader(UAVObject*, bool))); break; } delay::msleep(600); @@ -88,12 +94,13 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success) if (success) { log("Oops, unexpected success step 3"); log("Reset did NOT happen"); + disconnect(fwIAP, SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToBootloader(UAVObject*, bool))); break; } // The board is now reset: we have to disconnect telemetry Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager(); cm->disconnectDevice(); - log(QString("Board Reset")); + log("Board Reset"); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); disconnect(fwIAP, SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToBootloader(UAVObject*, bool))); @@ -105,8 +112,29 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success) RawHIDConnection *cnx = pm->getObject(); cnx->suspendPolling(); - } + // Tell the mainboard to get into bootloader state: + log("Going into Bootloader mode..."); + OP_DFU dfu(true); + dfu.AbortOperation(); + if(!dfu.enterDFU(0)) + { + log("Could not enter DFU mode."); + } + OP_DFU::Status ret=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;isystemElements->addTab(dw, QString("Device") + QString::number(i)); + } + } } } diff --git a/ground/src/plugins/uploader/uploadergadgetwidget.h b/ground/src/plugins/uploader/uploadergadgetwidget.h index 2d38097c6..99640898c 100755 --- a/ground/src/plugins/uploader/uploadergadgetwidget.h +++ b/ground/src/plugins/uploader/uploadergadgetwidget.h @@ -30,6 +30,8 @@ #include "ui_uploader.h" #include "delay.h" +#include "devicewidget.h" +#include "op_dfu.h" #include "extensionsystem/pluginmanager.h" #include "uavobjects/uavobjectmanager.h"