diff --git a/ground/src/plugins/gpsdisplay/gpsdisplay.pro b/ground/src/plugins/gpsdisplay/gpsdisplay.pro index 0ce91afe0..6370d6ac8 100644 --- a/ground/src/plugins/gpsdisplay/gpsdisplay.pro +++ b/ground/src/plugins/gpsdisplay/gpsdisplay.pro @@ -6,6 +6,7 @@ include(../../plugins/coreplugin/coreplugin.pri) include(gpsdisplay_dependencies.pri) include(../../libs/qwt/qwt.pri) HEADERS += gpsdisplayplugin.h +HEADERS += gpsdisplaythread.h HEADERS += buffer.h HEADERS += nmeaparser.h HEADERS += gpsdisplaygadget.h @@ -14,6 +15,7 @@ HEADERS += gpsdisplaygadgetfactory.h HEADERS += gpsdisplaygadgetconfiguration.h HEADERS += gpsdisplaygadgetoptionspage.h SOURCES += gpsdisplayplugin.cpp +SOURCES += gpsdisplaythread.cpp SOURCES += buffer.cpp SOURCES += nmeaparser.cpp SOURCES += gpsdisplaygadget.cpp diff --git a/ground/src/plugins/gpsdisplay/gpsdisplaythread.cpp b/ground/src/plugins/gpsdisplay/gpsdisplaythread.cpp new file mode 100644 index 000000000..3ea8aa8ee --- /dev/null +++ b/ground/src/plugins/gpsdisplay/gpsdisplaythread.cpp @@ -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 + +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."; + } +} diff --git a/ground/src/plugins/gpsdisplay/gpsdisplaythread.h b/ground/src/plugins/gpsdisplay/gpsdisplaythread.h new file mode 100644 index 000000000..0f6cd4f92 --- /dev/null +++ b/ground/src/plugins/gpsdisplay/gpsdisplaythread.h @@ -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 +#include +#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 diff --git a/ground/src/plugins/gpsdisplay/gpsdisplaywidget.cpp b/ground/src/plugins/gpsdisplay/gpsdisplaywidget.cpp index 77ce5d00c..a5fa8da26 100644 --- a/ground/src/plugins/gpsdisplay/gpsdisplaywidget.cpp +++ b/ground/src/plugins/gpsdisplay/gpsdisplaywidget.cpp @@ -26,6 +26,7 @@ */ #include "gpsdisplaywidget.h" +#include "gpsdisplaythread.h" #include "ui_gpsdisplaywidget.h" #include "extensionsystem/pluginmanager.h" #include "uavobjects/uavobjectmanager.h" @@ -33,22 +34,10 @@ #include #include #include -#include #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 */ @@ -171,50 +160,3 @@ void GpsDisplayWidget::connectButtonClicked() { gpsThread->setParser(parser); 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."; - } -} - -