Qt Positioning NMEA plugin

Overview

Included with Qt Positioning is a position plugin which parses NMEA sentences into position updates. This plugin can use serial port, socket or file as a source.

This plugin can be loaded by using the provider name nmea.

Parameters

The following table lists parameters that can be passed to the nmea plugin.

ParameterDescription
nmea.sourceThe source that will be used to get NMEA data.
nmea.baudrateThe baud rate to be used by the serial port connection, expressed with a positive integer number. Typically it should be one of the values from the QSerialPort::BaudRate enum. If the parameter is not specified or does not contain a positive integer, the default value of 4800 is used.
nmea.satellite_info_simulation_intervalThe interval for reading satellite information data from the file in simulation mode.

Different sources require different ways of providing the data. The following table lists different ways of providing nmea.source parameter for socket, serial port and file inputs.

SchemeExampleDescription
socket://hostname:portsocket://localhost:12345Use socket: keyword to specify that you want to get the nmea data from the socket. A TCP socket will be created, which will try to connect to host hostname using port port. Upon successful connection a text NMEA stream is expected to be received from the server.
serial:portnameserial:/dev/ttyUSB0Use serial: keyword to specify that you want to get the nmea data from the serial port. The plugin will try to establish a connection to port portname with a default baudrate = 4800 Bd (the baudrate value can be specified using nmea.baudrate parameter). Upon successful connection a text NMEA stream is expected to be received from the serial port. If you use serial: without any port name, the plugin will try to find one of the well known serial devices using vendor identifier. Note however that this is not a recommended way of using the serial port connection, as the list of well-known devices is small and most probably does not include your hardware.
serial:COM1
serial:
filepath/home/user/nmealog.txtUse file:/// or just full file path to specify a path to a local file.
file:///filepathfile:///home/user/nmealog.txt
qrc:///filepathqrc:///nmealog.txtUse qrc:/// prefix to specify a path to a file in the application resources.

Note: If nmea.source parameter is not specified, the plugin will try to locate one of the well-known serial devices (as if nmea.source = serial: was specified).

Position source usage example

The following examples show how to create a nmea PositionSource using different data sources.

QML

// text file
PositionSource {
    name: "nmea"
    PluginParameter { name: "nmea.source"; value: "qrc:///nmealog.txt" }
}

// socket
PositionSource {
    name: "nmea"
    PluginParameter { name: "nmea.source"; value: "socket://localhost:22222" }
}

// serial port
PositionSource {
    name: "nmea"
    PluginParameter { name: "nmea.source"; value: "serial:/dev/ttyACM0" }
    PluginParameter { name: "nmea.baudrate"; value: 4800 }
}

C++

// text file
QVariantMap params;
params["nmea.source"] = "qrc:///nmealog.txt";
QGeoPositionInfoSource *textPositionSource = QGeoPositionInfoSource::createSource("nmea", params, this);

// socket
params["nmea.source"] = "socket://localhost:22222";
QGeoPositionInfoSource *socketPositionSource = QGeoPositionInfoSource::createSource("nmea", params, this);

// serial port
params["nmea.source"] = "serial:/dev/ttyACM0";
params["nmea.baudrate"] = 4800;
QGeoPositionInfoSource *serialPositionSource = QGeoPositionInfoSource::createSource("nmea", params, this);

Note: Once a PositionSource is created, it can't be reconfigured to use other type of source data.

Satellite information source usage example

Apart from the position information, nmea plugin is also capable of providing satellite information.

QML

// serial port
SatelliteSource {
    name: "nmea"
    PluginParameter { name: "nmea.source"; value: "serial:/dev/ttyUSB0" }
    PluginParameter { name: "nmea.baudrate"; value: 9600 }
}

// socket
SatelliteSource {
    name: "nmea"
    PluginParameter { name: "nmea.source"; value: "socket://localhost:22222" }
}

C++

// serial port
QVariantMap parameters;
parameters["nmea.source"] = "serial:/dev/ttyUSB0";
params["nmea.baudrate"] = 9600;
QGeoSatelliteInfoSource *serialSource = QGeoSatelliteInfoSource::createSource("nmea", parameters, this);

// socket
parameters["nmea.source"] = "socket://localhost:22222";
QGeoSatelliteInfoSource *socketSource = QGeoSatelliteInfoSource::createSource("nmea", parameters, this);

Settings custom simulation speed

If you want to use QGeoSatelliteInfoSource to read file with NMEA stream, you can also use additional parameter "nmea.satellite_info_simulation_interval". This parameter is used to specify the playback rate (in milliseconds) for the satellite info messages. The minimum allowed frequency is specified by minimumUpdateInterval(). If you specify a smaller value, it will be ignored. If no value is specified, the default value is qMax(100, minimumUpdateInterval()). At runtime QNmeaSatelliteInfoSource::setBackendProperty() method can be used to update this parameter.

// file
QVariantMap parameters;
parameters["nmea.source"] = "qrc:///nmealog.txt";
parameters["nmea.satellite_info_simulation_interval"] = 1000;
QGeoSatelliteInfoSource *fileSource = QGeoSatelliteInfoSource::createSource("nmea", parameters, this);

This parameter is not applicable to position source because NMEA protocol already has timestamps in position messages. These timestamps are used to simulate the correct message rate while using QGeoPositionInfoSource with file as a data source.

Note: Once a QGeoSatelliteInfoSource is created, it can't be reconfigured to use other type of source data.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.