From 2a9fd99b06b87628a021b5e55e9f530b71d021ec Mon Sep 17 00:00:00 2001 From: peabody124 Date: Tue, 21 Sep 2010 21:43:23 +0000 Subject: [PATCH] Ground/Logging: Support for pausing and resuming playback and time rescaling plus an (ugly) toolbar to control it. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1712 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/logging/logfile.cpp | 21 ++- ground/src/plugins/logging/logfile.h | 10 ++ ground/src/plugins/logging/logging.pro | 20 ++- ground/src/plugins/logging/logging.ui | 144 ++++++++++++++++++ ground/src/plugins/logging/logginggadget.cpp | 47 ++++++ ground/src/plugins/logging/logginggadget.h | 60 ++++++++ .../plugins/logging/logginggadgetfactory.cpp | 49 ++++++ .../plugins/logging/logginggadgetfactory.h | 55 +++++++ .../plugins/logging/logginggadgetwidget.cpp | 68 +++++++++ .../src/plugins/logging/logginggadgetwidget.h | 59 +++++++ ground/src/plugins/logging/loggingplugin.cpp | 27 ++-- ground/src/plugins/logging/loggingplugin.h | 10 +- 12 files changed, 545 insertions(+), 25 deletions(-) create mode 100644 ground/src/plugins/logging/logging.ui create mode 100644 ground/src/plugins/logging/logginggadget.cpp create mode 100644 ground/src/plugins/logging/logginggadget.h create mode 100644 ground/src/plugins/logging/logginggadgetfactory.cpp create mode 100644 ground/src/plugins/logging/logginggadgetfactory.h create mode 100644 ground/src/plugins/logging/logginggadgetwidget.cpp create mode 100644 ground/src/plugins/logging/logginggadgetwidget.h diff --git a/ground/src/plugins/logging/logfile.cpp b/ground/src/plugins/logging/logfile.cpp index 6072de049..fe5817fcc 100644 --- a/ground/src/plugins/logging/logfile.cpp +++ b/ground/src/plugins/logging/logfile.cpp @@ -63,8 +63,8 @@ void LogFile::timerFired() { qint64 dataSize; - // TODO: support time rescaling and seeking - while (myTime.elapsed() > lastTimeStamp) { + // TODO: going back in time will be a problem + while ((myTime.elapsed() - timeOffset) * playbackSpeed > lastTimeStamp) { file.read((char *) &dataSize, sizeof(dataSize)); dataBuffer.append(file.read(dataSize)); emit readyRead(); @@ -76,9 +76,9 @@ void LogFile::timerFired() bool LogFile::startReplay() { dataBuffer.clear(); myTime.restart(); - + timeOffset = 0; + playbackSpeed = 1; file.read((char *) &lastTimeStamp,sizeof(lastTimeStamp)); - timer.setInterval(10); timer.start(); return true; @@ -88,3 +88,16 @@ bool LogFile::stopReplay() { timer.stop(); return true; } + +void LogFile::pauseReplay() +{ + timer.stop(); + pausedTime = myTime.elapsed(); +} + +void LogFile::resumeReplay() +{ + timeOffset += myTime.elapsed() - pausedTime; + timer.start(); +} + diff --git a/ground/src/plugins/logging/logfile.h b/ground/src/plugins/logging/logfile.h index 4b0976eb5..b6a0afbf7 100644 --- a/ground/src/plugins/logging/logfile.h +++ b/ground/src/plugins/logging/logfile.h @@ -7,6 +7,7 @@ #include #include #include +#include class LogFile : public QIODevice { @@ -25,6 +26,11 @@ public: bool stopReplay(); public slots: + void setReplaySpeed(int val) { playbackSpeed = pow(10,((double) val)/100); qDebug() << playbackSpeed; }; + void pauseReplay(); + void resumeReplay(); + +protected slots: void timerFired(); signals: @@ -36,6 +42,10 @@ protected: QTime myTime; QFile file; qint32 lastTimeStamp; + + int timeOffset; + int pausedTime; + double playbackSpeed; }; #endif // LOGFILE_H diff --git a/ground/src/plugins/logging/logging.pro b/ground/src/plugins/logging/logging.pro index 577b8668c..b0a4fa7e3 100644 --- a/ground/src/plugins/logging/logging.pro +++ b/ground/src/plugins/logging/logging.pro @@ -7,23 +7,21 @@ include(../../plugins/uavobjects/uavobjects.pri) include(../../plugins/uavtalk/uavtalk.pri) include(logging_dependencies.pri) HEADERS += loggingplugin.h \ - logfile.h -# logginggadgetwidget.h \ -# loggingdialog.h \ -# logginggadget.h \ -# logginggadgetfactory.h \ + logfile.h \ + logginggadgetwidget.h \ + logginggadget.h \ + logginggadgetfactory.h # logginggadgetconfiguration.h # logginggadgetoptionspage.h SOURCES += loggingplugin.cpp \ - logfile.cpp -# logginggadgetwidget.cpp \ -# loggingdialog.cpp \ -# logginggadget.cpp \ -# logginggadgetfactory.cpp \ + logfile.cpp \ + logginggadgetwidget.cpp \ + logginggadget.cpp \ + logginggadgetfactory.cpp # logginggadgetconfiguration.cpp \ # logginggadgetoptionspage.cpp OTHER_FILES += LoggingGadget.pluginspec -#FORMS += logginggadgetoptionspage.ui \ +FORMS += logging.ui # logginggadgetwidget.ui \ # loggingdialog.ui diff --git a/ground/src/plugins/logging/logging.ui b/ground/src/plugins/logging/logging.ui new file mode 100644 index 000000000..e3a3812e7 --- /dev/null +++ b/ground/src/plugins/logging/logging.ui @@ -0,0 +1,144 @@ + + + Logging + + + + 0 + 0 + 536 + 122 + + + + + 100 + 80 + + + + + 100 + 80 + + + + Form + + + + + + + + QLayout::SetNoConstraint + + + + + + 30 + 0 + + + + + 30 + 0 + + + + Play + + + + :/notify/images/play.png:/notify/images/play.png + + + + + + + + 30 + 0 + + + + + 30 + 0 + + + + Pause + + + + :/notify/images/stop.png:/notify/images/stop.png + + + + + + + + 100 + 0 + + + + -100 + + + 100 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 50 + + + + + + + Status: + + + + + + + Idle + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/ground/src/plugins/logging/logginggadget.cpp b/ground/src/plugins/logging/logginggadget.cpp new file mode 100644 index 000000000..a151c6720 --- /dev/null +++ b/ground/src/plugins/logging/logginggadget.cpp @@ -0,0 +1,47 @@ +/** + ****************************************************************************** + * + * @file GCSControlgadget.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin + * @{ + * @brief A gadget to control the UAV, either from the keyboard or a joystick + *****************************************************************************/ +/* + * 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 "logginggadget.h" +#include "logginggadgetwidget.h" + +#include "extensionsystem/pluginmanager.h" +#include "uavobjects/uavobjectmanager.h" +#include "uavobjects/uavobject.h" + +LoggingGadget::LoggingGadget(QString classId, LoggingGadgetWidget *widget, QWidget *parent) : + IUAVGadget(classId, parent), + m_widget(widget) +{ +} + +LoggingGadget::~LoggingGadget() +{ + +} + +void LoggingGadget::loadConfiguration(IUAVGadgetConfiguration* config) +{ +} diff --git a/ground/src/plugins/logging/logginggadget.h b/ground/src/plugins/logging/logginggadget.h new file mode 100644 index 000000000..11844549d --- /dev/null +++ b/ground/src/plugins/logging/logginggadget.h @@ -0,0 +1,60 @@ +/** + ****************************************************************************** + * + * @file GCSControlgadget.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin + * @{ + * @brief A gadget to control the UAV, either from the keyboard or a joystick + *****************************************************************************/ +/* + * 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 LoggingGADGET_H_ +#define LoggingGADGET_H_ + +#include + +namespace Core { +class IUAVGadget; +} +//class QWidget; +//class QString; +class LoggingGadgetWidget; + +using namespace Core; + +class LoggingGadget : public Core::IUAVGadget +{ + Q_OBJECT +public: + LoggingGadget(QString classId, LoggingGadgetWidget *widget, QWidget *parent = 0); + ~LoggingGadget(); + + QList context() const { return m_context; } + QWidget *widget() { return m_widget; } + QString contextHelpId() const { return QString(); } + + void loadConfiguration(IUAVGadgetConfiguration* config); +private: + QWidget *m_widget; + QList m_context; +}; + + +#endif // LoggingGADGET_H_ diff --git a/ground/src/plugins/logging/logginggadgetfactory.cpp b/ground/src/plugins/logging/logginggadgetfactory.cpp new file mode 100644 index 000000000..36c70f030 --- /dev/null +++ b/ground/src/plugins/logging/logginggadgetfactory.cpp @@ -0,0 +1,49 @@ +/** + ****************************************************************************** + * + * @file GCSControlgadgetfactory.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin + * @{ + * @brief A gadget to control the UAV, either from the keyboard or a joystick + *****************************************************************************/ +/* + * 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 "logginggadgetfactory.h" +#include "logginggadgetwidget.h" +#include "logginggadget.h" +#include + +LoggingGadgetFactory::LoggingGadgetFactory(QObject *parent) : + IUAVGadgetFactory(QString("LoggingGadget"), + tr("Logging"), + parent) +{ + loggingPlugin = (LoggingPlugin *) parent; +} + +LoggingGadgetFactory::~LoggingGadgetFactory() +{ + +} + +IUAVGadget* LoggingGadgetFactory::createGadget(QWidget *parent) { + LoggingGadgetWidget* gadgetWidget = new LoggingGadgetWidget(parent); + gadgetWidget->setPlugin(loggingPlugin); + return new LoggingGadget(QString("LoggingGadget"), gadgetWidget, parent); +} diff --git a/ground/src/plugins/logging/logginggadgetfactory.h b/ground/src/plugins/logging/logginggadgetfactory.h new file mode 100644 index 000000000..dc5dd8fb9 --- /dev/null +++ b/ground/src/plugins/logging/logginggadgetfactory.h @@ -0,0 +1,55 @@ +/** + ****************************************************************************** + * + * @file GCSControlgadgetfactory.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin + * @{ + * @brief A gadget to control the UAV, either from the keyboard or a joystick + *****************************************************************************/ +/* + * 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 LoggingGADGETFACTORY_H_ +#define LoggingGADGETFACTORY_H_ + +#include + +namespace Core { +class IUAVGadget; +class IUAVGadgetFactory; +} + +using namespace Core; +class LoggingPlugin; + +class LoggingGadgetFactory : public IUAVGadgetFactory +{ + Q_OBJECT +public: + LoggingGadgetFactory(QObject *parent = 0); + ~LoggingGadgetFactory(); + + void setPlugin(LoggingPlugin * p) { loggingPlugin = p; }; + + IUAVGadget *createGadget(QWidget *parent); +private: + LoggingPlugin * loggingPlugin; +}; + +#endif // LoggingGADGETFACTORY_H_ diff --git a/ground/src/plugins/logging/logginggadgetwidget.cpp b/ground/src/plugins/logging/logginggadgetwidget.cpp new file mode 100644 index 000000000..6c5b5303e --- /dev/null +++ b/ground/src/plugins/logging/logginggadgetwidget.cpp @@ -0,0 +1,68 @@ +/** + ****************************************************************************** + * + * @file GCSControlgadgetwidget.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin + * @{ + * @brief A gadget to control the UAV, either from the keyboard or a joystick + *****************************************************************************/ +/* + * 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 "logginggadgetwidget.h" +#include "ui_logging.h" + +#include +#include +#include +#include +#include +#include +#include + +LoggingGadgetWidget::LoggingGadgetWidget(QWidget *parent) : QLabel(parent) +{ + m_logging = new Ui_Logging(); + m_logging->setupUi(this); +} + +LoggingGadgetWidget::~LoggingGadgetWidget() +{ + // Do nothing +} + +void LoggingGadgetWidget::setPlugin(LoggingPlugin * p) +{ + loggingPlugin = p; + connect(p,SIGNAL(stateChanged(QString)),this,SLOT(stateChanged(QString))); + connect(m_logging->playButton,SIGNAL(clicked()),p->getLogfile(),SLOT(resumeReplay())); + connect(m_logging->pauseButton,SIGNAL(clicked()),p->getLogfile(),SLOT(pauseReplay())); + connect(m_logging->playbackSpeed,SIGNAL(valueChanged(int)),p->getLogfile(),SLOT(setReplaySpeed(int))); + void pauseReplay(); + void resumeReplay(); +} + +void LoggingGadgetWidget::stateChanged(QString status) +{ + m_logging->statusLabel->setText(status); +} + +/** + * @} + * @} + */ diff --git a/ground/src/plugins/logging/logginggadgetwidget.h b/ground/src/plugins/logging/logginggadgetwidget.h new file mode 100644 index 000000000..fa362cc66 --- /dev/null +++ b/ground/src/plugins/logging/logginggadgetwidget.h @@ -0,0 +1,59 @@ +/** + ****************************************************************************** + * + * @file GCSControlgadgetwidget.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin + * @{ + * @brief A place holder gadget plugin + *****************************************************************************/ +/* + * 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 LoggingGADGETWIDGET_H_ +#define LoggingGADGETWIDGET_H_ + +#include + +class Ui_Logging; +class LoggingPlugin; + +class LoggingGadgetWidget : public QLabel +{ + Q_OBJECT + +public: + LoggingGadgetWidget(QWidget *parent = 0); + ~LoggingGadgetWidget(); + void setPlugin(LoggingPlugin * p); + +protected slots: + void stateChanged(QString status); + +signals: + void pause(); + void play(); + +private: + Ui_Logging *m_logging; + LoggingPlugin * loggingPlugin; + + +}; + +#endif /* LoggingGADGETWIDGET_H_ */ diff --git a/ground/src/plugins/logging/loggingplugin.cpp b/ground/src/plugins/logging/loggingplugin.cpp index 05527f0b5..788dce431 100644 --- a/ground/src/plugins/logging/loggingplugin.cpp +++ b/ground/src/plugins/logging/loggingplugin.cpp @@ -28,6 +28,7 @@ */ #include "loggingplugin.h" +#include "logginggadgetfactory.h" #include #include #include @@ -167,6 +168,9 @@ bool LoggingPlugin::initialize(const QStringList& args, QString *errMsg) connect(cmd2->action(), SIGNAL(triggered(bool)), this, SLOT(toggleReplay())); + mf = new LoggingGadgetFactory(this); + addAutoReleasedObject(mf); + return true; } @@ -223,6 +227,7 @@ void LoggingPlugin::startLogging(QString file) connect(loggingThread,SIGNAL(finished()),this,SLOT(loggingStopped())); state = LOGGING; loggingThread->start(); + emit stateChanged("LOGGING"); } else { QErrorMessage err; err.showMessage("Unable to open file for logging"); @@ -236,17 +241,18 @@ void LoggingPlugin::startLogging(QString file) void LoggingPlugin::startReplay(QString file) { - logFile = new LogFile; - logFile->setFileName(file); - if(logFile->open(QIODevice::ReadOnly)) { + logFile.setFileName(file); + if(logFile.open(QIODevice::ReadOnly)) { qDebug() << "Replaying " << file; state = REPLAY; ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager *objManager = pm->getObject(); - uavTalk = new UAVTalk(logFile, objManager); - logFile->startReplay(); + uavTalk = new UAVTalk(&logFile, objManager); + logFile.startReplay(); + + emit stateChanged("REPLAY"); } else { QErrorMessage err; err.showMessage("Unable to open file for replay"); @@ -268,13 +274,13 @@ void LoggingPlugin::stopLogging() */ void LoggingPlugin::stopReplay() { - logFile->stopReplay(); - logFile->close(); + logFile.stopReplay(); + logFile.close(); free(uavTalk); - free(logFile); uavTalk = 0; - logFile = 0; state = IDLE; + + emit stateChanged("IDLE"); } /** @@ -285,6 +291,9 @@ void LoggingPlugin::loggingStopped() { if(state == LOGGING) state = IDLE; + + emit stateChanged("IDLE"); + free(loggingThread); loggingThread = NULL; } diff --git a/ground/src/plugins/logging/loggingplugin.h b/ground/src/plugins/logging/loggingplugin.h index 55e8ebc4f..abea393a8 100644 --- a/ground/src/plugins/logging/loggingplugin.h +++ b/ground/src/plugins/logging/loggingplugin.h @@ -36,6 +36,7 @@ #include class LoggingPlugin; +class LoggingGadgetFactory; class LoggingThread : public QThread { @@ -68,9 +69,13 @@ public: bool initialize(const QStringList & arguments, QString * errorString); void shutdown(); + LogFile * getLogfile() { return &logFile; }; + signals: void stopLoggingSignal(void); void stopReplaySignal(void); + void stateChanged(QString); + protected: enum {IDLE, LOGGING, REPLAY} state; @@ -78,7 +83,7 @@ protected: // These are used for replay, logging in its own thread UAVTalk * uavTalk; - LogFile * logFile; + LogFile logFile; private slots: void toggleLogging(); @@ -88,6 +93,9 @@ private slots: void stopLogging(); void stopReplay(); void loggingStopped(); + +private: + LoggingGadgetFactory *mf; }; #endif /* LoggingPLUGIN_H_ */ /**