QGIS API Documentation  3.0.2-Girona (307d082)
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 "qextserialport.h"
27 #include "qextserialenumerator.h"
28 
29 #include "qgsnmeaconnection.h"
30 #include "qgslogger.h"
31 
32 QgsGpsConnection::QgsGpsConnection( QIODevice *dev ): QObject( nullptr ), mSource( dev ), mStatus( NotConnected )
33 {
34  clearLastGPSInformation();
35  QObject::connect( dev, &QIODevice::readyRead, this, &QgsGpsConnection::parseData );
36 }
37 
39 {
40  cleanupSource();
41 }
42 
44 {
45  if ( !mSource )
46  {
47  return false;
48  }
49 
50  bool connected = mSource->open( QIODevice::ReadWrite | QIODevice::Unbuffered );
51  if ( connected )
52  {
54  }
55  return connected;
56 }
57 
59 {
60  if ( !mSource )
61  {
62  return false;
63  }
64 
65  mSource->close();
66  return true;
67 }
68 
69 void QgsGpsConnection::cleanupSource()
70 {
71  if ( mSource )
72  {
73  mSource->close();
74  }
75  delete mSource;
76  mSource = nullptr;
77 }
78 
79 void QgsGpsConnection::setSource( QIODevice *source )
80 {
81  cleanupSource();
82  mSource = source;
83  clearLastGPSInformation();
84 }
85 
86 void QgsGpsConnection::clearLastGPSInformation()
87 {
99  mLastGPSInformation.quality = -1; // valid values: 0,1,2, maybe others
102  mLastGPSInformation.fixType = 0; // valid values: 1,2,3
103  mLastGPSInformation.status = ' '; // valid values: A,V
104  mLastGPSInformation.utcDateTime.setDate( QDate() );
105  mLastGPSInformation.satPrn.clear();
106  mLastGPSInformation.utcDateTime.setTime( QTime() );
108 }
void setSource(QIODevice *source)
Sets the GPS source. The class takes ownership of the device class.
~QgsGpsConnection() override
QgsGpsInformation mLastGPSInformation
Last state of the gps related variables (e.g. position, time, ...)
virtual void parseData()=0
Parse available data source content.
QIODevice * mSource
Data source (e.g. serial device, socket, file,...)
bool connect()
Opens connection to device.
QList< QgsSatelliteInfo > satellitesInView
QList< int > satPrn
QgsGpsConnection(QIODevice *dev)
Constructor.
Status mStatus
Connection status.
bool close()
Closes connection to device.