QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsgpsconnection.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsgpsconnection.cpp - description
3 --------------------
4 begin : November 30th, 2009
5 copyright : (C) 2009 by Marco Hugentobler
6 email : marco at hugis dot net
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 "qgsgpsconnection.h"
19#include "moc_qgsgpsconnection.cpp"
22#include "qgssettingstree.h"
23
24
25#include <QIODevice>
26
27
29
30const QgsSettingsEntryEnumFlag<Qt::TimeSpec> *QgsGpsConnection::settingsGpsTimeStampSpecification = new QgsSettingsEntryEnumFlag<Qt::TimeSpec>( QStringLiteral( "timestamp-time-spec" ), QgsSettingsTree::sTreeGps, Qt::TimeSpec::LocalTime, QStringLiteral( "GPS time stamp specification" ) ) SIP_SKIP;
31
32const QgsSettingsEntryString *QgsGpsConnection::settingsGpsdHostName = new QgsSettingsEntryString( QStringLiteral( "gpsd-host-name" ), QgsSettingsTree::sTreeGps, QString(), QStringLiteral( "GPSD connection host name" ) ) SIP_SKIP;
33
34const QgsSettingsEntryInteger *QgsGpsConnection::settingsGpsdPortNumber = new QgsSettingsEntryInteger( QStringLiteral( "gpsd-port" ), QgsSettingsTree::sTreeGps, 2947, QStringLiteral( "GPSD port number" ) ) SIP_SKIP;
35
36const QgsSettingsEntryString *QgsGpsConnection::settingsGpsdDeviceName = new QgsSettingsEntryString( QStringLiteral( "gpsd-device-name" ), QgsSettingsTree::sTreeGps, QString(), QStringLiteral( "GPSD connection device name" ) ) SIP_SKIP;
37
38const QgsSettingsEntryString *QgsGpsConnection::settingsGpsSerialDevice = new QgsSettingsEntryString( QStringLiteral( "gpsd-serial-device" ), QgsSettingsTree::sTreeGps, QString(), QStringLiteral( "GPS serial device name" ) ) SIP_SKIP;
39
40const QgsSettingsEntryInteger *QgsGpsConnection::settingGpsAcquisitionInterval = new QgsSettingsEntryInteger( QStringLiteral( "acquisition-interval" ), QgsSettingsTree::sTreeGps, 0, QStringLiteral( "GPS track point acquisition interval" ) ) SIP_SKIP;
41
42const QgsSettingsEntryDouble *QgsGpsConnection::settingGpsDistanceThreshold = new QgsSettingsEntryDouble( QStringLiteral( "distance-threshold" ), QgsSettingsTree::sTreeGps, 0, QStringLiteral( "GPS track point distance threshold" ) ) SIP_SKIP;
43
44const QgsSettingsEntryBool *QgsGpsConnection::settingGpsBearingFromTravelDirection = new QgsSettingsEntryBool( QStringLiteral( "calculate-bearing-from-travel" ), QgsSettingsTree::sTreeGps, false, QStringLiteral( "Calculate GPS bearing from travel direction" ) ) SIP_SKIP;
45
46const QgsSettingsEntryBool *QgsGpsConnection::settingGpsApplyLeapSecondsCorrection = new QgsSettingsEntryBool( QStringLiteral( "apply-leap-seconds-correction" ), QgsSettingsTree::sTreeGps, true, QStringLiteral( "Whether leap seconds corrections should be applied to GPS timestamps" ) ) SIP_SKIP;
47
48const QgsSettingsEntryInteger *QgsGpsConnection::settingGpsLeapSeconds = new QgsSettingsEntryInteger( QStringLiteral( "leap-seconds" ), QgsSettingsTree::sTreeGps, 18, QStringLiteral( "Leap seconds correction amount (in seconds)" ) ) SIP_SKIP;
49
50const QgsSettingsEntryString *QgsGpsConnection::settingsGpsTimeStampTimeZone = new QgsSettingsEntryString( QStringLiteral( "timestamp-time-zone" ), QgsSettingsTree::sTreeGps, QString(), QStringLiteral( "GPS time stamp time zone" ) ) SIP_SKIP;
51
52const QgsSettingsEntryInteger *QgsGpsConnection::settingsGpsTimeStampOffsetFromUtc = new QgsSettingsEntryInteger( QStringLiteral( "timestamp-offset-from-utc" ), QgsSettingsTree::sTreeGps, 0, QStringLiteral( "GPS time stamp offset from UTC (in seconds)" ) ) SIP_SKIP;
53
55 : QObject( nullptr )
56 , mSource( dev )
57{
58 if ( mSource )
59 QObject::connect( mSource.get(), &QIODevice::readyRead, this, &QgsGpsConnection::parseData );
60
61 QObject::connect( this, &QgsGpsConnection::stateChanged, this, &QgsGpsConnection::onStateChanged );
62}
63
65{
66 cleanupSource();
67}
68
70{
71 if ( !mSource )
72 {
73 return false;
74 }
75
76 const bool connected = mSource->open( QIODevice::ReadWrite | QIODevice::Unbuffered );
77 if ( connected )
78 {
80 }
81 return connected;
82}
83
85{
86 if ( !mSource )
87 {
88 return false;
89 }
90
91 mSource->close();
92
93 if ( mLastFixStatus != Qgis::GpsFixStatus::NoData )
94 {
95 mLastFixStatus = Qgis::GpsFixStatus::NoData;
96 emit fixStatusChanged( mLastFixStatus );
97 }
98
99 return true;
100}
101
102void QgsGpsConnection::cleanupSource()
103{
104 if ( mSource )
105 {
106 mSource->close();
107 }
108 mSource.reset();
109
110 if ( mLastFixStatus != Qgis::GpsFixStatus::NoData )
111 {
112 mLastFixStatus = Qgis::GpsFixStatus::NoData;
113 emit fixStatusChanged( mLastFixStatus );
114 }
115}
116
117void QgsGpsConnection::setSource( QIODevice *source )
118{
119 cleanupSource();
120 mSource.reset( source );
121 QObject::connect( mSource.get(), &QIODevice::readyRead, this, &QgsGpsConnection::parseData );
122
123 clearLastGPSInformation();
124}
125
126void QgsGpsConnection::onStateChanged( const QgsGpsInformation &info )
127{
128 if ( info.isValid() )
129 {
130 const QgsPoint oldPosition = mLastLocation;
131 mLastLocation = QgsPoint( info.longitude, info.latitude, info.elevation );
132 if ( mLastLocation != oldPosition )
133 {
134 emit positionChanged( mLastLocation );
135 }
136 }
137
139 Qgis::GpsFixStatus bestFix = info.bestFixStatus( bestFixConstellation );
140 if ( bestFix != mLastFixStatus )
141 {
142 mLastFixStatus = bestFix;
143 emit fixStatusChanged( mLastFixStatus );
144 }
145}
146
147void QgsGpsConnection::clearLastGPSInformation()
148{
150}
GnssConstellation
GNSS constellation.
Definition qgis.h:1751
@ Unknown
Unknown/other system.
GpsFixStatus
GPS fix status.
Definition qgis.h:1736
@ NoData
No fix data available.
@ Automatic
Automatically detected GPS device connection.
Abstract base class for connection to a GPS device.
QgsGpsInformation mLastGPSInformation
Last state of the gps related variables (e.g. position, time, ...)
virtual void parseData()=0
Parse available data source content.
void setSource(QIODevice *source)
Sets the GPS source. The class takes ownership of the device class.
~QgsGpsConnection() override
static const QgsSettingsEntryEnumFlag< Qgis::GpsConnectionType > * settingsGpsConnectionType
Settings entry GPS connection type.
bool connect()
Opens connection to device.
bool close()
Closes connection to device.
void positionChanged(const QgsPoint &point)
Emitted when the GPS position changes.
std::unique_ptr< QIODevice > mSource
Data source (e.g. serial device, socket, file,...)
void fixStatusChanged(Qgis::GpsFixStatus status)
Emitted when the GPS device fix status is changed.
Status mStatus
Connection status.
void stateChanged(const QgsGpsInformation &info)
Emitted whenever the GPS state is changed.
Encapsulates information relating to a GPS position fix.
bool isValid() const
Returns whether the connection information is valid.
double latitude
Latitude in decimal degrees, using the WGS84 datum.
double longitude
Longitude in decimal degrees, using the WGS84 datum.
double elevation
Altitude (in meters) above or below the mean sea level.
Qgis::GpsFixStatus bestFixStatus(Qgis::GnssConstellation &constellation) const
Returns the best fix status and corresponding constellation.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
A boolean settings entry.
A double settings entry.
A template class for enum and flag settings entry.
An integer settings entry.
A string settings entry.
QgsSettingsTree holds the tree structure for the settings in QGIS core.
static QgsSettingsTreeNode * sTreeGps
#define SIP_SKIP
Definition qgis_sip.h:126