Skip to content

Commit 7b1fc1b

Browse files
author
jef
committedOct 4, 2010
[FEATURE] add gpsd support to live gps tracking
git-svn-id: http://svn.osgeo.org/qgis/trunk@14331 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8ffd816 commit 7b1fc1b

File tree

7 files changed

+481
-41
lines changed

7 files changed

+481
-41
lines changed
 

‎src/app/gps/qgsgpsinformationwidget.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,24 @@ QgsGPSInformationWidget::QgsGPSInformationWidget( QgsMapCanvas * thepCanvas, QWi
152152
mSliderMarkerSize->setValue( mySettings.value( "/gps/markerSize", "12" ).toInt() );
153153
mSpinTrackWidth->setValue( mySettings.value( "/gps/trackWidth", "2" ).toInt() );
154154
QString myPortMode = mySettings.value( "/gps/portMode", "scanPorts" ).toString();
155+
156+
mGpsdHost->setText( mySettings.value( "/gps/gpsdHost", "localhost" ).toString() );
157+
mGpsdPort->setText( mySettings.value( "/gps/gpsdPort", 2947 ).toString() );
158+
mGpsdDevice->setText( mySettings.value( "/gps/gpsdDevice" ).toString() );
159+
155160
//port mode
156161
if ( myPortMode == "scanPorts" )
157162
{
158163
mRadAutodetect->setChecked( true );
159164
}
160-
else
165+
else if ( myPortMode == "explicitPort" )
161166
{
162167
mRadUserPath->setChecked( true );
163168
}
169+
else if ( myPortMode == "gpsd" )
170+
{
171+
mRadGpsd->setChecked( true );
172+
}
164173
//auto digitising behaviour
165174
bool myAutoAddVertexFlag = mySettings.value( "/gps/autoAddVertices", "false" ).toBool();
166175
mCbxAutoAddVertices->setChecked( myAutoAddVertexFlag );
@@ -198,15 +207,23 @@ QgsGPSInformationWidget::~QgsGPSInformationWidget()
198207
mySettings.setValue( "/gps/trackWidth", mSpinTrackWidth->value() );
199208
mySettings.setValue( "/gps/markerSize", mSliderMarkerSize->value() );
200209
mySettings.setValue( "/gps/autoAddVertices", mCbxAutoAddVertices->isChecked() );
201-
// scan or explicit port
210+
// scan, explicit port or gpsd
202211
if ( mRadAutodetect->isChecked() )
203212
{
204213
mySettings.setValue( "/gps/portMode", "scanPorts" );
205214
}
206-
else
215+
else if ( mRadUserPath->isChecked() )
207216
{
208217
mySettings.setValue( "/gps/portMode", "explicitPort" );
209218
}
219+
else
220+
{
221+
mySettings.setValue( "/gps/portMode", "gpsd" );
222+
}
223+
224+
mySettings.setValue( "/gps/gpsdHost", mGpsdHost->text() );
225+
mySettings.setValue( "/gps/gpsdPort", mGpsdPort->text().toInt() );
226+
mySettings.setValue( "/gps/gpsdDevice", mGpsdDevice->text() );
210227

211228
// pan mode
212229
if ( radRecenterMap->isChecked() )
@@ -317,6 +334,10 @@ void QgsGPSInformationWidget::connectGps()
317334
return;
318335
}
319336
}
337+
else if ( mRadGpsd->isChecked() )
338+
{
339+
port = QString( "%1:%2:%3" ).arg( mGpsdHost->text() ).arg( mGpsdPort->text() ).arg( mGpsdDevice->text() );
340+
}
320341

321342
mGPSTextEdit->append( tr( "Connecting..." ) );
322343

