Skip to content

Commit bffa5cc

Browse files
author
jef
committed
improve gps detection
git-svn-id: http://svn.osgeo.org/qgis/trunk@12759 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 002416f commit bffa5cc

18 files changed

+345
-364
lines changed

src/app/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ INCLUDE_DIRECTORIES(
303303
${GEOS_INCLUDE_DIR}
304304
${GDAL_INCLUDE_DIR}
305305
../core
306-
../core/gps
306+
../core/gps ../core/gps/qextserialport
307307
../core/composer ../core/raster ../core/renderer ../core/symbology ../core/symbology-ng
308308
../gui ../gui/symbology-ng
309309
../plugins

src/app/gps/qgsgpsinformationwidget.cpp

+35-43
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "qgsgpsinformationwidget.h"
1919
#include "qgsvectorlayer.h"
2020
#include "qgsnmeaconnection.h"
21-
#include "qgsgpstrackerthread.h"
21+
#include "qgsgpsdetector.h"
2222
#include "qgscoordinatetransform.h"
2323
#include <qgspoint.h>
2424
#include <qgsrubberband.h>
@@ -58,9 +58,7 @@
5858

5959
QgsGPSInformationWidget::QgsGPSInformationWidget( QgsMapCanvas * thepCanvas, QWidget * parent, Qt::WindowFlags f ):
6060
QWidget( parent, f ),
61-
mSerialPort( 0 ),
6261
mNmea( 0 ),
63-
mThread( 0 ) ,
6462
mpCanvas( thepCanvas )
6563
{
6664
setupUi( this );
@@ -293,69 +291,62 @@ void QgsGPSInformationWidget::on_mConnectButton_toggled( bool theFlag )
293291
{
294292
if ( theFlag )
295293
{
296-
mConnectButton->setText( tr( "Connecting..." ) );
297294
connectGps();
298-
mConnectButton->setText( tr( "Disconnect" ) );
299295
}
300296
else
301297
{
302298
disconnectGps();
303-
mConnectButton->setText( tr( "Connect" ) );
304299
}
305300
}
306301

307302
void QgsGPSInformationWidget::connectGps()
308303
{
304+
QString port;
305+
309306
if ( mRadUserPath->isChecked() )
310307
{
311-
if ( !mCboDevices->itemData( mCboDevices->currentIndex() ).toString().isEmpty() )
312-
{
313-
mNmea = new QgsNMEAConnection( mCboDevices->itemData( mCboDevices->currentIndex() ).toString(), 500 );
314-
QObject::connect( mNmea, SIGNAL( stateChanged( const QgsGPSInformation& ) ),
315-
this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );
316-
mThread = new QgsGPSTrackerThread( mNmea );
317-
mThread->start();
318-
mGPSTextEdit->append( tr( "Connecting on %1" ).arg( mCboDevices->itemData( mCboDevices->currentIndex() ).toString() ) );
319-
}
320-
else
308+
port = mCboDevices->itemData( mCboDevices->currentIndex() ).toString();
309+
310+
if ( port.isEmpty() )
321311
{
322312
QMessageBox::information( this, tr( "/gps" ), tr( "No path to the GPS port "
323313
"is specified. Please enter a path then try again." ) );
324314
//toggle the button back off
325315
mConnectButton->setChecked( false );
326-
}
327-
}
328-
else //autodetect
329-
{
330-
mNmea = QgsGPSConnection::detectGPSConnection();
331-
if ( !mNmea )
332-
{
333-
mConnectButton->setChecked( false );
334316
return;
335317
}
336-
mNmea->setPollInterval( 1000 );
337-
QObject::connect( mNmea, SIGNAL( stateChanged( const QgsGPSInformation& ) ), this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );
338-
339-
mThread = new QgsGPSTrackerThread( mNmea );
340-
mThread->start();
341-
mGPSTextEdit->append( tr( "Connected..." ) );
342318
}
319+
320+
mGPSTextEdit->append( tr( "Connecting..." ) );
321+
322+
QgsGPSDetector *detector = new QgsGPSDetector( port );
323+
connect( detector, SIGNAL( detected( QgsGPSConnection * ) ), this, SLOT( connected( QgsGPSConnection * ) ) );
324+
connect( detector, SIGNAL( detectionFailed() ), this, SLOT( timedout() ) );
325+
}
326+
327+
void QgsGPSInformationWidget::timedout()
328+
{
329+
mConnectButton->setChecked( false );
330+
mNmea = NULL;
331+
mGPSTextEdit->append( tr( "Timed out!" ) );
343332
}
333+
334+
void QgsGPSInformationWidget::connected( QgsGPSConnection *conn )
335+
{
336+
mNmea = conn;
337+
QObject::connect( mNmea, SIGNAL( stateChanged( const QgsGPSInformation& ) ),
338+
this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );
339+
mGPSTextEdit->append( tr( "Connected!" ) );
340+
mConnectButton->setText( tr( "Disconnect" ) );
341+
}
342+
344343
void QgsGPSInformationWidget::disconnectGps()
345344
{
346-
if ( mThread )
347-
{
348-
mThread->quit();
349-
mThread->wait();
350-
delete mThread;
351-
mThread = 0;
352-
mNmea = 0;
353-
mSerialPort = 0;
354-
mGPSTextEdit->append( tr( "Disconnected..." ) );
355-
}
356-
//mGPSTextEdit->clear();
357-
//toggle the button back on
345+
delete mNmea;
346+
347+
mGPSTextEdit->append( tr( "Disconnected..." ) );
358348
mConnectButton->setChecked( false );
349+
mConnectButton->setText( tr( "Connect" ) );
359350
}
360351

361352

@@ -370,6 +361,7 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
370361
{
371362
delete mMarkerList.takeFirst();
372363
}
364+
373365
for ( int i = 0; i < info.satellitesInView.size(); ++i )
374366
{
375367
QgsSatelliteInfo currentInfo = info.satellitesInView.at( i );
@@ -858,7 +850,7 @@ void QgsGPSInformationWidget::on_mBtnRefreshDevices_clicked( )
858850
/* Copied from gps plugin */
859851
void QgsGPSInformationWidget::populateDevices()
860852
{
861-
QList< QPair<QString, QString> > ports = QgsGPSConnection::availablePorts();
853+
QList< QPair<QString, QString> > ports = QgsGPSDetector::availablePorts();
862854

863855
mCboDevices->clear();
864856
for ( int i = 0; i < ports.size(); i++ )

src/app/gps/qgsgpsinformationwidget.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ class QgsGPSInformationWidget: public QWidget, private Ui::QgsGPSInformationWidg
5858
void on_mBtnCloseFeature_clicked( );
5959
void on_mBtnResetFeature_clicked( );
6060
void on_mCbxAutoAddVertices_toggled( bool theFlag );
61+
62+
void connected( QgsGPSConnection * );
63+
void timedout();
64+
6165
private:
6266
void addVertex( );
6367
void connectGps();
6468
void connectGpsSlot( );
6569
void disconnectGps();
6670
void populateDevices();
67-
QextSerialPort* mSerialPort;
6871
QgsGPSConnection* mNmea;
69-
QgsGPSTrackerThread* mThread;
7072
QgsMapCanvas * mpCanvas;
7173
QgsGpsMarker * mpMapMarker;
7274
QwtPlot * mpPlot;

src/core/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ SET(QGIS_CORE_SRCS
1010

1111
gps/qgsgpsconnection.cpp
1212
gps/qgsgpsconnectionregistry.cpp
13-
gps/qgsgpstrackerthread.cpp
1413
gps/qgsnmeaconnection.cpp
14+
gps/qgsgpsdetector.cpp
1515
gps/parse.c
1616
gps/sentence.c
1717
gps/info.c
@@ -241,6 +241,7 @@ SET(QGIS_CORE_MOC_HDRS
241241
raster/qgsrasterlayer.h
242242

243243
gps/qgsgpsconnection.h
244+
gps/qgsgpsdetector.h
244245
gps/qgsnmeaconnection.h
245246
gps/qextserialport/qextserialport.h
246247
gps/qextserialport/qextserialenumerator.h

src/core/gps/qextserialport/posix_qextserialport.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -956,3 +956,7 @@ qint64 QextSerialPort::writeData(const char * data, qint64 maxSize)
956956

957957
return (qint64)retVal;
958958
}
959+
960+
void QextSerialPort::onWinEvent( HANDLE h )
961+
{
962+
}

src/core/gps/qextserialport/qextserialport.h

+6-39
Original file line numberDiff line numberDiff line change
@@ -129,46 +129,12 @@ struct PortSettings
129129
#include <sys/ioctl.h>
130130
#include <sys/select.h>
131131
#include <QSocketNotifier>
132-
#elif (defined Q_OS_WIN)
132+
typedef int HANDLE; // unused
133+
typedef
134+
#elif defined (Q_OS_WIN)
133135
#include <windows.h>
134136
#include <QThread>
135137
#include <QReadWriteLock>
136-
137-
// Ugly: copied private Qt header file
138-
QT_BEGIN_NAMESPACE
139-
140-
class Q_CORE_EXPORT QWinEventNotifier : public QObject
141-
{
142-
Q_OBJECT
143-
Q_DECLARE_PRIVATE(QObject)
144-
145-
public:
146-
explicit QWinEventNotifier(QObject *parent = 0);
147-
explicit QWinEventNotifier(HANDLE hEvent, QObject *parent = 0);
148-
~QWinEventNotifier();
149-
150-
void setHandle(HANDLE hEvent);
151-
HANDLE handle() const;
152-
153-
bool isEnabled() const;
154-
155-
public Q_SLOTS:
156-
void setEnabled(bool enable);
157-
158-
Q_SIGNALS:
159-
void activated(HANDLE hEvent);
160-
161-
protected:
162-
bool event(QEvent *e);
163-
164-
private:
165-
Q_DISABLE_COPY(QWinEventNotifier)
166-
167-
HANDLE handleToEvent;
168-
bool enabled;
169-
};
170-
171-
QT_END_NAMESPACE
172138
#endif
173139

174140
/*!
@@ -212,6 +178,9 @@ No guarantees are made as to the quality of POSIX support under NT/2000 however.
212178
213179
\author Stefan Sander, Michal Policht, Brandon Fosdick, Liam Staskawicz
214180
*/
181+
182+
class QWinEventNotifier;
183+
215184
class QextSerialPort: public QIODevice
216185
{
217186
Q_OBJECT
@@ -335,10 +304,8 @@ class QextSerialPort: public QIODevice
335304
qint64 readData(char * data, qint64 maxSize);
336305
qint64 writeData(const char * data, qint64 maxSize);
337306

338-
#ifdef Q_OS_WIN
339307
private slots:
340308
void onWinEvent(HANDLE h);
341-
#endif
342309

343310
private:
344311
Q_DISABLE_COPY(QextSerialPort)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef QWINEVENTNOTIFIER_H
2+
#define QWINEVENTNOTIFIER_H
3+
#include <QObject>
4+
5+
#include <windows.h>
6+
7+
// Ugly: copied private Qt header file
8+
QT_BEGIN_NAMESPACE
9+
10+
class Q_CORE_EXPORT QWinEventNotifier : public QObject
11+
{
12+
Q_OBJECT
13+
Q_DECLARE_PRIVATE(QObject)
14+
15+
public:
16+
explicit QWinEventNotifier(QObject *parent = 0);
17+
explicit QWinEventNotifier(HANDLE hEvent, QObject *parent = 0);
18+
~QWinEventNotifier();
19+
20+
void setHandle(HANDLE hEvent);
21+
HANDLE handle() const;
22+
23+
bool isEnabled() const;
24+
25+
public Q_SLOTS:
26+
void setEnabled(bool enable);
27+
28+
Q_SIGNALS:
29+
void activated(HANDLE hEvent);
30+
31+
protected:
32+
bool event(QEvent *e);
33+
34+
private:
35+
Q_DISABLE_COPY(QWinEventNotifier)
36+
37+
HANDLE handleToEvent;
38+
bool enabled;
39+
};
40+
41+
QT_END_NAMESPACE
42+
43+
#endif // QWINEVENTNOTIFIER_H

src/core/gps/qextserialport/win_qextserialport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#include "qwineventnotifier.h"
22

33
#include <QMutexLocker>
44
#include <QDebug>

0 commit comments

Comments
 (0)