1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-35 GCS/Qymodem_lib and Uploader plugin. Further cleaning up, and documenting.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@499 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2010-04-14 21:23:13 +00:00 committed by zedamota
parent 1a4e3c8d44
commit 2e9bb6eadc
15 changed files with 135 additions and 69 deletions

View File

@ -3,6 +3,7 @@
*
* @file qymodem.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by J.D.Medhurst (a.k.a. Tixy)
* @brief Implementation of base class for QymodemTx.
* @see The GNU Public License (GPL) Version 3
* @defgroup ymodem_lib

View File

@ -3,6 +3,7 @@
*
* @file qymodem_tx.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by J.D.Medhurst (a.k.a. Tixy)
* @brief Implementation of base class for QymodemSend.
* @see The GNU Public License (GPL) Version 3
* @defgroup ymodem_lib

View File

@ -3,6 +3,7 @@
*
* @file qymodemsend.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by J.D.Medhurst (a.k.a. Tixy)
* @brief Implementation of Class for presenting a file as a input stream.
* @see The GNU Public License (GPL) Version 3
* @defgroup ymodem_lib

View File

@ -1,9 +1,9 @@
/**
******************************************************************************
*
* @file UploaderGadget.cpp
* @file uploadergadget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @brief Uploader Plugin Gadget
* @see The GNU Public License (GPL) Version 3
* @defgroup Uploader
* @{
@ -27,11 +27,9 @@
#include "uploadergadget.h"
#include "uploadergadgetwidget.h"
#include "uploadergadgetconfiguration.h"
//#include "./qextserialport/qextserialbase.h"
//#include "./qextserialport/qextserialenumerator.h"
//#include "./qextserialport/qextserialPort.h"
#include <qextserialport/src/qextserialport.h>
#include <qextserialport/src/qextserialenumerator.h>
UploaderGadget::UploaderGadget(QString classId, UploaderGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
m_widget(widget)
@ -42,7 +40,10 @@ UploaderGadget::~UploaderGadget()
{
}
/**
* Loads a configuration.
*
*/
void UploaderGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{
UploaderGadgetConfiguration *m = qobject_cast< UploaderGadgetConfiguration*>(config);
@ -53,8 +54,8 @@ void UploaderGadget::loadConfiguration(IUAVGadgetConfiguration* config)
portsettings.Parity=m->Parity();
portsettings.StopBits=m->StopBits();
portsettings.Timeout_Millisec=m->TimeOut();
//Creates new serial port with the user configuration and passes it to the widget
QextSerialPort *port=new QextSerialPort(m->Port(),portsettings,QextSerialPort::Polling);
m_widget->setPort(port);
}

View File

