From 40dcd94b5c2f8a72d1ac2fe7142189c2c49c171c Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Fri, 2 May 2014 23:36:05 +0200 Subject: [PATCH] OP-1174 OP-1131 moved firmware version check from uploader gadget to uploader plugin. This ensures that the check is always done even if the uploader gadget is not displayed. --- .../plugins/uploader/uploadergadgetwidget.cpp | 61 +++------------ .../plugins/uploader/uploadergadgetwidget.h | 34 ++------- .../src/plugins/uploader/uploaderplugin.cpp | 74 +++++++++++++++++-- .../src/plugins/uploader/uploaderplugin.h | 6 ++ 4 files changed, 92 insertions(+), 83 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp index a7ce9534e..6ac8ee539 100644 --- a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp @@ -25,12 +25,20 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "uploadergadgetwidget.h" -#include "version_info/version_info.h" -#include "flightstatus.h" +#include "flightstatus.h" +//#include "delay.h" +#include "devicewidget.h" +#include "runningdevicewidget.h" + +#include +#include #include +#include #include +#include +#include #include #include @@ -125,14 +133,11 @@ UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent) currentStep = IAP_STATE_READY; resetOnly = false; dfu = NULL; - msg = new QErrorMessage(this); // Listen to autopilot connection events ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); TelemetryManager *telMngr = pm->getObject(); connect(telMngr, SIGNAL(connected()), this, SLOT(onAutopilotConnect())); - connect(telMngr, SIGNAL(connected()), this, SLOT(versionMatchCheck())); - connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect())); connect(m_config->haltButton, SIGNAL(clicked()), this, SLOT(systemHalt())); @@ -162,7 +167,6 @@ UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent) // And check whether by any chance we are not already connected if (telMngr->isConnected()) { onAutopilotConnect(); - versionMatchCheck(); } } @@ -459,10 +463,9 @@ void UploaderGadgetWidget::goToBootloader(UAVObject *callerObj, bool success) void UploaderGadgetWidget::systemHalt() { - FlightStatus *status = getFlightStatus(); - // The board can not be halted when in armed state. // If board is armed, or arming. Show message with notice. + FlightStatus *status = getFlightStatus(); if (status->getArmed() == FlightStatus::ARMED_DISARMED) { goToBootloader(); } else { @@ -1024,48 +1027,6 @@ void UploaderGadgetWidget::info(QString infoString, int infoNumber) m_config->boardStatus->setText(infoString); } -void UploaderGadgetWidget::versionMatchCheck() -{ - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectUtilManager *utilMngr = pm->getObject(); - deviceDescriptorStruct boardDescription = utilMngr->getBoardDescriptionStruct(); - QByteArray uavoHashArray; - QString uavoHash = VersionInfo::uavoHashArray(); - - - uavoHash.chop(2); - uavoHash.remove(0, 2); - uavoHash = uavoHash.trimmed(); - bool ok; - foreach(QString str, uavoHash.split(",")) { - uavoHashArray.append(str.toInt(&ok, 16)); - } - - QByteArray fwVersion = boardDescription.uavoHash; - if (fwVersion != uavoHashArray) { - QString gcsDescription = VersionInfo::revision(); - QString gcsGitHash = gcsDescription.mid(gcsDescription.indexOf(":") + 1, 8); - gcsGitHash.remove(QRegExp("^[0]*")); - QString gcsGitDate = gcsDescription.mid(gcsDescription.indexOf(" ") + 1, 14); - - QString gcsUavoHashStr; - QString fwUavoHashStr; - foreach(char i, fwVersion) { - fwUavoHashStr.append(QString::number(i, 16).right(2)); - } - foreach(char i, uavoHashArray) { - gcsUavoHashStr.append(QString::number(i, 16).right(2)); - } - QString gcsVersion = gcsGitDate + " (" + gcsGitHash + "-" + gcsUavoHashStr.left(8) + ")"; - QString fwVersion = boardDescription.gitDate + " (" + boardDescription.gitHash + "-" + fwUavoHashStr.left(8) + ")"; - - 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); - msg->showMessage(warning); - } -} - void UploaderGadgetWidget::openHelp() { QDesktopServices::openUrl(QUrl("http://wiki.openpilot.org/x/AoBZ", QUrl::StrictMode)); diff --git a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.h b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.h index 97a3abd06..153d94051 100644 --- a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.h @@ -29,38 +29,18 @@ #define UPLOADERGADGETWIDGET_H #include "ui_uploader.h" -#include "delay.h" -#include "devicewidget.h" -#include "runningdevicewidget.h" -#include "op_dfu.h" -#include -#include - -#include "extensionsystem/pluginmanager.h" -#include "uavobjectmanager.h" -#include "uavobject.h" - -#include "coreplugin/icore.h" -#include "coreplugin/connectionmanager.h" - -#include "ophid/inc/ophid_plugin.h" -#include -#include -#include -#include -#include -#include -#include "devicedescriptorstruct.h" -#include -#include -#include #include "uploader_global.h" + #include "enums.h" +#include "op_dfu.h" + +#include using namespace OP_DFU; using namespace uploader; class FlightStatus; +class UAVObject; class TimedDialog: public QProgressDialog { Q_OBJECT @@ -119,6 +99,7 @@ public: ~UploaderGadgetWidget(); static const int BOARD_EVENT_TIMEOUT; + static const int AUTOUPDATE_CLOSE_TIMEOUT; void log(QString str); bool autoUpdateCapable(); @@ -144,15 +125,12 @@ private: void clearLog(); QString getPortDevice(const QString &friendName); QLineEdit *openFileNameLE; - QErrorMessage *msg; void connectSignalSlot(QWidget *widget); FlightStatus *getFlightStatus(); void bootButtonsSetEnable(bool enabled); - static const int AUTOUPDATE_CLOSE_TIMEOUT; private slots: void onPhysicalHWConnect(); - void versionMatchCheck(); void error(QString errorString, int errorNumber); void info(QString infoString, int infoNumber); void goToBootloader(UAVObject * = NULL, bool = false); diff --git a/ground/openpilotgcs/src/plugins/uploader/uploaderplugin.cpp b/ground/openpilotgcs/src/plugins/uploader/uploaderplugin.cpp index e58a1eee6..7c4122656 100644 --- a/ground/openpilotgcs/src/plugins/uploader/uploaderplugin.cpp +++ b/ground/openpilotgcs/src/plugins/uploader/uploaderplugin.cpp @@ -26,11 +26,21 @@ */ #include "uploaderplugin.h" #include "uploadergadgetfactory.h" -#include -#include -#include -UploaderPlugin::UploaderPlugin() +#include "version_info/version_info.h" +#include "devicedescriptorstruct.h" +#include "uavobjectutilmanager.h" + +#include +#include +#include + +#include +#include +#include +#include + +UploaderPlugin::UploaderPlugin() : errorMsg(0) { // Do nothing } @@ -44,8 +54,15 @@ bool UploaderPlugin::initialize(const QStringList & args, QString *errMsg) { Q_UNUSED(args); Q_UNUSED(errMsg); + mf = new UploaderGadgetFactory(this); addAutoReleasedObject(mf); + + // Listen to autopilot connection events + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + TelemetryManager *telMngr = pm->getObject(); + connect(telMngr, SIGNAL(connected()), this, SLOT(versionMatchCheck())); + return true; } @@ -56,5 +73,52 @@ void UploaderPlugin::extensionsInitialized() void UploaderPlugin::shutdown() { - // Do nothing + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + TelemetryManager *telMngr = pm->getObject(); + disconnect(telMngr, SIGNAL(connected()), this, SLOT(versionMatchCheck())); +} + +void UploaderPlugin::versionMatchCheck() +{ + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + UAVObjectUtilManager *utilMngr = pm->getObject(); + deviceDescriptorStruct boardDescription = utilMngr->getBoardDescriptionStruct(); + + QString uavoHash = VersionInfo::uavoHashArray(); + uavoHash.chop(2); + uavoHash.remove(0, 2); + uavoHash = uavoHash.trimmed(); + + QByteArray uavoHashArray; + bool ok; + foreach(QString str, uavoHash.split(",")) { + uavoHashArray.append(str.toInt(&ok, 16)); + } + + QByteArray fwVersion = 0;//boardDescription.uavoHash; + if (fwVersion != uavoHashArray) { + QString gcsDescription = VersionInfo::revision(); + QString gcsGitHash = gcsDescription.mid(gcsDescription.indexOf(":") + 1, 8); + gcsGitHash.remove(QRegExp("^[0]*")); + QString gcsGitDate = gcsDescription.mid(gcsDescription.indexOf(" ") + 1, 14); + + QString gcsUavoHashStr; + QString fwUavoHashStr; + foreach(char i, fwVersion) { + fwUavoHashStr.append(QString::number(i, 16).right(2)); + } + foreach(char i, uavoHashArray) { + gcsUavoHashStr.append(QString::number(i, 16).right(2)); + } + QString gcsVersion = gcsGitDate + " (" + gcsGitHash + "-" + gcsUavoHashStr.left(8) + ")"; + QString fwVersion = boardDescription.gitDate + " (" + boardDescription.gitHash + "-" + fwUavoHashStr.left(8) + ")"; + + 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); + if (!errorMsg) { + errorMsg = new QErrorMessage(Core::ICore::instance()->mainWindow()); + } + errorMsg->showMessage(warning); + } } diff --git a/ground/openpilotgcs/src/plugins/uploader/uploaderplugin.h b/ground/openpilotgcs/src/plugins/uploader/uploaderplugin.h index 2fb6a19f9..a30102d39 100644 --- a/ground/openpilotgcs/src/plugins/uploader/uploaderplugin.h +++ b/ground/openpilotgcs/src/plugins/uploader/uploaderplugin.h @@ -32,6 +32,7 @@ #include "uploader_global.h" class UploaderGadgetFactory; +class QErrorMessage; class UPLOADER_EXPORT UploaderPlugin : public ExtensionSystem::IPlugin { Q_OBJECT @@ -44,8 +45,13 @@ public: void extensionsInitialized(); bool initialize(const QStringList & arguments, QString *errorString); void shutdown(); + +private slots: + void versionMatchCheck(); + private: UploaderGadgetFactory *mf; + QErrorMessage *errorMsg; }; #endif // UPLOADERPLUGIN_H