QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
20#include <QCoreApplication>
21#include <QTime>
22#include <QIODevice>
23#include <QStringList>
24#include <QFileInfo>
25
26#include "info.h"
27
29{
30 bool valid = false;
31 if ( status == 'V' || fixType == NMEA_FIX_BAD || qualityIndicator == Qgis::GpsQualityIndicator::Invalid ) // some sources say that 'V' indicates position fix, but is below acceptable quality
32 {
33 valid = false;
34 }
35 else if ( fixType == NMEA_FIX_2D )
36 {
37 valid = true;
38 }
39 else if ( status == 'A' || fixType == NMEA_FIX_3D || ( qualityIndicator != Qgis::GpsQualityIndicator::Invalid ) ) // good
40 {
41 valid = true;
42 }
43
44 return valid;
45}
46
48{
50
51 // no fix if any of the three report bad; default values are invalid values and won't be changed if the corresponding NMEA msg is not received
52 if ( status == 'V' || fixType == NMEA_FIX_BAD || qualityIndicator == Qgis::GpsQualityIndicator::Invalid ) // some sources say that 'V' indicates position fix, but is below acceptable quality
53 {
55 }
56 else if ( fixType == NMEA_FIX_2D ) // 2D indication (from GGA)
57 {
59 }
60 else if ( status == 'A' || fixType == NMEA_FIX_3D || qualityIndicator != Qgis::GpsQualityIndicator::Invalid ) // good
61 {
63 }
64 return fixStatus;
65}
66
68{
69 switch ( qualityIndicator )
70 {
72 return QCoreApplication::translate( "QgsGpsInformation", "Simulation mode" );
73
75 return QCoreApplication::translate( "QgsGpsInformation", "Manual input mode" );
76
78 return QCoreApplication::translate( "QgsGpsInformation", "Estimated" );
79
81 return QCoreApplication::translate( "QgsGpsInformation", "Float RTK" );
82
84 return QCoreApplication::translate( "QgsGpsInformation", "Fixed RTK" );
85
87 return QCoreApplication::translate( "QgsGpsInformation", "PPS" );
88
90 return QCoreApplication::translate( "QgsGpsInformation", "DGPS" );
91
93 return QCoreApplication::translate( "QgsGpsInformation", "Autonomous" );
94
96 return QCoreApplication::translate( "QgsGpsInformation", "Invalid" );
97
99 default:
100 return QCoreApplication::translate( "QgsGpsInformation", "Unknown (%1)" ).arg( QString::number( quality ) );
101 }
102}
103
105 : QObject( nullptr )
106 , mSource( dev )
107{
108 clearLastGPSInformation();
109 QObject::connect( dev, &QIODevice::readyRead, this, &QgsGpsConnection::parseData );
110}
111
113{
114 cleanupSource();
115}
116
118{
119 if ( !mSource )
120 {
121 return false;
122 }
123
124 const bool connected = mSource->open( QIODevice::ReadWrite | QIODevice::Unbuffered );
125 if ( connected )
126 {
128 }
129 return connected;
130}
131
133{
134 if ( !mSource )
135 {
136 return false;
137 }
138
139 mSource->close();
140 return true;
141}
142
143void QgsGpsConnection::cleanupSource()
144{
145 if ( mSource )
146 {
147 mSource->close();
148 }
149 mSource.reset();
150}
151
152void QgsGpsConnection::setSource( QIODevice *source )
153{
154 cleanupSource();
155 mSource.reset( source );
156 clearLastGPSInformation();
157}
158
159void QgsGpsConnection::clearLastGPSInformation()
160{
162}
@ RTK
Real-time-kynematic.
@ DGPS
Differential GPS.
@ Simulation
Simulation mode.
@ FloatRTK
Float real-time-kynematic.
@ Manual
Manual input mode.
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
bool connect()
Opens connection to device.
bool close()
Closes connection to device.
std::unique_ptr< QIODevice > mSource
Data source (e.g. serial device, socket, file,...)
QgsGpsConnection(QIODevice *dev)
Constructor.
Status mStatus
Connection status.
Encapsulates information relating to a GPS position fix.
FixStatus
GPS fix status.
bool isValid() const
Returns whether the connection information is valid.
int fixType
Contains the fix type, where 1 = no fix, 2 = 2d fix, 3 = 3d fix.
FixStatus fixStatus() const
Returns the fix status.
QChar status
Status (A = active or V = void)
QString qualityDescription() const
Returns a descriptive string for the signal quality.
Qgis::GpsQualityIndicator qualityIndicator
Returns the signal quality indicator.
int quality
GPS quality indicator (0 = Invalid; 1 = Fix; 2 = Differential, 3 = Sensitive, etc....