LP-106 Setup Wizard refresh : Add dual servo setup (dual aileron or
[librepilot.git] / ground / gcs / src / plugins / telemetry / telemetryplugin.cpp
blob07725ea3540976e11442712a091d5339e5f55d91
1 /**
2 ******************************************************************************
4 * @file telemetryplugin.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @brief
7 * @see The GNU Public License (GPL) Version 3
8 * @defgroup telemetryplugin
9 * @{
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
21 * for more details.
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 #include "telemetryplugin.h"
29 #include "monitorgadgetfactory.h"
31 #include "version_info/version_info.h"
32 #include "uavobjectmanager.h"
33 #include "uavobject.h"
34 #include "uavobjectutilmanager.h"
36 #include <extensionsystem/pluginmanager.h>
37 #include <extensionsystem/pluginmanager.h>
38 #include <coreplugin/icore.h>
39 #include <coreplugin/iuavgadget.h>
40 #include <coreplugin/connectionmanager.h>
41 #include <uavtalk/telemetrymanager.h>
43 #include <QDebug>
44 #include <QStringList>
45 #include <QWidget>
46 #include <QMainWindow>
47 #include <QMessageBox>
48 #include <QCheckBox>
50 TelemetryPlugin::TelemetryPlugin() : firmwareWarningMessageBox(0)
53 TelemetryPlugin::~TelemetryPlugin()
55 // Core::ICore::instance()->saveSettings(this);
58 bool TelemetryPlugin::initialize(const QStringList & args, QString *errMsg)
60 Q_UNUSED(args);
61 Q_UNUSED(errMsg);
63 MonitorGadgetFactory *mf = new MonitorGadgetFactory(this);
64 addAutoReleasedObject(mf);
66 // mop = new TelemetryPluginOptionsPage(this);
67 // addAutoReleasedObject(mop);
69 // TODO not so good... g is probalby leaked...
70 MonitorWidget *w = mf->createMonitorWidget(NULL);
71 w->setMaximumWidth(195);
73 // no border
74 w->setFrameStyle(QFrame::NoFrame);
75 w->setWindowFlags(Qt::FramelessWindowHint);
77 w->setBackgroundBrush(Qt::NoBrush);
79 // add monitor widget to connection manager
80 Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
82 cm->addWidget(w);
84 // Listen to autopilot connection events
85 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
86 TelemetryManager *telMngr = pm->getObject<TelemetryManager>();
87 connect(telMngr, SIGNAL(connected()), this, SLOT(versionMatchCheck()));
89 return true;
92 void TelemetryPlugin::extensionsInitialized()
94 // Do nothing
97 void TelemetryPlugin::shutdown()
99 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
100 TelemetryManager *telMngr = pm->getObject<TelemetryManager>();
102 disconnect(telMngr, SIGNAL(connected()), this, SLOT(versionMatchCheck()));
104 if (firmwareWarningMessageBox) {
105 delete firmwareWarningMessageBox;
109 void TelemetryPlugin::versionMatchCheck()
111 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
112 UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
113 deviceDescriptorStruct boardDescription = utilMngr->getBoardDescriptionStruct();
115 QString uavoHash = VersionInfo::uavoHashArray();
117 uavoHash.chop(2);
118 uavoHash.remove(0, 2);
119 uavoHash = uavoHash.trimmed();
121 QByteArray uavoHashArray;
122 bool ok;
123 foreach(QString str, uavoHash.split(",")) {
124 uavoHashArray.append(str.toInt(&ok, 16));
127 QByteArray fwVersion = boardDescription.uavoHash;
128 if (fwVersion != uavoHashArray) {
129 QString gcsDescription = VersionInfo::revision();
130 QString gcsGitHash = gcsDescription.mid(gcsDescription.indexOf(":") + 1, 8);
131 gcsGitHash.remove(QRegExp("^[0]*"));
132 QString gcsGitDate = gcsDescription.mid(gcsDescription.indexOf(" ") + 1, 14);
134 QString gcsUavoHashStr;
135 QString fwUavoHashStr;
136 foreach(char i, fwVersion) {
137 fwUavoHashStr.append(QString::number(i, 16).right(2));
139 foreach(char i, uavoHashArray) {
140 gcsUavoHashStr.append(QString::number(i, 16).right(2));
142 QString versionFormat = "%1 (%2-%3)";
143 QString gcsVersion = versionFormat.arg(gcsGitDate, gcsGitHash, gcsUavoHashStr.left(8));
144 QString fwVersion = versionFormat.arg(boardDescription.gitDate, boardDescription.gitHash, fwUavoHashStr.left(8));
146 if (!firmwareWarningMessageBox) {
147 firmwareWarningMessageBox = new QMessageBox(Core::ICore::instance()->mainWindow());
148 firmwareWarningMessageBox->setWindowModality(Qt::NonModal);
149 firmwareWarningMessageBox->setWindowTitle(tr("Firmware Version Mismatch!"));
150 firmwareWarningMessageBox->setIcon(QMessageBox::Warning);
151 firmwareWarningMessageBox->setStandardButtons(QMessageBox::Ok);
152 firmwareWarningMessageBox->setText(tr("GCS and firmware versions of the UAV objects set do not match which can cause configuration problems."));
153 // should we want to re-introduce the checkbox
154 // firmwareWarningMessageBox->setCheckBox(new QCheckBox(tr("&Don't show this message again.")));
156 QString detailTxt = tr("GCS version: %1").arg(gcsVersion) + "\n" + tr("Firmware version: %1").arg(fwVersion);
157 firmwareWarningMessageBox->setDetailedText(detailTxt);
158 firmwareWarningMessageBox->show();