mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Refactor: Move the GpsDisplayThread class to it's own h/cpp files.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1312 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
10b4df2100
commit
39a93a72fd
@ -6,6 +6,7 @@ include(../../plugins/coreplugin/coreplugin.pri)
|
|||||||
include(gpsdisplay_dependencies.pri)
|
include(gpsdisplay_dependencies.pri)
|
||||||
include(../../libs/qwt/qwt.pri)
|
include(../../libs/qwt/qwt.pri)
|
||||||
HEADERS += gpsdisplayplugin.h
|
HEADERS += gpsdisplayplugin.h
|
||||||
|
HEADERS += gpsdisplaythread.h
|
||||||
HEADERS += buffer.h
|
HEADERS += buffer.h
|
||||||
HEADERS += nmeaparser.h
|
HEADERS += nmeaparser.h
|
||||||
HEADERS += gpsdisplaygadget.h
|
HEADERS += gpsdisplaygadget.h
|
||||||
@ -14,6 +15,7 @@ HEADERS += gpsdisplaygadgetfactory.h
|
|||||||
HEADERS += gpsdisplaygadgetconfiguration.h
|
HEADERS += gpsdisplaygadgetconfiguration.h
|
||||||
HEADERS += gpsdisplaygadgetoptionspage.h
|
HEADERS += gpsdisplaygadgetoptionspage.h
|
||||||
SOURCES += gpsdisplayplugin.cpp
|
SOURCES += gpsdisplayplugin.cpp
|
||||||
|
SOURCES += gpsdisplaythread.cpp
|
||||||
SOURCES += buffer.cpp
|
SOURCES += buffer.cpp
|
||||||
SOURCES += nmeaparser.cpp
|
SOURCES += nmeaparser.cpp
|
||||||
SOURCES += gpsdisplaygadget.cpp
|
SOURCES += gpsdisplaygadget.cpp
|
||||||
|
75
ground/src/plugins/gpsdisplay/gpsdisplaythread.cpp
Normal file
75
ground/src/plugins/gpsdisplay/gpsdisplaythread.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file gpsdisplaythread.cpp
|
||||||
|
* @author Edouard Lafargue Copyright (C) 2010.
|
||||||
|
* @addtogroup GCSPlugins GCS Plugins
|
||||||
|
* @{
|
||||||
|
* @addtogroup GPSGadgetPlugin GPS Gadget Plugin
|
||||||
|
* @{
|
||||||
|
* @brief A gadget that displays GPS status and enables basic configuration
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 "gpsdisplaythread.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
void GpsDisplayThread::setPort(QextSerialPort* port)
|
||||||
|
{
|
||||||
|
|
||||||
|
this->port=port;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GpsDisplayThread::setParser(NMEAParser* parser)
|
||||||
|
{
|
||||||
|
|
||||||
|
this->parser=parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GpsDisplayThread::run()
|
||||||
|
{
|
||||||
|
|
||||||
|
qDebug() << "Opening.";
|
||||||
|
|
||||||
|
if (port) {
|
||||||
|
qDebug() << port->portName();
|
||||||
|
|
||||||
|
bool isOpen = port->open(QIODevice::ReadWrite);
|
||||||
|
qDebug() << "Open: " << isOpen;
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
char c;
|
||||||
|
while(true) {
|
||||||
|
qDebug() << "Reading.";
|
||||||
|
/*qint64 bytesRead = port->readLine(buf, sizeof(buf));
|
||||||
|
qDebug() << "bytesRead: " << bytesRead;
|
||||||
|
if (bytesRead != -1) {
|
||||||
|
qDebug() << "Result: '" << buf << "'";
|
||||||
|
}*/
|
||||||
|
while(port->bytesAvailable()>0)
|
||||||
|
{
|
||||||
|
port->read(&c,1);
|
||||||
|
parser->processInputStream(c);
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "Port undefined or invalid.";
|
||||||
|
}
|
||||||
|
}
|
47
ground/src/plugins/gpsdisplay/gpsdisplaythread.h
Normal file
47
ground/src/plugins/gpsdisplay/gpsdisplaythread.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file gpsdisplaythread.h
|
||||||
|
* @author Edouard Lafargue Copyright (C) 2010.
|
||||||
|
* @addtogroup GCSPlugins GCS Plugins
|
||||||
|
* @{
|
||||||
|
* @addtogroup GPSGadgetPlugin GPS Gadget Plugin
|
||||||
|
* @{
|
||||||
|
* @brief A gadget that displays GPS status and enables basic configuration
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 GPSDISPLAYTHREAD_H
|
||||||
|
#define GPSDISPLAYTHREAD_H
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
#include <qextserialport/src/qextserialport.h>
|
||||||
|
#include "nmeaparser.h"
|
||||||
|
|
||||||
|
class GpsDisplayThread : public QThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QextSerialPort *port;
|
||||||
|
NMEAParser *parser;
|
||||||
|
void setPort(QextSerialPort* port);
|
||||||
|
void setParser(NMEAParser* parser);
|
||||||
|
void processInputStream();
|
||||||
|
void run();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GPSDISPLAYTHREAD_H
|
@ -26,6 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gpsdisplaywidget.h"
|
#include "gpsdisplaywidget.h"
|
||||||
|
#include "gpsdisplaythread.h"
|
||||||
#include "ui_gpsdisplaywidget.h"
|
#include "ui_gpsdisplaywidget.h"
|
||||||
#include "extensionsystem/pluginmanager.h"
|
#include "extensionsystem/pluginmanager.h"
|
||||||
#include "uavobjects/uavobjectmanager.h"
|
#include "uavobjects/uavobjectmanager.h"
|
||||||
@ -33,22 +34,10 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QThread>
|
|
||||||
#include "nmeaparser.h"
|
#include "nmeaparser.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GpsDisplayThread : public QThread
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QextSerialPort *port;
|
|
||||||
NMEAParser *parser;
|
|
||||||
void setPort(QextSerialPort* port);
|
|
||||||
void setParser(NMEAParser* parser);
|
|
||||||
void processInputStream();
|
|
||||||
void run();
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the widget
|
* Initialize the widget
|
||||||
*/
|
*/
|
||||||
@ -171,50 +160,3 @@ void GpsDisplayWidget::connectButtonClicked() {
|
|||||||
gpsThread->setParser(parser);
|
gpsThread->setParser(parser);
|
||||||
gpsThread->start();
|
gpsThread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GpsDisplayThread::setPort(QextSerialPort* port)
|
|
||||||
{
|
|
||||||
|
|
||||||
this->port=port;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GpsDisplayThread::setParser(NMEAParser* parser)
|
|
||||||
{
|
|
||||||
|
|
||||||
this->parser=parser;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GpsDisplayThread::run()
|
|
||||||
{
|
|
||||||
|
|
||||||
qDebug() << "Opening.";
|
|
||||||
|
|
||||||
if (port) {
|
|
||||||
qDebug() << port->portName();
|
|
||||||
|
|
||||||
bool isOpen = port->open(QIODevice::ReadWrite);
|
|
||||||
qDebug() << "Open: " << isOpen;
|
|
||||||
|
|
||||||
char buf[1024];
|
|
||||||
char c;
|
|
||||||
while(true) {
|
|
||||||
qDebug() << "Reading.";
|
|
||||||
/*qint64 bytesRead = port->readLine(buf, sizeof(buf));
|
|
||||||
qDebug() << "bytesRead: " << bytesRead;
|
|
||||||
if (bytesRead != -1) {
|
|
||||||
qDebug() << "Result: '" << buf << "'";
|
|
||||||
}*/
|
|
||||||
while(port->bytesAvailable()>0)
|
|
||||||
{
|
|
||||||
port->read(&c,1);
|
|
||||||
parser->processInputStream(c);
|
|
||||||
}
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
qDebug() << "Port undefined or invalid.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user