2011-01-31 21:50:11 +00:00
/**
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @ file uploadergadgetwidget . 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 "uploadergadgetwidget.h"
2014-05-02 23:36:05 +02:00
2013-12-11 22:22:28 +01:00
# include "flightstatus.h"
2015-02-02 00:14:02 +01:00
# include "oplinkstatus.h"
2014-05-05 00:05:51 +02:00
# include "delay.h"
2014-05-02 23:36:05 +02:00
# include "devicewidget.h"
# include "runningdevicewidget.h"
2013-12-11 22:22:28 +01:00
2014-05-02 23:36:05 +02:00
# include <extensionsystem/pluginmanager.h>
# include <coreplugin/icore.h>
2011-11-13 16:05:36 +00:00
# include <coreplugin/coreconstants.h>
2014-05-02 23:36:05 +02:00
# include <coreplugin/connectionmanager.h>
2013-12-11 22:22:28 +01:00
# include <uavtalk/telemetrymanager.h>
2014-05-02 23:36:05 +02:00
# include <QDesktopServices>
# include <QMessageBox>
2014-05-02 08:55:46 +02:00
# include <QProgressBar>
2011-11-13 17:39:05 +00:00
# include <QDebug>
2015-01-09 00:42:43 +01:00
# include "rebootdialog.h"
2011-01-31 21:50:11 +00:00
# define DFU_DEBUG true
2011-06-19 00:50:38 +01:00
2014-05-01 22:48:22 +02:00
const int UploaderGadgetWidget : : BOARD_EVENT_TIMEOUT = 20000 ;
2013-06-25 15:51:33 +02:00
const int UploaderGadgetWidget : : AUTOUPDATE_CLOSE_TIMEOUT = 7000 ;
2015-01-26 23:03:39 +01:00
const int UploaderGadgetWidget : : REBOOT_TIMEOUT = 20000 ;
const int UploaderGadgetWidget : : ERASE_TIMEOUT = 20000 ;
const int UploaderGadgetWidget : : BOOTLOADER_TIMEOUT = 20000 ;
2013-06-25 15:51:33 +02:00
2014-05-01 16:37:12 +02:00
TimedDialog : : TimedDialog ( const QString & title , const QString & labelText , int timeout , QWidget * parent , Qt : : WindowFlags flags ) :
2014-05-05 00:05:51 +02:00
QProgressDialog ( labelText , tr ( " Cancel " ) , 0 , timeout , parent , flags ) , bar ( new QProgressBar ( this ) )
2014-05-01 16:37:12 +02:00
{
setWindowTitle ( title ) ;
setAutoReset ( false ) ;
// open immediately...
setMinimumDuration ( 0 ) ;
// setup progress bar
bar - > setRange ( 0 , timeout ) ;
bar - > setFormat ( tr ( " Timing out in %1 seconds " ) . arg ( timeout ) ) ;
setBar ( bar ) ;
}
void TimedDialog : : perform ( )
{
setValue ( value ( ) + 1 ) ;
int remaining = bar - > maximum ( ) - bar - > value ( ) ;
if ( remaining > 0 ) {
bar - > setFormat ( tr ( " Timing out in %1 seconds " ) . arg ( remaining ) ) ;
} else {
2014-05-02 08:55:46 +02:00
bar - > setFormat ( tr ( " Timed out after %1 seconds " ) . arg ( bar - > maximum ( ) ) ) ;
2014-05-01 16:37:12 +02:00
}
}
2014-05-01 22:48:22 +02:00
ConnectionWaiter : : ConnectionWaiter ( int targetDeviceCount , int timeout , QWidget * parent ) : QObject ( parent ) , eventLoop ( this ) , timer ( this ) , timeout ( timeout ) , elapsed ( 0 ) , targetDeviceCount ( targetDeviceCount ) , result ( ConnectionWaiter : : Ok )
2014-05-05 00:05:51 +02:00
{ }
2014-05-01 22:48:22 +02:00
2014-05-05 00:05:51 +02:00
int ConnectionWaiter : : exec ( )
{
2014-05-01 22:48:22 +02:00
connect ( USBMonitor : : instance ( ) , SIGNAL ( deviceDiscovered ( USBPortInfo ) ) , this , SLOT ( deviceEvent ( ) ) ) ;
connect ( USBMonitor : : instance ( ) , SIGNAL ( deviceRemoved ( USBPortInfo ) ) , this , SLOT ( deviceEvent ( ) ) ) ;
connect ( & timer , SIGNAL ( timeout ( ) ) , this , SLOT ( perform ( ) ) ) ;
timer . start ( 1000 ) ;
emit timeChanged ( 0 ) ;
eventLoop . exec ( ) ;
return result ;
}
2014-05-05 00:05:51 +02:00
void ConnectionWaiter : : cancel ( )
{
2014-05-02 08:55:46 +02:00
quit ( ) ;
result = ConnectionWaiter : : Canceled ;
}
2014-05-05 00:05:51 +02:00
void ConnectionWaiter : : quit ( )
{
2014-05-01 22:48:22 +02:00
disconnect ( USBMonitor : : instance ( ) , SIGNAL ( deviceDiscovered ( USBPortInfo ) ) , this , SLOT ( deviceEvent ( ) ) ) ;
disconnect ( USBMonitor : : instance ( ) , SIGNAL ( deviceRemoved ( USBPortInfo ) ) , this , SLOT ( deviceEvent ( ) ) ) ;
timer . stop ( ) ;
eventLoop . exit ( ) ;
}
void ConnectionWaiter : : perform ( )
{
+ + elapsed ;
emit timeChanged ( elapsed ) ;
int remaining = timeout - elapsed * 1000 ;
if ( remaining < = 0 ) {
result = ConnectionWaiter : : TimedOut ;
quit ( ) ;
}
}
void ConnectionWaiter : : deviceEvent ( )
{
if ( USBMonitor : : instance ( ) - > availableDevices ( 0x20a0 , - 1 , - 1 , - 1 ) . length ( ) = = targetDeviceCount ) {
quit ( ) ;
}
}
2014-05-05 00:05:51 +02:00
int ConnectionWaiter : : openDialog ( const QString & title , const QString & labelText , int targetDeviceCount , int timeout , QWidget * parent , Qt : : WindowFlags flags )
{
2014-05-02 08:55:46 +02:00
TimedDialog dlg ( title , labelText , timeout / 1000 , parent , flags ) ;
ConnectionWaiter waiter ( targetDeviceCount , timeout , parent ) ;
2014-05-05 00:05:51 +02:00
2014-05-02 08:55:46 +02:00
connect ( & dlg , SIGNAL ( canceled ( ) ) , & waiter , SLOT ( cancel ( ) ) ) ;
connect ( & waiter , SIGNAL ( timeChanged ( int ) ) , & dlg , SLOT ( perform ( ) ) ) ;
return waiter . exec ( ) ;
}
2011-01-31 21:50:11 +00:00
UploaderGadgetWidget : : UploaderGadgetWidget ( QWidget * parent ) : QWidget ( parent )
{
2013-05-19 17:37:30 +03:00
m_config = new Ui_UploaderWidget ( ) ;
2011-01-31 21:50:11 +00:00
m_config - > setupUi ( this ) ;
2015-02-02 00:14:02 +01:00
m_currentIAPStep = IAP_STATE_READY ;
2015-02-05 09:55:31 +01:00
m_resetOnly = false ;
2015-02-02 00:14:02 +01:00
m_dfu = NULL ;
2015-02-03 22:24:57 +01:00
m_autoUpdateClosing = false ;
2014-05-01 22:48:22 +02:00
2011-01-31 21:50:11 +00:00
// Listen to autopilot connection events
ExtensionSystem : : PluginManager * pm = ExtensionSystem : : PluginManager : : instance ( ) ;
2013-05-19 17:37:30 +03:00
TelemetryManager * telMngr = pm - > getObject < TelemetryManager > ( ) ;
2011-01-31 21:50:11 +00:00
connect ( telMngr , SIGNAL ( connected ( ) ) , this , SLOT ( onAutopilotConnect ( ) ) ) ;
connect ( telMngr , SIGNAL ( disconnected ( ) ) , this , SLOT ( onAutopilotDisconnect ( ) ) ) ;
2014-05-05 00:05:51 +02:00
Core : : ConnectionManager * cm = Core : : ICore : : instance ( ) - > connectionManager ( ) ;
connect ( cm , SIGNAL ( deviceConnected ( QIODevice * ) ) , this , SLOT ( onPhysicalHWConnect ( ) ) ) ;
2012-11-18 22:40:05 +01:00
connect ( m_config - > haltButton , SIGNAL ( clicked ( ) ) , this , SLOT ( systemHalt ( ) ) ) ;
2011-01-31 21:50:11 +00:00
connect ( m_config - > resetButton , SIGNAL ( clicked ( ) ) , this , SLOT ( systemReset ( ) ) ) ;
connect ( m_config - > bootButton , SIGNAL ( clicked ( ) ) , this , SLOT ( systemBoot ( ) ) ) ;
2012-01-02 14:21:12 -05:00
connect ( m_config - > safeBootButton , SIGNAL ( clicked ( ) ) , this , SLOT ( systemSafeBoot ( ) ) ) ;
2013-04-08 01:09:31 +02:00
connect ( m_config - > eraseBootButton , SIGNAL ( clicked ( ) ) , this , SLOT ( systemEraseBoot ( ) ) ) ;
2011-01-31 21:50:11 +00:00
connect ( m_config - > rescueButton , SIGNAL ( clicked ( ) ) , this , SLOT ( systemRescue ( ) ) ) ;
2014-05-05 00:05:51 +02:00
2011-01-31 21:50:11 +00:00
getSerialPorts ( ) ;
2013-05-19 13:08:50 +02:00
connect ( m_config - > autoUpdateButton , SIGNAL ( clicked ( ) ) , this , SLOT ( startAutoUpdate ( ) ) ) ;
2014-12-08 16:36:17 +01:00
connect ( m_config - > autoUpdateEraseButton , SIGNAL ( clicked ( ) ) , this , SLOT ( startAutoUpdateErase ( ) ) ) ;
2013-05-19 13:08:50 +02:00
connect ( m_config - > autoUpdateOkButton , SIGNAL ( clicked ( ) ) , this , SLOT ( closeAutoUpdate ( ) ) ) ;
2014-05-05 00:05:51 +02:00
m_config - > autoUpdateButton - > setEnabled ( autoUpdateCapable ( ) ) ;
2014-12-08 16:36:17 +01:00
m_config - > autoUpdateEraseButton - > setEnabled ( autoUpdateCapable ( ) ) ;
2013-05-19 13:08:50 +02:00
m_config - > autoUpdateGroupBox - > setVisible ( false ) ;
2014-05-05 00:05:51 +02:00
m_config - > refreshPorts - > setIcon ( QIcon ( " :uploader/images/view-refresh.svg " ) ) ;
2011-01-31 21:50:11 +00:00
2013-04-08 23:55:11 +02:00
bootButtonsSetEnable ( false ) ;
2011-01-31 21:50:11 +00:00
connect ( m_config - > refreshPorts , SIGNAL ( clicked ( ) ) , this , SLOT ( getSerialPorts ( ) ) ) ;
2013-05-19 17:37:30 +03:00
connect ( m_config - > pbHelp , SIGNAL ( clicked ( ) ) , this , SLOT ( openHelp ( ) ) ) ;
2011-04-10 08:23:03 +00:00
// And check whether by any chance we are not already connected
2013-05-19 17:37:30 +03:00
if ( telMngr - > isConnected ( ) ) {
2011-04-10 08:23:03 +00:00
onAutopilotConnect ( ) ;
2011-11-13 17:39:05 +00:00
}
2011-01-31 21:50:11 +00:00
}
2013-09-15 23:06:25 +02:00
bool sortPorts ( const QSerialPortInfo & s1 , const QSerialPortInfo & s2 )
2011-01-31 21:50:11 +00:00
{
2013-09-15 23:06:25 +02:00
return s1 . portName ( ) < s2 . portName ( ) ;
2011-01-31 21:50:11 +00:00
}
/**
2013-05-19 17:37:30 +03:00
Gets the list of serial ports
*/
2011-01-31 21:50:11 +00:00
void UploaderGadgetWidget : : getSerialPorts ( )
{
QStringList list ;
2013-05-19 17:37:30 +03:00
2011-01-31 21:50:11 +00:00
// Populate the telemetry combo box:
m_config - > telemetryLink - > clear ( ) ;
list . append ( QString ( " USB " ) ) ;
2013-09-15 23:06:25 +02:00
QList < QSerialPortInfo > ports = QSerialPortInfo : : availablePorts ( ) ;
2011-01-31 21:50:11 +00:00
2013-05-19 17:37:30 +03:00
// sort the list by port number (nice idea from PT_Dreamer :))
qSort ( ports . begin ( ) , ports . end ( ) , sortPorts ) ;
2013-09-15 23:06:25 +02:00
foreach ( QSerialPortInfo port , ports ) {
list . append ( port . portName ( ) ) ;
2011-01-31 21:50:11 +00:00
}
m_config - > telemetryLink - > addItems ( list ) ;
}
QString UploaderGadgetWidget : : getPortDevice ( const QString & friendName )
{
2013-09-15 23:06:25 +02:00
QList < QSerialPortInfo > ports = QSerialPortInfo : : availablePorts ( ) ;
foreach ( QSerialPortInfo port , ports ) {
if ( port . portName ( ) = = friendName ) {
return port . portName ( ) ;
}
2013-05-19 17:37:30 +03:00
}
2011-01-31 21:50:11 +00:00
return " " ;
}
2012-05-07 15:11:51 +01:00
void UploaderGadgetWidget : : connectSignalSlot ( QWidget * widget )
{
2013-05-19 17:37:30 +03:00
connect ( qobject_cast < DeviceWidget * > ( widget ) , SIGNAL ( uploadStarted ( ) ) , this , SLOT ( uploadStarted ( ) ) ) ;
connect ( qobject_cast < DeviceWidget * > ( widget ) , SIGNAL ( uploadEnded ( bool ) ) , this , SLOT ( uploadEnded ( bool ) ) ) ;
connect ( qobject_cast < DeviceWidget * > ( widget ) , SIGNAL ( downloadStarted ( ) ) , this , SLOT ( downloadStarted ( ) ) ) ;
connect ( qobject_cast < DeviceWidget * > ( widget ) , SIGNAL ( downloadEnded ( bool ) ) , this , SLOT ( downloadEnded ( bool ) ) ) ;
2012-05-07 15:11:51 +01:00
}
2012-11-19 19:43:38 +01:00
FlightStatus * UploaderGadgetWidget : : getFlightStatus ( )
{
ExtensionSystem : : PluginManager * pm = ExtensionSystem : : PluginManager : : instance ( ) ;
2015-02-05 09:55:31 +01:00
2012-11-19 19:43:38 +01:00
Q_ASSERT ( pm ) ;
UAVObjectManager * objManager = pm - > getObject < UAVObjectManager > ( ) ;
Q_ASSERT ( objManager ) ;
2014-05-01 23:48:17 +02:00
FlightStatus * status = dynamic_cast < FlightStatus * > ( objManager - > getObject ( " FlightStatus " ) ) ;
2012-11-19 19:43:38 +01:00
Q_ASSERT ( status ) ;
return status ;
}
2013-04-08 01:09:31 +02:00
void UploaderGadgetWidget : : bootButtonsSetEnable ( bool enabled )
{
m_config - > bootButton - > setEnabled ( enabled ) ;
m_config - > safeBootButton - > setEnabled ( enabled ) ;
2013-04-08 01:31:29 +02:00
2014-05-01 16:47:21 +02:00
// this feature is supported only on BL revision >= 4
2015-02-02 00:14:02 +01:00
bool isBL4 = ( ( m_dfu ! = NULL ) & & ( m_dfu - > devices [ 0 ] . BL_Version > = 4 ) ) ;
2014-05-01 16:47:21 +02:00
m_config - > eraseBootButton - > setEnabled ( isBL4 & & enabled ) ;
2013-05-19 17:37:30 +03:00
}
2013-04-08 01:09:31 +02:00
2014-05-01 16:47:21 +02:00
void UploaderGadgetWidget : : onPhysicalHWConnect ( )
2011-10-12 16:43:14 +01:00
{
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( false ) ;
2011-10-12 16:43:14 +01:00
m_config - > rescueButton - > setEnabled ( false ) ;
m_config - > telemetryLink - > setEnabled ( false ) ;
}
2011-01-31 21:50:11 +00:00
/**
2013-05-19 17:37:30 +03:00
Enables widget buttons if autopilot connected
*/
void UploaderGadgetWidget : : onAutopilotConnect ( )
{
2013-04-02 19:43:19 +02:00
QTimer : : singleShot ( 1000 , this , SLOT ( populate ( ) ) ) ;
2011-11-25 23:59:42 +00:00
}
void UploaderGadgetWidget : : populate ( )
{
2011-01-31 21:50:11 +00:00
m_config - > haltButton - > setEnabled ( true ) ;
m_config - > resetButton - > setEnabled ( true ) ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( false ) ;
2011-01-31 21:50:11 +00:00
m_config - > rescueButton - > setEnabled ( false ) ;
m_config - > telemetryLink - > setEnabled ( false ) ;
2011-05-15 22:48:18 +02:00
// Add a very simple widget with Board model & serial number
// Delete all previous tabs:
while ( m_config - > systemElements - > count ( ) ) {
2013-05-19 17:37:30 +03:00
QWidget * qw = m_config - > systemElements - > widget ( 0 ) ;
m_config - > systemElements - > removeTab ( 0 ) ;
delete qw ;
2011-05-15 22:48:18 +02:00
}
2013-05-19 17:37:30 +03:00
RunningDeviceWidget * dw = new RunningDeviceWidget ( this ) ;
2011-05-15 22:48:18 +02:00
dw - > populate ( ) ;
2014-05-01 23:48:17 +02:00
m_config - > systemElements - > addTab ( dw , tr ( " Connected Device " ) ) ;
2011-01-31 21:50:11 +00:00
}
/**
2013-05-19 17:37:30 +03:00
Enables widget buttons if autopilot disconnected
*/
void UploaderGadgetWidget : : onAutopilotDisconnect ( )
{
2011-01-31 21:50:11 +00:00
m_config - > haltButton - > setEnabled ( false ) ;
m_config - > resetButton - > setEnabled ( false ) ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( true ) ;
2015-02-02 00:14:02 +01:00
if ( m_currentIAPStep = = IAP_STATE_BOOTLOADER ) {
2011-01-31 21:50:11 +00:00
m_config - > rescueButton - > setEnabled ( false ) ;
m_config - > telemetryLink - > setEnabled ( false ) ;
} else {
m_config - > rescueButton - > setEnabled ( true ) ;
m_config - > telemetryLink - > setEnabled ( true ) ;
}
}
2014-05-01 16:51:53 +02:00
static void sleep ( int ms )
{
2014-05-01 23:21:57 +02:00
QEventLoop eventLoop ;
QTimer : : singleShot ( ms , & eventLoop , SLOT ( quit ( ) ) ) ;
2014-05-05 00:05:51 +02:00
2014-05-01 23:21:57 +02:00
eventLoop . exec ( ) ;
2014-05-01 16:51:53 +02:00
}
2011-01-31 21:50:11 +00:00
/**
2013-05-19 17:37:30 +03:00
Tell the mainboard to go to bootloader :
2011-01-31 21:50:11 +00:00
- Send the relevant IAP commands
- setup callback for MoBo acknowledge
2013-05-19 17:37:30 +03:00
*/
void UploaderGadgetWidget : : goToBootloader ( UAVObject * callerObj , bool success )
2011-01-31 21:50:11 +00:00
{
Q_UNUSED ( callerObj ) ;
ExtensionSystem : : PluginManager * pm = ExtensionSystem : : PluginManager : : instance ( ) ;
UAVObjectManager * objManager = pm - > getObject < UAVObjectManager > ( ) ;
2014-05-01 23:48:17 +02:00
UAVObject * fwIAP = dynamic_cast < UAVDataObject * > ( objManager - > getObject ( " FirmwareIAPObj " ) ) ;
2011-01-31 21:50:11 +00:00
2015-02-02 00:14:02 +01:00
switch ( m_currentIAPStep ) {
2011-01-31 21:50:11 +00:00
case IAP_STATE_READY :
2011-05-16 20:03:41 +02:00
m_config - > haltButton - > setEnabled ( false ) ;
2011-01-31 21:50:11 +00:00
getSerialPorts ( ) ; // Useful in case a new serial port appeared since the initial list,
// otherwise we won't find it when we stop the board.
// The board is running, send the 1st IAP Reset order:
fwIAP - > getField ( " Command " ) - > setValue ( " 1122 " ) ;
2011-03-26 11:22:31 +00:00
fwIAP - > getField ( " BoardRevision " ) - > setDouble ( 0 ) ;
fwIAP - > getField ( " BoardType " ) - > setDouble ( 0 ) ;
2013-05-19 17:37:30 +03:00
connect ( fwIAP , SIGNAL ( transactionCompleted ( UAVObject * , bool ) ) , this , SLOT ( goToBootloader ( UAVObject * , bool ) ) ) ;
2015-02-02 00:14:02 +01:00
m_currentIAPStep = IAP_STATE_STEP_1 ;
2011-01-31 21:50:11 +00:00
clearLog ( ) ;
2014-05-01 23:48:17 +02:00
log ( " IAP Step 1 " ) ;
2011-01-31 21:50:11 +00:00
fwIAP - > updated ( ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( JUMP_TO_BL , QVariant ( 1 ) ) ;
2011-01-31 21:50:11 +00:00
break ;
case IAP_STATE_STEP_1 :
2013-05-19 17:37:30 +03:00
if ( ! success ) {
2014-05-01 23:48:17 +02:00
log ( " Oops, failure step 1 " ) ;
2011-01-31 21:50:11 +00:00
log ( " Reset did NOT happen " ) ;
2015-02-02 00:14:02 +01:00
m_currentIAPStep = IAP_STATE_READY ;
2013-05-19 17:37:30 +03:00
disconnect ( fwIAP , SIGNAL ( transactionCompleted ( UAVObject * , bool ) ) , this , SLOT ( goToBootloader ( UAVObject * , bool ) ) ) ;
2011-05-16 20:03:41 +02:00
m_config - > haltButton - > setEnabled ( true ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( FAILURE , QVariant ( ) ) ;
emit bootloaderFailed ( ) ;
2011-01-31 21:50:11 +00:00
break ;
}
2014-05-01 16:51:53 +02:00
sleep ( 600 ) ;
2011-01-31 21:50:11 +00:00
fwIAP - > getField ( " Command " ) - > setValue ( " 2233 " ) ;
2015-02-02 00:14:02 +01:00
m_currentIAPStep = IAP_STATE_STEP_2 ;
2014-05-01 23:48:17 +02:00
log ( " IAP Step 2 " ) ;
2011-01-31 21:50:11 +00:00
fwIAP - > updated ( ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( JUMP_TO_BL , QVariant ( 2 ) ) ;
2011-01-31 21:50:11 +00:00
break ;
case IAP_STATE_STEP_2 :
if ( ! success ) {
2014-05-01 23:48:17 +02:00
log ( " Oops, failure step 2 " ) ;
2011-01-31 21:50:11 +00:00
log ( " Reset did NOT happen " ) ;
2015-02-02 00:14:02 +01:00
m_currentIAPStep = IAP_STATE_READY ;
2013-05-19 17:37:30 +03:00
disconnect ( fwIAP , SIGNAL ( transactionCompleted ( UAVObject * , bool ) ) , this , SLOT ( goToBootloader ( UAVObject * , bool ) ) ) ;
2011-05-16 20:03:41 +02:00
m_config - > haltButton - > setEnabled ( true ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( FAILURE , QVariant ( ) ) ;
emit bootloaderFailed ( ) ;
2011-01-31 21:50:11 +00:00
break ;
}
2014-05-01 16:51:53 +02:00
sleep ( 600 ) ;
2011-01-31 21:50:11 +00:00
fwIAP - > getField ( " Command " ) - > setValue ( " 3344 " ) ;
2015-02-02 00:14:02 +01:00
m_currentIAPStep = IAP_STEP_RESET ;
2014-05-01 23:48:17 +02:00
log ( " IAP Step 3 " ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( JUMP_TO_BL , QVariant ( 3 ) ) ;
2011-01-31 21:50:11 +00:00
fwIAP - > updated ( ) ;
break ;
case IAP_STEP_RESET :
{
2015-02-02 00:14:02 +01:00
m_currentIAPStep = IAP_STATE_READY ;
2011-01-31 21:50:11 +00:00
if ( ! success ) {
log ( " Oops, failure step 3 " ) ;
log ( " Reset did NOT happen " ) ;
2013-05-19 17:37:30 +03:00
disconnect ( fwIAP , SIGNAL ( transactionCompleted ( UAVObject * , bool ) ) , this , SLOT ( goToBootloader ( UAVObject * , bool ) ) ) ;
2011-05-16 20:03:41 +02:00
m_config - > haltButton - > setEnabled ( true ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( FAILURE , QVariant ( ) ) ;
emit bootloaderFailed ( ) ;
2011-01-31 21:50:11 +00:00
break ;
}
// The board is now reset: we have to disconnect telemetry
Core : : ConnectionManager * cm = Core : : ICore : : instance ( ) - > connectionManager ( ) ;
2012-09-08 15:14:06 -05:00
QString dli = cm - > getCurrentDevice ( ) . getConName ( ) ;
QString dlj = cm - > getCurrentDevice ( ) . getConName ( ) ;
2011-01-31 21:50:11 +00:00
cm - > disconnectDevice ( ) ;
2014-05-01 16:51:53 +02:00
sleep ( 200 ) ;
2011-01-31 21:50:11 +00:00
// Tell connections to stop their polling threads: otherwise it will mess up DFU
cm - > suspendPolling ( ) ;
2014-05-01 16:51:53 +02:00
sleep ( 200 ) ;
2011-01-31 21:50:11 +00:00
log ( " Board Halt " ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( JUMP_TO_BL , QVariant ( 4 ) ) ;
2014-05-01 23:48:17 +02:00
m_config - > boardStatus - > setText ( tr ( " Bootloader " ) ) ;
2013-05-19 17:37:30 +03:00
if ( dlj . startsWith ( " USB " ) ) {
2011-01-31 21:50:11 +00:00
m_config - > telemetryLink - > setCurrentIndex ( m_config - > telemetryLink - > findText ( " USB " ) ) ;
2013-05-19 17:37:30 +03:00
} else {
2011-01-31 21:50:11 +00:00
m_config - > telemetryLink - > setCurrentIndex ( m_config - > telemetryLink - > findText ( dli ) ) ;
2013-05-19 17:37:30 +03:00
}
2011-01-31 21:50:11 +00:00
2013-05-19 17:37:30 +03:00
disconnect ( fwIAP , SIGNAL ( transactionCompleted ( UAVObject * , bool ) ) , this , SLOT ( goToBootloader ( UAVObject * , bool ) ) ) ;
2011-01-31 21:50:11 +00:00
2015-02-02 00:14:02 +01:00
m_currentIAPStep = IAP_STATE_BOOTLOADER ;
2011-01-31 21:50:11 +00:00
// Tell the mainboard to get into bootloader state:
2011-09-25 15:26:12 +02:00
log ( " Detecting devices, please wait a few seconds... " ) ;
2015-02-02 00:14:02 +01:00
if ( ! m_dfu ) {
2013-05-19 17:37:30 +03:00
if ( dlj . startsWith ( " USB " ) ) {
2015-02-02 00:14:02 +01:00
m_dfu = new DFUObject ( DFU_DEBUG , false , QString ( ) ) ;
2013-05-19 17:37:30 +03:00
} else {
2015-02-02 00:14:02 +01:00
m_dfu = new DFUObject ( DFU_DEBUG , true , getPortDevice ( dli ) ) ;
2013-05-19 17:37:30 +03:00
}
2011-01-31 21:50:11 +00:00
}
2015-02-02 00:14:02 +01:00
if ( ! m_dfu - > ready ( ) ) {
2011-01-31 21:50:11 +00:00
log ( " Could not enter DFU mode. " ) ;
2015-02-02 00:14:02 +01:00
delete m_dfu ;
m_dfu = NULL ;
2011-01-31 21:50:11 +00:00
cm - > resumePolling ( ) ;
2015-02-02 00:14:02 +01:00
m_currentIAPStep = IAP_STATE_READY ;
2014-05-01 23:48:17 +02:00
m_config - > boardStatus - > setText ( tr ( " Bootloader? " ) ) ;
2011-05-16 20:03:41 +02:00
m_config - > haltButton - > setEnabled ( true ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( FAILURE , QVariant ( ) ) ;
emit bootloaderFailed ( ) ;
2011-01-31 21:50:11 +00:00
return ;
}
2015-02-02 00:14:02 +01:00
m_dfu - > AbortOperation ( ) ;
if ( ! m_dfu - > enterDFU ( 0 ) ) {
2011-01-31 21:50:11 +00:00
log ( " Could not enter DFU mode. " ) ;
2015-02-02 00:14:02 +01:00
delete m_dfu ;
m_dfu = NULL ;
2011-01-31 21:50:11 +00:00
cm - > resumePolling ( ) ;
2015-02-02 00:14:02 +01:00
m_currentIAPStep = IAP_STATE_READY ;
2014-05-01 23:48:17 +02:00
m_config - > boardStatus - > setText ( tr ( " Bootloader? " ) ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( FAILURE , QVariant ( ) ) ;
emit bootloaderFailed ( ) ;
2011-01-31 21:50:11 +00:00
return ;
}
2013-03-13 03:24:25 +01:00
2014-05-01 16:51:53 +02:00
sleep ( 500 ) ;
2015-02-02 00:14:02 +01:00
m_dfu - > findDevices ( ) ;
log ( QString ( " Found %1 device(s). " ) . arg ( QString : : number ( m_dfu - > numberOfDevices ) ) ) ;
if ( m_dfu - > numberOfDevices < 0 | | m_dfu - > numberOfDevices > 3 ) {
2011-01-31 21:50:11 +00:00
log ( " Inconsistent number of devices! Aborting " ) ;
2015-02-02 00:14:02 +01:00
delete m_dfu ;
m_dfu = NULL ;
2011-01-31 21:50:11 +00:00
cm - > resumePolling ( ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( FAILURE , QVariant ( ) ) ;
emit bootloaderFailed ( ) ;
2011-01-31 21:50:11 +00:00
return ;
}
// Delete all previous tabs:
while ( m_config - > systemElements - > count ( ) ) {
2013-05-19 17:37:30 +03:00
QWidget * qw = m_config - > systemElements - > widget ( 0 ) ;
m_config - > systemElements - > removeTab ( 0 ) ;
delete qw ;
2011-01-31 21:50:11 +00:00
}
2015-02-02 00:14:02 +01:00
for ( int i = 0 ; i < m_dfu - > numberOfDevices ; i + + ) {
2013-05-19 17:37:30 +03:00
DeviceWidget * dw = new DeviceWidget ( this ) ;
2012-05-07 15:11:51 +01:00
connectSignalSlot ( dw ) ;
2011-01-31 21:50:11 +00:00
dw - > setDeviceID ( i ) ;
2015-02-02 00:14:02 +01:00
dw - > setDfu ( m_dfu ) ;
2011-01-31 21:50:11 +00:00
dw - > populate ( ) ;
2014-05-01 23:48:17 +02:00
m_config - > systemElements - > addTab ( dw , tr ( " Device " ) + QString : : number ( i ) ) ;
2011-01-31 21:50:11 +00:00
}
2013-06-25 15:51:33 +02:00
2015-01-26 22:59:41 +01:00
QApplication : : processEvents ( ) ;
2011-05-24 08:15:57 +02:00
// Need to re-enable in case we were not connected
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( true ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( JUMP_TO_BL , QVariant ( 5 ) ) ;
emit bootloaderSuccess ( ) ;
2013-06-25 15:51:33 +02:00
2015-02-02 00:14:02 +01:00
if ( m_resetOnly ) {
m_resetOnly = false ;
2011-01-31 21:50:11 +00:00
delay : : msleep ( 3500 ) ;
systemBoot ( ) ;
break ;
}
}
2013-05-19 17:37:30 +03:00
break ;
2011-01-31 21:50:11 +00:00
case IAP_STATE_BOOTLOADER :
// We should never end up here anyway.
2014-12-09 00:48:30 +01:00
emit progressUpdate ( FAILURE , QVariant ( ) ) ;
emit bootloaderFailed ( ) ;
2011-01-31 21:50:11 +00:00
break ;
}
}
2012-11-18 22:40:05 +01:00
void UploaderGadgetWidget : : systemHalt ( )
{
// The board can not be halted when in armed state.
// If board is armed, or arming. Show message with notice.
2014-05-02 23:36:05 +02:00
FlightStatus * status = getFlightStatus ( ) ;
2014-05-05 00:05:51 +02:00
2012-11-18 22:40:05 +01:00
if ( status - > getArmed ( ) = = FlightStatus : : ARMED_DISARMED ) {
goToBootloader ( ) ;
2013-05-19 17:37:30 +03:00
} else {
2014-05-04 22:53:14 +02:00
cannotHaltMessageBox ( ) ;
2012-11-18 22:40:05 +01:00
}
}
2011-01-31 21:50:11 +00:00
/**
2013-05-19 17:37:30 +03:00
Tell the mainboard to reset :
2011-01-31 21:50:11 +00:00
- Send the relevant IAP commands
- setup callback for MoBo acknowledge
2013-05-19 17:37:30 +03:00
*/
2011-01-31 21:50:11 +00:00
void UploaderGadgetWidget : : systemReset ( )
{
2013-05-19 17:37:30 +03:00
FlightStatus * status = getFlightStatus ( ) ;
2012-11-19 19:43:38 +01:00
// The board can not be reset when in armed state.
// If board is armed, or arming. Show message with notice.
if ( status - > getArmed ( ) = = FlightStatus : : ARMED_DISARMED ) {
2015-02-02 00:14:02 +01:00
m_resetOnly = true ;
if ( m_dfu ) {
delete m_dfu ;
m_dfu = NULL ;
2012-11-19 19:43:38 +01:00
}
2013-01-24 03:53:24 +01:00
clearLog ( ) ;
2012-11-19 19:43:38 +01:00
log ( " Board Reset initiated. " ) ;
goToBootloader ( ) ;
2013-05-19 17:37:30 +03:00
} else {
2014-05-04 22:53:14 +02:00
cannotResetMessageBox ( ) ;
2011-01-31 21:50:11 +00:00
}
}
2012-01-02 14:21:12 -05:00
void UploaderGadgetWidget : : systemBoot ( )
{
2013-05-19 17:37:30 +03:00
commonSystemBoot ( false , false ) ;
2012-01-02 14:21:12 -05:00
}
void UploaderGadgetWidget : : systemSafeBoot ( )
{
2013-05-19 17:37:30 +03:00
commonSystemBoot ( true , false ) ;
2013-04-08 01:09:31 +02:00
}
void UploaderGadgetWidget : : systemEraseBoot ( )
{
2014-05-05 00:05:51 +02:00
switch ( confirmEraseSettingsMessageBox ( ) ) {
2014-05-04 22:53:14 +02:00
case QMessageBox : : Ok :
2013-05-19 17:37:30 +03:00
commonSystemBoot ( true , true ) ;
2014-05-04 22:53:14 +02:00
break ;
case QMessageBox : : Help :
2013-05-19 17:37:30 +03:00
QDesktopServices : : openUrl ( QUrl ( tr ( " http://wiki.openpilot.org/display/Doc/Erase+board+settings " ) , QUrl : : StrictMode ) ) ;
2014-05-04 22:53:14 +02:00
break ;
2013-05-19 17:37:30 +03:00
}
2012-01-02 14:21:12 -05:00
}
2015-01-09 00:42:43 +01:00
void UploaderGadgetWidget : : rebootWithDialog ( )
{
RebootDialog dialog ( this ) ;
2015-01-20 00:01:03 +01:00
2015-01-09 00:42:43 +01:00
dialog . exec ( ) ;
}
2014-12-29 14:50:20 +01:00
void UploaderGadgetWidget : : systemReboot ( )
{
ResultEventLoop eventLoop ;
connect ( this , SIGNAL ( bootloaderSuccess ( ) ) , & eventLoop , SLOT ( success ( ) ) ) ;
connect ( this , SIGNAL ( bootloaderFailed ( ) ) , & eventLoop , SLOT ( fail ( ) ) ) ;
goToBootloader ( ) ;
2015-01-26 22:59:41 +01:00
if ( eventLoop . run ( REBOOT_TIMEOUT ) ! = 0 ) {
2014-12-29 14:50:20 +01:00
emit progressUpdate ( FAILURE , QVariant ( ) ) ;
return ;
}
disconnect ( this , SIGNAL ( bootloaderSuccess ( ) ) , & eventLoop , SLOT ( success ( ) ) ) ;
disconnect ( this , SIGNAL ( bootloaderFailed ( ) ) , & eventLoop , SLOT ( fail ( ) ) ) ;
commonSystemBoot ( false , false ) ;
ExtensionSystem : : PluginManager * pluginManager = ExtensionSystem : : PluginManager : : instance ( ) ;
Q_ASSERT ( pluginManager ) ;
TelemetryManager * telemetryManager = pluginManager - > getObject < TelemetryManager > ( ) ;
Q_ASSERT ( telemetryManager ) ;
if ( ! telemetryManager - > isConnected ( ) ) {
progressUpdate ( BOOTING , QVariant ( ) ) ;
ResultEventLoop eventLoop ;
connect ( telemetryManager , SIGNAL ( connected ( ) ) , & eventLoop , SLOT ( success ( ) ) ) ;
2015-01-26 22:59:41 +01:00
if ( eventLoop . run ( REBOOT_TIMEOUT ) ! = 0 ) {
2014-12-29 14:50:20 +01:00
emit progressUpdate ( FAILURE , QVariant ( ) ) ;
return ;
}
disconnect ( telemetryManager , SIGNAL ( connected ( ) ) , & eventLoop , SLOT ( success ( ) ) ) ;
}
emit progressUpdate ( SUCCESS , QVariant ( ) ) ;
}
2011-01-31 21:50:11 +00:00
/**
2013-05-19 17:37:30 +03:00
* Tells the system to boot ( from Bootloader state )
* @ param [ in ] safeboot Indicates whether the firmware should use the stock HWSettings
*/
2013-04-08 01:09:31 +02:00
void UploaderGadgetWidget : : commonSystemBoot ( bool safeboot , bool erase )
2011-01-31 21:50:11 +00:00
{
clearLog ( ) ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( false ) ;
2011-01-31 21:50:11 +00:00
// Suspend telemety & polling in case it is not done yet
Core : : ConnectionManager * cm = Core : : ICore : : instance ( ) - > connectionManager ( ) ;
cm - > disconnectDevice ( ) ;
cm - > suspendPolling ( ) ;
QString devName = m_config - > telemetryLink - > currentText ( ) ;
log ( " Attempting to boot the system through " + devName + " . " ) ;
repaint ( ) ;
2015-02-02 00:14:02 +01:00
if ( ! m_dfu ) {
2013-05-19 17:37:30 +03:00
if ( devName = = " USB " ) {
2015-02-02 00:14:02 +01:00
m_dfu = new DFUObject ( DFU_DEBUG , false , QString ( ) ) ;
2013-05-19 17:37:30 +03:00
} else {
2015-02-02 00:14:02 +01:00
m_dfu = new DFUObject ( DFU_DEBUG , true , getPortDevice ( devName ) ) ;
2013-05-19 17:37:30 +03:00
}
2011-01-31 21:50:11 +00:00
}
2015-02-02 00:14:02 +01:00
m_dfu - > AbortOperation ( ) ;
if ( ! m_dfu - > enterDFU ( 0 ) ) {
2011-01-31 21:50:11 +00:00
log ( " Could not enter DFU mode. " ) ;
2015-02-02 00:14:02 +01:00
delete m_dfu ;
m_dfu = NULL ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( true ) ;
2011-05-24 08:15:57 +02:00
m_config - > rescueButton - > setEnabled ( true ) ; // Boot not possible, maybe Rescue OK?
2014-12-09 00:48:30 +01:00
emit bootFailed ( ) ;
2011-01-31 21:50:11 +00:00
return ;
}
log ( " Booting system... " ) ;
2015-02-02 00:14:02 +01:00
m_dfu - > JumpToApp ( safeboot , erase ) ;
2011-01-31 21:50:11 +00:00
// Restart the polling thread
cm - > resumePolling ( ) ;
m_config - > rescueButton - > setEnabled ( true ) ;
m_config - > telemetryLink - > setEnabled ( true ) ;
2014-05-01 23:48:17 +02:00
m_config - > boardStatus - > setText ( tr ( " Running " ) ) ;
2015-02-02 00:14:02 +01:00
if ( m_currentIAPStep = = IAP_STATE_BOOTLOADER ) {
2011-01-31 21:50:11 +00:00
// Freeze the tabs, they are not useful anymore and their buttons
// will cause segfaults or weird stuff if we use them.
2013-05-19 17:37:30 +03:00
for ( int i = 0 ; i < m_config - > systemElements - > count ( ) ; i + + ) {
2013-01-26 15:10:30 +01:00
// OP-682 arriving here too "early" (before the devices are refreshed) was leading to a crash
// OP-682 the crash was due to an unchecked cast in the line below that would cast a RunningDeviceGadget to a DeviceGadget
2013-05-19 17:37:30 +03:00
DeviceWidget * qw = dynamic_cast < DeviceWidget * > ( m_config - > systemElements - > widget ( i ) ) ;
2013-01-24 03:53:24 +01:00
if ( qw ) {
2013-01-26 15:10:30 +01:00
// OP-682 fixed a second crash by disabling *all* buttons in the device widget
// disabling the buttons is only half of the solution as even if the buttons are enabled
// the app should not crash
2013-01-24 03:53:24 +01:00
qw - > freeze ( ) ;
}
2011-01-31 21:50:11 +00:00
}
}
2015-02-02 00:14:02 +01:00
m_currentIAPStep = IAP_STATE_READY ;
2011-01-31 21:50:11 +00:00
log ( " You can now reconnect telemetry... " ) ;
2015-02-02 00:14:02 +01:00
delete m_dfu ; // Frees up the USB/Serial port too
2014-12-09 00:48:30 +01:00
emit bootSuccess ( ) ;
2015-02-02 00:14:02 +01:00
m_dfu = NULL ;
2011-01-31 21:50:11 +00:00
}
2013-01-24 03:53:24 +01:00
2012-10-06 23:23:44 +01:00
bool UploaderGadgetWidget : : autoUpdateCapable ( )
{
2013-03-19 17:52:24 +02:00
return QDir ( " :/firmware " ) . exists ( ) ;
2012-10-06 23:23:44 +01:00
}
2014-12-08 16:36:17 +01:00
bool UploaderGadgetWidget : : autoUpdate ( bool erase )
2012-10-05 19:55:43 +01:00
{
2015-02-02 00:14:02 +01:00
if ( m_oplinkwatchdog . isConnected ( ) & &
2015-02-05 09:55:31 +01:00
m_oplinkwatchdog . opLinkType ( ) = = OPLinkWatchdog : : OPLINK_MINI ) {
2015-02-03 22:24:57 +01:00
emit progressUpdate ( FAILURE , QVariant ( tr ( " To upgrade the OPLinkMini board please disconnect it from the USB port, "
2015-02-02 00:14:02 +01:00
" press the Upgrade again button and follow instructions on screen. " ) ) ) ;
emit autoUpdateFailed ( ) ;
return false ;
}
2015-01-26 23:03:39 +01:00
2015-02-02 00:14:02 +01:00
ExtensionSystem : : PluginManager * pluginManager = ExtensionSystem : : PluginManager : : instance ( ) ;
2015-01-23 00:44:50 +01:00
Q_ASSERT ( pluginManager ) ;
TelemetryManager * telemetryManager = pluginManager - > getObject < TelemetryManager > ( ) ;
Q_ASSERT ( telemetryManager ) ;
if ( USBMonitor : : instance ( ) - > availableDevices ( 0x20a0 , - 1 , - 1 , - 1 ) . length ( ) > 0 & &
2015-01-26 23:03:39 +01:00
telemetryManager - > connectionState ( ) ! = TelemetryManager : : TELEMETRY_CONNECTED ) {
2015-01-23 00:44:50 +01:00
// Wait for the board to completely connect
ResultEventLoop eventLoop ;
connect ( telemetryManager , SIGNAL ( connected ( ) ) , & eventLoop , SLOT ( success ( ) ) ) ;
if ( telemetryManager - > connectionState ( ) ! = TelemetryManager : : TELEMETRY_CONNECTED
2015-01-26 23:03:39 +01:00
& & eventLoop . run ( REBOOT_TIMEOUT ) ! = 0 ) {
2015-01-26 22:59:41 +01:00
emit progressUpdate ( FAILURE , QVariant ( tr ( " Timed out while waiting for a board to be fully connected! " ) ) ) ;
2015-01-23 00:44:50 +01:00
emit autoUpdateFailed ( ) ;
return false ;
}
disconnect ( telemetryManager , SIGNAL ( connected ( ) ) , & eventLoop , SLOT ( success ( ) ) ) ;
}
2014-12-09 01:15:49 +01:00
if ( USBMonitor : : instance ( ) - > availableDevices ( 0x20a0 , - 1 , - 1 , - 1 ) . length ( ) = = 0 ) {
ConnectionWaiter waiter ( 1 , BOARD_EVENT_TIMEOUT ) ;
connect ( & waiter , SIGNAL ( timeChanged ( int ) ) , this , SLOT ( autoUpdateConnectProgress ( int ) ) ) ;
if ( waiter . exec ( ) = = ConnectionWaiter : : TimedOut ) {
emit progressUpdate ( FAILURE , QVariant ( tr ( " Timed out while waiting for a board to be connected! " ) ) ) ;
emit autoUpdateFailed ( ) ;
return false ;
}
} else {
ResultEventLoop eventLoop ;
connect ( this , SIGNAL ( bootloaderSuccess ( ) ) , & eventLoop , SLOT ( success ( ) ) ) ;
connect ( this , SIGNAL ( bootloaderFailed ( ) ) , & eventLoop , SLOT ( fail ( ) ) ) ;
2014-12-09 00:48:30 +01:00
2014-12-09 01:15:49 +01:00
goToBootloader ( ) ;
2014-12-08 15:04:28 +01:00
2015-01-26 22:59:41 +01:00
if ( eventLoop . run ( BOOTLOADER_TIMEOUT ) ! = 0 ) {
emit progressUpdate ( FAILURE , QVariant ( tr ( " Failed to enter bootloader mode. " ) ) ) ;
2014-12-09 01:15:49 +01:00
emit autoUpdateFailed ( ) ;
return false ;
}
2014-12-16 14:18:43 +01:00
disconnect ( this , SIGNAL ( bootloaderSuccess ( ) ) , & eventLoop , SLOT ( success ( ) ) ) ;
disconnect ( this , SIGNAL ( bootloaderFailed ( ) ) , & eventLoop , SLOT ( fail ( ) ) ) ;
2014-12-09 00:48:30 +01:00
}
2013-05-19 17:37:30 +03:00
2015-02-02 00:14:02 +01:00
if ( m_dfu ) {
delete m_dfu ;
m_dfu = NULL ;
2012-10-05 19:55:43 +01:00
}
2014-05-01 22:48:22 +02:00
2014-12-16 14:18:43 +01:00
Core : : ConnectionManager * connectionManager = Core : : ICore : : instance ( ) - > connectionManager ( ) ;
2015-02-02 00:14:02 +01:00
m_dfu = new DFUObject ( DFU_DEBUG , false , QString ( ) ) ;
m_dfu - > AbortOperation ( ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( JUMP_TO_BL , QVariant ( ) ) ;
2015-02-02 00:14:02 +01:00
if ( ! m_dfu - > enterDFU ( 0 ) | | ! m_dfu - > findDevices ( ) | |
( m_dfu - > numberOfDevices ! = 1 ) | | m_dfu - > numberOfDevices > 5 ) {
delete m_dfu ;
m_dfu = NULL ;
2014-12-16 14:18:43 +01:00
connectionManager - > resumePolling ( ) ;
2015-01-26 22:59:41 +01:00
emit progressUpdate ( FAILURE , QVariant ( tr ( " Failed to enter bootloader mode. " ) ) ) ;
2014-12-09 00:48:30 +01:00
emit autoUpdateFailed ( ) ;
2012-10-05 19:55:43 +01:00
return false ;
}
2014-05-01 22:48:22 +02:00
2012-10-05 19:55:43 +01:00
QString filename ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( LOADING_FW , QVariant ( ) ) ;
2015-02-02 00:14:02 +01:00
switch ( m_dfu - > devices [ 0 ] . ID ) {
2013-03-19 17:52:24 +02:00
case 0x301 :
2013-04-13 00:24:30 +03:00
filename = " fw_oplinkmini " ;
2012-10-05 19:55:43 +01:00
break ;
2013-03-19 17:52:24 +02:00
case 0x501 :
filename = " fw_osd " ;
break ;
case 0x902 :
2013-04-24 00:57:33 +03:00
filename = " fw_revoproto " ;
2013-03-19 17:52:24 +02:00
break ;
case 0x903 :
2013-04-14 01:34:43 +02:00
filename = " fw_revolution " ;
2012-10-05 19:55:43 +01:00
break ;
2014-09-15 23:30:17 +02:00
case 0x904 :
filename = " fw_discoveryf4bare " ;
break ;
2014-12-20 22:56:46 +01:00
case 0x905 :
filename = " fw_revonano " ;
break ;
2012-10-05 19:55:43 +01:00
default :
2015-02-02 00:14:02 +01:00
emit progressUpdate ( FAILURE , QVariant ( tr ( " Unknown board id '0x%1' " ) . arg ( QString : : number ( m_dfu - > devices [ 0 ] . ID , 16 ) ) ) ) ;
2014-12-09 00:48:30 +01:00
emit autoUpdateFailed ( ) ;
2012-10-05 19:55:43 +01:00
return false ;
}
2013-03-19 17:52:24 +02:00
filename = " :/firmware/ " + filename + " .opfw " ;
2012-10-05 19:55:43 +01:00
QByteArray firmware ;
2013-05-19 17:37:30 +03:00
if ( ! QFile : : exists ( filename ) ) {
2015-01-26 22:59:41 +01:00
emit progressUpdate ( FAILURE , QVariant ( tr ( " Firmware image not found. " ) ) ) ;
2014-12-09 00:48:30 +01:00
emit autoUpdateFailed ( ) ;
2012-10-06 23:23:44 +01:00
return false ;
}
2012-10-05 19:55:43 +01:00
QFile file ( filename ) ;
if ( ! file . open ( QIODevice : : ReadOnly ) ) {
2015-01-26 22:59:41 +01:00
emit progressUpdate ( FAILURE , QVariant ( tr ( " Could not open firmware image for reading. " ) ) ) ;
2014-12-09 00:48:30 +01:00
emit autoUpdateFailed ( ) ;
2012-10-05 19:55:43 +01:00
return false ;
}
firmware = file . readAll ( ) ;
2014-12-08 15:04:28 +01:00
QEventLoop eventLoop2 ;
2015-02-02 00:14:02 +01:00
connect ( m_dfu , SIGNAL ( progressUpdated ( int ) ) , this , SLOT ( autoUpdateFlashProgress ( int ) ) ) ;
connect ( m_dfu , SIGNAL ( uploadFinished ( OP_DFU : : Status ) ) , & eventLoop2 , SLOT ( quit ( ) ) ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( UPLOADING_FW , QVariant ( ) ) ;
2015-02-02 00:14:02 +01:00
if ( ! m_dfu - > enterDFU ( 0 ) ) {
2015-01-26 22:59:41 +01:00
emit progressUpdate ( FAILURE , QVariant ( tr ( " Could not enter direct firmware upload mode. " ) ) ) ;
2014-12-09 00:48:30 +01:00
emit autoUpdateFailed ( ) ;
2012-10-05 19:55:43 +01:00
return false ;
}
2015-02-02 00:14:02 +01:00
m_dfu - > AbortOperation ( ) ;
if ( ! m_dfu - > UploadFirmware ( filename , false , 0 ) ) {
2015-01-26 22:59:41 +01:00
emit progressUpdate ( FAILURE , QVariant ( tr ( " Firmware upload failed. " ) ) ) ;
2014-12-09 00:48:30 +01:00
emit autoUpdateFailed ( ) ;
2012-10-05 19:55:43 +01:00
return false ;
}
2014-12-08 15:04:28 +01:00
eventLoop2 . exec ( ) ;
2012-10-05 19:55:43 +01:00
QByteArray desc = firmware . right ( 100 ) ;
2014-12-09 00:48:30 +01:00
emit progressUpdate ( UPLOADING_DESC , QVariant ( ) ) ;
2015-02-02 00:14:02 +01:00
if ( m_dfu - > UploadDescription ( desc ) ! = OP_DFU : : Last_operation_Success ) {
2015-01-26 22:59:41 +01:00
emit progressUpdate ( FAILURE , QVariant ( tr ( " Failed to upload firmware description. " ) ) ) ;
2014-12-09 00:48:30 +01:00
emit autoUpdateFailed ( ) ;
2012-10-05 19:55:43 +01:00
return false ;
}
2014-12-16 14:18:43 +01:00
2014-12-08 16:36:17 +01:00
commonSystemBoot ( false , erase ) ;
2014-12-16 14:18:43 +01:00
// Wait for board to connect to GCS again after boot and erase
2015-02-02 00:14:02 +01:00
// Theres a special case with OPLink
if ( ! telemetryManager - > isConnected ( ) & & ! m_oplinkwatchdog . isConnected ( ) ) {
2015-01-27 08:43:06 +01:00
progressUpdate ( erase ? BOOTING_AND_ERASING : BOOTING , QVariant ( ) ) ;
2014-12-16 14:18:43 +01:00
ResultEventLoop eventLoop ;
connect ( telemetryManager , SIGNAL ( connected ( ) ) , & eventLoop , SLOT ( success ( ) ) ) ;
2015-02-05 10:05:47 +01:00
connect ( & m_oplinkwatchdog , SIGNAL ( opLinkMiniConnected ( ) ) , & eventLoop , SLOT ( success ( ) ) ) ;
2014-12-16 14:18:43 +01:00
2015-01-26 22:59:41 +01:00
if ( eventLoop . run ( REBOOT_TIMEOUT + ( erase ? ERASE_TIMEOUT : 0 ) ) ! = 0 ) {
emit progressUpdate ( FAILURE , QVariant ( tr ( " Timed out while booting. " ) ) ) ;
2014-12-16 14:18:43 +01:00
emit autoUpdateFailed ( ) ;
return false ;
}
2015-02-05 10:05:47 +01:00
disconnect ( & m_oplinkwatchdog , SIGNAL ( opLinkMiniConnected ( ) ) , & eventLoop , SLOT ( success ( ) ) ) ;
2014-12-16 14:18:43 +01:00
disconnect ( telemetryManager , SIGNAL ( connected ( ) ) , & eventLoop , SLOT ( success ( ) ) ) ;
}
2014-12-09 00:48:30 +01:00
emit progressUpdate ( SUCCESS , QVariant ( ) ) ;
emit autoUpdateSuccess ( ) ;
2012-10-05 19:55:43 +01:00
return true ;
}
2014-05-01 22:48:22 +02:00
void UploaderGadgetWidget : : autoUpdateDisconnectProgress ( int value )
{
2014-12-09 00:48:30 +01:00
emit progressUpdate ( WAITING_DISCONNECT , value ) ;
2014-05-01 22:48:22 +02:00
}
void UploaderGadgetWidget : : autoUpdateConnectProgress ( int value )
{
2014-12-09 00:48:30 +01:00
emit progressUpdate ( WAITING_CONNECT , value ) ;
2014-05-01 22:48:22 +02:00
}
void UploaderGadgetWidget : : autoUpdateFlashProgress ( int value )
2012-10-05 19:55:43 +01:00
{
2014-12-09 00:48:30 +01:00
emit progressUpdate ( UPLOADING_FW , value ) ;
2012-10-05 19:55:43 +01:00
}
2011-01-31 21:50:11 +00:00
/**
2013-05-19 17:37:30 +03:00
Attempt a guided procedure to put both boards in BL mode when
the system is not bootable
*/
2011-01-31 21:50:11 +00:00
void UploaderGadgetWidget : : systemRescue ( )
{
Core : : ConnectionManager * cm = Core : : ICore : : instance ( ) - > connectionManager ( ) ;
2013-05-19 17:37:30 +03:00
2011-05-27 11:49:15 +01:00
cm - > disconnectDevice ( ) ;
// stop the polling thread: otherwise it will mess up DFU
cm - > suspendPolling ( ) ;
2014-05-01 16:37:12 +02:00
2011-05-27 11:49:15 +01:00
// Delete all previous tabs:
while ( m_config - > systemElements - > count ( ) ) {
QWidget * qw = m_config - > systemElements - > widget ( 0 ) ;
m_config - > systemElements - > removeTab ( 0 ) ;
delete qw ;
2011-01-31 21:50:11 +00:00
}
2014-05-01 16:37:12 +02:00
2011-05-27 11:49:15 +01:00
// Existing DFU objects will have a handle over USB and will
// disturb everything for the rescue process:
2015-02-02 00:14:02 +01:00
if ( m_dfu ) {
delete m_dfu ;
m_dfu = NULL ;
2011-05-27 11:49:15 +01:00
}
2014-05-01 16:37:12 +02:00
2012-09-08 19:07:14 -05:00
// Avoid users pressing Rescue twice.
2011-05-27 11:49:15 +01:00
m_config - > rescueButton - > setEnabled ( false ) ;
2014-05-01 16:37:12 +02:00
// Now we're good to go
2011-05-27 11:49:15 +01:00
clearLog ( ) ;
log ( " ********************************************************** " ) ;
log ( " ** Follow those instructions to attempt a system rescue ** " ) ;
log ( " ********************************************************** " ) ;
log ( " You will be prompted to first connect USB, then system power " ) ;
2014-05-01 17:17:28 +02:00
2014-05-01 23:48:17 +02:00
// Check if boards are connected and, if yes, prompt user to disconnect them all
2013-05-19 17:37:30 +03:00
if ( USBMonitor : : instance ( ) - > availableDevices ( 0x20a0 , - 1 , - 1 , - 1 ) . length ( ) > 0 ) {
2014-05-01 16:37:12 +02:00
QString labelText = QString ( " <p align= \" left \" >%1</p> " ) . arg ( tr ( " Please disconnect your OpenPilot board. " ) ) ;
2014-05-02 08:55:46 +02:00
int result = ConnectionWaiter : : openDialog ( tr ( " System Rescue " ) , labelText , 0 , BOARD_EVENT_TIMEOUT , this ) ;
2014-05-05 00:05:51 +02:00
switch ( result ) {
2014-05-02 08:55:46 +02:00
case ConnectionWaiter : : Canceled :
2014-05-01 16:37:12 +02:00
m_config - > rescueButton - > setEnabled ( true ) ;
return ;
2014-05-05 00:05:51 +02:00
2014-05-02 08:55:46 +02:00
case ConnectionWaiter : : TimedOut :
2014-05-01 23:48:17 +02:00
QMessageBox : : warning ( this , tr ( " System Rescue " ) , tr ( " Timed out while waiting for all boards to be disconnected! " ) ) ;
2011-04-10 08:46:41 +00:00
m_config - > rescueButton - > setEnabled ( true ) ;
2011-01-31 21:50:11 +00:00
return ;
}
2011-05-27 11:49:15 +01:00
}
2014-05-01 16:37:12 +02:00
2014-05-01 17:17:28 +02:00
// Now prompt user to connect board
2014-05-01 23:48:17 +02:00
QString labelText = QString ( " <p align= \" left \" >%1<br>%2</p> " ) . arg ( tr ( " Please connect your OpenPilot board. " ) ) . arg ( tr ( " Board must be connected to the USB port! " ) ) ;
2014-05-02 08:55:46 +02:00
int result = ConnectionWaiter : : openDialog ( tr ( " System Rescue " ) , labelText , 1 , BOARD_EVENT_TIMEOUT , this ) ;
2014-05-05 00:05:51 +02:00
switch ( result ) {
2014-05-02 08:55:46 +02:00
case ConnectionWaiter : : Canceled :
2014-05-01 16:37:12 +02:00
m_config - > rescueButton - > setEnabled ( true ) ;
return ;
2014-05-05 00:05:51 +02:00
2014-05-02 08:55:46 +02:00
case ConnectionWaiter : : TimedOut :
2014-05-01 23:48:17 +02:00
QMessageBox : : warning ( this , tr ( " System Rescue " ) , tr ( " Timed out while waiting for a board to be connected! " ) ) ;
2011-05-27 11:49:15 +01:00
m_config - > rescueButton - > setEnabled ( true ) ;
return ;
}
2014-05-01 16:37:12 +02:00
2014-05-01 17:17:28 +02:00
log ( " Detecting first board... " ) ;
2015-02-02 00:14:02 +01:00
m_dfu = new DFUObject ( DFU_DEBUG , false , QString ( ) ) ;
m_dfu - > AbortOperation ( ) ;
if ( ! m_dfu - > enterDFU ( 0 ) ) {
2011-05-27 11:49:15 +01:00
log ( " Could not enter DFU mode. " ) ;
2015-02-02 00:14:02 +01:00
delete m_dfu ;
m_dfu = NULL ;
2011-05-27 11:49:15 +01:00
cm - > resumePolling ( ) ;
m_config - > rescueButton - > setEnabled ( true ) ;
return ;
}
2015-02-02 00:14:02 +01:00
if ( ! m_dfu - > findDevices ( ) | | ( m_dfu - > numberOfDevices ! = 1 ) ) {
2011-05-27 11:49:15 +01:00
log ( " Could not detect a board, aborting! " ) ;
2015-02-02 00:14:02 +01:00
delete m_dfu ;
m_dfu = NULL ;
2011-05-27 11:49:15 +01:00
cm - > resumePolling ( ) ;
m_config - > rescueButton - > setEnabled ( true ) ;
return ;
}
2015-02-02 00:14:02 +01:00
log ( QString ( " Found %1 device(s). " ) . arg ( m_dfu - > numberOfDevices ) ) ;
2014-05-01 16:37:12 +02:00
2015-02-02 00:14:02 +01:00
if ( m_dfu - > numberOfDevices > 5 ) {
2011-05-27 11:49:15 +01:00
log ( " Inconsistent number of devices, aborting! " ) ;
2015-02-02 00:14:02 +01:00
delete m_dfu ;
m_dfu = NULL ;
2011-05-27 11:49:15 +01:00
cm - > resumePolling ( ) ;
m_config - > rescueButton - > setEnabled ( true ) ;
return ;
}
2015-02-02 00:14:02 +01:00
for ( int i = 0 ; i < m_dfu - > numberOfDevices ; i + + ) {
2013-05-19 17:37:30 +03:00
DeviceWidget * dw = new DeviceWidget ( this ) ;
2012-05-07 15:11:51 +01:00
connectSignalSlot ( dw ) ;
2011-05-27 11:49:15 +01:00
dw - > setDeviceID ( i ) ;
2015-02-02 00:14:02 +01:00
dw - > setDfu ( m_dfu ) ;
2011-05-27 11:49:15 +01:00
dw - > populate ( ) ;
2014-05-01 23:48:17 +02:00
m_config - > systemElements - > addTab ( dw , tr ( " Device " ) + QString : : number ( i ) ) ;
2011-05-27 11:49:15 +01:00
}
m_config - > haltButton - > setEnabled ( false ) ;
m_config - > resetButton - > setEnabled ( false ) ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( true ) ;
2011-05-27 11:49:15 +01:00
m_config - > rescueButton - > setEnabled ( false ) ;
2014-05-01 17:17:28 +02:00
2014-05-01 16:37:12 +02:00
// So that we can boot from the GUI afterwards.
2015-02-02 00:14:02 +01:00
m_currentIAPStep = IAP_STATE_BOOTLOADER ;
2011-05-27 11:49:15 +01:00
}
2012-09-10 01:57:06 -05:00
2012-05-07 15:11:51 +01:00
void UploaderGadgetWidget : : uploadStarted ( )
{
2013-02-21 01:34:17 +01:00
m_config - > haltButton - > setEnabled ( false ) ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( false ) ;
2013-02-21 01:34:17 +01:00
m_config - > resetButton - > setEnabled ( false ) ;
m_config - > rescueButton - > setEnabled ( false ) ;
2012-05-07 15:11:51 +01:00
}
void UploaderGadgetWidget : : uploadEnded ( bool succeed )
{
Q_UNUSED ( succeed ) ;
2013-02-21 01:34:17 +01:00
// device is halted so no halt
m_config - > haltButton - > setEnabled ( false ) ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( true ) ;
2013-02-21 01:34:17 +01:00
// device is halted so no reset
m_config - > resetButton - > setEnabled ( false ) ;
m_config - > rescueButton - > setEnabled ( true ) ;
}
void UploaderGadgetWidget : : downloadStarted ( )
{
m_config - > haltButton - > setEnabled ( false ) ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( false ) ;
2013-02-21 01:34:17 +01:00
m_config - > resetButton - > setEnabled ( false ) ;
m_config - > rescueButton - > setEnabled ( false ) ;
}
void UploaderGadgetWidget : : downloadEnded ( bool succeed )
{
Q_UNUSED ( succeed ) ;
// device is halted so no halt
m_config - > haltButton - > setEnabled ( false ) ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( true ) ;
2013-02-21 01:34:17 +01:00
// device is halted so no reset
m_config - > resetButton - > setEnabled ( false ) ;
m_config - > rescueButton - > setEnabled ( true ) ;
2012-05-07 15:11:51 +01:00
}
2013-05-19 13:08:50 +02:00
void UploaderGadgetWidget : : startAutoUpdate ( )
2014-12-08 16:36:17 +01:00
{
startAutoUpdate ( false ) ;
}
void UploaderGadgetWidget : : startAutoUpdateErase ( )
{
startAutoUpdate ( true ) ;
}
void UploaderGadgetWidget : : startAutoUpdate ( bool erase )
2013-05-19 13:08:50 +02:00
{
2014-12-08 15:04:28 +01:00
m_config - > autoUpdateProgressBar - > setValue ( 0 ) ;
autoUpdateStatus ( uploader : : JUMP_TO_BL , QVariant ( ) ) ;
2013-05-19 13:08:50 +02:00
m_config - > buttonFrame - > setEnabled ( false ) ;
m_config - > splitter - > setEnabled ( false ) ;
m_config - > autoUpdateGroupBox - > setVisible ( true ) ;
m_config - > autoUpdateOkButton - > setEnabled ( false ) ;
2014-05-01 22:48:22 +02:00
2014-12-09 00:48:30 +01:00
connect ( this , SIGNAL ( progressUpdate ( uploader : : ProgressStep , QVariant ) ) , this , SLOT ( autoUpdateStatus ( uploader : : ProgressStep , QVariant ) ) ) ;
2014-12-08 16:36:17 +01:00
autoUpdate ( erase ) ;
2013-05-19 13:08:50 +02:00
}
void UploaderGadgetWidget : : finishAutoUpdate ( )
{
2014-12-09 00:48:30 +01:00
disconnect ( this , SIGNAL ( progressUpdate ( uploader : : ProgressStep , QVariant ) ) , this , SLOT ( autoUpdateStatus ( uploader : : ProgressStep , QVariant ) ) ) ;
2013-05-19 13:08:50 +02:00
m_config - > autoUpdateOkButton - > setEnabled ( true ) ;
2015-02-03 22:24:57 +01:00
m_autoUpdateClosing = true ;
2014-05-01 22:48:22 +02:00
// wait a bit and "close" auto update
QTimer : : singleShot ( AUTOUPDATE_CLOSE_TIMEOUT , this , SLOT ( closeAutoUpdate ( ) ) ) ;
2013-05-19 13:08:50 +02:00
}
void UploaderGadgetWidget : : closeAutoUpdate ( )
{
2015-02-03 22:24:57 +01:00
if ( m_autoUpdateClosing ) {
2015-02-02 00:14:02 +01:00
m_config - > autoUpdateGroupBox - > setVisible ( false ) ;
m_config - > buttonFrame - > setEnabled ( true ) ;
m_config - > splitter - > setEnabled ( true ) ;
}
2015-02-03 22:24:57 +01:00
m_autoUpdateClosing = false ;
2013-05-19 13:08:50 +02:00
}
2014-12-09 00:48:30 +01:00
void UploaderGadgetWidget : : autoUpdateStatus ( uploader : : ProgressStep status , QVariant value )
2013-05-19 13:08:50 +02:00
{
2014-05-01 22:48:22 +02:00
QString msg ;
int remaining ;
2015-01-20 00:01:03 +01:00
2013-05-20 00:02:34 +03:00
switch ( status ) {
2013-05-19 13:08:50 +02:00
case uploader : : WAITING_DISCONNECT :
2014-05-01 23:48:17 +02:00
m_config - > autoUpdateLabel - > setText ( tr ( " Waiting for all OpenPilot boards to be disconnected from USB. " ) ) ;
2014-05-01 22:48:22 +02:00
m_config - > autoUpdateProgressBar - > setMaximum ( BOARD_EVENT_TIMEOUT / 1000 ) ;
m_config - > autoUpdateProgressBar - > setValue ( value . toInt ( ) ) ;
remaining = m_config - > autoUpdateProgressBar - > maximum ( ) - m_config - > autoUpdateProgressBar - > value ( ) ;
m_config - > autoUpdateProgressBar - > setFormat ( tr ( " Timing out in %1 seconds " ) . arg ( remaining ) ) ;
2013-05-19 13:08:50 +02:00
break ;
case uploader : : WAITING_CONNECT :
2014-05-01 23:48:17 +02:00
m_config - > autoUpdateLabel - > setText ( tr ( " Please connect the OpenPilot board to the USB port. " ) ) ;
2014-05-01 22:48:22 +02:00
m_config - > autoUpdateProgressBar - > setMaximum ( BOARD_EVENT_TIMEOUT / 1000 ) ;
2013-05-19 13:08:50 +02:00
m_config - > autoUpdateProgressBar - > setValue ( value . toInt ( ) ) ;
2014-05-01 22:48:22 +02:00
remaining = m_config - > autoUpdateProgressBar - > maximum ( ) - m_config - > autoUpdateProgressBar - > value ( ) ;
m_config - > autoUpdateProgressBar - > setFormat ( tr ( " Timing out in %1 seconds " ) . arg ( remaining ) ) ;
2013-05-19 13:08:50 +02:00
break ;
case uploader : : JUMP_TO_BL :
2014-12-16 14:18:43 +01:00
m_config - > autoUpdateLabel - > setText ( tr ( " Bringing the board into boot loader mode. Please wait. " ) ) ;
2014-12-08 15:04:28 +01:00
m_config - > autoUpdateProgressBar - > setFormat ( tr ( " Step %1 " ) . arg ( value . toInt ( ) ) ) ;
m_config - > autoUpdateProgressBar - > setMaximum ( 5 ) ;
m_config - > autoUpdateProgressBar - > setValue ( value . toInt ( ) ) ;
2013-05-19 13:08:50 +02:00
break ;
case uploader : : LOADING_FW :
2014-05-01 23:48:17 +02:00
m_config - > autoUpdateLabel - > setText ( tr ( " Preparing to upload firmware to the board. " ) ) ;
2013-05-19 13:08:50 +02:00
break ;
case uploader : : UPLOADING_FW :
2014-05-01 23:48:17 +02:00
m_config - > autoUpdateLabel - > setText ( tr ( " Uploading firmware to the board. " ) ) ;
2014-05-01 22:48:22 +02:00
m_config - > autoUpdateProgressBar - > setFormat ( " %p% " ) ;
m_config - > autoUpdateProgressBar - > setMaximum ( 100 ) ;
2013-05-19 13:08:50 +02:00
m_config - > autoUpdateProgressBar - > setValue ( value . toInt ( ) ) ;
break ;
case uploader : : UPLOADING_DESC :
2014-05-01 23:48:17 +02:00
m_config - > autoUpdateLabel - > setText ( tr ( " Uploading description of the new firmware to the board. " ) ) ;
2013-05-19 13:08:50 +02:00
break ;
case uploader : : BOOTING :
2015-01-27 08:43:06 +01:00
m_config - > autoUpdateLabel - > setText ( tr ( " Rebooting the board. Please wait. " ) ) ;
break ;
case uploader : : BOOTING_AND_ERASING :
m_config - > autoUpdateLabel - > setText ( tr ( " Rebooting and erasing the board. Please wait. " ) ) ;
2013-05-19 13:08:50 +02:00
break ;
case uploader : : SUCCESS :
2014-05-01 22:48:22 +02:00
m_config - > autoUpdateProgressBar - > setValue ( m_config - > autoUpdateProgressBar - > maximum ( ) ) ;
2015-01-27 08:43:06 +01:00
msg = tr ( " Board was updated successfully. Press OK to finish. " ) ;
2014-05-01 22:48:22 +02:00
m_config - > autoUpdateLabel - > setText ( QString ( " <font color='green'>%1</font> " ) . arg ( msg ) ) ;
2013-05-19 13:08:50 +02:00
finishAutoUpdate ( ) ;
break ;
case uploader : : FAILURE :
2014-05-01 23:48:17 +02:00
msg = value . toString ( ) ;
2014-05-01 22:48:22 +02:00
if ( msg . isEmpty ( ) ) {
2015-01-27 08:43:06 +01:00
msg = tr ( " Something went wrong. " ) ;
2014-05-01 22:48:22 +02:00
}
2015-01-27 08:43:06 +01:00
msg + = tr ( " Press OK to finish, you will have to manually upgrade the board. " ) ;
2014-05-01 22:48:22 +02:00
m_config - > autoUpdateLabel - > setText ( QString ( " <font color='red'>%1</font> " ) . arg ( msg ) ) ;
2013-05-19 13:08:50 +02:00
finishAutoUpdate ( ) ;
break ;
}
}
2011-01-31 21:50:11 +00:00
/**
2013-05-19 17:37:30 +03:00
Update log entry
*/
2011-01-31 21:50:11 +00:00
void UploaderGadgetWidget : : log ( QString str )
{
2014-05-01 17:17:28 +02:00
qDebug ( ) < < " UploaderGadgetWidget - " < < str ;
2013-05-19 17:37:30 +03:00
m_config - > textBrowser - > append ( str ) ;
2011-01-31 21:50:11 +00:00
}
void UploaderGadgetWidget : : clearLog ( )
{
m_config - > textBrowser - > clear ( ) ;
}
/**
2013-05-19 17:37:30 +03:00
* Remove all the device widgets . . .
*/
2011-01-31 21:50:11 +00:00
UploaderGadgetWidget : : ~ UploaderGadgetWidget ( )
{
while ( m_config - > systemElements - > count ( ) ) {
2013-05-19 17:37:30 +03:00
QWidget * qw = m_config - > systemElements - > widget ( 0 ) ;
m_config - > systemElements - > removeTab ( 0 ) ;
delete qw ;
qw = 0 ;
2011-05-31 23:31:40 -07:00
}
2011-01-31 21:50:11 +00:00
}
2014-05-04 22:53:14 +02:00
void UploaderGadgetWidget : : openHelp ( )
2011-01-31 21:50:11 +00:00
{
2014-05-10 11:56:24 +02:00
QDesktopServices : : openUrl ( QUrl ( tr ( " http://wiki.openpilot.org/x/AoBZ " ) , QUrl : : StrictMode ) ) ;
2011-01-31 21:50:11 +00:00
}
2013-01-24 03:53:24 +01:00
2014-05-04 22:53:14 +02:00
int UploaderGadgetWidget : : confirmEraseSettingsMessageBox ( )
{
QMessageBox msgBox ( this ) ;
2014-05-05 00:05:51 +02:00
2014-05-04 22:53:14 +02:00
msgBox . setWindowTitle ( tr ( " Confirm Settings Erase? " ) ) ;
msgBox . setIcon ( QMessageBox : : Question ) ;
msgBox . setText ( tr ( " Do you want to erase all settings from the board? " ) ) ;
msgBox . setInformativeText ( tr ( " Settings cannot be recovered after this operation. \n The board will be restarted and all settings erased. " ) ) ;
msgBox . setStandardButtons ( QMessageBox : : Ok | QMessageBox : : Cancel | QMessageBox : : Help ) ;
return msgBox . exec ( ) ;
}
2011-01-31 21:50:11 +00:00
2014-05-04 22:53:14 +02:00
int UploaderGadgetWidget : : cannotHaltMessageBox ( )
2011-01-31 21:50:11 +00:00
{
2014-05-04 22:53:14 +02:00
QMessageBox msgBox ( this ) ;
2014-05-05 00:05:51 +02:00
2014-05-04 22:53:14 +02:00
msgBox . setWindowTitle ( tr ( " Cannot Halt Board! " ) ) ;
msgBox . setIcon ( QMessageBox : : Warning ) ;
msgBox . setText ( tr ( " The controller board is armed and can not be halted. " ) ) ;
msgBox . setInformativeText ( tr ( " Please make sure the board is not armed and then press Halt again to proceed or use Rescue to force a firmware upgrade. " ) ) ;
msgBox . setStandardButtons ( QMessageBox : : Ok ) ;
return msgBox . exec ( ) ;
2011-01-31 21:50:11 +00:00
}
2011-11-13 16:05:36 +00:00
2014-05-04 22:53:14 +02:00
int UploaderGadgetWidget : : cannotResetMessageBox ( )
2012-01-09 16:35:35 +00:00
{
2014-05-04 22:53:14 +02:00
QMessageBox msgBox ( this ) ;
2014-05-05 00:05:51 +02:00
2014-05-04 22:53:14 +02:00
msgBox . setWindowTitle ( tr ( " Cannot Reset Board! " ) ) ;
msgBox . setIcon ( QMessageBox : : Warning ) ;
msgBox . setText ( tr ( " The controller board is armed and can not be reset. " ) ) ;
msgBox . setInformativeText ( tr ( " Please make sure the board is not armed and then press reset again to proceed or power cycle to force a board reset. " ) ) ;
msgBox . setStandardButtons ( QMessageBox : : Ok ) ;
return msgBox . exec ( ) ;
2012-01-09 16:35:35 +00:00
}
2014-12-09 00:48:30 +01:00
2014-12-09 00:50:26 +01:00
int ResultEventLoop : : run ( int millisTimout )
{
2014-12-09 00:48:30 +01:00
m_timer . singleShot ( millisTimout , this , SLOT ( fail ( ) ) ) ;
return exec ( ) ;
}
2014-12-09 00:50:26 +01:00
void ResultEventLoop : : success ( )
{
2014-12-09 00:48:30 +01:00
m_timer . stop ( ) ;
exit ( 0 ) ;
}
2014-12-09 00:50:26 +01:00
void ResultEventLoop : : fail ( )
{
2014-12-09 00:48:30 +01:00
m_timer . stop ( ) ;
exit ( - 1 ) ;
}