QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  {
54  fixStatus = NoFix;
55  }
56  else if ( fixType == NMEA_FIX_2D ) // 2D indication (from GGA)
57  {
58  fixStatus = Fix2D;
59  }
60  else if ( status == 'A' || fixType == NMEA_FIX_3D || qualityIndicator != Qgis::GpsQualityIndicator::Invalid ) // good
61  {
62  fixStatus = Fix3D;
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  {
127  mStatus = Connected;
128  }
129  return connected;
130 }
131 
133 {
134  if ( !mSource )
135  {
136  return false;
137  }
138 
139  mSource->close();
140  return true;
141 }
142 
143 void QgsGpsConnection::cleanupSource()
144 {
145  if ( mSource )
146  {
147  mSource->close();
148  }
149  mSource.reset();
150 }
151 
152 void QgsGpsConnection::setSource( QIODevice *source )
153 {
154  cleanupSource();
155  mSource.reset( source );
156  clearLastGPSInformation();
157 }
158 
159 void QgsGpsConnection::clearLastGPSInformation()
160 {
162 }
QgsGpsInformation::Fix3D
@ Fix3D
Definition: qgsgpsconnection.h:125
Qgis::GpsQualityIndicator::RTK
@ RTK
Real-time-kynematic.
QgsGpsInformation::FixStatus
FixStatus
GPS fix status.
Definition: qgsgpsconnection.h:120
QgsGpsConnection::Connected
@ Connected
Definition: qgsgpsconnection.h:312
QgsGpsInformation::qualityDescription
QString qualityDescription() const
Returns a descriptive string for the signal quality.
Definition: qgsgpsconnection.cpp:67
Qgis::GpsQualityIndicator::Estimated
@ Estimated
Estimated.
Qgis::GpsQualityIndicator::Simulation
@ Simulation
Simulation mode.
QgsGpsConnection::QgsGpsConnection
QgsGpsConnection(QIODevice *dev)
Constructor.
Definition: qgsgpsconnection.cpp:104
QgsGpsConnection::mStatus
Status mStatus
Connection status.
Definition: qgsgpsconnection.h:347
Qgis::GpsQualityIndicator::FloatRTK
@ FloatRTK
Float real-time-kynematic.
QgsGpsConnection::close
bool close()
Closes connection to device.
Definition: qgsgpsconnection.cpp:132
QgsGpsInformation::fixStatus
FixStatus fixStatus() const
Returns the fix status.
Definition: qgsgpsconnection.cpp:47
Qgis::GpsQualityIndicator::Unknown
@ Unknown
Unknown.
QgsGpsConnection::mSource
std::unique_ptr< QIODevice > mSource
Data source (e.g. serial device, socket, file,...)
Definition: qgsgpsconnection.h:343
Qgis::GpsQualityIndicator::PPS
@ PPS
PPS.
QgsGpsConnection::setSource
void setSource(QIODevice *source)
Sets the GPS source. The class takes ownership of the device class.
Definition: qgsgpsconnection.cpp:152
QgsGpsInformation
Encapsulates information relating to a GPS position fix.
Definition: qgsgpsconnection.h:112
Qgis::GpsQualityIndicator::GPS
@ GPS
Standalone.
QgsGpsInformation::fixType
int fixType
Contains the fix type, where 1 = no fix, 2 = 2d fix, 3 = 3d fix.
Definition: qgsgpsconnection.h:229
QgsGpsConnection::~QgsGpsConnection
~QgsGpsConnection() override
Definition: qgsgpsconnection.cpp:112
qgsgpsconnection.h
QgsGpsInformation::Fix2D
@ Fix2D
Definition: qgsgpsconnection.h:124
QgsGpsConnection::mLastGPSInformation
QgsGpsInformation mLastGPSInformation
Last state of the gps related variables (e.g. position, time, ...)
Definition: qgsgpsconnection.h:345
QgsGpsInformation::qualityIndicator
Qgis::GpsQualityIndicator qualityIndicator
Returns the signal quality indicator.
Definition: qgsgpsconnection.h:241
QgsGpsConnection::parseData
virtual void parseData()=0
Parse available data source content.
QgsGpsInformation::NoFix
@ NoFix
Definition: qgsgpsconnection.h:123
QgsGpsInformation::quality
int quality
GPS quality indicator (0 = Invalid; 1 = Fix; 2 = Differential, 3 = Sensitive, etc....
Definition: qgsgpsconnection.h:235
QgsGpsConnection::connect
bool connect()
Opens connection to device.
Definition: qgsgpsconnection.cpp:117
Qgis::GpsQualityIndicator::Invalid
@ Invalid
Invalid.
QgsGpsInformation::isValid
bool isValid() const
Returns whether the connection information is valid.
Definition: qgsgpsconnection.cpp:28
Qgis::GpsQualityIndicator::DGPS
@ DGPS
Differential GPS.
Qgis::GpsQualityIndicator::Manual
@ Manual
Manual input mode.
QgsGpsInformation::status
QChar status
Status (A = active or V = void)
Definition: qgsgpsconnection.h:251
QgsGpsInformation::NoData
@ NoData
Definition: qgsgpsconnection.h:122