@ -1,9 +1,9 @@
/**
******************************************************************************
*
* @file Uploadergadget.h
* @file uploadergadget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @brief Uploader Plugin Gadget configuration
* @see The GNU Public License (GPL) Version 3
* @defgroup Uploader
* @{
@ -32,7 +32,6 @@
#include "uploadergadgetwidget.h"
class IUAVGadget;
//class QList<int>;
class QWidget;
class QString;
class UploaderGadgetWidget;

View File

@ -1,9 +1,9 @@
/**
******************************************************************************
*
* @file UploaderGadgetconfiguration.cpp
* @file uploadergadgetconfiguration.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @brief Uploader Plugin Gadget configuration
* @see The GNU Public License (GPL) Version 3
* @defgroup Uploader
* @{
@ -29,6 +29,10 @@
#include <QtCore/QDataStream>
#include <qextserialport/src/qextserialport.h>
/**
* Loads a saved configuration or defaults if non exist.
*
*/
UploaderGadgetConfiguration::UploaderGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent) :
IUAVGadgetConfiguration(classId, parent),
m_defaultPort("Unknown"),
@ -40,9 +44,9 @@ UploaderGadgetConfiguration::UploaderGadgetConfiguration(QString classId, const
m_defaultTimeOut(5000)
{
//if a saved configuration exists load it
if (state.count() > 0) {
QDataStream stream(state);
BaudRateType speed;
DataBitsType databits;
FlowType flow;
@ -76,7 +80,10 @@ UploaderGadgetConfiguration::UploaderGadgetConfiguration(QString classId, const
}
}
/**
* Clones a configuration.
*
*/
IUAVGadgetConfiguration *UploaderGadgetConfiguration::clone()
{
UploaderGadgetConfiguration *m = new UploaderGadgetConfiguration(this->classId());
@ -89,7 +96,10 @@ IUAVGadgetConfiguration *UploaderGadgetConfiguration::clone()
m->m_defaultPort=m_defaultPort;
return m;
}
/**
* Saves a configuration.
*
*/
QByteArray UploaderGadgetConfiguration::saveState() const
{
QByteArray bytes;
@ -100,7 +110,6 @@ QByteArray UploaderGadgetConfiguration::saveState() const
stream << (int)m_defaultParity;
stream << (int)m_defaultStopBits;
stream << m_defaultPort;
return bytes;
}

View File

@ -1,9 +1,9 @@
/**
******************************************************************************
*
* @file UploaderGadgetconfiguration.h
* @file uploadergadgetconfiguration.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @brief Uploader Plugin Gadget configuration
* @see The GNU Public License (GPL) Version 3
* @defgroup Uploader
* @{
@ -38,6 +38,8 @@ class UploaderGadgetConfiguration : public IUAVGadgetConfiguration
Q_OBJECT
public:
explicit UploaderGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
//set port configuration functions
void setSpeed(BaudRateType speed) {m_defaultSpeed=speed;}
void setDataBits(DataBitsType databits) {m_defaultDataBits=databits;}
void setFlow(FlowType flow) {m_defaultFlow=flow;}
@ -46,6 +48,7 @@ public:
void setPort(QString port){m_defaultPort=port;}
void setTimeOut(long timeout){m_defaultTimeOut=timeout;}
//get port configuration functions
BaudRateType Speed() {return m_defaultSpeed;}
DataBitsType DataBits() {return m_defaultDataBits;}
FlowType Flow() {return m_defaultFlow;}
@ -53,13 +56,10 @@ public:
StopBitsType StopBits() {return m_defaultStopBits;}
QString Port(){return m_defaultPort;}
long TimeOut(){return m_defaultTimeOut;}
QByteArray saveState() const;
IUAVGadgetConfiguration *clone();
signals:
public slots:
private:
QString m_defaultPort;
BaudRateType m_defaultSpeed;

View File

@ -1,9 +1,9 @@
/**
******************************************************************************
*
* @file UploaderGadgetfactory.cpp
* @file uploadergadgetfactory.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @brief Uploader Plugin Gadget factory
* @see The GNU Public License (GPL) Version 3
* @defgroup Uploader
* @{
@ -24,6 +24,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "uploadergadgetfactory.h"
#include "uploadergadgetwidget.h"
#include "uploadergadget.h"

View File

@ -1,9 +1,9 @@
/**
******************************************************************************
*
* @file UploaderGadgetfactory.h
* @file uploadergadgetfactory.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @brief Uploader Plugin Gadget factory
* @see The GNU Public License (GPL) Version 3
* @defgroup Uploader
* @{

View File

@ -1,9 +1,9 @@
/**
******************************************************************************
*
* @file UploaderGadgetoptionspage.cpp
* @file uploadergadgetoptionspage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @brief Uploader Plugin Gadget options page
* @see The GNU Public License (GPL) Version 3
* @defgroup Uploader
* @{
@ -37,12 +37,15 @@
#include <QtAlgorithms>
#include <QStringList>
#include <qextserialport/src/qextserialenumerator.h>
UploaderGadgetOptionsPage::UploaderGadgetOptionsPage(UploaderGadgetConfiguration *config, QObject *parent) :
IOptionsPage(parent),
m_config(config)
{
//the begining of some ugly code
//diferent OS's have diferent serial port capabilities
#ifdef Q_OS_WIN
//load windows port capabilities
BaudRateTypeString
<<"BAUD110"
<<"BAUD300"
@ -75,6 +78,7 @@ UploaderGadgetOptionsPage::UploaderGadgetOptionsPage(UploaderGadgetConfiguration
<<"STOP_1_5" //WINDOWS ONLY
<<"STOP_2";
#else
//load POSIX port capabilities
BaudRateTypeString
<<"BAUD50" //POSIX ONLY
@ -109,7 +113,7 @@ UploaderGadgetOptionsPage::UploaderGadgetOptionsPage(UploaderGadgetConfiguration
<<"STOP_1"
<<"STOP_2";
#endif
//load all OS's capabilities
BaudRateTypeStringALL
<<"BAUD50" //POSIX ONLY
<<"BAUD75" //POSIX ONLY
@ -155,18 +159,16 @@ UploaderGadgetOptionsPage::UploaderGadgetOptionsPage(UploaderGadgetConfiguration
<<"FLOW_XONXOFF";
}
//creates options page widget
QWidget *UploaderGadgetOptionsPage::createPage(QWidget *parent)
{
//main widget
QWidget *widget = new QWidget;
//main layout
QVBoxLayout *vl = new QVBoxLayout();
widget->setLayout(vl);
//port layout
//port layout and widget
QHBoxLayout *portLayout = new QHBoxLayout();
QWidget *x = new QWidget;
x->setLayout(portLayout);
@ -176,7 +178,7 @@ QWidget *UploaderGadgetOptionsPage::createPage(QWidget *parent)
portLayout->addWidget(label);
portLayout->addWidget(m_portCB);
//port speed layout
//port speed layout and widget
QHBoxLayout *speedLayout = new QHBoxLayout();
QWidget *y = new QWidget;
y->setLayout(speedLayout);
@ -186,7 +188,7 @@ QWidget *UploaderGadgetOptionsPage::createPage(QWidget *parent)
speedLayout->addWidget(label);
speedLayout->addWidget(m_speedCB);
//flow control layout
//flow control layout and widget
QHBoxLayout *flowLayout = new QHBoxLayout();
QWidget *z = new QWidget;
z->setLayout(flowLayout);
@ -196,7 +198,7 @@ QWidget *UploaderGadgetOptionsPage::createPage(QWidget *parent)
flowLayout->addWidget(label);
flowLayout->addWidget(m_flowCB);
//databits layout
//databits layout and widget
QHBoxLayout *databitsLayout = new QHBoxLayout();
QWidget *a = new QWidget;
a->setLayout(databitsLayout);
@ -206,7 +208,7 @@ QWidget *UploaderGadgetOptionsPage::createPage(QWidget *parent)
databitsLayout->addWidget(label);
databitsLayout->addWidget(m_databitsCB);
//stopbits layout
//stopbits layout and widget
QHBoxLayout *stopbitsLayout = new QHBoxLayout();
QWidget *b = new QWidget;
b->setLayout(stopbitsLayout);
@ -216,7 +218,7 @@ QWidget *UploaderGadgetOptionsPage::createPage(QWidget *parent)
stopbitsLayout->addWidget(label);
stopbitsLayout->addWidget(m_stopbitsCB);
//parity layout
//parity layout and widget
QHBoxLayout *parityLayout = new QHBoxLayout();
QWidget *c = new QWidget;
c->setLayout(parityLayout);
@ -226,7 +228,7 @@ QWidget *UploaderGadgetOptionsPage::createPage(QWidget *parent)
parityLayout->addWidget(label);
parityLayout->addWidget(m_parityCB);
//timeout layout
//timeout layout and widget
QHBoxLayout *timeoutLayout = new QHBoxLayout();
QWidget *d = new QWidget;
d->setLayout(timeoutLayout);
@ -240,6 +242,7 @@ QWidget *UploaderGadgetOptionsPage::createPage(QWidget *parent)
QSpacerItem *spacer = new QSpacerItem(100, 100, QSizePolicy::Expanding, QSizePolicy::Expanding);
//add partial widget to main widget
vl->addWidget(x);
vl->addWidget(y);
vl->addWidget(z);
@ -249,6 +252,8 @@ QWidget *UploaderGadgetOptionsPage::createPage(QWidget *parent)
vl->addWidget(d);
vl->addSpacerItem(spacer);
//clears comboboxes, if not every time the user enters options page the lists
//duplicate
m_portCB->clear();
m_speedCB->clear();
m_databitsCB->clear();
@ -256,6 +261,7 @@ QWidget *UploaderGadgetOptionsPage::createPage(QWidget *parent)
m_parityCB->clear();
m_stopbitsCB->clear();
//gets available serial ports
QList<QextPortInfo> ports =QextSerialEnumerator ::getPorts();
qSort(ports.begin(), ports.end());
qDebug() << "List of ports:";
@ -269,53 +275,63 @@ QWidget *UploaderGadgetOptionsPage::createPage(QWidget *parent)
qDebug() << "===================================";
}
#ifdef Q_OS_WIN
//on windows populate ports combobox with ports name
for (int i = 0; i < ports.size(); i++) {
m_portCB->addItem((QString)ports.at(i).portName.toLocal8Bit().constData());
}
#else
//on other OS's populate ports combobox with ports physical name
for (int i = 0; i < ports.size(); i++) {
m_portCB->addItem((QString)ports.at(i).physName.toLocal8Bit().constData());
}
#endif
//The next selections of comboboxe's saved value are ugly as hell
//There must be a better wat for doing this.
//select saved port
if(m_portCB->findText(m_config->Port())!=-1){
m_portCB->setCurrentIndex(m_portCB->findText(m_config->Port()));
}
//populate serial speed combobox
for (int i=0;i<BaudRateTypeString.size();i++){
m_speedCB->addItem(BaudRateTypeString.at(i).toLocal8Bit().constData() );
}
//select saved speed
if(m_speedCB->findText(BaudRateTypeStringALL.at((int)m_config->Speed()).toLocal8Bit().constData())!=-1){
m_speedCB->setCurrentIndex(m_speedCB->findText(BaudRateTypeStringALL.at((int)m_config->Speed()).toLocal8Bit().constData()));
}
//populate databits combobox
for (int i=0;i<DataBitsTypeString.size();i++){
m_databitsCB->addItem(DataBitsTypeString.at(i).toLocal8Bit().constData() );
}
//select saved databits
if(m_databitsCB->findText(DataBitsTypeStringALL.at((int)m_config->DataBits()).toLocal8Bit().constData())!=-1){
m_databitsCB->setCurrentIndex(m_databitsCB->findText(DataBitsTypeStringALL.at((int)m_config->DataBits()).toLocal8Bit().constData()));
}
//populate parity combobox
for (int i=0;i<ParityTypeString.size();i++){
m_parityCB->addItem(ParityTypeString.at(i).toLocal8Bit().constData() );
}
//select saved parity
if(m_parityCB->findText(ParityTypeStringALL.at((int)m_config->Parity()).toLocal8Bit().constData())!=-1){
m_parityCB->setCurrentIndex(m_parityCB->findText(ParityTypeStringALL.at((int)m_config->Parity()).toLocal8Bit().constData()));
}
//populate stopbits combobox
for (int i=0;i<StopBitsTypeString.size();i++){
m_stopbitsCB->addItem(StopBitsTypeString.at(i).toLocal8Bit().constData() );
}
//select saved stopbits
if(m_stopbitsCB->findText(StopBitsTypeStringALL.at((int)m_config->StopBits()).toLocal8Bit().constData())!=-1){
m_stopbitsCB->setCurrentIndex(m_stopbitsCB->findText(StopBitsTypeStringALL.at((int)m_config->StopBits()).toLocal8Bit().constData()));
}
//populate flow control combobox
for (int i=0;i<FlowTypeString.size();i++){
m_flowCB->addItem(FlowTypeString.at(i).toLocal8Bit().constData() );
}
//select saved flow control
if(m_flowCB->findText(FlowTypeString.at((int)m_config->Flow()).toLocal8Bit().constData())!=-1){
m_flowCB->setCurrentIndex(m_flowCB->findText(FlowTypeString.at((int)m_config->Flow()).toLocal8Bit().constData()));
}
//fill time out spinbox with saved value
m_timeoutSpin->setValue(m_config->TimeOut());
return widget;
}
@ -327,7 +343,6 @@ QWidget *UploaderGadgetOptionsPage::createPage(QWidget *parent)
*/
void UploaderGadgetOptionsPage::apply()
{
m_config->setPort(m_portCB->currentText());
m_config->setSpeed((BaudRateType)BaudRateTypeStringALL.indexOf(m_speedCB->currentText()));
m_config->setDataBits((DataBitsType)DataBitsTypeStringALL.indexOf(m_databitsCB->currentText()));

View File

@ -1,9 +1,9 @@
/**
******************************************************************************
*
* @file UploaderGadgetoptionspage.h
* @file uploadergadgetoptionspage.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @brief Uploader Plugin Gadget options page
* @see The GNU Public License (GPL) Version 3
* @defgroup Uploader
* @{
@ -32,6 +32,7 @@
#include "QString"
#include <QStringList>
#include <QDebug>
namespace Core {
class IUAVGadgetConfiguration;
}
@ -52,9 +53,6 @@ public:
void apply();
void finish();
signals:
public slots:
private:
UploaderGadgetConfiguration *m_config;
QComboBox *m_portCB;

View File

@ -1,9 +1,9 @@
/**
******************************************************************************
*
* @file UploaderGadgetwidget.cpp
* @file uploadergadgetwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @brief Uploader Plugin Gadget widget
* @see The GNU Public License (GPL) Version 3
* @defgroup Uploader
* @{
@ -29,8 +29,10 @@
UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent)
{
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
QVBoxLayout *layout = new QVBoxLayout;
//main layout
QVBoxLayout *layout = new QVBoxLayout;
//choose file layout and widget
QHBoxLayout *FileLayout = new QHBoxLayout;
QWidget *FileWidget = new QWidget;
FileWidget->setLayout(FileLayout);
@ -40,7 +42,7 @@ UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent)
FileLayout->addWidget(openFileNameLE);
FileLayout->addWidget(loadfile);
//send file layout and widget
QHBoxLayout *SendLayout = new QHBoxLayout;
QWidget *SendWidget = new QWidget;
SendWidget->setLayout(SendLayout);
@ -51,52 +53,79 @@ UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent)
SendLayout->addWidget(progressBar);
SendLayout->addWidget(sendBt);
//status layout and widget
QHBoxLayout *StatusLayout = new QHBoxLayout;
QWidget *StatusWidget = new QWidget;
StatusWidget->setLayout(StatusLayout);
status=new QLabel();
StatusLayout->addWidget(status);
//add partial widgets to main widget
layout->addWidget(FileWidget);
layout->addWidget(SendWidget);
layout->addWidget(StatusWidget);
setLayout(layout);
//connect signals to slots
//fires when the user presses file button
connect(loadfile, SIGNAL(clicked(bool)),
this,SLOT(setOpenFileName()));
//fires when the user presses send button
connect(sendBt, SIGNAL(clicked(bool)),
this,SLOT(send()));
}
//user pressed send, send file using a new thread with qymodem library
void UploaderGadgetWidget::send()
{
Ymodem->SendFileT(openFileNameLE->text());
}
//destructor !!?! do I need to delete something else?
UploaderGadgetWidget::~UploaderGadgetWidget()
{
delete Port;
delete Ymodem;
}
//from load configuration, creates a new qymodemsend class with the the port
/**
Cteates a new qymodemsend class.
@param port The serial port to use.
*/
void UploaderGadgetWidget::setPort(QextSerialPort* port)
{
Port=port;
Ymodem=new QymodemSend(*Port);
//only now can we connect this signals
//signals errors
connect(Ymodem,SIGNAL(Error(QString,int))
,this,SLOT(error(QString,int)));
//signals new information
connect(Ymodem,SIGNAL(Information(QString,int)),
this,SLOT(info(QString,int)));
//signals new percentage value
connect(Ymodem,SIGNAL(Percent(int)),
this,SLOT(updatePercSlot(int)));
}
/**
Updates progress bar value.
@param i New percentage value.
*/
void UploaderGadgetWidget::updatePercSlot(int i)
{
progressBar->setValue(i);
}
/**
Opens an open file dialog.
*/
void UploaderGadgetWidget::setOpenFileName()
{
QFileDialog::Options options;
@ -110,7 +139,14 @@ void UploaderGadgetWidget::setOpenFileName()
if (!fileName.isEmpty()) openFileNameLE->setText(fileName);
}
/**
Shows a message box with an error string.
@param errorString The error string to display.
@param errorNumber Not used
*/
void UploaderGadgetWidget::error(QString errorString, int errorNumber)
{
QMessageBox msgBox;
@ -119,6 +155,14 @@ void UploaderGadgetWidget::error(QString errorString, int errorNumber)
msgBox.exec();
status->setText(errorString);
}
/**
Shows a message box with an information string.
@param infoString The information string to display.
@param infoNumber Not used
*/
void UploaderGadgetWidget::info(QString infoString, int infoNumber)
{
status->setText(infoString);

View File

@ -1,9 +1,9 @@
/**
******************************************************************************
*
* @file UploaderGadgetwidget.h
* @file uploadergadgetwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @brief Uploader Plugin Gadget widget
* @see The GNU Public License (GPL) Version 3
* @defgroup Uploader
* @{
@ -56,9 +56,6 @@ public:
void setPort(QextSerialPort* port);
protected:
// void resizeEvent(QResizeEvent *event);
private:
QLineEdit* openFileNameLE;

View File

@ -2,9 +2,9 @@
/**
******************************************************************************
*
* @file UploaderPlugin.cpp
* @file uploaderplugin.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @brief A plugin to upload a file using y-modem protocol and a serial port
* @see The GNU Public License (GPL) Version 3
* @defgroup Uploader
* @{
@ -47,7 +47,6 @@ bool UploaderPlugin::initialize(const QStringList& args, QString *errMsg)
Q_UNUSED(errMsg);
mf = new UploaderGadgetFactory(this);
addAutoReleasedObject(mf);
return true;
}

View File

@ -1,9 +1,9 @@
/**
******************************************************************************
*
* @file UploaderPlugin.h
* @file uploaderplugin.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @brief A plugin to upload a file using y-modem protocol and a serial port
* @see The GNU Public License (GPL) Version 3
* @defgroup Uploader
* @{