QGIS API Documentation  master-3f58142
src/core/gps/qgsgpsdconnection.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgsgpsdconnection.cpp  -  description
00003                           ---------------------
00004     begin                : October 4th, 2010
00005     copyright            : (C) 2010 by Jürgen E. Fischer, norBIT GmbH
00006     email                : jef at norbit dot de
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 "qgsgpsdconnection.h"
00019 #include "qgslogger.h"
00020 
00021 #include <QTcpSocket>
00022 
00023 QgsGpsdConnection::QgsGpsdConnection( QString host, qint16 port, QString device )
00024     : QgsNMEAConnection( new QTcpSocket() )
00025     , mDevice( device )
00026 {
00027   QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource );
00028 
00029   QObject::connect( socket, SIGNAL( connected() ), this, SLOT( connected() ) );
00030   QObject::connect( socket, SIGNAL( error( QAbstractSocket::SocketError ) ), this, SLOT( error( QAbstractSocket::SocketError ) ) );
00031   socket->connectToHost( host, port );
00032 }
00033 
00034 QgsGpsdConnection::~QgsGpsdConnection()
00035 {
00036   //connection will be closed by base class
00037   QgsDebugMsg( "entered." );
00038 }
00039 
00040 void QgsGpsdConnection::connected()
00041 {
00042   QgsDebugMsg( "connected!" );
00043   QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource );
00044   socket->write( QString( "?WATCH={\"enable\":true,\"nmea\":true,\"raw\":true%1};" ).arg( mDevice.isEmpty() ? mDevice : QString( ",\"device\":%1" ).arg( mDevice ) ).toUtf8() );
00045 }
00046 
00047 void QgsGpsdConnection::error( QAbstractSocket::SocketError socketError )
00048 {
00049 #if QGISDEBUG
00050   QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource );
00051   QgsDebugMsg( QString( "error: %1 %2" ).arg( socketError ).arg( socket->errorString() ) );
00052 #else
00053   Q_UNUSED( socketError );
00054 #endif
00055 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines