2011-01-31 22:50:11 +01: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"
2013-05-18 20:28:52 +02:00
# include "version_info/version_info.h"
2011-11-13 17:05:36 +01:00
# include <coreplugin/coreconstants.h>
2011-11-13 18:39:05 +01:00
# include <QDebug>
2012-11-18 22:40:05 +01:00
# include "flightstatus.h"
2011-01-31 22:50:11 +01:00
# define DFU_DEBUG true
2011-06-19 01:50:38 +02:00
2013-06-25 15:51:33 +02:00
const int UploaderGadgetWidget : : AUTOUPDATE_CLOSE_TIMEOUT = 7000 ;
2011-01-31 22:50:11 +01:00
UploaderGadgetWidget : : UploaderGadgetWidget ( QWidget * parent ) : QWidget ( parent )
{
2013-05-19 16:37:30 +02:00
m_config = new Ui_UploaderWidget ( ) ;
2011-01-31 22:50:11 +01:00
m_config - > setupUi ( this ) ;
currentStep = IAP_STATE_READY ;
2013-05-19 16:37:30 +02:00
resetOnly = false ;
2011-01-31 22:50:11 +01:00
dfu = NULL ;
2013-05-19 16:37:30 +02:00
m_timer = 0 ;
m_progress = 0 ;
msg = new QErrorMessage ( this ) ;
2011-01-31 22:50:11 +01:00
// Listen to autopilot connection events
ExtensionSystem : : PluginManager * pm = ExtensionSystem : : PluginManager : : instance ( ) ;
2013-05-19 16:37:30 +02:00
TelemetryManager * telMngr = pm - > getObject < TelemetryManager > ( ) ;
2011-01-31 22:50:11 +01:00
connect ( telMngr , SIGNAL ( connected ( ) ) , this , SLOT ( onAutopilotConnect ( ) ) ) ;
2011-11-13 17:05:36 +01:00
connect ( telMngr , SIGNAL ( connected ( ) ) , this , SLOT ( versionMatchCheck ( ) ) ) ;
2011-01-31 22:50:11 +01:00
connect ( telMngr , SIGNAL ( disconnected ( ) ) , this , SLOT ( onAutopilotDisconnect ( ) ) ) ;
2012-11-18 22:40:05 +01:00
connect ( m_config - > haltButton , SIGNAL ( clicked ( ) ) , this , SLOT ( systemHalt ( ) ) ) ;
2011-01-31 22:50:11 +01:00
connect ( m_config - > resetButton , SIGNAL ( clicked ( ) ) , this , SLOT ( systemReset ( ) ) ) ;
connect ( m_config - > bootButton , SIGNAL ( clicked ( ) ) , this , SLOT ( systemBoot ( ) ) ) ;
2012-01-02 20:21:12 +01: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 22:50:11 +01:00
connect ( m_config - > rescueButton , SIGNAL ( clicked ( ) ) , this , SLOT ( systemRescue ( ) ) ) ;
2011-10-12 17:43:14 +02:00
Core : : ConnectionManager * cm = Core : : ICore : : instance ( ) - > connectionManager ( ) ;
2013-05-19 16:37:30 +02:00
connect ( cm , SIGNAL ( deviceConnected ( QIODevice * ) ) , this , SLOT ( onPhisicalHWConnect ( ) ) ) ;
2011-01-31 22:50:11 +01:00
getSerialPorts ( ) ;
2013-05-19 13:08:50 +02:00
m_config - > autoUpdateButton - > setEnabled ( autoUpdateCapable ( ) ) ;
connect ( m_config - > autoUpdateButton , SIGNAL ( clicked ( ) ) , this , SLOT ( startAutoUpdate ( ) ) ) ;
connect ( m_config - > autoUpdateOkButton , SIGNAL ( clicked ( ) ) , this , SLOT ( closeAutoUpdate ( ) ) ) ;
m_config - > autoUpdateGroupBox - > setVisible ( false ) ;
2011-01-31 22:50:11 +01:00
QIcon rbi ;
rbi . addFile ( QString ( " :uploader/images/view-refresh.svg " ) ) ;
m_config - > refreshPorts - > setIcon ( rbi ) ;
2013-04-08 23:55:11 +02:00
bootButtonsSetEnable ( false ) ;
2011-01-31 22:50:11 +01:00
connect ( m_config - > refreshPorts , SIGNAL ( clicked ( ) ) , this , SLOT ( getSerialPorts ( ) ) ) ;
2013-05-19 16:37:30 +02:00
connect ( m_config - > pbHelp , SIGNAL ( clicked ( ) ) , this , SLOT ( openHelp ( ) ) ) ;
2011-04-10 10:23:03 +02:00
// And check whether by any chance we are not already connected
2013-05-19 16:37:30 +02:00
if ( telMngr - > isConnected ( ) ) {
2011-04-10 10:23:03 +02:00
onAutopilotConnect ( ) ;
2011-11-13 18:39:05 +01:00
versionMatchCheck ( ) ;
}
2011-01-31 22:50:11 +01:00
}
2013-09-15 23:06:25 +02:00
bool sortPorts ( const QSerialPortInfo & s1 , const QSerialPortInfo & s2 )
2011-01-31 22:50:11 +01:00
{
2013-09-15 23:06:25 +02:00
return s1 . portName ( ) < s2 . portName ( ) ;
2011-01-31 22:50:11 +01:00
}
/**
2013-05-19 16:37:30 +02:00
Gets the list of serial ports
*/
2011-01-31 22:50:11 +01:00
void UploaderGadgetWidget : : getSerialPorts ( )
{
QStringList list ;
2013-05-19 16:37:30 +02:00
2011-01-31 22:50:11 +01: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 22:50:11 +01:00
2013-05-19 16:37:30 +02: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 22:50:11 +01: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 16:37:30 +02:00
}
2011-01-31 22:50:11 +01:00
return " " ;
}
2012-05-07 16:11:51 +02:00
void UploaderGadgetWidget : : connectSignalSlot ( QWidget * widget )
{
2013-05-19 16:37:30 +02: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 16:11:51 +02:00
}
2012-11-19 19:43:38 +01:00
FlightStatus * UploaderGadgetWidget : : getFlightStatus ( )
{
ExtensionSystem : : PluginManager * pm = ExtensionSystem : : PluginManager : : instance ( ) ;
2013-05-19 16:37:30 +02:00
2012-11-19 19:43:38 +01:00
Q_ASSERT ( pm ) ;
UAVObjectManager * objManager = pm - > getObject < UAVObjectManager > ( ) ;
Q_ASSERT ( objManager ) ;
2013-05-19 16:37:30 +02:00
FlightStatus * status = dynamic_cast < FlightStatus * > ( objManager - > getObject ( QString ( " 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
2013-05-19 16:37:30 +02:00
m_config - > eraseBootButton - > setEnabled (
enabled & &
// this feature is supported only on BL revision >= 4
( ( dfu ! = NULL ) & & ( dfu - > devices [ 0 ] . BL_Version > = 4 ) ) ) ;
}
2013-04-08 01:09:31 +02:00
2011-10-12 17:43:14 +02:00
void UploaderGadgetWidget : : onPhisicalHWConnect ( )
{
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( false ) ;
2011-10-12 17:43:14 +02:00
m_config - > rescueButton - > setEnabled ( false ) ;
m_config - > telemetryLink - > setEnabled ( false ) ;
}
2011-01-31 22:50:11 +01:00
/**
2013-05-19 16:37:30 +02: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-26 00:59:42 +01:00
}
void UploaderGadgetWidget : : populate ( )
{
2011-01-31 22:50:11 +01:00
m_config - > haltButton - > setEnabled ( true ) ;
m_config - > resetButton - > setEnabled ( true ) ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( false ) ;
2011-01-31 22:50:11 +01: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 16:37:30 +02: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 16:37:30 +02:00
RunningDeviceWidget * dw = new RunningDeviceWidget ( this ) ;
2011-05-15 22:48:18 +02:00
dw - > populate ( ) ;
m_config - > systemElements - > addTab ( dw , QString ( " Connected Device " ) ) ;
2011-01-31 22:50:11 +01:00
}
/**
2013-05-19 16:37:30 +02:00
Enables widget buttons if autopilot disconnected
*/
void UploaderGadgetWidget : : onAutopilotDisconnect ( )
{
2011-01-31 22:50:11 +01:00
m_config - > haltButton - > setEnabled ( false ) ;
m_config - > resetButton - > setEnabled ( false ) ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( true ) ;
2011-01-31 22:50:11 +01:00
if ( currentStep = = IAP_STATE_BOOTLOADER ) {
m_config - > rescueButton - > setEnabled ( false ) ;
m_config - > telemetryLink - > setEnabled ( false ) ;
} else {
m_config - > rescueButton - > setEnabled ( true ) ;
m_config - > telemetryLink - > setEnabled ( true ) ;
}
}
/**
2013-05-19 16:37:30 +02:00
Tell the mainboard to go to bootloader :
2011-01-31 22:50:11 +01:00
- Send the relevant IAP commands
- setup callback for MoBo acknowledge
2013-05-19 16:37:30 +02:00
*/
void UploaderGadgetWidget : : goToBootloader ( UAVObject * callerObj , bool success )
2011-01-31 22:50:11 +01:00
{
Q_UNUSED ( callerObj ) ;
ExtensionSystem : : PluginManager * pm = ExtensionSystem : : PluginManager : : instance ( ) ;
UAVObjectManager * objManager = pm - > getObject < UAVObjectManager > ( ) ;
2013-05-19 16:37:30 +02:00
UAVObject * fwIAP = dynamic_cast < UAVDataObject * > ( objManager - > getObject ( QString ( " FirmwareIAPObj " ) ) ) ;
2011-01-31 22:50:11 +01:00
switch ( currentStep ) {
case IAP_STATE_READY :
2011-05-16 20:03:41 +02:00
m_config - > haltButton - > setEnabled ( false ) ;
2011-01-31 22:50:11 +01: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 12:22:31 +01:00
fwIAP - > getField ( " BoardRevision " ) - > setDouble ( 0 ) ;
fwIAP - > getField ( " BoardType " ) - > setDouble ( 0 ) ;
2013-05-19 16:37:30 +02:00
connect ( fwIAP , SIGNAL ( transactionCompleted ( UAVObject * , bool ) ) , this , SLOT ( goToBootloader ( UAVObject * , bool ) ) ) ;
2011-01-31 22:50:11 +01:00
currentStep = IAP_STATE_STEP_1 ;
clearLog ( ) ;
log ( QString ( " IAP Step 1 " ) ) ;
fwIAP - > updated ( ) ;
break ;
case IAP_STATE_STEP_1 :
2013-05-19 16:37:30 +02:00
if ( ! success ) {
2011-01-31 22:50:11 +01:00
log ( QString ( " Oops, failure step 1 " ) ) ;
log ( " Reset did NOT happen " ) ;
currentStep = IAP_STATE_READY ;
2013-05-19 16:37:30 +02: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 ) ;
2011-01-31 22:50:11 +01:00
break ;
}
2012-07-02 17:11:34 +02:00
QTimer : : singleShot ( 600 , & m_eventloop , SLOT ( quit ( ) ) ) ;
m_eventloop . exec ( ) ;
2011-01-31 22:50:11 +01:00
fwIAP - > getField ( " Command " ) - > setValue ( " 2233 " ) ;
currentStep = IAP_STATE_STEP_2 ;
log ( QString ( " IAP Step 2 " ) ) ;
fwIAP - > updated ( ) ;
break ;
case IAP_STATE_STEP_2 :
if ( ! success ) {
log ( QString ( " Oops, failure step 2 " ) ) ;
log ( " Reset did NOT happen " ) ;
currentStep = IAP_STATE_READY ;
2013-05-19 16:37:30 +02: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 ) ;
2011-01-31 22:50:11 +01:00
break ;
}
2012-07-02 17:11:34 +02:00
QTimer : : singleShot ( 600 , & m_eventloop , SLOT ( quit ( ) ) ) ;
m_eventloop . exec ( ) ;
2011-01-31 22:50:11 +01:00
fwIAP - > getField ( " Command " ) - > setValue ( " 3344 " ) ;
currentStep = IAP_STEP_RESET ;
log ( QString ( " IAP Step 3 " ) ) ;
fwIAP - > updated ( ) ;
break ;
case IAP_STEP_RESET :
{
currentStep = IAP_STATE_READY ;
if ( ! success ) {
log ( " Oops, failure step 3 " ) ;
log ( " Reset did NOT happen " ) ;
2013-05-19 16:37:30 +02: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 ) ;
2011-01-31 22:50:11 +01:00
break ;
}
// The board is now reset: we have to disconnect telemetry
Core : : ConnectionManager * cm = Core : : ICore : : instance ( ) - > connectionManager ( ) ;
2012-09-08 22:14:06 +02:00
QString dli = cm - > getCurrentDevice ( ) . getConName ( ) ;
QString dlj = cm - > getCurrentDevice ( ) . getConName ( ) ;
2011-01-31 22:50:11 +01:00
cm - > disconnectDevice ( ) ;
2012-07-02 17:11:34 +02:00
QTimer : : singleShot ( 200 , & m_eventloop , SLOT ( quit ( ) ) ) ;
m_eventloop . exec ( ) ;
2011-01-31 22:50:11 +01:00
// Tell connections to stop their polling threads: otherwise it will mess up DFU
cm - > suspendPolling ( ) ;
2012-07-02 17:11:34 +02:00
QTimer : : singleShot ( 200 , & m_eventloop , SLOT ( quit ( ) ) ) ;
m_eventloop . exec ( ) ;
2011-01-31 22:50:11 +01:00
log ( " Board Halt " ) ;
m_config - > boardStatus - > setText ( " Bootloader " ) ;
2013-05-19 16:37:30 +02:00
if ( dlj . startsWith ( " USB " ) ) {
2011-01-31 22:50:11 +01:00
m_config - > telemetryLink - > setCurrentIndex ( m_config - > telemetryLink - > findText ( " USB " ) ) ;
2013-05-19 16:37:30 +02:00
} else {
2011-01-31 22:50:11 +01:00
m_config - > telemetryLink - > setCurrentIndex ( m_config - > telemetryLink - > findText ( dli ) ) ;
2013-05-19 16:37:30 +02:00
}
2011-01-31 22:50:11 +01:00
2013-05-19 16:37:30 +02:00
disconnect ( fwIAP , SIGNAL ( transactionCompleted ( UAVObject * , bool ) ) , this , SLOT ( goToBootloader ( UAVObject * , bool ) ) ) ;
2011-01-31 22:50:11 +01:00
currentStep = IAP_STATE_BOOTLOADER ;
// Tell the mainboard to get into bootloader state:
2011-09-25 15:26:12 +02:00
log ( " Detecting devices, please wait a few seconds... " ) ;
2011-01-31 22:50:11 +01:00
if ( ! dfu ) {
2013-05-19 16:37:30 +02:00
if ( dlj . startsWith ( " USB " ) ) {
2011-01-31 22:50:11 +01:00
dfu = new DFUObject ( DFU_DEBUG , false , QString ( ) ) ;
2013-05-19 16:37:30 +02:00
} else {
dfu = new DFUObject ( DFU_DEBUG , true , getPortDevice ( dli ) ) ;
}
2011-01-31 22:50:11 +01:00
}
2013-05-19 16:37:30 +02:00
if ( ! dfu - > ready ( ) ) {
2011-01-31 22:50:11 +01:00
log ( " Could not enter DFU mode. " ) ;
delete dfu ;
dfu = NULL ;
cm - > resumePolling ( ) ;
2011-03-26 12:22:31 +01:00
currentStep = IAP_STATE_READY ;
m_config - > boardStatus - > setText ( " Bootloader? " ) ;
2011-05-16 20:03:41 +02:00
m_config - > haltButton - > setEnabled ( true ) ;
2011-01-31 22:50:11 +01:00
return ;
}
dfu - > AbortOperation ( ) ;
2013-05-19 16:37:30 +02:00
if ( ! dfu - > enterDFU ( 0 ) ) {
2011-01-31 22:50:11 +01:00
log ( " Could not enter DFU mode. " ) ;
delete dfu ;
dfu = NULL ;
cm - > resumePolling ( ) ;
2011-03-26 12:22:31 +01:00
currentStep = IAP_STATE_READY ;
m_config - > boardStatus - > setText ( " Bootloader? " ) ;
2011-01-31 22:50:11 +01:00
return ;
}
2013-05-19 16:37:30 +02:00
// dfu.StatusRequest();
2013-03-13 03:24:25 +01:00
2013-05-19 16:37:30 +02:00
QTimer : : singleShot ( 500 , & m_eventloop , SLOT ( quit ( ) ) ) ;
m_eventloop . exec ( ) ;
2011-01-31 22:50:11 +01:00
dfu - > findDevices ( ) ;
log ( QString ( " Found " ) + QString : : number ( dfu - > numberOfDevices ) + QString ( " device(s). " ) ) ;
if ( dfu - > numberOfDevices < 0 | | dfu - > numberOfDevices > 3 ) {
log ( " Inconsistent number of devices! Aborting " ) ;
delete dfu ;
dfu = NULL ;
cm - > resumePolling ( ) ;
return ;
}
// Delete all previous tabs:
while ( m_config - > systemElements - > count ( ) ) {
2013-05-19 16:37:30 +02:00
QWidget * qw = m_config - > systemElements - > widget ( 0 ) ;
m_config - > systemElements - > removeTab ( 0 ) ;
delete qw ;
2011-01-31 22:50:11 +01:00
}
2013-05-19 16:37:30 +02:00
for ( int i = 0 ; i < dfu - > numberOfDevices ; i + + ) {
DeviceWidget * dw = new DeviceWidget ( this ) ;
2012-05-07 16:11:51 +02:00
connectSignalSlot ( dw ) ;
2011-01-31 22:50:11 +01:00
dw - > setDeviceID ( i ) ;
dw - > setDfu ( dfu ) ;
dw - > populate ( ) ;
m_config - > systemElements - > addTab ( dw , QString ( " Device " ) + QString : : number ( i ) ) ;
}
2013-06-25 15:51:33 +02:00
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 ) ;
2013-06-25 15:51:33 +02:00
2011-01-31 22:50:11 +01:00
if ( resetOnly ) {
2013-05-19 16:37:30 +02:00
resetOnly = false ;
2011-01-31 22:50:11 +01:00
delay : : msleep ( 3500 ) ;
systemBoot ( ) ;
break ;
}
}
2013-05-19 16:37:30 +02:00
break ;
2011-01-31 22:50:11 +01:00
case IAP_STATE_BOOTLOADER :
// We should never end up here anyway.
break ;
}
}
2012-11-18 22:40:05 +01:00
void UploaderGadgetWidget : : systemHalt ( )
{
2013-05-19 16:37:30 +02:00
FlightStatus * status = getFlightStatus ( ) ;
2012-11-18 22:40:05 +01:00
// The board can not be halted when in armed state.
// If board is armed, or arming. Show message with notice.
if ( status - > getArmed ( ) = = FlightStatus : : ARMED_DISARMED ) {
goToBootloader ( ) ;
2013-05-19 16:37:30 +02:00
} else {
2012-11-18 22:40:05 +01:00
QMessageBox mbox ( this ) ;
2012-11-21 07:32:19 +01:00
mbox . setText ( QString ( tr ( " The controller board is armed and can not be halted. \n \n "
" Please make sure the board is not armed and then press halt again to proceed \n "
" or use the rescue option to force a firmware upgrade. " ) ) ) ;
2012-11-18 22:40:05 +01:00
mbox . setStandardButtons ( QMessageBox : : Ok ) ;
mbox . setIcon ( QMessageBox : : Warning ) ;
mbox . exec ( ) ;
}
}
2011-01-31 22:50:11 +01:00
/**
2013-05-19 16:37:30 +02:00
Tell the mainboard to reset :
2011-01-31 22:50:11 +01:00
- Send the relevant IAP commands
- setup callback for MoBo acknowledge
2013-05-19 16:37:30 +02:00
*/
2011-01-31 22:50:11 +01:00
void UploaderGadgetWidget : : systemReset ( )
{
2013-05-19 16:37:30 +02: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 ) {
resetOnly = true ;
if ( dfu ) {
delete dfu ;
dfu = NULL ;
}
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 16:37:30 +02:00
} else {
2012-11-19 19:43:38 +01:00
QMessageBox mbox ( this ) ;
2012-11-21 07:32:19 +01:00
mbox . setText ( QString ( tr ( " The controller board is armed and can not be reset. \n \n "
" Please make sure the board is not armed and then press reset again to proceed \n "
" or power cycle to force a board reset. " ) ) ) ;
2012-11-19 19:43:38 +01:00
mbox . setStandardButtons ( QMessageBox : : Ok ) ;
mbox . setIcon ( QMessageBox : : Warning ) ;
mbox . exec ( ) ;
2011-01-31 22:50:11 +01:00
}
}
2012-01-02 20:21:12 +01:00
void UploaderGadgetWidget : : systemBoot ( )
{
2013-05-19 16:37:30 +02:00
commonSystemBoot ( false , false ) ;
2012-01-02 20:21:12 +01:00
}
void UploaderGadgetWidget : : systemSafeBoot ( )
{
2013-05-19 16:37:30 +02:00
commonSystemBoot ( true , false ) ;
2013-04-08 01:09:31 +02:00
}
void UploaderGadgetWidget : : systemEraseBoot ( )
{
2013-05-19 16:37:30 +02:00
QMessageBox msgBox ;
int result ;
msgBox . setWindowTitle ( tr ( " Erase Settings " ) ) ;
msgBox . setInformativeText ( tr ( " Do you want to erase all settings from the board? \n Settings cannot be recovered after this operation. \n The board will be restarted and all the setting erased " ) ) ;
msgBox . setStandardButtons ( QMessageBox : : Ok | QMessageBox : : Cancel | QMessageBox : : Help ) ;
result = msgBox . exec ( ) ;
if ( result = = QMessageBox : : Ok ) {
commonSystemBoot ( true , true ) ;
} else if ( result = = QMessageBox : : Help ) {
QDesktopServices : : openUrl ( QUrl ( tr ( " http://wiki.openpilot.org/display/Doc/Erase+board+settings " ) , QUrl : : StrictMode ) ) ;
}
2012-01-02 20:21:12 +01:00
}
2011-01-31 22:50:11 +01:00
/**
2013-05-19 16:37:30 +02: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 22:50:11 +01:00
{
clearLog ( ) ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( false ) ;
2011-01-31 22:50:11 +01: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 ( ) ;
if ( ! dfu ) {
2013-05-19 16:37:30 +02:00
if ( devName = = " USB " ) {
2011-01-31 22:50:11 +01:00
dfu = new DFUObject ( DFU_DEBUG , false , QString ( ) ) ;
2013-05-19 16:37:30 +02:00
} else {
dfu = new DFUObject ( DFU_DEBUG , true , getPortDevice ( devName ) ) ;
}
2011-01-31 22:50:11 +01:00
}
dfu - > AbortOperation ( ) ;
2013-05-19 16:37:30 +02:00
if ( ! dfu - > enterDFU ( 0 ) ) {
2011-01-31 22:50:11 +01:00
log ( " Could not enter DFU mode. " ) ;
delete dfu ;
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?
2011-01-31 22:50:11 +01:00
return ;
}
log ( " Booting system... " ) ;
2013-04-08 01:09:31 +02:00
dfu - > JumpToApp ( safeboot , erase ) ;
2011-01-31 22:50:11 +01:00
// Restart the polling thread
cm - > resumePolling ( ) ;
m_config - > rescueButton - > setEnabled ( true ) ;
m_config - > telemetryLink - > setEnabled ( true ) ;
m_config - > boardStatus - > setText ( " Running " ) ;
2013-05-19 16:37:30 +02:00
if ( currentStep = = IAP_STATE_BOOTLOADER ) {
2011-01-31 22:50:11 +01: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 16:37:30 +02: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 16:37:30 +02: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 22:50:11 +01:00
}
}
currentStep = IAP_STATE_READY ;
log ( " You can now reconnect telemetry... " ) ;
delete dfu ; // Frees up the USB/Serial port too
dfu = NULL ;
}
2013-01-24 03:53:24 +01:00
2012-10-07 00:23:44 +02:00
bool UploaderGadgetWidget : : autoUpdateCapable ( )
{
2013-03-19 16:52:24 +01:00
return QDir ( " :/firmware " ) . exists ( ) ;
2012-10-07 00:23:44 +02:00
}
2012-10-05 20:55:43 +02:00
bool UploaderGadgetWidget : : autoUpdate ( )
{
Core : : ConnectionManager * cm = Core : : ICore : : instance ( ) - > connectionManager ( ) ;
2013-05-19 16:37:30 +02:00
2012-10-05 20:55:43 +02:00
cm - > disconnectDevice ( ) ;
cm - > suspendPolling ( ) ;
if ( dfu ) {
delete dfu ;
dfu = NULL ;
}
2012-10-15 20:39:20 +02:00
QEventLoop loop ;
QTimer timer ;
timer . setSingleShot ( true ) ;
2013-05-19 16:37:30 +02:00
connect ( & timer , SIGNAL ( timeout ( ) ) , & loop , SLOT ( quit ( ) ) ) ;
while ( USBMonitor : : instance ( ) - > availableDevices ( 0x20a0 , - 1 , - 1 , - 1 ) . length ( ) > 0 ) {
emit autoUpdateSignal ( WAITING_DISCONNECT , QVariant ( ) ) ;
2013-06-02 12:42:15 +02:00
if ( QMessageBox : : warning ( this , tr ( " OpenPilot Uploader " ) , tr ( " Please disconnect your OpenPilot board " ) , QMessageBox : : Ok , QMessageBox : : Cancel ) = = QMessageBox : : Cancel ) {
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( FAILURE , QVariant ( ) ) ;
return false ;
}
timer . start ( 500 ) ;
loop . exec ( ) ;
}
emit autoUpdateSignal ( WAITING_CONNECT , 0 ) ;
autoUpdateConnectTimeout = 0 ;
2012-10-05 20:55:43 +02:00
m_timer = new QTimer ( this ) ;
connect ( m_timer , SIGNAL ( timeout ( ) ) , this , SLOT ( performAuto ( ) ) ) ;
m_timer - > start ( 1000 ) ;
2013-05-19 16:37:30 +02:00
connect ( USBMonitor : : instance ( ) , SIGNAL ( deviceDiscovered ( USBPortInfo ) ) , & m_eventloop , SLOT ( quit ( ) ) ) ;
2012-10-05 20:55:43 +02:00
m_eventloop . exec ( ) ;
2013-05-19 16:37:30 +02:00
if ( ! m_timer - > isActive ( ) ) {
2012-10-05 20:55:43 +02:00
m_timer - > stop ( ) ;
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( FAILURE , QVariant ( ) ) ;
2012-10-05 20:55:43 +02:00
return false ;
}
m_timer - > stop ( ) ;
dfu = new DFUObject ( DFU_DEBUG , false , QString ( ) ) ;
dfu - > AbortOperation ( ) ;
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( JUMP_TO_BL , QVariant ( ) ) ;
if ( ! dfu - > enterDFU ( 0 ) ) {
2012-10-05 20:55:43 +02:00
delete dfu ;
dfu = NULL ;
cm - > resumePolling ( ) ;
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( FAILURE , QVariant ( ) ) ;
2012-10-05 20:55:43 +02:00
return false ;
}
2013-05-19 16:37:30 +02:00
if ( ! dfu - > findDevices ( ) | | ( dfu - > numberOfDevices ! = 1 ) ) {
2012-10-05 20:55:43 +02:00
delete dfu ;
dfu = NULL ;
cm - > resumePolling ( ) ;
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( FAILURE , QVariant ( ) ) ;
2012-10-05 20:55:43 +02:00
return false ;
}
if ( dfu - > numberOfDevices > 5 ) {
delete dfu ;
dfu = NULL ;
cm - > resumePolling ( ) ;
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( FAILURE , QVariant ( ) ) ;
2012-10-05 20:55:43 +02:00
return false ;
}
QString filename ;
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( LOADING_FW , QVariant ( ) ) ;
2013-03-19 16:52:24 +01:00
switch ( dfu - > devices [ 0 ] . ID ) {
case 0x301 :
2013-04-12 23:24:30 +02:00
filename = " fw_oplinkmini " ;
2012-10-05 20:55:43 +02:00
break ;
2013-03-19 16:52:24 +01:00
case 0x401 :
2012-10-05 20:55:43 +02:00
case 0x402 :
2013-03-19 16:52:24 +01:00
filename = " fw_coptercontrol " ;
break ;
case 0x501 :
filename = " fw_osd " ;
break ;
case 0x902 :
2013-04-23 23:57:33 +02:00
filename = " fw_revoproto " ;
2013-03-19 16:52:24 +01:00
break ;
case 0x903 :
2013-04-14 01:34:43 +02:00
filename = " fw_revolution " ;
2012-10-05 20:55:43 +02:00
break ;
default :
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( FAILURE , QVariant ( ) ) ;
2012-10-05 20:55:43 +02:00
return false ;
2013-05-19 16:37:30 +02:00
2012-10-05 20:55:43 +02:00
break ;
}
2013-03-19 16:52:24 +01:00
filename = " :/firmware/ " + filename + " .opfw " ;
2012-10-05 20:55:43 +02:00
QByteArray firmware ;
2013-05-19 16:37:30 +02:00
if ( ! QFile : : exists ( filename ) ) {
emit autoUpdateSignal ( FAILURE , QVariant ( ) ) ;
2012-10-07 00:23:44 +02:00
return false ;
}
2012-10-05 20:55:43 +02:00
QFile file ( filename ) ;
if ( ! file . open ( QIODevice : : ReadOnly ) ) {
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( FAILURE , QVariant ( ) ) ;
2012-10-05 20:55:43 +02:00
return false ;
}
firmware = file . readAll ( ) ;
connect ( dfu , SIGNAL ( progressUpdated ( int ) ) , this , SLOT ( autoUpdateProgress ( int ) ) ) ;
connect ( dfu , SIGNAL ( uploadFinished ( OP_DFU : : Status ) ) , & m_eventloop , SLOT ( quit ( ) ) ) ;
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( UPLOADING_FW , QVariant ( ) ) ;
if ( ! dfu - > enterDFU ( 0 ) ) {
emit autoUpdateSignal ( FAILURE , QVariant ( ) ) ;
2012-10-05 20:55:43 +02:00
return false ;
}
dfu - > AbortOperation ( ) ;
2013-05-19 16:37:30 +02:00
if ( ! dfu - > UploadFirmware ( filename , false , 0 ) ) {
emit autoUpdateSignal ( FAILURE , QVariant ( ) ) ;
2012-10-05 20:55:43 +02:00
return false ;
}
m_eventloop . exec ( ) ;
QByteArray desc = firmware . right ( 100 ) ;
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( UPLOADING_DESC , QVariant ( ) ) ;
if ( dfu - > UploadDescription ( desc ) ! = OP_DFU : : Last_operation_Success ) {
emit autoUpdateSignal ( FAILURE , QVariant ( ) ) ;
2012-10-05 20:55:43 +02:00
return false ;
}
systemBoot ( ) ;
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( SUCCESS , QVariant ( ) ) ;
2012-10-05 20:55:43 +02:00
return true ;
}
void UploaderGadgetWidget : : autoUpdateProgress ( int value )
{
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( UPLOADING_FW , value ) ;
2012-10-05 20:55:43 +02:00
}
2011-01-31 22:50:11 +01:00
/**
2013-05-19 16:37:30 +02:00
Attempt a guided procedure to put both boards in BL mode when
the system is not bootable
*/
2011-01-31 22:50:11 +01:00
void UploaderGadgetWidget : : systemRescue ( )
{
Core : : ConnectionManager * cm = Core : : ICore : : instance ( ) - > connectionManager ( ) ;
2013-05-19 16:37:30 +02:00
2011-05-27 12:49:15 +02:00
cm - > disconnectDevice ( ) ;
// stop the polling thread: otherwise it will mess up DFU
cm - > suspendPolling ( ) ;
// 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 22:50:11 +01:00
}
2011-05-27 12:49:15 +02:00
// Existing DFU objects will have a handle over USB and will
// disturb everything for the rescue process:
if ( dfu ) {
delete dfu ;
dfu = NULL ;
}
2012-09-09 02:07:14 +02:00
// Avoid users pressing Rescue twice.
2011-05-27 12:49:15 +02:00
m_config - > rescueButton - > setEnabled ( false ) ;
// Now we're good to go:
clearLog ( ) ;
log ( " ********************************************************** " ) ;
log ( " ** Follow those instructions to attempt a system rescue ** " ) ;
log ( " ********************************************************** " ) ;
log ( " You will be prompted to first connect USB, then system power " ) ;
2013-05-19 16:37:30 +02:00
if ( USBMonitor : : instance ( ) - > availableDevices ( 0x20a0 , - 1 , - 1 , - 1 ) . length ( ) > 0 ) {
2013-06-02 12:42:15 +02:00
if ( QMessageBox : : warning ( this , tr ( " OpenPilot Uploader " ) , tr ( " Please disconnect your OpenPilot board " ) , QMessageBox : : Ok , QMessageBox : : Cancel ) = = QMessageBox : : Cancel ) {
2011-04-10 10:46:41 +02:00
m_config - > rescueButton - > setEnabled ( true ) ;
2011-01-31 22:50:11 +01:00
return ;
}
2011-05-27 12:49:15 +02:00
}
// Now we're good to go:
clearLog ( ) ;
log ( " ********************************************************** " ) ;
log ( " ** Follow those instructions to attempt a system rescue ** " ) ;
log ( " ********************************************************** " ) ;
log ( " You will be prompted to first connect USB, then system power " ) ;
2013-06-02 12:42:15 +02:00
m_progress = new QProgressDialog ( tr ( " Please connect your OpenPilot board (USB only!) " ) , tr ( " Cancel " ) , 0 , 20 ) ;
2013-05-19 16:37:30 +02:00
QProgressBar * bar = new QProgressBar ( m_progress ) ;
2011-05-27 12:49:15 +02:00
bar - > setFormat ( " Timeout " ) ;
2011-06-01 08:31:40 +02:00
m_progress - > setBar ( bar ) ;
m_progress - > setMinimumDuration ( 0 ) ;
2013-05-19 16:37:30 +02:00
m_progress - > setRange ( 0 , 20 ) ;
2011-06-01 08:31:40 +02:00
connect ( m_progress , SIGNAL ( canceled ( ) ) , this , SLOT ( cancel ( ) ) ) ;
m_timer = new QTimer ( this ) ;
connect ( m_timer , SIGNAL ( timeout ( ) ) , this , SLOT ( perform ( ) ) ) ;
m_timer - > start ( 1000 ) ;
2013-05-19 16:37:30 +02:00
connect ( USBMonitor : : instance ( ) , SIGNAL ( deviceDiscovered ( USBPortInfo ) ) , & m_eventloop , SLOT ( quit ( ) ) ) ;
2011-06-01 08:31:40 +02:00
m_eventloop . exec ( ) ;
2013-05-19 16:37:30 +02:00
if ( ! m_timer - > isActive ( ) ) {
2011-06-01 08:31:40 +02:00
m_progress - > close ( ) ;
m_timer - > stop ( ) ;
2013-06-02 12:42:15 +02:00
QMessageBox : : warning ( this , tr ( " OpenPilot Uploader " ) , tr ( " No board connection was detected! " ) ) ;
2011-05-27 12:49:15 +02:00
m_config - > rescueButton - > setEnabled ( true ) ;
return ;
}
2011-06-01 08:31:40 +02:00
m_progress - > close ( ) ;
m_timer - > stop ( ) ;
2011-05-27 12:49:15 +02:00
log ( " ... Detecting First Board... " ) ;
repaint ( ) ;
dfu = new DFUObject ( DFU_DEBUG , false , QString ( ) ) ;
dfu - > AbortOperation ( ) ;
2013-05-19 16:37:30 +02:00
if ( ! dfu - > enterDFU ( 0 ) ) {
2011-05-27 12:49:15 +02:00
log ( " Could not enter DFU mode. " ) ;
delete dfu ;
dfu = NULL ;
cm - > resumePolling ( ) ;
m_config - > rescueButton - > setEnabled ( true ) ;
return ;
}
2013-05-19 16:37:30 +02:00
if ( ! dfu - > findDevices ( ) | | ( dfu - > numberOfDevices ! = 1 ) ) {
2011-05-27 12:49:15 +02:00
log ( " Could not detect a board, aborting! " ) ;
delete dfu ;
dfu = NULL ;
cm - > resumePolling ( ) ;
m_config - > rescueButton - > setEnabled ( true ) ;
return ;
}
log ( QString ( " Found " ) + QString : : number ( dfu - > numberOfDevices ) + QString ( " device(s). " ) ) ;
if ( dfu - > numberOfDevices > 5 ) {
log ( " Inconsistent number of devices, aborting! " ) ;
delete dfu ;
dfu = NULL ;
cm - > resumePolling ( ) ;
m_config - > rescueButton - > setEnabled ( true ) ;
return ;
}
2013-05-19 16:37:30 +02:00
for ( int i = 0 ; i < dfu - > numberOfDevices ; i + + ) {
DeviceWidget * dw = new DeviceWidget ( this ) ;
2012-05-07 16:11:51 +02:00
connectSignalSlot ( dw ) ;
2011-05-27 12:49:15 +02:00
dw - > setDeviceID ( i ) ;
dw - > setDfu ( dfu ) ;
dw - > populate ( ) ;
m_config - > systemElements - > addTab ( dw , QString ( " Device " ) + QString : : number ( i ) ) ;
}
m_config - > haltButton - > setEnabled ( false ) ;
m_config - > resetButton - > setEnabled ( false ) ;
2013-04-08 01:09:31 +02:00
bootButtonsSetEnable ( true ) ;
2011-05-27 12:49:15 +02:00
m_config - > rescueButton - > setEnabled ( false ) ;
currentStep = IAP_STATE_BOOTLOADER ; // So that we can boot from the GUI afterwards.
}
2012-09-10 08:57:06 +02:00
2011-05-27 12:49:15 +02:00
void UploaderGadgetWidget : : perform ( )
{
2013-05-19 16:37:30 +02:00
if ( m_progress - > value ( ) = = 19 ) {
2011-06-01 08:31:40 +02:00
m_timer - > stop ( ) ;
m_eventloop . exit ( ) ;
2011-05-27 12:49:15 +02:00
}
2013-05-19 16:37:30 +02:00
m_progress - > setValue ( m_progress - > value ( ) + 1 ) ;
2011-05-27 12:49:15 +02:00
}
2012-10-05 20:55:43 +02:00
void UploaderGadgetWidget : : performAuto ( )
{
+ + autoUpdateConnectTimeout ;
2013-05-19 16:37:30 +02:00
emit autoUpdateSignal ( WAITING_CONNECT , autoUpdateConnectTimeout * 5 ) ;
if ( autoUpdateConnectTimeout = = 20 ) {
2012-10-05 20:55:43 +02:00
m_timer - > stop ( ) ;
m_eventloop . exit ( ) ;
}
}
2011-05-27 12:49:15 +02:00
void UploaderGadgetWidget : : cancel ( )
{
2011-06-01 08:31:40 +02:00
m_timer - > stop ( ) ;
m_eventloop . exit ( ) ;
2011-01-31 22:50:11 +01:00
}
2012-05-07 16:11:51 +02: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 16:11:51 +02: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 16:11:51 +02:00
}
2013-05-19 13:08:50 +02:00
void UploaderGadgetWidget : : startAutoUpdate ( )
{
m_config - > buttonFrame - > setEnabled ( false ) ;
m_config - > splitter - > setEnabled ( false ) ;
m_config - > autoUpdateGroupBox - > setVisible ( true ) ;
m_config - > autoUpdateOkButton - > setEnabled ( false ) ;
connect ( this , SIGNAL ( autoUpdateSignal ( uploader : : AutoUpdateStep , QVariant ) ) , this , SLOT ( autoUpdateStatus ( uploader : : AutoUpdateStep , QVariant ) ) ) ;
autoUpdate ( ) ;
}
void UploaderGadgetWidget : : finishAutoUpdate ( )
{
disconnect ( this , SIGNAL ( autoUpdateSignal ( uploader : : AutoUpdateStep , QVariant ) ) , this , SLOT ( autoUpdateStatus ( uploader : : AutoUpdateStep , QVariant ) ) ) ;
m_config - > autoUpdateOkButton - > setEnabled ( true ) ;
2013-06-25 15:51:33 +02:00
connect ( & autoUpdateCloseTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( closeAutoUpdate ( ) ) ) ;
autoUpdateCloseTimer . start ( AUTOUPDATE_CLOSE_TIMEOUT ) ;
2013-05-19 13:08:50 +02:00
}
void UploaderGadgetWidget : : closeAutoUpdate ( )
{
2013-06-25 15:51:33 +02:00
autoUpdateCloseTimer . stop ( ) ;
disconnect ( & autoUpdateCloseTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( closeAutoUpdate ( ) ) ) ;
2013-05-19 13:08:50 +02:00
m_config - > autoUpdateGroupBox - > setVisible ( false ) ;
m_config - > buttonFrame - > setEnabled ( true ) ;
m_config - > splitter - > setEnabled ( true ) ;
}
void UploaderGadgetWidget : : autoUpdateStatus ( uploader : : AutoUpdateStep status , QVariant value )
{
2013-05-19 23:02:34 +02:00
switch ( status ) {
2013-05-19 13:08:50 +02:00
case uploader : : WAITING_DISCONNECT :
m_config - > autoUpdateLabel - > setText ( " Waiting for all OpenPilot boards to be disconnected from USB. " ) ;
break ;
case uploader : : WAITING_CONNECT :
m_config - > autoUpdateLabel - > setText ( " Please connect the OpenPilot board to the USB port. " ) ;
m_config - > autoUpdateProgressBar - > setValue ( value . toInt ( ) ) ;
break ;
case uploader : : JUMP_TO_BL :
m_config - > autoUpdateProgressBar - > setValue ( 0 ) ;
m_config - > autoUpdateLabel - > setText ( " Bringing the board into boot loader mode. " ) ;
break ;
case uploader : : LOADING_FW :
m_config - > autoUpdateLabel - > setText ( " Preparing to upload firmware to the board. " ) ;
break ;
case uploader : : UPLOADING_FW :
m_config - > autoUpdateLabel - > setText ( " Uploading firmware to the board. " ) ;
m_config - > autoUpdateProgressBar - > setValue ( value . toInt ( ) ) ;
break ;
case uploader : : UPLOADING_DESC :
m_config - > autoUpdateLabel - > setText ( " Uploading description of the new firmware to the board. " ) ;
break ;
case uploader : : BOOTING :
m_config - > autoUpdateLabel - > setText ( " Rebooting the board. " ) ;
break ;
case uploader : : SUCCESS :
m_config - > autoUpdateLabel - > setText ( " <font color='green'>Board was updated successfully, press OK to finish.</font> " ) ;
finishAutoUpdate ( ) ;
break ;
case uploader : : FAILURE :
m_config - > autoUpdateLabel - > setText ( " <font color='red'>Something went wrong, you will have to manually upgrade the board. Press OK to continue.</font> " ) ;
finishAutoUpdate ( ) ;
break ;
}
}
2011-01-31 22:50:11 +01:00
/**
2013-05-19 16:37:30 +02:00
Update log entry
*/
2011-01-31 22:50:11 +01:00
void UploaderGadgetWidget : : log ( QString str )
{
2013-05-19 16:37:30 +02:00
qDebug ( ) < < str ;
m_config - > textBrowser - > append ( str ) ;
m_config - > textBrowser - > repaint ( ) ;
2011-01-31 22:50:11 +01:00
}
void UploaderGadgetWidget : : clearLog ( )
{
m_config - > textBrowser - > clear ( ) ;
}
/**
2013-05-19 16:37:30 +02:00
* Remove all the device widgets . . .
*/
2011-01-31 22:50:11 +01:00
UploaderGadgetWidget : : ~ UploaderGadgetWidget ( )
{
while ( m_config - > systemElements - > count ( ) ) {
2013-05-19 16:37:30 +02:00
QWidget * qw = m_config - > systemElements - > widget ( 0 ) ;
m_config - > systemElements - > removeTab ( 0 ) ;
delete qw ;
qw = 0 ;
2011-06-01 08:31:40 +02:00
}
if ( m_progress ) {
delete m_progress ;
m_progress = 0 ;
}
if ( m_timer ) {
delete m_timer ;
m_timer = 0 ;
2011-01-31 22:50:11 +01:00
}
}
/**
2013-05-19 16:37:30 +02:00
Shows a message box with an error string .
2011-01-31 22:50:11 +01:00
2013-05-19 16:37:30 +02:00
@ param errorString The error string to display .
2011-01-31 22:50:11 +01:00
2013-05-19 16:37:30 +02:00
@ param errorNumber Not used
2011-01-31 22:50:11 +01:00
2013-05-19 16:37:30 +02:00
*/
2011-01-31 22:50:11 +01:00
void UploaderGadgetWidget : : error ( QString errorString , int errorNumber )
{
Q_UNUSED ( errorNumber ) ;
QMessageBox msgBox ;
msgBox . setIcon ( QMessageBox : : Critical ) ;
msgBox . setText ( errorString ) ;
msgBox . exec ( ) ;
m_config - > boardStatus - > setText ( errorString ) ;
}
2013-01-24 03:53:24 +01:00
2011-01-31 22:50:11 +01:00
/**
2013-05-19 16:37:30 +02:00
Shows a message box with an information string .
2011-01-31 22:50:11 +01:00
2013-05-19 16:37:30 +02:00
@ param infoString The information string to display .
2011-01-31 22:50:11 +01:00
2013-05-19 16:37:30 +02:00
@ param infoNumber Not used
2011-01-31 22:50:11 +01:00
2013-05-19 16:37:30 +02:00
*/
2011-01-31 22:50:11 +01:00
void UploaderGadgetWidget : : info ( QString infoString , int infoNumber )
{
Q_UNUSED ( infoNumber ) ;
m_config - > boardStatus - > setText ( infoString ) ;
}
2011-11-13 17:05:36 +01:00
void UploaderGadgetWidget : : versionMatchCheck ( )
{
ExtensionSystem : : PluginManager * pm = ExtensionSystem : : PluginManager : : instance ( ) ;
2013-05-19 16:37:30 +02:00
UAVObjectUtilManager * utilMngr = pm - > getObject < UAVObjectUtilManager > ( ) ;
2012-01-15 14:36:52 +01:00
deviceDescriptorStruct boardDescription = utilMngr - > getBoardDescriptionStruct ( ) ;
2012-09-17 18:08:15 +02:00
QByteArray uavoHashArray ;
2013-05-25 16:40:58 +02:00
QString uavoHash = VersionInfo : : uavoHashArray ( ) ;
2013-05-19 16:37:30 +02:00
2013-09-15 23:06:25 +02:00
2012-09-17 18:08:15 +02:00
uavoHash . chop ( 2 ) ;
2013-05-19 16:37:30 +02:00
uavoHash . remove ( 0 , 2 ) ;
uavoHash = uavoHash . trimmed ( ) ;
2012-09-17 18:08:15 +02:00
bool ok ;
2013-05-19 16:37:30 +02:00
foreach ( QString str , uavoHash . split ( " , " ) ) {
uavoHashArray . append ( str . toInt ( & ok , 16 ) ) ;
2012-09-17 18:08:15 +02:00
}
2012-09-16 00:02:45 +02:00
2013-05-19 16:37:30 +02:00
QByteArray fwVersion = boardDescription . uavoHash ;
2012-09-17 18:08:15 +02:00
if ( fwVersion ! = uavoHashArray ) {
2013-05-18 14:28:46 +02:00
QString gcsDescription = VersionInfo : : revision ( ) ;
2013-05-19 16:37:30 +02:00
QString gcsGitHash = gcsDescription . mid ( gcsDescription . indexOf ( " : " ) + 1 , 8 ) ;
gcsGitHash . remove ( QRegExp ( " ^[0]* " ) ) ;
QString gcsGitDate = gcsDescription . mid ( gcsDescription . indexOf ( " " ) + 1 , 14 ) ;
2012-09-18 14:51:44 +02:00
QString gcsUavoHashStr ;
QString fwUavoHashStr ;
2013-05-19 16:37:30 +02:00
foreach ( char i , fwVersion ) {
fwUavoHashStr . append ( QString : : number ( i , 16 ) . right ( 2 ) ) ;
2012-09-17 18:08:15 +02:00
}
2013-05-19 16:37:30 +02:00
foreach ( char i , uavoHashArray ) {
gcsUavoHashStr . append ( QString : : number ( i , 16 ) . right ( 2 ) ) ;
2012-09-17 18:08:15 +02:00
}
2013-05-19 16:37:30 +02:00
QString gcsVersion = gcsGitDate + " ( " + gcsGitHash + " - " + gcsUavoHashStr . left ( 8 ) + " ) " ;
QString fwVersion = boardDescription . gitDate + " ( " + boardDescription . gitHash + " - " + fwUavoHashStr . left ( 8 ) + " ) " ;
2012-09-18 14:51:44 +02:00
2013-05-19 16:37:30 +02:00
QString warning = QString ( tr (
" GCS and firmware versions of the UAV objects set do not match which can cause configuration problems. "
" GCS version: %1 Firmware version: %2. " ) ) . arg ( gcsVersion ) . arg ( fwVersion ) ;
2012-01-15 14:36:52 +01:00
msg - > showMessage ( warning ) ;
2011-11-13 18:39:05 +01:00
}
2012-10-01 21:50:00 +02:00
}
2012-01-09 17:35:35 +01:00
void UploaderGadgetWidget : : openHelp ( )
{
2013-05-19 16:37:30 +02:00
QDesktopServices : : openUrl ( QUrl ( " http://wiki.openpilot.org/x/AoBZ " , QUrl : : StrictMode ) ) ;
2012-01-09 17:35:35 +01:00
}