QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsgpsdconnection.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsgpsdconnection.cpp - description
3 ---------------------
4 begin : October 4th, 2010
5 copyright : (C) 2010 by Jürgen E. Fischer, norBIT GmbH
6 email : jef at norbit dot de
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 "qgsgpsdconnection.h"
19#include "moc_qgsgpsdconnection.cpp"
20#include "qgslogger.h"
21
22#include <QTcpSocket>
23
24QgsGpsdConnection::QgsGpsdConnection( const QString &host, qint16 port, const QString &device )
25 : QgsNmeaConnection( new QTcpSocket() )
26 , mDevice( device )
27{
28 QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource.get() );
29
30 QObject::connect( socket, SIGNAL( connected() ), this, SLOT( connected() ) );
31 QObject::connect( socket, SIGNAL( error( QAbstractSocket::SocketError ) ), this, SLOT( error( QAbstractSocket::SocketError ) ) );
32 socket->connectToHost( host, port );
33}
34
35void QgsGpsdConnection::connected()
36{
37 QgsDebugMsgLevel( QStringLiteral( "connected!" ), 2 );
38 QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource.get() );
39 socket->write( QStringLiteral( "?WATCH={\"enable\":true,\"nmea\":true,\"raw\":true%1};" ).arg( mDevice.isEmpty() ? mDevice : QStringLiteral( ",\"device\":%1" ).arg( mDevice ) ).toUtf8() );
40}
41
42void QgsGpsdConnection::error( QAbstractSocket::SocketError socketError )
43{
44#ifdef QGISDEBUG
45 QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource.get() );
46 QgsDebugError( QStringLiteral( "error: %1 %2" ).arg( socketError ).arg( socket->errorString() ) );
47#else
48 Q_UNUSED( socketError )
49#endif
50}
std::unique_ptr< QIODevice > mSource
Data source (e.g. serial device, socket, file,...)
QgsGpsdConnection(const QString &host, qint16 port, const QString &device)
Evaluates NMEA sentences coming from a GPS device.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39
#define QgsDebugError(str)
Definition qgslogger.h:38