QGIS API Documentation  3.9.0-Master (224899f119)
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 
70 
71 QgsGpsConnection::QgsGpsConnection( QIODevice *dev ): QObject( nullptr ), mSource( dev ), mStatus( NotConnected )
72 {
73  clearLastGPSInformation();
74  QObject::connect( dev, &QIODevice::readyRead, this, &QgsGpsConnection::parseData );
75 }
76 
78 {
79  cleanupSource();
80 }
81 
83 {
84  if ( !mSource )
85  {
86  return false;
87  }
88 
89  bool connected = mSource->open( QIODevice::ReadWrite | QIODevice::Unbuffered );
90  if ( connected )
91  {
93  }
94  return connected;
95 }
96 
98 {
99  if ( !mSource )
100  {
101  return false;
102  }
103 
104  mSource->close();
105  return true;
106 }
107 
108 void QgsGpsConnection::cleanupSource()
109 {
110  if ( mSource )
111  {
112  mSource->close();
113  }
114  delete mSource;
115  mSource = nullptr;
116 }
117 
118 void QgsGpsConnection::setSource( QIODevice *source )
119 {
120  cleanupSource();
121  mSource = source;
122  clearLastGPSInformation();
123 }
124 
125 void QgsGpsConnection::clearLastGPSInformation()
126 {
128 }
void setSource(QIODevice *source)
Sets the GPS source. The class takes ownership of the device class.
~QgsGpsConnection() override
bool isValid() const
Returns whether the connection information is valid.
QgsGpsInformation mLastGPSInformation
Last state of the gps related variables (e.g. position, time, ...)
virtual void parseData()=0
Parse available data source content.
FixStatus fixStatus() const
Returns the fix status.
QIODevice * mSource
Data source (e.g. serial device, socket, file,...)
bool connect()
Opens connection to device.
QgsGpsConnection(QIODevice *dev)
Constructor.
Status mStatus
Connection status.
bool close()
Closes connection to device.
FixStatus
GPS fix status.