QGIS API Documentation 3.99.0-Master (e9821da5c6b)
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 <QString>
23#include <QTcpSocket>
24
25#include "moc_qgsgpsdconnection.cpp"
26
27using namespace Qt::StringLiterals;
28
29QgsGpsdConnection::QgsGpsdConnection( const QString &host, qint16 port, const QString &device )
30 : QgsNmeaConnection( new QTcpSocket() )
31 , mDevice( device )
32{
33 QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource.get() );
34
35 QObject::connect( socket, &QTcpSocket::connected, this, &QgsGpsdConnection::connected );
36 QObject::connect( socket, &QTcpSocket::errorOccurred, this, &QgsGpsdConnection::errorOccurred );
37 socket->connectToHost( host, port );
38}
39
40void QgsGpsdConnection::connected()
41{
42 QgsDebugMsgLevel( u"connected!"_s, 2 );
43 QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource.get() );
44 socket->write( u"?WATCH={\"enable\":true,\"nmea\":true,\"raw\":true%1};"_s.arg( mDevice.isEmpty() ? mDevice : u",\"device\":%1"_s.arg( mDevice ) ).toUtf8() );
45}
46
47void QgsGpsdConnection::errorOccurred( QAbstractSocket::SocketError socketError )
48{
49#ifdef QGISDEBUG
50 QTcpSocket *socket = qobject_cast< QTcpSocket * >( mSource.get() );
51 QgsDebugError( u"error: %1 %2"_s.arg( socketError ).arg( socket->errorString() ) );
52#else
53 Q_UNUSED( socketError )
54#endif
55}
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:63
#define QgsDebugError(str)
Definition qgslogger.h:59