QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
20#include "qgslogger.h"
21
22#include <QTcpSocket>
23
24#include "moc_qgsgpsdconnection.cpp"
25
26QgsGpsdConnection::QgsGpsdConnection( const QString &host, qint16 port, const QString &device )
27 : QgsNmeaConnection( new QTcpSocket() )
28 , mDevice( device )
29{
30 QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource.get() );
31
32 QObject::connect( socket, &QTcpSocket::connected, this, &QgsGpsdConnection::connected );
33 QObject::connect( socket, &QTcpSocket::errorOccurred, this, &QgsGpsdConnection::errorOccurred );
34 socket->connectToHost( host, port );
35}
36
37void QgsGpsdConnection::connected()
38{
39 QgsDebugMsgLevel( QStringLiteral( "connected!" ), 2 );
40 QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource.get() );
41 socket->write( QStringLiteral( "?WATCH={\"enable\":true,\"nmea\":true,\"raw\":true%1};" ).arg( mDevice.isEmpty() ? mDevice : QStringLiteral( ",\"device\":%1" ).arg( mDevice ) ).toUtf8() );
42}
43
44void QgsGpsdConnection::errorOccurred( QAbstractSocket::SocketError socketError )
45{
46#ifdef QGISDEBUG
47 QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource.get() );
48 QgsDebugError( QStringLiteral( "error: %1 %2" ).arg( socketError ).arg( socket->errorString() ) );
49#else
50 Q_UNUSED( socketError )
51#endif
52}
std::unique_ptr< QIODevice > mSource
Data source (e.g. serial device, socket, file,...).
QgsGpsdConnection(const QString &host, qint16 port, const QString &device)
QgsNmeaConnection(QIODevice *device)
Constructs a QgsNmeaConnection with given device.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:61
#define QgsDebugError(str)
Definition qgslogger.h:57