2 ******************************************************************************
4 * @file uploadergadgetwidget.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup YModemUploader YModem Serial Uploader Plugin
10 * @brief The YModem protocol serial uploader plugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef UPLOADERGADGETWIDGET_H
29 #define UPLOADERGADGETWIDGET_H
31 #include "ui_uploader.h"
32 #include "uploader_global.h"
37 #include <QProgressDialog>
38 #include "oplinkwatchdog.h"
40 using namespace OP_DFU
;
41 using namespace uploader
;
48 class TimedDialog
: public QProgressDialog
{
52 TimedDialog(const QString
&title
, const QString
&labelText
, int timeout
, QWidget
*parent
= 0, Qt::WindowFlags flags
= 0);
61 // A helper class to wait for board connection and disconnection events
62 // until a the desired number of connected boards is found
63 // or until a timeout is reached
64 class ConnectionWaiter
: public QObject
{
68 ConnectionWaiter(int targetDeviceCount
, int timeout
, QWidget
*parent
= 0);
70 enum ResultCode
{ Ok
, Canceled
, TimedOut
};
77 static int openDialog(const QString
&title
, const QString
&labelText
, int targetDeviceCount
, int timeout
, QWidget
*parent
= 0, Qt::WindowFlags flags
= 0);
80 void timeChanged(int elapsed
);
91 // elapsed time in seconds
93 int targetDeviceCount
;
97 class ResultEventLoop
: public QEventLoop
{
100 int run(int millisTimout
);
110 class UPLOADER_EXPORT UploaderGadgetWidget
: public QWidget
{
114 UploaderGadgetWidget(QWidget
*parent
= 0);
115 ~UploaderGadgetWidget();
117 static const int BOARD_EVENT_TIMEOUT
;
118 static const int AUTOUPDATE_CLOSE_TIMEOUT
;
119 static const int REBOOT_TIMEOUT
;
120 static const int ERASE_TIMEOUT
;
121 static const int BOOTLOADER_TIMEOUT
;
123 void log(QString str
);
124 bool autoUpdateCapable();
127 void onAutopilotConnect();
128 void onAutopilotDisconnect();
131 void autoUpdateDisconnectProgress(int);
132 void autoUpdateConnectProgress(int);
133 void autoUpdateFlashProgress(int);
136 void progressUpdate(uploader::ProgressStep
, QVariant
);
137 void bootloaderFailed();
138 void bootloaderSuccess();
141 void autoUpdateFailed();
142 void autoUpdateSuccess();
145 Ui_UploaderWidget
*m_config
;
147 IAPStep m_currentIAPStep
;
149 OPLinkWatchdog m_oplinkwatchdog
;
150 bool m_autoUpdateClosing
;
153 QString
getPortDevice(const QString
&friendName
);
154 void connectSignalSlot(QWidget
*widget
);
155 FlightStatus
*getFlightStatus();
156 void bootButtonsSetEnable(bool enabled
);
157 int confirmEraseSettingsMessageBox();
158 int cannotHaltMessageBox();
159 int cannotResetMessageBox();
160 void startAutoUpdate(bool erase
);
163 void onPhysicalHWConnect();
164 void goToBootloader(UAVObject
* = NULL
, bool = false);
168 void systemSafeBoot();
169 void systemEraseBoot();
170 void rebootWithDialog();
172 void commonSystemBoot(bool safeboot
= false, bool erase
= false);
174 void getSerialPorts();
175 void uploadStarted();
176 void uploadEnded(bool succeed
);
177 void downloadStarted();
178 void downloadEnded(bool succeed
);
179 void startAutoUpdate();
180 void startAutoUpdateErase();
181 bool autoUpdate(bool erase
);
182 void finishAutoUpdate();
183 void closeAutoUpdate();
184 void autoUpdateStatus(uploader::ProgressStep status
, QVariant value
);
187 #endif // UPLOADERGADGETWIDGET_H