From a8dbeb2c914da3958564ae284a805f77d324d4e3 Mon Sep 17 00:00:00 2001 From: zedamota Date: Fri, 11 Nov 2011 23:09:44 +0000 Subject: [PATCH 1/2] Make the GCS serial telemetry speed configurable --- .../serialconnection/serialconnection.pro | 14 +-- .../plugins/serialconnection/serialplugin.cpp | 42 +++++++- .../plugins/serialconnection/serialplugin.h | 10 +- .../serialpluginconfiguration.cpp | 79 ++++++++++++++ .../serialpluginconfiguration.h | 58 ++++++++++ .../serialconnection/serialpluginoptions.ui | 100 ++++++++++++++++++ .../serialpluginoptionspage.cpp | 71 +++++++++++++ .../serialpluginoptionspage.h | 71 +++++++++++++ 8 files changed, 434 insertions(+), 11 deletions(-) create mode 100644 ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.cpp create mode 100644 ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.h create mode 100644 ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptions.ui create mode 100644 ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.cpp create mode 100644 ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.h diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialconnection.pro b/ground/openpilotgcs/src/plugins/serialconnection/serialconnection.pro index 057c1f249..1c2f0fcf8 100644 --- a/ground/openpilotgcs/src/plugins/serialconnection/serialconnection.pro +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialconnection.pro @@ -3,11 +3,13 @@ TARGET = Serial include(../../openpilotgcsplugin.pri) include(serial_dependencies.pri) INCLUDEPATH += ../../libs/qextserialport/src -HEADERS += serialplugin.h -#HEADERS += serialplugin.h \ -# serial_global.h -SOURCES += serialplugin.cpp -FORMS += +HEADERS += serialplugin.h \ + serialpluginconfiguration.h \ + serialpluginoptionspage.h +SOURCES += serialplugin.cpp \ + serialpluginconfiguration.cpp \ + serialpluginoptionspage.cpp +FORMS += \ + serialpluginoptions.ui RESOURCES += -#DEFINES += SERIAL_LIBRARY OTHER_FILES += Serial.pluginspec diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.cpp b/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.cpp index e62afb44a..bae5a885a 100644 --- a/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.cpp +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.cpp @@ -76,6 +76,11 @@ SerialConnection::SerialConnection() : enablePolling(true), m_enumerateThread(this) { serialHandle = NULL; + m_config = new SerialPluginConfiguration("Serial Telemetry", NULL, this); + m_config->restoresettings(); + + m_optionspage = new SerialPluginOptionsPage(m_config,this); + // Experimental: enable polling on all OS'es since there // were reports that autodetect does not work on XP amongst @@ -142,7 +147,7 @@ QIODevice *SerialConnection::openDevice(const QString &deviceName) { //we need to handle port settings here... PortSettings set; - set.BaudRate = BAUD57600; + set.BaudRate = stringToBaud(m_config->speed()); set.DataBits = DATA_8; set.Parity = PAR_NONE; set.StopBits = STOP_1; @@ -198,6 +203,31 @@ void SerialConnection::resumePolling() enablePolling = true; } +BaudRateType SerialConnection::stringToBaud(QString str) +{ + if(str=="1200") + return BAUD1200; + else if(str=="2400") + return BAUD1200; + else if(str== "4800") + return BAUD2400; + else if(str== "9600") + return BAUD9600; + else if(str== "19200") + return BAUD19200; + else if(str== "38400") + return BAUD38400; + else if(str== "57600") + return BAUD56000; + else if(str== "115200") + return BAUD115200; + else if(str== "230400") + return BAUD230400; + else if(str== "460800") + return BAUD460800; + else if(str== "921600") + return BAUD921600; +} SerialPlugin::SerialPlugin() { @@ -205,19 +235,23 @@ SerialPlugin::SerialPlugin() SerialPlugin::~SerialPlugin() { - + removeObject(m_connection->Optionspage()); } void SerialPlugin::extensionsInitialized() { - addAutoReleasedObject(new SerialConnection); + addAutoReleasedObject(m_connection); } bool SerialPlugin::initialize(const QStringList &arguments, QString *errorString) { Q_UNUSED(arguments); Q_UNUSED(errorString); - + m_connection = new SerialConnection(); + //must manage this registration of child object ourselves + //if we use an autorelease here it causes the GCS to crash + //as it is deleting objects as the app closes... + addObject(m_connection->Optionspage()); return true; } diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.h b/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.h index 829ee6512..388117ead 100644 --- a/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.h +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.h @@ -33,6 +33,8 @@ #include #include "coreplugin/iconnection.h" #include +#include "serialpluginconfiguration.h" +#include "serialpluginoptionspage.h" #include class IConnection; @@ -87,12 +89,16 @@ public: virtual void resumePolling(); bool deviceOpened() {return m_deviceOpened;} + SerialPluginConfiguration * Config() const { return m_config; } + SerialPluginOptionsPage * Optionspage() const { return m_optionspage; } private: QextSerialPort* serialHandle; bool enablePolling; - + SerialPluginConfiguration *m_config; + SerialPluginOptionsPage *m_optionspage; + BaudRateType stringToBaud(QString str); protected slots: void onEnumerationChanged(); @@ -116,6 +122,8 @@ public: virtual bool initialize(const QStringList &arguments, QString *error_message); virtual void extensionsInitialized(); +private: + SerialConnection *m_connection; }; diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.cpp b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.cpp new file mode 100644 index 000000000..49bcf2ae8 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.cpp @@ -0,0 +1,79 @@ +/** + ****************************************************************************** + * + * @file dialpluginconfiguration.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @see The GNU Public License (GPL) Version 3 + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup DialPlugin Dial Plugin + * @{ + * @brief Plots flight information rotary style dials + *****************************************************************************/ +/* + * 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 "serialpluginconfiguration.h" +#include "utils/pathutils.h" +#include + +/** + * Loads a saved configuration or defaults if non exist. + * + */ +SerialPluginConfiguration::SerialPluginConfiguration(QString classId, QSettings* qSettings, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + m_speed("57600") +{ + settings = Core::ICore::instance()->settings(); +} + +/** + * Clones a configuration. + * + */ +IUAVGadgetConfiguration *SerialPluginConfiguration::clone() +{ + SerialPluginConfiguration *m = new SerialPluginConfiguration(this->classId()); + m->m_speed=m_speed; + return m; +} + +/** + * Saves a configuration. + * + */ +void SerialPluginConfiguration::saveConfig(QSettings* settings) const { + settings->setValue("speed", m_speed); +} +void SerialPluginConfiguration::restoresettings() +{ + settings->beginGroup(QLatin1String("SerialConnection")); + + QString str=(settings->value(QLatin1String("speed"), tr("")).toString()); + if(str.isEmpty()) + m_speed="57600"; + else + m_speed=str; + settings->endGroup(); + +} +void SerialPluginConfiguration::savesettings() const +{ + settings->beginGroup(QLatin1String("SerialConnection")); + settings->setValue(QLatin1String("speed"), m_speed); + settings->endGroup(); +} diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.h b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.h new file mode 100644 index 000000000..968595fb2 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.h @@ -0,0 +1,58 @@ +/** + ****************************************************************************** + * + * @file serialpluginconfiguration.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 SerialPlugin Serial Plugin + * @{ + * @brief Plots flight information rotary style Serials + *****************************************************************************/ +/* + * 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 SERIALPLUGINCONFIGURATION_H +#define SERIALPLUGINCONFIGURATION_H + +#include + +using namespace Core; + +/* Despite its name, this is actually a generic analog Serial + supporting up to two rotating "needle" indicators. + */ +class SerialPluginConfiguration : public IUAVGadgetConfiguration +{ +Q_OBJECT +public: + explicit SerialPluginConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); + QString speed() {return m_speed;} + void saveConfig(QSettings* settings) const; + IUAVGadgetConfiguration *clone(); + void savesettings() const; + void restoresettings(); + +private: + QString m_speed; + QSettings* settings; +public slots: + void setSpeed(QString speed) { m_speed = speed; } + +}; + +#endif // SERIALPLUGINCONFIGURATION_H diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptions.ui b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptions.ui new file mode 100644 index 000000000..04f9faf06 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptions.ui @@ -0,0 +1,100 @@ + + + SerialPluginOptionsPage + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Serial telemetry speed: + + + + + + + + 1200 + + + + + 2400 + + + + + 4800 + + + + + 9600 + + + + + 19200 + + + + + 38400 + + + + + 57600 + + + + + 115200 + + + + + 230400 + + + + + 460800 + + + + + 921600 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.cpp b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.cpp new file mode 100644 index 000000000..b861a5cee --- /dev/null +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.cpp @@ -0,0 +1,71 @@ +/** + ****************************************************************************** + * + * @file dialpluginoptionspage.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @see The GNU Public License (GPL) Version 3 + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup DialPlugin Dial Plugin + * @{ + * @brief Plots flight information rotary style dials + *****************************************************************************/ +/* + * 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 "serialpluginoptionspage.h" +#include "serialpluginconfiguration.h" +#include "ui_serialpluginoptions.h" +#include "extensionsystem/pluginmanager.h" + +SerialPluginOptionsPage::SerialPluginOptionsPage(SerialPluginConfiguration *config, QObject *parent) : + IOptionsPage(parent), + m_config(config) +{ +} + +//creates options page widget (uses the UI file) +QWidget *SerialPluginOptionsPage::createPage(QWidget *parent) +{ + + Q_UNUSED(parent); + options_page = new Ui::SerialPluginOptionsPage(); + //main widget + QWidget *optionsPageWidget = new QWidget; + //main layout + options_page->setupUi(optionsPageWidget); + options_page->cb_speed->setCurrentIndex(options_page->cb_speed->findText(m_config->speed())); + return optionsPageWidget; +} + +/** + * Called when the user presses apply or OK. + * + * Saves the current values + * + */ +void SerialPluginOptionsPage::apply() +{ + m_config->setSpeed(options_page->cb_speed->currentText()); + m_config->savesettings(); +} + + + +void SerialPluginOptionsPage::finish() +{ + delete m_config; +} diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.h b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.h new file mode 100644 index 000000000..97ea604c8 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.h @@ -0,0 +1,71 @@ +/** + ****************************************************************************** + * + * @file Serialpluginoptionspage.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 SerialPlugin Serial Plugin + * @{ + * @brief Plots flight information rotary style Serials + *****************************************************************************/ +/* + * 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 SERIALpluginOPTIONSPAGE_H +#define SERIALpluginOPTIONSPAGE_H + +#include "coreplugin/dialogs/ioptionspage.h" +#include "QString" +#include +#include +#include + +namespace Core { +class IUAVpluginConfiguration; +} + +class SerialPluginConfiguration; + +namespace Ui { + class SerialPluginOptionsPage; +} + +using namespace Core; + +class SerialPluginOptionsPage : public IOptionsPage +{ +Q_OBJECT +public: + explicit SerialPluginOptionsPage(SerialPluginConfiguration *config, QObject *parent = 0); + + QString id() const { return QLatin1String("settings"); } + QString trName() const { return tr("settings"); } + QString category() const { return "Serial Telemetry"; } + QString trCategory() const { return "Serial Telemetry"; } + QWidget *createPage(QWidget *parent); + void apply(); + void finish(); + +private: + Ui::SerialPluginOptionsPage *options_page; + SerialPluginConfiguration *m_config; + + +}; + +#endif // SERIALpluginOPTIONSPAGE_H From deac94253e2fdd5fac1686e949bc4b16e0455c8e Mon Sep 17 00:00:00 2001 From: zedamota Date: Fri, 11 Nov 2011 23:42:36 +0000 Subject: [PATCH 2/2] small fix and some cleaning --- .../plugins/serialconnection/serialplugin.cpp | 3 +++ .../serialpluginconfiguration.cpp | 22 ++++++++++--------- .../serialpluginconfiguration.h | 6 ++--- .../serialpluginoptionspage.cpp | 10 ++++----- .../serialpluginoptionspage.h | 8 +++---- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.cpp b/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.cpp index bae5a885a..23bb8f9f9 100644 --- a/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.cpp +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.cpp @@ -148,6 +148,7 @@ QIODevice *SerialConnection::openDevice(const QString &deviceName) //we need to handle port settings here... PortSettings set; set.BaudRate = stringToBaud(m_config->speed()); + qDebug()<<"Serial telemetry running at "<speed(); set.DataBits = DATA_8; set.Parity = PAR_NONE; set.StopBits = STOP_1; @@ -227,6 +228,8 @@ BaudRateType SerialConnection::stringToBaud(QString str) return BAUD460800; else if(str== "921600") return BAUD921600; + else + return BAUD56000; } SerialPlugin::SerialPlugin() diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.cpp b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.cpp index 49bcf2ae8..789085596 100644 --- a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.cpp +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.cpp @@ -1,14 +1,14 @@ /** ****************************************************************************** * - * @file dialpluginconfiguration.cpp + * @file serialpluginconfiguration.cpp * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @see The GNU Public License (GPL) Version 3 * @addtogroup GCSPlugins GCS Plugins * @{ - * @addtogroup DialPlugin Dial Plugin + * @addtogroup SerialPlugin Serial Connection Plugin * @{ - * @brief Plots flight information rotary style dials + * @brief Impliments serial connection to the flight hardware for Telemetry *****************************************************************************/ /* * This program is free software; you can redistribute it and/or modify @@ -62,13 +62,12 @@ void SerialPluginConfiguration::saveConfig(QSettings* settings) const { void SerialPluginConfiguration::restoresettings() { settings->beginGroup(QLatin1String("SerialConnection")); - - QString str=(settings->value(QLatin1String("speed"), tr("")).toString()); - if(str.isEmpty()) - m_speed="57600"; - else - m_speed=str; - settings->endGroup(); + QString str=(settings->value(QLatin1String("speed"), tr("")).toString()); + if(str.isEmpty()) + m_speed="57600"; + else + m_speed=str; + settings->endGroup(); } void SerialPluginConfiguration::savesettings() const @@ -77,3 +76,6 @@ void SerialPluginConfiguration::savesettings() const settings->setValue(QLatin1String("speed"), m_speed); settings->endGroup(); } +SerialPluginConfiguration::~SerialPluginConfiguration() +{ +} diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.h b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.h index 968595fb2..793ad102b 100644 --- a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.h +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginconfiguration.h @@ -6,9 +6,9 @@ * @see The GNU Public License (GPL) Version 3 * @addtogroup GCSPlugins GCS Plugins * @{ - * @addtogroup SerialPlugin Serial Plugin + * @addtogroup SerialPlugin Serial Connection Plugin * @{ - * @brief Plots flight information rotary style Serials + * @brief Impliments serial connection to the flight hardware for Telemetry *****************************************************************************/ /* * This program is free software; you can redistribute it and/or modify @@ -46,7 +46,7 @@ public: IUAVGadgetConfiguration *clone(); void savesettings() const; void restoresettings(); - + virtual ~SerialPluginConfiguration(); private: QString m_speed; QSettings* settings; diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.cpp b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.cpp index b861a5cee..29d8b3784 100644 --- a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.cpp @@ -1,16 +1,16 @@ /** ****************************************************************************** * - * @file dialpluginoptionspage.cpp + * @file serialpluginoptionspage.cpp * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @see The GNU Public License (GPL) Version 3 * @addtogroup GCSPlugins GCS Plugins * @{ - * @addtogroup DialPlugin Dial Plugin + * @addtogroup SerialPlugin Serial Connection Plugin * @{ - * @brief Plots flight information rotary style dials + * @brief Impliments serial connection to the flight hardware for Telemetry *****************************************************************************/ -/* + /* * 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 @@ -67,5 +67,5 @@ void SerialPluginOptionsPage::apply() void SerialPluginOptionsPage::finish() { - delete m_config; + delete options_page; } diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.h b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.h index 97ea604c8..6ce23b743 100644 --- a/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.h +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialpluginoptionspage.h @@ -1,16 +1,16 @@ /** ****************************************************************************** * - * @file Serialpluginoptionspage.h + * @file serialpluginoptionspage.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 SerialPlugin Serial Plugin + * @addtogroup SerialPlugin Serial Connection Plugin * @{ - * @brief Plots flight information rotary style Serials + * @brief Impliments serial connection to the flight hardware for Telemetry *****************************************************************************/ -/* + /* * 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