2013-04-28 19:41:15 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file telemetryplugin.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @brief
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
* @defgroup telemetryplugin
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* 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 "telemetryplugin.h"
|
|
|
|
#include "monitorgadgetfactory.h"
|
|
|
|
|
|
|
|
#include "extensionsystem/pluginmanager.h"
|
|
|
|
#include "uavobjectmanager.h"
|
|
|
|
#include "uavobject.h"
|
|
|
|
#include "coreplugin/icore.h"
|
|
|
|
#include "coreplugin/connectionmanager.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QtPlugin>
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
#include <coreplugin/iuavgadget.h>
|
|
|
|
|
|
|
|
TelemetryPlugin::TelemetryPlugin()
|
2013-12-02 23:47:27 +01:00
|
|
|
{}
|
2013-04-28 19:41:15 +02:00
|
|
|
|
|
|
|
TelemetryPlugin::~TelemetryPlugin()
|
|
|
|
{
|
2013-12-02 23:47:27 +01:00
|
|
|
// Core::ICore::instance()->saveSettings(this);
|
2013-04-28 19:41:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TelemetryPlugin::initialize(const QStringList & args, QString *errMsg)
|
|
|
|
{
|
|
|
|
Q_UNUSED(args);
|
|
|
|
Q_UNUSED(errMsg);
|
|
|
|
|
|
|
|
MonitorGadgetFactory *mf = new MonitorGadgetFactory(this);
|
|
|
|
addAutoReleasedObject(mf);
|
|
|
|
|
2013-12-02 23:47:27 +01:00
|
|
|
// mop = new TelemetryPluginOptionsPage(this);
|
|
|
|
// addAutoReleasedObject(mop);
|
2013-04-28 19:41:15 +02:00
|
|
|
|
|
|
|
// TODO not so good... g is probalby leaked...
|
|
|
|
MonitorWidget *w = mf->createMonitorWidget(NULL);
|
|
|
|
w->setMaximumWidth(180);
|
|
|
|
|
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
// setAlignment(Qt::AlignCenter);
|
2013-04-28 19:41:15 +02:00
|
|
|
|
|
|
|
// no border
|
|
|
|
w->setFrameStyle(QFrame::NoFrame);
|
|
|
|
w->setWindowFlags(Qt::FramelessWindowHint);
|
|
|
|
|
|
|
|
// set svg background translucent
|
|
|
|
w->setStyleSheet("background:transparent;");
|
|
|
|
// set widget background translucent
|
|
|
|
w->setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
|
|
|
|
w->setBackgroundBrush(Qt::NoBrush);
|
|
|
|
|
|
|
|
// add monitor widget to connection manager
|
|
|
|
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
2013-12-02 23:47:27 +01:00
|
|
|
// connect(cm, SIGNAL(deviceConnected(QIODevice *)), w, SLOT(telemetryConnected()));
|
|
|
|
// connect(cm, SIGNAL(deviceDisconnected()), w, SLOT(telemetryDisconnected()));
|
2013-04-28 19:41:15 +02:00
|
|
|
|
|
|
|
cm->addWidget(w);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TelemetryPlugin::extensionsInitialized()
|
|
|
|
{
|
2013-12-02 23:47:27 +01:00
|
|
|
// Core::ICore::instance()->readSettings(this);
|
2013-04-28 19:41:15 +02:00
|
|
|
|
2013-12-02 23:47:27 +01:00
|
|
|
// ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
2013-04-28 19:41:15 +02:00
|
|
|
|
2013-12-02 23:47:27 +01:00
|
|
|
// connect(pm, SIGNAL(objectAdded(QObject *)), this, SLOT(onTelemetryManagerAdded(QObject *)));
|
|
|
|
// _toRemoveNotifications.clear();
|
|
|
|
// connectNotifications();
|
2013-04-28 19:41:15 +02:00
|
|
|
}
|
|
|
|
|
2013-12-02 23:47:27 +01:00
|
|
|
// void TelemetryPlugin::saveConfig(QSettings *settings, UAVConfigInfo *configInfo)
|
|
|
|
// {
|
|
|
|
// configInfo->setVersion(VERSION);
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
// settings->beginWriteArray("Current");
|
|
|
|
// settings->setArrayIndex(0);
|
|
|
|
// currentNotification.saveState(settings);
|
|
|
|
// settings->endArray();
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
// settings->beginGroup("listNotifies");
|
|
|
|
// settings->remove("");
|
|
|
|
// settings->endGroup();
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
// settings->beginWriteArray("listNotifies");
|
|
|
|
// for (int i = 0; i < _notificationList.size(); i++) {
|
|
|
|
// settings->setArrayIndex(i);
|
|
|
|
// _notificationList.at(i)->saveState(settings);
|
|
|
|
// }
|
|
|
|
// settings->endArray();
|
|
|
|
// settings->setValue(QLatin1String("Enable"), enable);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// void TelemetryPlugin::readConfig(QSettings *settings, UAVConfigInfo * /* configInfo */)
|
|
|
|
// {
|
|
|
|
//// Just for migration to the new format.
|
|
|
|
//// Q_ASSERT(configInfo->version() == UAVConfigVersion());
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
// settings->beginReadArray("Current");
|
|
|
|
// settings->setArrayIndex(0);
|
|
|
|
// currentNotification.restoreState(settings);
|
|
|
|
// settings->endArray();
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
//// read list of notifications from settings
|
|
|
|
// int size = settings->beginReadArray("listNotifies");
|
|
|
|
// for (int i = 0; i < size; ++i) {
|
|
|
|
// settings->setArrayIndex(i);
|
|
|
|
// NotificationItem *notification = new NotificationItem;
|
|
|
|
// notification->restoreState(settings);
|
|
|
|
// _notificationList.append(notification);
|
|
|
|
// }
|
|
|
|
// settings->endArray();
|
|
|
|
// setEnable(settings->value(QLatin1String("Enable"), 0).toBool());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// void TelemetryPlugin::onTelemetryManagerAdded(QObject *obj)
|
|
|
|
// {
|
|
|
|
// telMngr = qobject_cast<TelemetryManager *>(obj);
|
|
|
|
// if (telMngr) {
|
|
|
|
// connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect()));
|
|
|
|
// }
|
|
|
|
// }
|
2013-04-28 19:41:15 +02:00
|
|
|
|
|
|
|
void TelemetryPlugin::shutdown()
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
2013-12-02 23:47:27 +01:00
|
|
|
// void TelemetryPlugin::onAutopilotDisconnect()
|
|
|
|
// {
|
|
|
|
// connectNotifications();
|
|
|
|
// }
|
2013-04-28 19:41:15 +02:00
|
|
|
|
|
|
|
///*!
|
2013-12-02 23:47:27 +01:00
|
|
|
// clear any telemetry timers from previous flight;
|
|
|
|
// reset will be perform on start of option page
|
2013-04-28 19:41:15 +02:00
|
|
|
// */
|
2013-12-02 23:47:27 +01:00
|
|
|
// void TelemetryPlugin::resetNotification(void)
|
|
|
|
// {
|
|
|
|
//// first, reject empty args and unknown fields.
|
|
|
|
// foreach(NotificationItem * ntf, _notificationList) {
|
|
|
|
// ntf->disposeTimer();
|
|
|
|
// disconnect(ntf->getTimer(), SIGNAL(timeout()), this, SLOT(on_timerRepeated_Notification()));
|
|
|
|
// ntf->disposeExpireTimer();
|
|
|
|
// disconnect(ntf->getExpireTimer(), SIGNAL(timeout()), this, SLOT(on_timerRepeated_Notification()));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// void TelemetryPlugin::connectNotifications()
|
|
|
|
// {
|
|
|
|
// foreach(UAVDataObject * obj, lstNotifiedUAVObjects) {
|
|
|
|
// if (obj != NULL) {
|
|
|
|
// disconnect(obj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(on_arrived_Notification(UAVObject *)));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// if (phonon.mo != NULL) {
|
|
|
|
// delete phonon.mo;
|
|
|
|
// phonon.mo = NULL;
|
|
|
|
// }
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
// if (!enable) {
|
|
|
|
// return;
|
|
|
|
// }
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
// ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
// UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
// lstNotifiedUAVObjects.clear();
|
|
|
|
// _pendingNotifications.clear();
|
|
|
|
// _notificationList.append(_toRemoveNotifications);
|
|
|
|
// _toRemoveNotifications.clear();
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
//// first, reject empty args and unknown fields.
|
|
|
|
// foreach(NotificationItem * telemetry, _notificationList) {
|
|
|
|
// telemetry->_isPlayed = false;
|
|
|
|
// telemetry->isNowPlaying = false;
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
// if (telemetry->mute()) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
//// check is all sounds presented for notification,
|
|
|
|
//// if not - we must not subscribe to it at all
|
|
|
|
// if (telemetry->toList().isEmpty()) {
|
|
|
|
// continue;
|
|
|
|
// }
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
// UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(telemetry->getDataObject()));
|
|
|
|
// if (obj != NULL) {
|
|
|
|
// if (!lstNotifiedUAVObjects.contains(obj)) {
|
|
|
|
// lstNotifiedUAVObjects.append(obj);
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
// connect(obj, SIGNAL(objectUpdated(UAVObject *)),
|
|
|
|
// this, SLOT(on_arrived_Notification(UAVObject *)),
|
|
|
|
// Qt::QueuedConnection);
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// qTelemetryDebug() << "Error: Object is unknown (" << telemetry->getDataObject() << ").";
|
|
|
|
// }
|
|
|
|
// }
|
2013-04-28 19:41:15 +02:00
|
|
|
//
|
2013-12-02 23:47:27 +01:00
|
|
|
// if (_notificationList.isEmpty()) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//// set notification message to current event
|
|
|
|
// phonon.mo = Phonon::createPlayer(Phonon::NotificationCategory);
|
|
|
|
// phonon.mo->clearQueue();
|
|
|
|
// phonon.firstPlay = true;
|
|
|
|
// QList<Phonon::AudioOutputDevice> audioOutputDevices =
|
|
|
|
// Phonon::BackendCapabilities::availableAudioOutputDevices();
|
|
|
|
// foreach(Phonon::AudioOutputDevice dev, audioOutputDevices) {
|
|
|
|
// qTelemetryDebug() << "Telemetry: Audio Output device: " << dev.name() << " - " << dev.description();
|
|
|
|
// }
|
|
|
|
// connect(phonon.mo, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
|
|
|
|
// this, SLOT(stateChanged(Phonon::State, Phonon::State)));
|
|
|
|
// }
|