QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
29 QgsGpsConnection::QgsGpsConnection( QIODevice *dev ): QObject( nullptr ), mSource( dev ), mStatus( NotConnected )
30 {
31  clearLastGPSInformation();
32  QObject::connect( dev, &QIODevice::readyRead, this, &QgsGpsConnection::parseData );
33 }
34 
36 {
37  cleanupSource();
38 }
39 
41 {
42  if ( !mSource )
43  {
44  return false;
45  }
46 
47  bool connected = mSource->open( QIODevice::ReadWrite | QIODevice::Unbuffered );
48  if ( connected )
49  {
51  }
52  return connected;
53 }
54 
56 {
57  if ( !mSource )
58  {
59  return false;
60  }
61 
62  mSource->close();
63  return true;
64 }
65 
66 void QgsGpsConnection::cleanupSource()
67 {
68  if ( mSource )
69  {
70  mSource->close();
71  }
72  delete mSource;
73  mSource = nullptr;
74 }
75 
76 void QgsGpsConnection::setSource( QIODevice *source )
77 {
78  cleanupSource();
79  mSource = source;
80  clearLastGPSInformation();
81 }
82 
83 void QgsGpsConnection::clearLastGPSInformation()
84 {
96  mLastGPSInformation.quality = -1; // valid values: 0,1,2, maybe others
99  mLastGPSInformation.fixType = 0; // valid values: 1,2,3
100  mLastGPSInformation.status = ' '; // valid values: A,V
101  mLastGPSInformation.utcDateTime.setDate( QDate() );
102  mLastGPSInformation.satPrn.clear();
103  mLastGPSInformation.utcDateTime.setTime( QTime() );
105 }
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.