QGIS API Documentation  master-6227475
src/core/gps/qgsgpsconnection.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgsgpsconnection.cpp  -  description
00003                           --------------------
00004     begin                : November 30th, 2009
00005     copyright            : (C) 2009 by Marco Hugentobler
00006     email                : marco at hugis dot net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "qgsgpsconnection.h"
00019 
00020 #include <QCoreApplication>
00021 #include <QTime>
00022 #include <QIODevice>
00023 #include <QStringList>
00024 #include <QFileInfo>
00025 
00026 #include "qextserialport.h"
00027 #include "qextserialenumerator.h"
00028 
00029 #include "qgsnmeaconnection.h"
00030 #include "qgslogger.h"
00031 
00032 QgsGPSConnection::QgsGPSConnection( QIODevice* dev ): QObject( 0 ), mSource( dev ), mStatus( NotConnected )
00033 {
00034   clearLastGPSInformation();
00035   QObject::connect( dev, SIGNAL( readyRead() ), this, SLOT( parseData() ) );
00036 }
00037 
00038 QgsGPSConnection::~QgsGPSConnection()
00039 {
00040   cleanupSource();
00041 }
00042 
00043 bool QgsGPSConnection::connect()
00044 {
00045   if ( !mSource )
00046   {
00047     return false;
00048   }
00049 
00050   bool connected = mSource->open( QIODevice::ReadWrite | QIODevice::Unbuffered );
00051   if ( connected )
00052   {
00053     mStatus = Connected;
00054   }
00055   return connected;
00056 }
00057 
00058 bool QgsGPSConnection::close()
00059 {
00060   if ( !mSource )
00061   {
00062     return false;
00063   }
00064 
00065   mSource->close();
00066   return true;
00067 }
00068 
00069 void QgsGPSConnection::cleanupSource()
00070 {
00071   if ( mSource )
00072   {
00073     mSource->close();
00074   }
00075   delete mSource;
00076   mSource = 0;
00077 }
00078 
00079 void QgsGPSConnection::setSource( QIODevice* source )
00080 {
00081   cleanupSource();
00082   mSource = source;
00083   clearLastGPSInformation();
00084 }
00085 
00086 void QgsGPSConnection::clearLastGPSInformation()
00087 {
00088   mLastGPSInformation.direction = 0;
00089   mLastGPSInformation.elevation = 0;
00090   mLastGPSInformation.hdop = 0;
00091   mLastGPSInformation.latitude = 0;
00092   mLastGPSInformation.longitude = 0;
00093   mLastGPSInformation.pdop = 0;
00094   mLastGPSInformation.satellitesInView.clear();
00095   mLastGPSInformation.speed = 0;
00096   mLastGPSInformation.vdop = 0;
00097   mLastGPSInformation.hacc = -1;
00098   mLastGPSInformation.vacc = -1;
00099   mLastGPSInformation.quality = -1;  // valid values: 0,1,2, maybe others
00100   mLastGPSInformation.satellitesUsed = 0;
00101   mLastGPSInformation.fixMode = ' ';
00102   mLastGPSInformation.fixType = 0; // valid values: 1,2,3
00103   mLastGPSInformation.status = ' '; // valid values: A,V
00104   mLastGPSInformation.utcDateTime.setDate( QDate() );
00105   mLastGPSInformation.satPrn.clear();
00106   mLastGPSInformation.utcDateTime.setTime( QTime() );
00107   mLastGPSInformation.satInfoComplete = false;
00108 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines