QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 || quality == 0 ) // 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  }
42  else if ( status == 'A' || fixType == NMEA_FIX_3D || quality > 0 ) // good
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 || quality == 0 ) // some sources say that 'V' indicates position fix, but is below acceptable quality
56  {
57  fixStatus = NoFix;
58  }
59  else if ( fixType == NMEA_FIX_2D ) // 2D indication (from GGA)
60  {
61  fixStatus = Fix2D;
62  }
63  else if ( status == 'A' || fixType == NMEA_FIX_3D || quality > 0 ) // good
64  {
65  fixStatus = Fix3D;
66  }
67  return fixStatus;
68 }
69 
71 {
72  switch ( quality )
73  {
74  case 8:
75  return QCoreApplication::translate( "QgsGpsInformation", "Simulation mode" );
76 
77  case 7:
78  return QCoreApplication::translate( "QgsGpsInformation", "Manual input mode" );
79 
80  case 6:
81  return QCoreApplication::translate( "QgsGpsInformation", "Estimated" );
82 
83  case 5:
84  return QCoreApplication::translate( "QgsGpsInformation", "Float RTK" );
85 
86  case 4:
87  return QCoreApplication::translate( "QgsGpsInformation", "Fixed RTK" );
88 
89  case 3:
90  return QCoreApplication::translate( "QgsGpsInformation", "PPS" );
91 
92  case 2:
93  return QCoreApplication::translate( "QgsGpsInformation", "DGPS" );
94 
95  case 1:
96  return QCoreApplication::translate( "QgsGpsInformation", "Autonomous" );
97 
98  case 0:
99  return QCoreApplication::translate( "QgsGpsInformation", "Invalid" );
100 
101  default:
102  return QCoreApplication::translate( "QgsGpsInformation", "Unknown (%1)" ).arg( QString::number( quality ) );
103  }
104 }
105 
107  : QObject( nullptr )
108  , mSource( dev )
109 {
110  clearLastGPSInformation();
111  QObject::connect( dev, &QIODevice::readyRead, this, &QgsGpsConnection::parseData );
112 }
113 
115 {
116  cleanupSource();
117 }
118 
120 {
121  if ( !mSource )
122  {
123  return false;
124  }
125 
126  bool connected = mSource->open( QIODevice::ReadWrite | QIODevice::Unbuffered );
127  if ( connected )
128  {
129  mStatus = Connected;
130  }
131  return connected;
132 }
133 
135 {
136  if ( !mSource )
137  {
138  return false;
139  }
140 
141  mSource->close();
142  return true;
143 }
144 
145 void QgsGpsConnection::cleanupSource()
146 {
147  if ( mSource )
148  {
149  mSource->close();
150  }
151  mSource.reset();
152 }
153 
154 void QgsGpsConnection::setSource( QIODevice *source )
155 {
156  cleanupSource();
157  mSource.reset( source );
158  clearLastGPSInformation();
159 }
160 
161 void QgsGpsConnection::clearLastGPSInformation()
162 {
164 }
QgsGpsInformation::Fix3D
@ Fix3D
Definition: qgsgpsconnection.h:111
QgsGpsInformation::FixStatus
FixStatus
GPS fix status.
Definition: qgsgpsconnection.h:107
QgsGpsConnection::Connected
@ Connected
Definition: qgsgpsconnection.h:271
QgsGpsInformation::qualityDescription
QString qualityDescription() const
Returns a descriptive string for the signal quality.
Definition: qgsgpsconnection.cpp:70
QgsGpsConnection::QgsGpsConnection
QgsGpsConnection(QIODevice *dev)
Constructor.
Definition: qgsgpsconnection.cpp:106
QgsGpsConnection::mStatus
Status mStatus
Connection status.
Definition: qgsgpsconnection.h:306
QgsGpsConnection::close
bool close()
Closes connection to device.
Definition: qgsgpsconnection.cpp:134
QgsGpsInformation::fixStatus
FixStatus fixStatus() const
Returns the fix status.
Definition: qgsgpsconnection.cpp:50
QgsGpsConnection::mSource
std::unique_ptr< QIODevice > mSource
Data source (e.g. serial device, socket, file,...)
Definition: qgsgpsconnection.h:302
QgsGpsConnection::setSource
void setSource(QIODevice *source)
Sets the GPS source. The class takes ownership of the device class.
Definition: qgsgpsconnection.cpp:154
QgsGpsInformation
Encapsulates information relating to a GPS position fix.
Definition: qgsgpsconnection.h:99
QgsGpsInformation::fixType
int fixType
Contains the fix type, where 1 = no fix, 2 = 2d fix, 3 = 3d fix.
Definition: qgsgpsconnection.h:195
QgsGpsConnection::~QgsGpsConnection
~QgsGpsConnection() override
Definition: qgsgpsconnection.cpp:114
qgsgpsconnection.h
QgsGpsInformation::Fix2D
@ Fix2D
Definition: qgsgpsconnection.h:110
QgsGpsConnection::mLastGPSInformation
QgsGpsInformation mLastGPSInformation
Last state of the gps related variables (e.g. position, time, ...)
Definition: qgsgpsconnection.h:304
QgsGpsConnection::parseData
virtual void parseData()=0
Parse available data source content.
QgsGpsInformation::NoFix
@ NoFix
Definition: qgsgpsconnection.h:109
QgsGpsInformation::quality
int quality
GPS quality indicator (0 = Invalid; 1 = Fix; 2 = Differential, 3 = Sensitive)
Definition: qgsgpsconnection.h:200
QgsGpsConnection::connect
bool connect()
Opens connection to device.
Definition: qgsgpsconnection.cpp:119
qgslogger.h
QgsGpsInformation::isValid
bool isValid() const
Returns whether the connection information is valid.
Definition: qgsgpsconnection.cpp:31
qgsnmeaconnection.h
QgsGpsInformation::status
QChar status
Status (A = active or V = void)
Definition: qgsgpsconnection.h:210
QgsGpsInformation::NoData
@ NoData
Definition: qgsgpsconnection.h:108