QGIS API Documentation 3.27.0-Master (f261cc1f8b)
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 "qgsnmeaconnection.h"
27#include "qgslogger.h"
28#include "info.h"
29
30
32{
33 bool valid = false;
34 if ( status == 'V' || fixType == NMEA_FIX_BAD || qualityIndicator == Qgis::GpsQualityIndicator::Invalid || qualityIndicator == Qgis::GpsQualityIndicator::Unknown ) // some sources say that 'V' indicates position fix, but is below acceptable quality
35 {
36 valid = false;
37 }
38 else if ( fixType == NMEA_FIX_2D )
39 {
40 valid = true;
41 }
43 {
44 valid = true;
45 }
46
47 return valid;
48}
49
51{
53
54 // 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
55 if ( status == 'V' || fixType == NMEA_FIX_BAD || qualityIndicator == Qgis::GpsQualityIndicator::Invalid || qualityIndicator == Qgis::GpsQualityIndicator::Unknown ) // some sources say that 'V' indicates position fix, but is below acceptable quality
56 {
58 }
59 else if ( fixType == NMEA_FIX_2D ) // 2D indication (from GGA)
60 {
62 }
64 {
66 }
67 return fixStatus;
68}
69
71{
72 switch ( qualityIndicator )
73 {
75 return QCoreApplication::translate( "QgsGpsInformation", "Simulation mode" );
76
78 return QCoreApplication::translate( "QgsGpsInformation", "Manual input mode" );
79
81 return QCoreApplication::translate( "QgsGpsInformation", "Estimated" );
82
84 return QCoreApplication::translate( "QgsGpsInformation", "Float RTK" );
85
87 return QCoreApplication::translate( "QgsGpsInformation", "Fixed RTK" );
88
90 return QCoreApplication::translate( "QgsGpsInformation", "PPS" );
91
93 return QCoreApplication::translate( "QgsGpsInformation", "DGPS" );
94
96 return QCoreApplication::translate( "QgsGpsInformation", "Autonomous" );
97
99 return QCoreApplication::translate( "QgsGpsInformation", "Invalid" );
100
102 default:
103 return QCoreApplication::translate( "QgsGpsInformation", "Unknown (%1)" ).arg( QString::number( quality ) );
104 }
105}
106
108 : QObject( nullptr )
109 , mSource( dev )
110{
111 clearLastGPSInformation();
112 QObject::connect( dev, &QIODevice::readyRead, this, &QgsGpsConnection::parseData );
113}
114
116{
117 cleanupSource();
118}
119
121{
122 if ( !mSource )
123 {
124 return false;
125 }
126
127 const bool connected = mSource->open( QIODevice::ReadWrite | QIODevice::Unbuffered );
128 if ( connected )
129 {
131 }
132 return connected;
133}
134
136{
137 if ( !mSource )
138 {
139 return false;
140 }
141
142 mSource->close();
143 return true;
144}
145
146void QgsGpsConnection::cleanupSource()
147{
148 if ( mSource )
149 {
150 mSource->close();
151 }
152 mSource.reset();
153}
154
155void QgsGpsConnection::setSource( QIODevice *source )
156{
157 cleanupSource();
158 mSource.reset( source );
159 clearLastGPSInformation();
160}
161
162void QgsGpsConnection::clearLastGPSInformation()
163{
165}
@ 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....