QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 #include <QSerialPort>
26 #include <QSerialPortInfo>
27 
28 #include "qgsnmeaconnection.h"
29 #include "qgslogger.h"
30 
31 QgsGpsConnection::QgsGpsConnection( QIODevice *dev ): QObject( nullptr ), mSource( dev ), mStatus( NotConnected )
32 {
33  clearLastGPSInformation();
34  QObject::connect( dev, &QIODevice::readyRead, this, &QgsGpsConnection::parseData );
35 }
36 
38 {
39  cleanupSource();
40 }
41 
43 {
44  if ( !mSource )
45  {
46  return false;
47  }
48 
49  bool connected = mSource->open( QIODevice::ReadWrite | QIODevice::Unbuffered );
50  if ( connected )
51  {
53  }
54  return connected;
55 }
56 
58 {
59  if ( !mSource )
60  {
61  return false;
62  }
63 
64  mSource->close();
65  return true;
66 }
67 
68 void QgsGpsConnection::cleanupSource()
69 {
70  if ( mSource )
71  {
72  mSource->close();
73  }
74  delete mSource;
75  mSource = nullptr;
76 }
77 
78 void QgsGpsConnection::setSource( QIODevice *source )
79 {
80  cleanupSource();
81  mSource = source;
82  clearLastGPSInformation();
83 }
84 
85 void QgsGpsConnection::clearLastGPSInformation()
86 {
98  mLastGPSInformation.quality = -1; // valid values: 0,1,2, maybe others
101  mLastGPSInformation.fixType = 0; // valid values: 1,2,3
102  mLastGPSInformation.status = ' '; // valid values: A,V
103  mLastGPSInformation.utcDateTime.setDate( QDate() );
104  mLastGPSInformation.satPrn.clear();
105  mLastGPSInformation.utcDateTime.setTime( QTime() );
107 }
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.