Skip to content
Permalink
Browse files

improve gps detection

git-svn-id: http://svn.osgeo.org/qgis/trunk@12759 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Jan 14, 2010
1 parent 002416f commit bffa5cc9bd5e57f5e232f0079f062dd197fa7c1b
@@ -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
@@ -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++ )
@@ -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;
@@ -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
@@ -956,3 +956,7 @@ qint64 QextSerialPort::writeData(const char * data, qint64 maxSize)

return (qint64)retVal;
}

void QextSerialPort::onWinEvent( HANDLE h )
{
}
@@ -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)
@@ -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
@@ -1,4 +1,4 @@

#include "qwineventnotifier.h"

#include <QMutexLocker>
#include <QDebug>

0 comments on commit bffa5cc

Please sign in to comment.