‎src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SET(QGIS_CORE_SRCS
1111
gps/qgsgpsconnection.cpp
1212
gps/qgsgpsconnectionregistry.cpp
1313
gps/qgsnmeaconnection.cpp
14+
gps/qgsgpsdconnection.cpp
1415
gps/qgsgpsdetector.cpp
1516
gps/parse.c
1617
gps/sentence.c
@@ -257,6 +258,7 @@ SET(QGIS_CORE_MOC_HDRS
257258
gps/qgsgpsconnection.h
258259
gps/qgsgpsdetector.h
259260
gps/qgsnmeaconnection.h
261+
gps/qgsgpsdconnection.h
260262
gps/qextserialport/qextserialport.h
261263
gps/qextserialport/qextserialenumerator.h
262264
)

‎src/core/gps/qgsgpsdconnection.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/***************************************************************************
2+
qgsgpsdconnection.cpp - description
3+
---------------------
4+
begin : October 4th, 2010
5+
copyright : (C) 2010 by Jürgen E. Fischer, norBIT GmbH
6+
email : jef at norbit dot de
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsgpsdconnection.h"
19+
#include "qgslogger.h"
20+
21+
#include <QTcpSocket>
22+
23+
QgsGpsdConnection::QgsGpsdConnection( QString host, qint16 port, QString device )
24+
: QgsNMEAConnection( new QTcpSocket() )
25+
, mDevice( device )
26+
{
27+
QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource );
28+
29+
QObject::connect( socket, SIGNAL( connected() ), this, SLOT( connected() ) );
30+
QObject::connect( socket, SIGNAL( error( QAbstractSocket::SocketError ) ), this, SLOT( error( QAbstractSocket::SocketError ) ) );
31+
socket->connectToHost( host, port );
32+
}
33+
34+
QgsGpsdConnection::~QgsGpsdConnection()
35+
{
36+
//connection will be closed by base class
37+
QgsDebugMsg( "entered." );
38+
}
39+
40+
void QgsGpsdConnection::connected()
41+
{
42+
QgsDebugMsg( "connected!" );
43+
QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource );
44+
socket->write( QString( "?WATCH={\"enable\":true,\"nmea\":true%1};" ).arg( mDevice.isEmpty() ? mDevice : QString( "\"device\":%1" ).arg( mDevice ) ).toUtf8() );
45+
}
46+
47+
void QgsGpsdConnection::error( QAbstractSocket::SocketError socketError )
48+
{
49+
QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource );
50+
QgsDebugMsg( QString( "error: %1 %2" ).arg( socketError ).arg( socket->errorString() ) );
51+
}

‎src/core/gps/qgsgpsdconnection.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/***************************************************************************
2+
qgsgpsdconnection.h - description
3+
-------------------
4+
begin : October 4th, 2010
5+
copyright : (C) 2010 by Jürgen E. Fischer, norBIT GmbH
6+
email : jef at norbit dot de
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSGPSDCONNECTION_H
19+
#define QGSGPSDCONNECTION_H
20+
21+
#include "qgsgpsdconnection.h"
22+
#include "qgsnmeaconnection.h"
23+
24+
#include <QAbstractSocket>
25+
26+
/**Evaluates NMEA sentences coming from gpsd*/
27+
class CORE_EXPORT QgsGpsdConnection: public QgsNMEAConnection
28+
{
29+
Q_OBJECT
30+
public:
31+
QgsGpsdConnection( QString host, qint16 port, QString device );
32+
~QgsGpsdConnection();
33+
34+
private slots:
35+
void connected();
36+
void error( QAbstractSocket::SocketError );
37+
38+
private:
39+
QString mDevice;
40+
};
41+
42+
#endif // QGSGPSDCONNECTION_H

‎src/core/gps/qgsgpsdetector.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgslogger.h"
2121
#include "qgsgpsconnection.h"
2222
#include "qgsnmeaconnection.h"
23+
#include "qgsgpsdconnection.h"
2324

2425
#include <QStringList>
2526
#include <QFileInfo>
@@ -29,6 +30,9 @@ QList< QPair<QString, QString> > QgsGPSDetector::availablePorts()
2930
{
3031
QList< QPair<QString, QString> > devs;
3132

33+
// try local gpsd first
34+
devs << QPair<QString, QString>( "localhost:2947:", tr( "local gpsd" ) );
35+
3236
#ifdef linux
3337
// look for linux serial devices
3438
foreach( QString linuxDev, QStringList() << "/dev/ttyS%1" << "/dev/ttyUSB%1" << "/dev/rfcomm%1" )
@@ -115,9 +119,9 @@ void QgsGPSDetector::advance()
115119
delete mConn;
116120
}
117121

118-
QextSerialPort *port = 0;
122+
mConn = 0;
119123

120-
do
124+
while ( !mConn )
121125
{
122126
mBaudIndex++;
123127
if ( mBaudIndex == mBaudList.size() )
@@ -133,19 +137,37 @@ void QgsGPSDetector::advance()
133137
return;
134138
}
135139

136-
if ( port )
137-
delete port;
140+
if ( mPortList[ mPortIndex ].first.contains( ":" ) )
141+
{
142+
mBaudIndex = mBaudList.size() - 1;
143+
144+
QStringList gpsParams = mPortList[ mPortIndex ].first.split( ":" );
145+
146+
Q_ASSERT( gpsParams.size() == 3 );
147+
148+
mConn = new QgsGpsdConnection( gpsParams[0], gpsParams[1].toInt(), gpsParams[2] );
149+
}
150+
else
151+
{
152+
QextSerialPort *serial = new QextSerialPort( mPortList[ mPortIndex ].first, QextSerialPort::EventDriven );
153+
154+
serial->setBaudRate( mBaudList[ mBaudIndex ] );
155+
serial->setFlowControl( FLOW_OFF );
156+
serial->setParity( PAR_NONE );
157+
serial->setDataBits( DATA_8 );
158+
serial->setStopBits( STOP_1 );
138159

139-
port = new QextSerialPort( mPortList[ mPortIndex ].first, QextSerialPort::EventDriven );
140-
port->setBaudRate( mBaudList[ mBaudIndex ] );
141-
port->setFlowControl( FLOW_OFF );
142-
port->setParity( PAR_NONE );
143-
port->setDataBits( DATA_8 );
144-
port->setStopBits( STOP_1 );
160+
if ( serial->open( QIODevice::ReadOnly | QIODevice::Unbuffered ) )
161+
{
162+
mConn = new QgsNMEAConnection( serial );
163+
}
164+
else
165+
{
166+
delete serial;
167+
}
168+
}
145169
}
146-
while ( !port->open( QIODevice::ReadOnly | QIODevice::Unbuffered ) );
147170

148-
mConn = new QgsNMEAConnection( port );
149171
connect( mConn, SIGNAL( stateChanged( const QgsGPSInformation & ) ), this, SLOT( detected( const QgsGPSInformation & ) ) );
150172
connect( mConn, SIGNAL( destroyed( QObject * ) ), this, SLOT( connDestroyed( QObject * ) ) );
151173

‎src/core/gps/qgsnmeaconnection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CORE_EXPORT QgsNMEAConnection: public QgsGPSConnection
3434
/**Parse available data source content*/
3535
void parseData();
3636

37-
private:
37+
protected:
3838
/**Store data from the device before it is processed*/
3939
QString mStringBuffer;
4040
/**Splits mStringBuffer into sentences and calls libnmea*/

‎src/ui/qgsgpsinformationwidgetbase.ui

Lines changed: 327 additions & 25 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.