improve gps detection

git-svn-id: http://svn.osgeo.org/qgis/trunk@12759 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
jef 2010-01-14 18:13:35 +00:00
parent 002416f519
commit bffa5cc9bd
18 changed files with 345 additions and 364 deletions

View File

@ -303,7 +303,7 @@ INCLUDE_DIRECTORIES(
${GEOS_INCLUDE_DIR}
${GDAL_INCLUDE_DIR}
../core
../core/gps
../core/gps ../core/gps/qextserialport
../core/composer ../core/raster ../core/renderer ../core/symbology ../core/symbology-ng
../gui ../gui/symbology-ng
../plugins

View File

@ -18,7 +18,7 @@
#include "qgsgpsinformationwidget.h"
#include "qgsvectorlayer.h"
#include "qgsnmeaconnection.h"
#include "qgsgpstrackerthread.h"
#include "qgsgpsdetector.h"
#include "qgscoordinatetransform.h"
#include <qgspoint.h>
#include <qgsrubberband.h>
@ -58,9 +58,7 @@
QgsGPSInformationWidget::QgsGPSInformationWidget( QgsMapCanvas * thepCanvas, QWidget * parent, Qt::WindowFlags f ):
QWidget( parent, f ),
mSerialPort( 0 ),
mNmea( 0 ),
mThread( 0 ) ,
mpCanvas( thepCanvas )
{
setupUi( this );
@ -293,69 +291,62 @@ void QgsGPSInformationWidget::on_mConnectButton_toggled( bool theFlag )
{
if ( theFlag )
{
mConnectButton->setText( tr( "Connecting..." ) );
connectGps();
mConnectButton->setText( tr( "Disconnect" ) );
}
else
{
disconnectGps();
mConnectButton->setText( tr( "Connect" ) );
}
}
void QgsGPSInformationWidget::connectGps()
{
QString port;
if ( mRadUserPath->isChecked() )
{
if ( !mCboDevices->itemData( mCboDevices->currentIndex() ).toString().isEmpty() )
{
mNmea = new QgsNMEAConnection( mCboDevices->itemData( mCboDevices->currentIndex() ).toString(), 500 );
QObject::connect( mNmea, SIGNAL( stateChanged( const QgsGPSInformation& ) ),
this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );
mThread = new QgsGPSTrackerThread( mNmea );
mThread->start();
mGPSTextEdit->append( tr( "Connecting on %1" ).arg( mCboDevices->itemData( mCboDevices->currentIndex() ).toString() ) );
}
else
port = mCboDevices->itemData( mCboDevices->currentIndex() ).toString();
if ( port.isEmpty() )
{
QMessageBox::information( this, tr( "/gps" ), tr( "No path to the GPS port "
"is specified. Please enter a path then try again." ) );
//toggle the button back off
mConnectButton->setChecked( false );
}
}
else //autodetect
{
mNmea = QgsGPSConnection::detectGPSConnection();
if ( !mNmea )
{
mConnectButton->setChecked( false );
return;
}
mNmea->setPollInterval( 1000 );
QObject::connect( mNmea, SIGNAL( stateChanged( const QgsGPSInformation& ) ), this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );
mThread = new QgsGPSTrackerThread( mNmea );
mThread->start();
mGPSTextEdit->append( tr( "Connected..." ) );
}
mGPSTextEdit->append( tr( "Connecting..." ) );
QgsGPSDetector *detector = new QgsGPSDetector( port );
connect( detector, SIGNAL( detected( QgsGPSConnection * ) ), this, SLOT( connected( QgsGPSConnection * ) ) );
connect( detector, SIGNAL( detectionFailed() ), this, SLOT( timedout() ) );
}
void QgsGPSInformationWidget::timedout()
{
mConnectButton->setChecked( false );
mNmea = NULL;
mGPSTextEdit->append( tr( "Timed out!" ) );
}
void QgsGPSInformationWidget::connected( QgsGPSConnection *conn )
{
mNmea = conn;
QObject::connect( mNmea, SIGNAL( stateChanged( const QgsGPSInformation& ) ),
this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );
mGPSTextEdit->append( tr( "Connected!" ) );
mConnectButton->setText( tr( "Disconnect" ) );
}
void QgsGPSInformationWidget::disconnectGps()
{
if ( mThread )
{
mThread->quit();
mThread->wait();
delete mThread;
mThread = 0;
mNmea = 0;
mSerialPort = 0;
mGPSTextEdit->append( tr( "Disconnected..." ) );
}
//mGPSTextEdit->clear();
//toggle the button back on
delete mNmea;
mGPSTextEdit->append( tr( "Disconnected..." ) );
mConnectButton->setChecked( false );
mConnectButton->setText( tr( "Connect" ) );
}
@ -370,6 +361,7 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
{
delete mMarkerList.takeFirst();
}
for ( int i = 0; i < info.satellitesInView.size(); ++i )
{
QgsSatelliteInfo currentInfo = info.satellitesInView.at( i );
@ -858,7 +850,7 @@ void QgsGPSInformationWidget::on_mBtnRefreshDevices_clicked( )
/* Copied from gps plugin */
void QgsGPSInformationWidget::populateDevices()
{
QList< QPair<QString, QString> > ports = QgsGPSConnection::availablePorts();
QList< QPair<QString, QString> > ports = QgsGPSDetector::availablePorts();
mCboDevices->clear();
for ( int i = 0; i < ports.size(); i++ )

View File

@ -58,15 +58,17 @@ class QgsGPSInformationWidget: public QWidget, private Ui::QgsGPSInformationWidg
void on_mBtnCloseFeature_clicked( );
void on_mBtnResetFeature_clicked( );
void on_mCbxAutoAddVertices_toggled( bool theFlag );
void connected( QgsGPSConnection * );
void timedout();
private:
void addVertex( );
void connectGps();
void connectGpsSlot( );
void disconnectGps();
void populateDevices();
QextSerialPort* mSerialPort;
QgsGPSConnection* mNmea;
QgsGPSTrackerThread* mThread;
QgsMapCanvas * mpCanvas;
QgsGpsMarker * mpMapMarker;
QwtPlot * mpPlot;

View File

@ -10,8 +10,8 @@ SET(QGIS_CORE_SRCS
gps/qgsgpsconnection.cpp
gps/qgsgpsconnectionregistry.cpp
gps/qgsgpstrackerthread.cpp
gps/qgsnmeaconnection.cpp
gps/qgsgpsdetector.cpp
gps/parse.c
gps/sentence.c
gps/info.c
@ -241,6 +241,7 @@ SET(QGIS_CORE_MOC_HDRS
raster/qgsrasterlayer.h
gps/qgsgpsconnection.h
gps/qgsgpsdetector.h
gps/qgsnmeaconnection.h
gps/qextserialport/qextserialport.h
gps/qextserialport/qextserialenumerator.h

View File

@ -956,3 +956,7 @@ qint64 QextSerialPort::writeData(const char * data, qint64 maxSize)
return (qint64)retVal;
}
void QextSerialPort::onWinEvent( HANDLE h )
{
}

View File

@ -129,46 +129,12 @@ struct PortSettings
#include <sys/ioctl.h>
#include <sys/select.h>
#include <QSocketNotifier>
#elif (defined Q_OS_WIN)
typedef int HANDLE; // unused
typedef
#elif defined (Q_OS_WIN)
#include <windows.h>
#include <QThread>
#include <QReadWriteLock>
// Ugly: copied private Qt header file
QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QWinEventNotifier : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(QObject)
public:
explicit QWinEventNotifier(QObject *parent = 0);
explicit QWinEventNotifier(HANDLE hEvent, QObject *parent = 0);
~QWinEventNotifier();
void setHandle(HANDLE hEvent);
HANDLE handle() const;
bool isEnabled() const;
public Q_SLOTS:
void setEnabled(bool enable);
Q_SIGNALS:
void activated(HANDLE hEvent);
protected:
bool event(QEvent *e);
private:
Q_DISABLE_COPY(QWinEventNotifier)
HANDLE handleToEvent;
bool enabled;
};
QT_END_NAMESPACE
#endif
/*!
@ -212,6 +178,9 @@ No guarantees are made as to the quality of POSIX support under NT/2000 however.
\author Stefan Sander, Michal Policht, Brandon Fosdick, Liam Staskawicz
*/
class QWinEventNotifier;
class QextSerialPort: public QIODevice
{
Q_OBJECT
@ -335,10 +304,8 @@ class QextSerialPort: public QIODevice
qint64 readData(char * data, qint64 maxSize);
qint64 writeData(const char * data, qint64 maxSize);
#ifdef Q_OS_WIN
private slots:
void onWinEvent(HANDLE h);
#endif
private:
Q_DISABLE_COPY(QextSerialPort)

View File

@ -0,0 +1,43 @@
#ifndef QWINEVENTNOTIFIER_H
#define QWINEVENTNOTIFIER_H
#include <QObject>
#include <windows.h>
// Ugly: copied private Qt header file
QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QWinEventNotifier : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(QObject)
public:
explicit QWinEventNotifier(QObject *parent = 0);
explicit QWinEventNotifier(HANDLE hEvent, QObject *parent = 0);
~QWinEventNotifier();
void setHandle(HANDLE hEvent);
HANDLE handle() const;
bool isEnabled() const;
public Q_SLOTS:
void setEnabled(bool enable);
Q_SIGNALS:
void activated(HANDLE hEvent);
protected:
bool event(QEvent *e);
private:
Q_DISABLE_COPY(QWinEventNotifier)
HANDLE handleToEvent;
bool enabled;
};
QT_END_NAMESPACE
#endif // QWINEVENTNOTIFIER_H

View File

@ -1,4 +1,4 @@
#include "qwineventnotifier.h"
#include <QMutexLocker>
#include <QDebug>

View File

@ -27,54 +27,17 @@
#include "qextserialenumerator.h"
#include "qgsnmeaconnection.h"
#include "qgslogger.h"
QgsGPSConnection::QgsGPSConnection( QIODevice* dev, int pollInterval ): QObject( 0 ), mSource( dev ), mStatus( NotConnected )
{
init( pollInterval );
}
QgsGPSConnection::QgsGPSConnection( QString port, int pollInterval ): QObject( 0 ), mStatus( NotConnected )
{
QextSerialPort *s = new QextSerialPort( port );
s->setBaudRate( BAUD4800 );
s->setFlowControl( FLOW_OFF );
s->setParity( PAR_NONE );
s->setDataBits( DATA_8 );
s->setStopBits( STOP_2 );
mSource = s;
init( pollInterval );
}
void QgsGPSConnection::init( int pollInterval )
QgsGPSConnection::QgsGPSConnection( QIODevice* dev ): QObject( 0 ), mSource( dev ), mStatus( NotConnected )
{
clearLastGPSInformation();
mPollTimer = new QTimer();
mPollTimer->setInterval( pollInterval );
QObject::connect( mPollTimer, SIGNAL( timeout() ), this, SLOT( parseData() ) );
QObject::connect( dev, SIGNAL( readyRead() ), this, SLOT( parseData() ) );
}
QgsGPSConnection::~QgsGPSConnection()
{
cleanupSource();
delete mPollTimer;
}
bool QgsGPSConnection::startPolling()
{
if ( mPollTimer )
{
mPollTimer->start();
}
return true;
}
bool QgsGPSConnection::stopPolling()
{
if ( mPollTimer )
{
mPollTimer->stop();
}
return true;
}
bool QgsGPSConnection::connect()
@ -132,121 +95,3 @@ void QgsGPSConnection::clearLastGPSInformation()
mLastGPSInformation.speed = 0;
mLastGPSInformation.vdop = 0;
}
void QgsGPSConnection::setTimer( QTimer* t )
{
delete mPollTimer;
mPollTimer = t;
QObject::connect( mPollTimer, SIGNAL( timeout() ), this, SLOT( parseData() ) );
}
QgsGPSConnection* QgsGPSConnection::detectGPSConnection()
{
QList<BaudRateType> baudRatesToTry;
baudRatesToTry << BAUD4800 << BAUD9600 << BAUD38400;
QextSerialPort* port = 0;
QList<BaudRateType>::const_iterator baudIt = baudRatesToTry.constBegin();
for ( ; baudIt != baudRatesToTry.constEnd(); ++baudIt )
{
QList< QPair<QString, QString> > ports = availablePorts();
for ( int i = 0; i < ports.size(); i++ )
{
port = new QextSerialPort( ports[i].first );
port->setBaudRate( *baudIt );
port->setFlowControl( FLOW_OFF );
port->setParity( PAR_NONE );
port->setDataBits( DATA_8 );
port->setStopBits( STOP_1 );
if ( !port->open( QIODevice::ReadOnly | QIODevice::Unbuffered ) )
{
delete port;
continue;
}
//setup connection
QgsNMEAConnection* c = new QgsNMEAConnection( port, 200 );
//return connection if gps data has been received
c->startPolling();
QTime t = QTime::currentTime().addSecs( 4 );
while ( QTime::currentTime() < t )
{
QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents, 1000 );
}
c->stopPolling();
if ( c->status() != GPSDataReceived )
{
delete c;
continue;
}
return c;
}
}
return 0;
}
QList< QPair<QString, QString> > QgsGPSConnection::availablePorts()
{
QList< QPair<QString, QString> > devs;
#ifdef linux
// look for linux serial devices
foreach( QString linuxDev, QStringList() << "/dev/ttyS%1" << "/dev/ttyUSB%1" << "/dev/rfcomm%1" )
{
for ( int i = 0; i < 10; ++i )
{
if ( QFileInfo( linuxDev.arg( i ) ).exists() )
{
devs << QPair<QString, QString>( linuxDev.arg( i ), linuxDev.arg( i ) );
}
}
}
#endif
#ifdef __FreeBSD__ // freebsd
// and freebsd devices (untested)
foreach( QString freebsdDev, QStringList() << "/dev/cuaa%1" << "/dev/ucom%1" )
{
for ( int i = 0; i < 10; ++i )
{
if ( QFileInfo( freebsdDev.arg( i ) ).exists() )
{
devs << QPair<QString, QString>( freebsdDev.arg( i ), freebsdDev.arg( i ) );
}
}
}
#endif
#ifdef sparc
// and solaris devices (also untested)
QString solarisDev( "/dev/cua/%1" );
for ( char i = 'a'; i < 'k'; ++i )
{
if ( QFileInfo( solarisDev.arg( i ) ).exists() )
{
devs << QPair<QString, QString>( solarisDev.arg( i ), solarisDev.arg( i ) );
}
}
#endif
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
foreach( QextPortInfo port, ports )
{
devs << QPair<QString, QString>( port.portName, port.friendName );
}
#endif
// OpenBSD, NetBSD etc? Anyone?
return devs;
}

View File

@ -19,8 +19,6 @@
#define QGSGPSCONNECTION_H
#include <QObject>
#include <QTimer>
#include <QPair>
class QIODevice;
@ -63,25 +61,15 @@ class CORE_EXPORT QgsGPSConnection : public QObject
/**Constructor
@param dev input device for the connection (e.g. serial device). The class takes ownership of the object
@param pollIntervall update intervall in milliseconds*/
QgsGPSConnection( QIODevice* dev, int pollInterval = 1000 );
QgsGPSConnection( QString port, int pollInterval = 1000 );
QgsGPSConnection( QIODevice* dev );
virtual ~QgsGPSConnection();
/**Opens connection to device*/
bool connect();
/**Closes connection to device*/
bool close();
/**Starts polling and sending stateChanged signals*/
bool startPolling();
/**Stops polling*/
bool stopPolling();
/**Tries different interfaces and settings
@return true in case of success*/
static QgsGPSConnection* detectGPSConnection();
/**Sets the GPS source. The class takes ownership of the device class*/
void setSource( QIODevice* source );
void setPollInterval( int i ) { mPollTimer->setInterval( i ); }
int pollInterval() const { return mPollTimer->interval(); }
/**Returns the status. Possible state are not connected, connected, data received*/
Status status() const { return mStatus; }
@ -89,20 +77,12 @@ class CORE_EXPORT QgsGPSConnection : public QObject
/**Returns the current gps information (lat, lon, etc.)*/
QgsGPSInformation currentGPSInformation() const { return mLastGPSInformation; }
/**Sets a new timer object*/
const QTimer* timer() const { return mPollTimer; }
void setTimer( QTimer* t );
static QList< QPair<QString, QString> > availablePorts();
signals:
void stateChanged( const QgsGPSInformation& info );
protected:
/**Data source (e.g. serial device, socket, file,...)*/
QIODevice* mSource;
/**Timer that triggers polling*/
QTimer* mPollTimer;
/**Last state of the gps related variables (e.g. position, time, ...)*/
QgsGPSInformation mLastGPSInformation;
/**Connection status*/
@ -112,7 +92,6 @@ class CORE_EXPORT QgsGPSConnection : public QObject
/**Closes and deletes mSource*/
void cleanupSource();
void clearLastGPSInformation();
void init( int pollInterval );
protected slots:
/**Parse available data source content*/

View File

@ -0,0 +1,179 @@
/***************************************************************************
qgsgpsdetector.cpp - description
--------------------
begin : January 13th, 2009
copyright : (C) 2009 by Juergen E. Fischer
email : jef at norbit dot de
***************************************************************************/
/***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsgpsdetector.h"
#include "qextserialenumerator.h"
#include "qgslogger.h"
#include "qgsgpsconnection.h"
#include "qgsnmeaconnection.h"
#include <QStringList>
#include <QFileInfo>
#include <QTimer>
QList< QPair<QString, QString> > QgsGPSDetector::availablePorts()
{
QList< QPair<QString, QString> > devs;
#ifdef linux
// look for linux serial devices
foreach( QString linuxDev, QStringList() << "/dev/ttyS%1" << "/dev/ttyUSB%1" << "/dev/rfcomm%1" )
{
for ( int i = 0; i < 10; ++i )
{
if ( QFileInfo( linuxDev.arg( i ) ).exists() )
{
devs << QPair<QString, QString>( linuxDev.arg( i ), linuxDev.arg( i ) );
}
}
}
#endif
#ifdef __FreeBSD__ // freebsd
// and freebsd devices (untested)
foreach( QString freebsdDev, QStringList() << "/dev/cuaa%1" << "/dev/ucom%1" )
{
for ( int i = 0; i < 10; ++i )
{
if ( QFileInfo( freebsdDev.arg( i ) ).exists() )
{
devs << QPair<QString, QString>( freebsdDev.arg( i ), freebsdDev.arg( i ) );
}
}
}
#endif
#ifdef sparc
// and solaris devices (also untested)
QString solarisDev( "/dev/cua/%1" );
for ( char i = 'a'; i < 'k'; ++i )
{
if ( QFileInfo( solarisDev.arg( i ) ).exists() )
{
devs << QPair<QString, QString>( solarisDev.arg( i ), solarisDev.arg( i ) );
}
}
#endif
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
foreach( QextPortInfo port, ports )
{
devs << QPair<QString, QString>( port.portName, port.friendName );
}
#endif
// OpenBSD, NetBSD etc? Anyone?
return devs;
}
QgsGPSDetector::QgsGPSDetector( QString portName )
{
mConn = 0;
mBaudList << BAUD4800 << BAUD9600 << BAUD38400;
if ( portName.isEmpty() )
{
mPortList = availablePorts();
}
else
{
mPortList << QPair<QString, QString>( portName, portName );
}
mPortIndex = 0;
mBaudIndex = -1;
advance();
}
QgsGPSDetector::~QgsGPSDetector()
{
if ( mConn )
delete mConn;
}
void QgsGPSDetector::advance()
{
if ( mConn )
{
delete mConn;
}
QextSerialPort *port = 0;
do
{
mBaudIndex++;
if ( mBaudIndex == mBaudList.size() )
{
mBaudIndex = 0;
mPortIndex++;
}
if ( mPortIndex == mPortList.size() )
{
emit detectionFailed();
deleteLater();
return;
}
if ( port )
delete port;
port = new QextSerialPort( mPortList[ mPortIndex ].first, QextSerialPort::EventDriven );
port->setBaudRate( mBaudList[ mBaudIndex ] );
port->setFlowControl( FLOW_OFF );
port->setParity( PAR_NONE );
port->setDataBits( DATA_8 );
port->setStopBits( STOP_1 );
}
while ( !port->open( QIODevice::ReadOnly | QIODevice::Unbuffered ) );
mConn = new QgsNMEAConnection( port );
connect( mConn, SIGNAL( stateChanged( const QgsGPSInformation & ) ), this, SLOT( detected( const QgsGPSInformation & ) ) );
connect( mConn, SIGNAL( destroyed( QObject * ) ), this, SLOT( connDestroyed( QObject * ) ) );
// leave 2s to pickup a valid string
QTimer::singleShot( 2000, this, SLOT( advance() ) );
}
void QgsGPSDetector::detected( const QgsGPSInformation& info )
{
if ( !mConn )
{
// advance if connection was destroyed
advance();
}
else if ( mConn->status() == QgsGPSConnection::GPSDataReceived )
{
// signal detection
QgsGPSConnection *conn = mConn;
mConn = 0;
emit detected( conn );
deleteLater();
}
}
void QgsGPSDetector::connDestroyed( QObject *obj )
{
if ( obj == mConn )
{
mConn = 0;
}
}

View File

@ -0,0 +1,58 @@
/***************************************************************************
qgsgpsdetector.h - description
-------------------
begin : January 13th, 2009
copyright : (C) 2009 by Juergen E. Fischer
email : jef at norbit dot de
***************************************************************************/
/***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGPSDETECTOR_H
#define QGSGPSDETECTOR_H
#include <QObject>
#include <QList>
#include <QPair>
#include "qextserialport.h"
class QgsGPSConnection;
struct QgsGPSInformation;
// Class to detect the GPS port
class CORE_EXPORT QgsGPSDetector : public QObject
{
Q_OBJECT
public:
QgsGPSDetector( QString portName );
~QgsGPSDetector();
static QList< QPair<QString, QString> > availablePorts();
public slots:
void advance();
void detected( const QgsGPSInformation& );
void connDestroyed( QObject * );
signals:
void detected( QgsGPSConnection * );
void detectionFailed();
private:
int mPortIndex;
int mBaudIndex;
QList< QPair< QString, QString > > mPortList;
QList<BaudRateType> mBaudList;
QgsGPSConnection *mConn;
};
#endif // QGSGPSDETECTOR_H

View File

@ -1,53 +0,0 @@
#include "qgsgpstrackerthread.h"
#include "qgsgpsconnection.h"
QgsGPSTrackerThread::QgsGPSTrackerThread( QgsGPSConnection* conn ): mConnection( conn )
{
}
QgsGPSTrackerThread::QgsGPSTrackerThread(): mConnection( 0 )
{
cleanupConnection();
}
QgsGPSTrackerThread::~QgsGPSTrackerThread()
{
delete mConnection;
}
void QgsGPSTrackerThread::run()
{
if ( !mConnection )
{
return;
}
if ( !mConnection->connect() )
{
return;
}
//QTimer needs to be started in the same thread, so we create a new instance here
QTimer* t = new QTimer();
t->setInterval( mConnection->timer()->interval() );
mConnection->setTimer( t );
mConnection->startPolling();
exec();
mConnection->stopPolling();
mConnection->close();
}
void QgsGPSTrackerThread::cleanupConnection()
{
delete mConnection;
mConnection = 0;
}
void QgsGPSTrackerThread::setConnection( QgsGPSConnection* c )
{
cleanupConnection();
mConnection = c;
}

View File

@ -1,28 +0,0 @@
#ifndef QGSGPSTRACKERTHREAD_H
#define QGSGPSTRACKERTHREAD_H
#include <QThread>
class QgsGPSConnection;
/**Queries GPS informations in a thread*/
class CORE_EXPORT QgsGPSTrackerThread: public QThread
{
public:
QgsGPSTrackerThread( QgsGPSConnection* conn );
~QgsGPSTrackerThread();
void setConnection( QgsGPSConnection* c );
const QgsGPSConnection* connection() { return mConnection; }
protected:
void run();
private:
QgsGPSTrackerThread();
QgsGPSConnection* mConnection;
void cleanupConnection();
};
#endif // QGSGPSTRACKERTHREAD_H

View File

@ -30,11 +30,7 @@
#define KNOTS_TO_KMH 1.852
QgsNMEAConnection::QgsNMEAConnection( QIODevice* dev, int pollInterval ): QgsGPSConnection( dev, pollInterval )
{
}
QgsNMEAConnection::QgsNMEAConnection( QString port, int pollInterval ): QgsGPSConnection( port, pollInterval )
QgsNMEAConnection::QgsNMEAConnection( QIODevice* dev ): QgsGPSConnection( dev )
{
}
@ -61,12 +57,9 @@ void QgsNMEAConnection::parseData()
numBytes = mSource->bytesAvailable();
}
QgsDebugMsg( "numBytes" );
QgsDebugMsg( QString::number( numBytes ) );
QgsDebugMsg( "numBytes:" + QString::number( numBytes ) );
if ( numBytes > 0 )
if ( numBytes >= 6 )
{
if ( mStatus != GPSDataReceived )
{
@ -77,7 +70,6 @@ void QgsNMEAConnection::parseData()
mStringBuffer.append( mSource->read( numBytes ) );
processStringBuffer();
emit stateChanged( mLastGPSInformation );
QgsDebugMsg( mStringBuffer );
}
}

View File

@ -25,8 +25,7 @@ class CORE_EXPORT QgsNMEAConnection: public QgsGPSConnection
{
Q_OBJECT
public:
QgsNMEAConnection( QIODevice* dev, int pollInterval = 1000 );
QgsNMEAConnection( QString port, int pollInterval = 1000 );
QgsNMEAConnection( QIODevice *dev );
~QgsNMEAConnection();
//bool poll( QgsGPSInformation& info, int maxTime );

View File

@ -38,7 +38,8 @@ ADD_LIBRARY (gpsimporterplugin MODULE ${GPS_SRCS} ${GPS_MOC_SRCS} ${GPS_RCC_SRCS
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
../../core ../../core/gps
../../core ../../core/gps ../../core/gps/qextserialport
../../gui
..
${EXPAT_INCLUDE_DIR}

View File

@ -15,7 +15,7 @@
#include "qgsdataprovider.h"
#include "qgscontexthelp.h"
#include "qgslogger.h"
#include "qgsgpsconnection.h"
#include "qgsgpsdetector.h"
//qt includes
#include <QFileDialog>
@ -306,7 +306,7 @@ void QgsGPSPluginGui::on_pbnRefresh_clicked()
void QgsGPSPluginGui::populatePortComboBoxes()
{
QList< QPair<QString, QString> > devs = QgsGPSConnection::availablePorts() << QPair<QString, QString>( "usb:", "usb:" );
QList< QPair<QString, QString> > devs = QgsGPSDetector::availablePorts() << QPair<QString, QString>( "usb:", "usb:" );
cmbDLPort->clear();
cmbULPort->clear();