mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-27 16:54:15 +01:00
OP-1777 Adding usage tracker plugin and basic functionality.
This commit is contained in:
parent
f5811e7747
commit
867742d102
@ -252,3 +252,11 @@ plugin_flightlog.depends += plugin_uavobjects
|
||||
plugin_flightlog.depends += plugin_uavtalk
|
||||
SUBDIRS += plugin_flightlog
|
||||
|
||||
# Usage Tracker plugin
|
||||
plugin_usagetracker.subdir = usagetracker
|
||||
plugin_usagetracker.depends = plugin_coreplugin
|
||||
plugin_usagetracker.depends += plugin_uavobjects
|
||||
plugin_usagetracker.depends += plugin_uavtalk
|
||||
plugin_setupwizard.depends += plugin_uavobjectutil
|
||||
SUBDIRS += plugin_usagetracker
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
<plugin name="UsageTracker" version="1.0.0" compatVersion="1.0.0">
|
||||
<vendor>The OpenPilot Project</vendor>
|
||||
<copyright>(C) 2015 OpenPilot Project</copyright>
|
||||
<description>A plugin that tracks GCS usage</description>
|
||||
<url>http://www.openpilot.org</url>
|
||||
<dependencyList>
|
||||
<dependency name="Core" version="1.0.0"/>
|
||||
<dependency name="UAVTalk" version="1.0.0"/>
|
||||
<dependency name="UAVObjectUtil" version="1.0.0"/>
|
||||
<dependency name="UAVObjects" version="1.0.0"/>
|
||||
</dependencyList>
|
||||
</plugin>
|
@ -0,0 +1,14 @@
|
||||
|
||||
TEMPLATE = lib
|
||||
TARGET = UsageTracker
|
||||
|
||||
include(../../openpilotgcsplugin.pri)
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(../../plugins/uavobjects/uavobjects.pri)
|
||||
include(../../plugins/uavobjectutil/uavobjectutil.pri)
|
||||
include(../../plugins/uavtalk/uavtalk.pri)
|
||||
|
||||
HEADERS += usagetrackerplugin.h
|
||||
SOURCES += usagetrackerplugin.cpp
|
||||
|
||||
OTHER_FILES += usagetracker.pluginspec
|
@ -0,0 +1,107 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file usagetrackerplugin.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup UsageTrackerPlugin Usage Tracker Plugin
|
||||
* @{
|
||||
* @brief A plugin tracking GCS usage
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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 "usagetrackerplugin.h"
|
||||
#include <QtPlugin>
|
||||
#include <QStringList>
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
#include <QtNetwork/QNetworkRequest>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <QDebug>
|
||||
#include <uavobjectutil/devicedescriptorstruct.h>
|
||||
#include <uavobjectutil/uavobjectutilmanager.h>
|
||||
|
||||
UsageTrackerPlugin::UsageTrackerPlugin() :
|
||||
m_telemetryManager(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
UsageTrackerPlugin::~UsageTrackerPlugin()
|
||||
{
|
||||
}
|
||||
|
||||
bool UsageTrackerPlugin::initialize(const QStringList & args, QString *errMsg)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
Q_UNUSED(errMsg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void UsageTrackerPlugin::extensionsInitialized()
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
m_telemetryManager = pm->getObject<TelemetryManager>();
|
||||
connect(m_telemetryManager, SIGNAL(connected()), this, SLOT(onAutopilotConnect()));
|
||||
}
|
||||
|
||||
void UsageTrackerPlugin::shutdown()
|
||||
{
|
||||
if (m_telemetryManager != NULL) {
|
||||
disconnect(m_telemetryManager, SIGNAL(connected()), this, SLOT(onAutopilotConnect()));
|
||||
}
|
||||
}
|
||||
|
||||
void UsageTrackerPlugin::onAutopilotConnect()
|
||||
{
|
||||
QTimer::singleShot(1000, this, SLOT(trackUsage()));
|
||||
}
|
||||
|
||||
void UsageTrackerPlugin::trackUsage()
|
||||
{
|
||||
QNetworkAccessManager *networkAccessManager = new QNetworkAccessManager();
|
||||
|
||||
// This will delete the network access manager instance when we're done
|
||||
connect(networkAccessManager, SIGNAL(finished(QNetworkReply *)), networkAccessManager, SLOT(deleteLater()));
|
||||
|
||||
QMap<QString, QString> parameters;
|
||||
collectUsageParameters(parameters);
|
||||
|
||||
QUrlQuery query;
|
||||
QMapIterator<QString, QString> iter(parameters);
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
query.addQueryItem(iter.key(), iter.value());
|
||||
}
|
||||
QUrl url("https://www.openpilot.org/opver?" + query.toString());
|
||||
qDebug() << "Sending usage tracking as:" << url.toString();
|
||||
networkAccessManager->get(QNetworkRequest(url));
|
||||
}
|
||||
|
||||
void UsageTrackerPlugin::collectUsageParameters(QMap<QString, QString> ¶meters)
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
|
||||
|
||||
QByteArray description = utilMngr->getBoardDescription();
|
||||
deviceDescriptorStruct devDesc;
|
||||
if (UAVObjectUtilManager::descriptionToStructure(description, devDesc)) {
|
||||
parameters["bt"] = QString("0x%1").arg(QString::number(utilMngr->getBoardModel(),16).toUpper());
|
||||
parameters["bid"] = utilMngr->getBoardCPUSerial().toHex();
|
||||
parameters["bfwt"] = devDesc.gitTag;
|
||||
parameters["bfwh"] = devDesc.gitHash;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file usagetrackerplugin.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup UsageTrackerPlugin Usage Tracker Plugin
|
||||
* @{
|
||||
* @brief A plugin tracking GCS usage
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
#ifndef USAGETRACKERPLUGIN_H
|
||||
#define USAGETRACKERPLUGIN_H
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include <uavtalk/telemetrymanager.h>
|
||||
|
||||
class UsageTrackerPlugin : public ExtensionSystem::IPlugin {
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "OpenPilot.UsageTracker")
|
||||
public:
|
||||
UsageTrackerPlugin();
|
||||
~UsageTrackerPlugin();
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString *errorString);
|
||||
void shutdown();
|
||||
|
||||
private slots:
|
||||
void onAutopilotConnect();
|
||||
void trackUsage();
|
||||
void collectUsageParameters(QMap<QString, QString> ¶meters);
|
||||
|
||||
private:
|
||||
TelemetryManager * m_telemetryManager;
|
||||
};
|
||||
|
||||
#endif // USAGETRACKERPLUGIN_H
|
Loading…
x
Reference in New Issue
Block a user