Skip to content

Commit

Permalink
improve gps detection
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@12759 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jan 14, 2010
1 parent 002416f commit bffa5cc
Show file tree
Hide file tree
Showing 18 changed files with 345 additions and 364 deletions.
2 changes: 1 addition & 1 deletion src/app/CMakeLists.txt
Expand Up @@ -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
Expand Down
78 changes: 35 additions & 43 deletions src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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" ) );
}


Expand All @@ -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 );
Expand Down Expand Up @@ -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++ )
Expand Down
6 changes: 4 additions & 2 deletions src/app/gps/qgsgpsinformationwidget.h
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/core/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/core/gps/qextserialport/posix_qextserialport.cpp
Expand Up @@ -956,3 +956,7 @@ qint64 QextSerialPort::writeData(const char * data, qint64 maxSize)

return (qint64)retVal;
}

void QextSerialPort::onWinEvent( HANDLE h )
{
}
45 changes: 6 additions & 39 deletions src/core/gps/qextserialport/qextserialport.h
Expand Up @@ -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

/*!
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
43 changes: 43 additions & 0 deletions src/core/gps/qextserialport/qwineventnotifier.h
@@ -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
2 changes: 1 addition & 1 deletion src/core/gps/qextserialport/win_qextserialport.cpp
@@ -1,4 +1,4 @@

#include "qwineventnotifier.h"

#include <QMutexLocker>
#include <QDebug>
Expand Down

0 comments on commit bffa5cc

Please sign in to comment.