From 00737925611448d1523ca45155720d892590d455 Mon Sep 17 00:00:00 2001 From: Mathieu Rondonneau Date: Fri, 14 Jun 2013 19:24:42 -0700 Subject: [PATCH] OP-1011: Remove deprecated powerlog --- .../translations/openpilotgcs_de.ts | 18 - .../translations/openpilotgcs_es.ts | 18 - .../translations/openpilotgcs_fr.ts | 18 - .../translations/openpilotgcs_ru.ts | 18 - .../translations/openpilotgcs_zh_CN.ts | 18 - ground/openpilotgcs/src/plugins/plugins.pro | 5 - .../src/plugins/powerlog/PowerLog.pluginspec | 11 - .../src/plugins/powerlog/powerlog.pro | 11 - .../powerlog/powerlog_dependencies.pri | 2 - .../src/plugins/powerlog/powerlogplugin.cpp | 369 ------------------ .../src/plugins/powerlog/powerlogplugin.h | 135 ------- 11 files changed, 623 deletions(-) delete mode 100644 ground/openpilotgcs/src/plugins/powerlog/PowerLog.pluginspec delete mode 100644 ground/openpilotgcs/src/plugins/powerlog/powerlog.pro delete mode 100644 ground/openpilotgcs/src/plugins/powerlog/powerlog_dependencies.pri delete mode 100644 ground/openpilotgcs/src/plugins/powerlog/powerlogplugin.cpp delete mode 100644 ground/openpilotgcs/src/plugins/powerlog/powerlogplugin.h diff --git a/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_de.ts b/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_de.ts index fad9557a4..106433d33 100644 --- a/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_de.ts +++ b/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_de.ts @@ -13562,24 +13562,6 @@ Move the %1 stick. - - PowerlogPlugin - - - Log filename - - - - - PowerLog-%0.csv - - - - - Comma Separated Values (*.csv) - - - QmlViewGadgetFactory diff --git a/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_es.ts b/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_es.ts index 5f29e13a0..1a9d98543 100644 --- a/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_es.ts +++ b/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_es.ts @@ -13563,24 +13563,6 @@ Move the %1 stick. - - PowerlogPlugin - - - Log filename - - - - - PowerLog-%0.csv - - - - - Comma Separated Values (*.csv) - - - QmlViewGadgetFactory diff --git a/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_fr.ts b/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_fr.ts index d7414840c..165057d2f 100644 --- a/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_fr.ts +++ b/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_fr.ts @@ -14000,24 +14000,6 @@ Bougez le manche %1. - - PowerlogPlugin - - - Log filename - Fichier de journal - - - - PowerLog-%0.csv - - - - - Comma Separated Values (*.csv) - - - QmlViewGadgetFactory diff --git a/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_ru.ts b/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_ru.ts index 842ad65d1..5d625d8a2 100644 --- a/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_ru.ts +++ b/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_ru.ts @@ -13585,24 +13585,6 @@ Move the %1 stick. - - PowerlogPlugin - - - Log filename - - - - - PowerLog-%0.csv - - - - - Comma Separated Values (*.csv) - - - QmlViewGadgetFactory diff --git a/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_zh_CN.ts b/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_zh_CN.ts index 6c3652305..c1c16f9ed 100644 --- a/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_zh_CN.ts +++ b/ground/openpilotgcs/share/openpilotgcs/translations/openpilotgcs_zh_CN.ts @@ -13565,24 +13565,6 @@ Move the %1 stick. - - PowerlogPlugin - - - Log filename - - - - - PowerLog-%0.csv - - - - - Comma Separated Values (*.csv) - - - QmlViewGadgetFactory diff --git a/ground/openpilotgcs/src/plugins/plugins.pro b/ground/openpilotgcs/src/plugins/plugins.pro index 20b402704..3f371b722 100644 --- a/ground/openpilotgcs/src/plugins/plugins.pro +++ b/ground/openpilotgcs/src/plugins/plugins.pro @@ -244,8 +244,3 @@ plugin_setupwizard.depends += plugin_config plugin_setupwizard.depends += plugin_uploader SUBDIRS += plugin_setupwizard -# Junsi Powerlog plugin -#plugin_powerlog.subdir = powerlog -#plugin_powerlog.depends = plugin_coreplugin -#plugin_powerlog.depends += plugin_rawhid -#SUBDIRS += plugin_powerlog diff --git a/ground/openpilotgcs/src/plugins/powerlog/PowerLog.pluginspec b/ground/openpilotgcs/src/plugins/powerlog/PowerLog.pluginspec deleted file mode 100644 index 24ac39811..000000000 --- a/ground/openpilotgcs/src/plugins/powerlog/PowerLog.pluginspec +++ /dev/null @@ -1,11 +0,0 @@ - - The OpenPilot Project - (C) 2010 OpenPilot - The GNU Public License (GPL) Version 3 - A plugin that downloads the log from a Junsi PowerLog6S to a file - http://www.openpilot.org - - - - - diff --git a/ground/openpilotgcs/src/plugins/powerlog/powerlog.pro b/ground/openpilotgcs/src/plugins/powerlog/powerlog.pro deleted file mode 100644 index e521ad17c..000000000 --- a/ground/openpilotgcs/src/plugins/powerlog/powerlog.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = lib -TARGET = PowerLog -DEFINES += POWERLOG_LIBRARY -include(../../openpilotgcsplugin.pri) -include(powerlog_dependencies.pri) -HEADERS += powerlogplugin.h - -SOURCES += powerlogplugin.cpp - -OTHER_FILES += PowerLog.pluginspec - diff --git a/ground/openpilotgcs/src/plugins/powerlog/powerlog_dependencies.pri b/ground/openpilotgcs/src/plugins/powerlog/powerlog_dependencies.pri deleted file mode 100644 index f77ee6b96..000000000 --- a/ground/openpilotgcs/src/plugins/powerlog/powerlog_dependencies.pri +++ /dev/null @@ -1,2 +0,0 @@ -include(../../plugins/coreplugin/coreplugin.pri) -include(../../plugins/rawhid/opHID.pri) diff --git a/ground/openpilotgcs/src/plugins/powerlog/powerlogplugin.cpp b/ground/openpilotgcs/src/plugins/powerlog/powerlogplugin.cpp deleted file mode 100644 index 5f0b9c820..000000000 --- a/ground/openpilotgcs/src/plugins/powerlog/powerlogplugin.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/** - ****************************************************************************** - * - * @file powerlogplugin.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @see The GNU Public License (GPL) Version 3 - * @brief Junsi Powerlog utility Plugin - * @addtogroup GCSPlugins GCS Plugins - * @{ - * @addtogroup PowerLog - * @{ - * - *****************************************************************************/ -/* - * 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 "powerlogplugin.h" -#include "rawhid/usbmonitor.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - - -/** - * Sets the file to use for logging and takes the parent plugin - * to connect to stop logging signal - * @param[in] file File name to write to - * @param[in] parent plugin - */ -bool PowerlogThread::openFile(QString file, PowerlogPlugin *parent) -{ - logFile.setFileName(file); - logFile.open(QIODevice::WriteOnly); - fileStream.setDevice(&logFile); - - connect(parent, SIGNAL(stopLoggingSignal()), this, SLOT(stopLogging())); - - return true; -}; - -/** - * Get all logs from Powerlog - */ -void PowerlogThread::run() -{ - // TODO: pop up a dialog here! - - qDebug() << "Connect a Junsi PowerLog 6S and watch the logging output"; - opHID_hidapi hidHandle; - int numDevices = hidHandle.open(1, 0x0483, 0x5750, 0, 0); // 0xff9c,0x0001); - if (numDevices == 0) { - numDevices = hidHandle.open(1, 0x0483, 0, 0, 0); - } - - qDebug() << numDevices << " device(s) opened"; - if (numDevices == 0) { - return; - } - - // hidHandle.mytest(0); - - char buf[BUF_LEN]; - buf[0] = 2; - buf[1] = 0; - - fileStream << "Interval,Current,Volt,Cap,Cell1,Cell2,Cell3,Cell4,Cell5,Cell6,RPM,Temp0,Temp1,Temp2,Temp3,Period,Pulse\n"; - - while (int received = hidHandle.receive(0, buf, BUF_LEN, 3500)) { - ShowInf(buf); - fileStream.flush(); // Just to be sure... - } - - stopLogging(); -} - -/** - * Pass this command to the correct thread then close the file - */ -void PowerlogThread::stopLogging() -{ - QWriteLocker locker(&lock); - - fileStream.flush(); - logFile.close(); - quit(); -} - -/** - * Formats the content of the buffer we just read and write - * to the logfile - */ -void PowerlogThread::ShowInf(char *pBuf) -{ - POWERLOG_HID_PACK Inf; - int i; - int Count; - - Count = 0; - Inf.Len = pBuf[Count]; - Count += sizeof(Inf.Len); - - Inf.Type = pBuf[Count]; - Count += sizeof(Inf.Type); - - Inf.Interval = *((DWORD *)&pBuf[Count]); - fileStream << QString::number(Inf.Interval) << ","; - - Count += sizeof(Inf.Interval); - - Inf.LogState = pBuf[Count]; - Count += sizeof(Inf.LogState); - - if (((Inf.Type == TYPE_DATA_ONLINE) || (Inf.Type == TYPE_DATA_OFFLINE)) && (Inf.Len == 0x29)) { // 0x27 - Inf.Current = *((SHORT *)&pBuf[Count]); - Count += sizeof(Inf.Current); - GetShowValue(QString("Current"), Inf.Current, 5, 2); - - Inf.Volt = *((USHORT *)&pBuf[Count]); - Count += sizeof(Inf.Volt); - GetShowValue(QString("Voltage"), Inf.Volt, 5, 2); - - Inf.Cap = *((DWORD *)&pBuf[Count]); - Count += sizeof(Inf.Cap); - GetShowValue(QString("Cap"), Inf.Cap, 6, 0); - - for (i = 0; i < 6; i++) { - Inf.Cell[i] = *((SHORT *)&pBuf[Count]); - Count += sizeof(Inf.Cell[i]); - } - GetShowValue(QString("Cell 1"), Inf.Cell[0], 5, 3); - GetShowValue(QString("Cell 2"), Inf.Cell[1], 5, 3); - GetShowValue(QString("Cell 3"), Inf.Cell[2], 5, 3); - GetShowValue(QString("Cell 4"), Inf.Cell[3], 5, 3); - GetShowValue(QString("Cell 5"), Inf.Cell[4], 5, 3); - GetShowValue(QString("Cell 6"), Inf.Cell[5], 5, 3); - - Inf.RPM = *((USHORT *)&pBuf[Count]); - Count += sizeof(Inf.RPM); - GetShowValue(QString("RPM"), Inf.RPM, 6, 0); - - for (i = 0; i < 4; i++) { - Inf.Temp[i] = *((SHORT *)&pBuf[Count]); - Count += sizeof(Inf.Temp[i]); - } - GetShowValue(QString("Int Temp0"), Inf.Temp[0], 4, 1); - - if (Inf.Temp[1] == 0x7fff) { - fileStream << "0.0,"; - } else { - GetShowValue(QString("Ext temp1"), Inf.Temp[1], 4, 1); - } - - if (Inf.Temp[2] == 0x7fff) { - fileStream << "0.0,"; - } else { - GetShowValue(QString("Ext temp2"), Inf.Temp[2], 4, 1); - } - - if (Inf.Temp[3] == 0x7fff) { - fileStream << "0.0,"; - } else { - GetShowValue(QString("Ext temp3"), Inf.Temp[3], 4, 1); - } - - Inf.Period = *((USHORT *)&pBuf[Count]); - Count += sizeof(Inf.Period); - GetShowValue(QString("Period:"), Inf.Period, 6, 0); - - Inf.Pulse = *((USHORT *)&pBuf[Count]); - Count += sizeof(Inf.Pulse); - GetShowValue(QString("Pulse:"), Inf.Pulse, 6, 0); - - fileStream << "\n"; - } -} - -/** - * Formats a numeric value - */ -void PowerlogThread::GetShowValue(QString label, DWORD Value, WORD Len, WORD Dot) -{ - QString out; - - if (Value < 0) { - fileStream << "-"; - Value = -Value; - } - - if (Dot == 1) { - fileStream << Value / 10 << "." << Value % 10; // printf("%ld.%01lu",Value/10,Value%10); - } else if (Dot == 2) { - fileStream << Value / 100 << "." << Value % 100; // printf("%ld.%02lu",Value/100,Value%100); - } else if (Dot == 3) { - fileStream << Value / 1000 << "." << Value % 1000; // printf("%ld.%03lu",Value/1000,Value%1000); - } else if (Dot == 4) { - fileStream << Value / 10000 << "." << Value % 10000; // printf("%ld.%04lu",Value/10000,Value%10000); - } else { - fileStream << Value; // printf("%ld",Value); - } - fileStream << out << ","; -} - - -/**************************************************************** - Logging plugin - ********************************/ - - -PowerlogPlugin::PowerlogPlugin() : - devSerialNumber(""), - logging(false), - loggingThread(NULL) -{} - -PowerlogPlugin::~PowerlogPlugin() -{} - -/** - * Add Powerlog plugin entry to File menu - */ -bool PowerlogPlugin::initialize(const QStringList & args, QString *errMsg) -{ - Q_UNUSED(args); - Q_UNUSED(errMsg); - - - // Add Menu entry - Core::ActionManager *am = Core::ICore::instance()->actionManager(); - Core::ActionContainer *ac = am->actionContainer(Core::Constants::M_TOOLS); - - // Command to start logging - cmd = am->registerAction(new QAction(this), - "PowerlogPlugin.Transfer", - QList() << - Core::Constants::C_GLOBAL_ID); - cmd->action()->setText("Receive from PowerLog6S..."); - - ac->menu()->addSeparator(); - ac->appendGroup("Utilities"); - ac->addAction(cmd, "Utilities"); - - connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(receiveLog())); - - // At this stage we know that other plugins we depend upon are - // initialized, in prticular the USB Monitor is now running: - USBMonitor *mon = USBMonitor::instance(); - connect(mon, SIGNAL(deviceDiscovered(USBPortInfo)), this, SLOT(devConnected(USBPortInfo))); - connect(mon, SIGNAL(deviceRemoved(USBPortInfo)), this, SLOT(devRemoved(USBPortInfo))); - - return true; -} - -/** - * The action that is triggered by the menu item which opens the - * file and begins log reception if successful - */ -void PowerlogPlugin::receiveLog() -{ - if (logging) { - loggingThread->stopLogging(); - logging = false; - cmd->action()->setText("Receive from PowerLog6S..."); - } else { - QString fileName = QFileDialog::getSaveFileName(NULL, tr("Log filename"), - tr("PowerLog-%0.csv").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss")), - tr("Comma Separated Values (*.csv)")); - if (fileName.isEmpty()) { - return; - } - - loggingThread = new PowerlogThread(); - if (loggingThread->openFile(fileName, this)) { - loggingThread->start(); - cmd->action()->setText("Stop PowerLog6S reception"); - logging = true; - } - } -} - -/** - Device connected, check whether it is a powerlog & act accordingly - */ -void PowerlogPlugin::devConnected(USBPortInfo port) -{ - if (devSerialNumber.length() > 0) { - return; - } - if ((port.vendorID == 0x0483) && (port.productID == 0x5750)) { - devSerialNumber = port.serialNumber; - cmd->action()->setEnabled(true); - } -} - - -/** - Device Removed, check whether it is a powerlog & act accordingly. - As when the device is removed, we don't get the info on the device, - we have to list all available remaining devices and check if the serial - number of our device is missing... - */ -void PowerlogPlugin::devRemoved(USBPortInfo port) -{ - bool foundDevice; - - QList ports = USBMonitor::instance()->availableDevices(); - foreach(USBPortInfo port, ports) { - if ((port.vendorID == 0x0483) && (port.productID == 0x5750) && - (devSerialNumber == port.serialNumber)) { - foundDevice = true; - break; - } - } - if (!foundDevice) { - devSerialNumber = QString(""); - cmd->action()->setEnabled(false); - // Also stop logging in case we were logging: - if (loggingThread) { - loggingThread->stopLogging(); - } - } -} - - -void PowerlogPlugin::extensionsInitialized() -{ - cmd->action()->setEnabled(false); - QList ports = USBMonitor::instance()->availableDevices(); - foreach(USBPortInfo port, ports) { - if ((port.vendorID == 0x0483) && (port.productID == 0x5750)) { - devSerialNumber = port.serialNumber; - cmd->action()->setEnabled(true); - break; - } - } -} - -void PowerlogPlugin::shutdown() -{ - // Do nothing -} -Q_EXPORT_PLUGIN(PowerlogPlugin) - -/** - * @} - * @} - */ diff --git a/ground/openpilotgcs/src/plugins/powerlog/powerlogplugin.h b/ground/openpilotgcs/src/plugins/powerlog/powerlogplugin.h deleted file mode 100644 index 70054cfab..000000000 --- a/ground/openpilotgcs/src/plugins/powerlog/powerlogplugin.h +++ /dev/null @@ -1,135 +0,0 @@ -/** - ****************************************************************************** - * @file powerlogplugin.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @see The GNU Public License (GPL) Version 3 - * @addtogroup GCSPlugins GCS Plugins - * @{ - * @addtogroup powerlogplugin - * @{ - *****************************************************************************/ -/* - * 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 POWERLOGPLUGIN_H_ -#define POWERLOGPLUGIN_H_ - -#include -#include -#include -#include -#include -#include "opHID/inc/opHID_usbmon.h" -#include "opHID/inc/opHID_hidapi.h" - -#include -#include -#include - -using namespace std; - -typedef unsigned long ULONG; // 4 Bytes -typedef short SHORT; -typedef unsigned short USHORT; // 2 Bytes -typedef unsigned char BYTE; // 1 Byte -typedef unsigned short WORD; // 2 Bytes -typedef unsigned long DWORD; // 4 Bytes - - -#define BUF_LEN 64 -struct POWERLOG_HID_PACK { - BYTE Len; - BYTE Type; - DWORD Interval; - BYTE LogState; - SHORT Current; - USHORT Volt; - DWORD Cap; - SHORT Cell[6]; - USHORT RPM; - SHORT Temp[4]; - USHORT Period; - USHORT Pulse; -}; - -enum { - TYPE_DATA_ONLINE = 0x10, - TYPE_DATA_OFFLINE = 0x11, - TYPE_ORDER = 0x20, -}; - - -class PowerlogPlugin; - -class PowerlogThread : public QThread { - Q_OBJECT - -public: - bool openFile(QString file, PowerlogPlugin *parent); - -private slots: - -public slots: - void stopLogging(); - -protected: - void run(); - QReadWriteLock lock; - QFile logFile; - QTextStream fileStream; - -private: - void ShowInf(char *pBuf); - void GetShowValue(QString label, DWORD Value, WORD Len, WORD Dot); -}; - - -class PowerlogPlugin : public ExtensionSystem::IPlugin { - Q_OBJECT - - -public: - PowerlogPlugin(); - ~PowerlogPlugin(); - - void extensionsInitialized(); - bool initialize(const QStringList & arguments, QString *errorString); - void shutdown(); - - void setPowerlogMenuTitle(QString str); - - -signals: - void stopLoggingSignal(void); - -protected: - -private slots: - void receiveLog(); - void devConnected(USBPortInfo); - void devRemoved(USBPortInfo); - -private: - Core::Command *cmd; - QString devSerialNumber; - PowerlogThread *loggingThread; - bool logging; -}; -#endif /* POWERLOGPLUGIN_H_ */ -/** - * @} - * @} - */