QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
gps
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
27
using namespace
Qt::StringLiterals;
28
29
QgsGpsdConnection::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
40
void
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
47
void
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
}
QgsGpsConnection::mSource
std::unique_ptr< QIODevice > mSource
Data source (e.g. serial device, socket, file,...).
Definition
qgsgpsconnection.h:182
QgsGpsdConnection::QgsGpsdConnection
QgsGpsdConnection(const QString &host, qint16 port, const QString &device)
Definition
qgsgpsdconnection.cpp:29
QgsNmeaConnection::QgsNmeaConnection
QgsNmeaConnection(QIODevice *device)
Constructs a QgsNmeaConnection with given device.
Definition
qgsnmeaconnection.cpp:43
qgsgpsdconnection.h
qgslogger.h
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition
qgslogger.h:80
QgsDebugError
#define QgsDebugError(str)
Definition
qgslogger.h:71
Generated on
for QGIS API Documentation by
1.17.0