QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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( 0 ), mSource( dev ), mStatus( NotConnected )
33 {
34  clearLastGPSInformation();
35  QObject::connect( dev, SIGNAL( readyRead() ), this, SLOT( 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 = 0;
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 }
Status mStatus
Connection status.
QgsGPSConnection(QIODevice *dev)
Constructor.
void setSource(QIODevice *source)
Sets the GPS source.
QList< QgsSatelliteInfo > satellitesInView
QList< int > satPrn
virtual void parseData()=0
Parse available data source content.
bool close()
Closes connection to device.
QgsGPSInformation mLastGPSInformation
Last state of the gps related variables (e.g.
virtual ~QgsGPSConnection()
QIODevice * mSource
Data source (e.g.
bool connect()
Opens connection to device.