mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
Merge remote-tracking branch 'origin/pt/configurable_gcs_serial_speed' into next
This commit is contained in:
commit
24af36bba3
@ -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
|
||||
|
@ -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,8 @@ QIODevice *SerialConnection::openDevice(const QString &deviceName)
|
||||
{
|
||||
//we need to handle port settings here...
|
||||
PortSettings set;
|
||||
set.BaudRate = BAUD57600;
|
||||
set.BaudRate = stringToBaud(m_config->speed());
|
||||
qDebug()<<"Serial telemetry running at "<<m_config->speed();
|
||||
set.DataBits = DATA_8;
|
||||
set.Parity = PAR_NONE;
|
||||
set.StopBits = STOP_1;
|
||||
@ -198,6 +204,33 @@ 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;
|
||||
else
|
||||
return BAUD56000;
|
||||
}
|
||||
|
||||
SerialPlugin::SerialPlugin()
|
||||
{
|
||||
@ -205,19 +238,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;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,8 @@
|
||||
#include <qextserialenumerator.h>
|
||||
#include "coreplugin/iconnection.h"
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include "serialpluginconfiguration.h"
|
||||
#include "serialpluginoptionspage.h"
|
||||
#include <QThread>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -0,0 +1,81 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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 SerialPlugin Serial Connection Plugin
|
||||
* @{
|
||||
* @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
|
||||
* (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 <coreplugin/icore.h>
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
SerialPluginConfiguration::~SerialPluginConfiguration()
|
||||
{
|
||||
}
|
@ -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 Connection Plugin
|
||||
* @{
|
||||
* @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
|
||||
* (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 <coreplugin/iuavgadgetconfiguration.h>
|
||||
|
||||
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();
|
||||
virtual ~SerialPluginConfiguration();
|
||||
private:
|
||||
QString m_speed;
|
||||
QSettings* settings;
|
||||
public slots:
|
||||
void setSpeed(QString speed) { m_speed = speed; }
|
||||
|
||||
};
|
||||
|
||||
#endif // SERIALPLUGINCONFIGURATION_H
|
@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SerialPluginOptionsPage</class>
|
||||
<widget class="QWidget" name="SerialPluginOptionsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Serial telemetry speed:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cb_speed">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>1200</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>2400</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>4800</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>9600</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>19200</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>38400</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>57600</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>115200</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>230400</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>460800</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>921600</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -0,0 +1,71 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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 SerialPlugin Serial Connection Plugin
|
||||
* @{
|
||||
* @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
|
||||
* (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 options_page;
|
||||
}
|
@ -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 Connection Plugin
|
||||
* @{
|
||||
* @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
|
||||
* (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 <QStringList>
|
||||
#include <QDebug>
|
||||
#include <QFont>
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user