1// Copyright (C) 2021 The Qt Company Ltd.
 
    2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
 
    5\page position-plugin-nmea.html
 
    6\title Qt Positioning NMEA plugin
 
    7\ingroup QtPositioning-plugins
 
    9\brief Reads the NMEA stream to provide position updates.
 
   13Included with Qt Positioning is a position plugin which parses NMEA sentences
 
   14into position updates. This plugin can use serial port, socket or file as a
 
   17This plugin can be loaded by using the provider name \b nmea.
 
   21The following table lists parameters that \e can be passed to the nmea plugin.
 
   29    \li The source that will be used to get NMEA data.
 
   32    \li The baud rate to be used by the serial port connection, expressed with
 
   33        a positive integer number. Typically it should be one of the values
 
   34        from the \l QSerialPort::BaudRate enum. If the parameter is not
 
   35        specified or does not contain a positive integer, the default value
 
   38    \li nmea.satellite_info_simulation_interval
 
   39    \li The interval for reading satellite information data from the file in
 
   43Different sources require different ways of providing the data. The following
 
   44table lists different ways of providing \c {nmea.source} parameter for socket,
 
   45serial port and file inputs.
 
   53    \li socket://hostname:port
 
   54    \li \c {socket://localhost:12345}
 
   55    \li Use \b {socket:} keyword to specify that you want to get the nmea data
 
   56        from the socket. A TCP socket will be created, which will try to connect
 
   57        to host \c hostname using port \c port. Upon successful connection
 
   58        a text NMEA stream is expected to be received from the server.
 
   60    \li {1, 3} serial:portname
 
   61    \li \c {serial:/dev/ttyUSB0}
 
   62    \li {1, 3} Use \b {serial:} keyword to specify that you want to get the nmea
 
   63        data from the serial port. The plugin will try to establish a connection
 
   64        to port \c portname with a default baudrate = 4800 Bd (the baudrate
 
   65        value can be specified using \b {nmea.baudrate} parameter). Upon
 
   67        a text NMEA stream is expected to be received from the serial port.
 
   68        If you use \b {serial:} without any port name, the plugin will try to
 
   69        find one of the well known serial devices using vendor identifier. Note
 
   70        however that this is not a recommended way of using the serial port
 
   71        connection, as the list of well-known devices is small and most probably
 
   72        does not include your hardware.
 
   79    \li \c {/home/user/nmealog.txt}
 
   80    \li {1, 2} Use \b {file:///} or just full file path to specify a path to a
 
   84    \li \c {file:///home/user/nmealog.txt}
 
   87    \li \c {qrc:///nmealog.txt}
 
   88    \li Use \b {qrc:///} prefix to specify a path to a file in the application
 
   92\note If \c {nmea.source} parameter is not specified, the plugin will try to
 
   93locate one of the well-known serial devices (as if \c {nmea.source = serial:}
 
   96\section1 Position source usage example
 
   98The following examples show how to create a \b nmea PositionSource
 
   99using different data sources.
 
  107    PluginParameter { name: "nmea.source"; value: "qrc:///nmealog.txt" }
 
  113    PluginParameter { name: "nmea.source"; value: "socket://localhost:22222" }
 
  119    PluginParameter { name: "nmea.source"; value: "serial:/dev/ttyACM0" }
 
  120    PluginParameter { name: "nmea.baudrate"; value: 4800 }
 
  129params["nmea.source"] = "qrc:///nmealog.txt";
 
  130QGeoPositionInfoSource *textPositionSource = QGeoPositionInfoSource::createSource("nmea", params, this);
 
  133params["nmea.source"] = "socket://localhost:22222";
 
  134QGeoPositionInfoSource *socketPositionSource = QGeoPositionInfoSource::createSource("nmea", params, this);
 
  137params["nmea.source"] = "serial:/dev/ttyACM0";
 
  138params["nmea.baudrate"] = 4800;
 
  139QGeoPositionInfoSource *serialPositionSource = QGeoPositionInfoSource::createSource("nmea", params, this);
 
  142\note Once a PositionSource is created, it can't be reconfigured to use other
 
  145\section1 Satellite information source usage example
 
  147Apart from the position information, \b nmea plugin is also capable of providing
 
  148satellite information.
 
  156    PluginParameter { name: "nmea.source"; value: "serial:/dev/ttyUSB0" }
 
  157    PluginParameter { name: "nmea.baudrate"; value: 9600 }
 
  163    PluginParameter { name: "nmea.source"; value: "socket://localhost:22222" }
 
  171QVariantMap parameters;
 
  172parameters["nmea.source"] = "serial:/dev/ttyUSB0";
 
  173params["nmea.baudrate"] = 9600;
 
  174QGeoSatelliteInfoSource *serialSource = QGeoSatelliteInfoSource::createSource("nmea", parameters, this);
 
  177parameters["nmea.source"] = "socket://localhost:22222";
 
  178QGeoSatelliteInfoSource *socketSource = QGeoSatelliteInfoSource::createSource("nmea", parameters, this);
 
  181\section2 Settings Custom Simulation Speed
 
  183If you want to use \l QGeoSatelliteInfoSource to read file with NMEA stream, you
 
  184can also use additional parameter \c "nmea.satellite_info_simulation_interval".
 
  185This parameter is used to specify the playback rate (in milliseconds) for the
 
  186satellite info messages. The minimum allowed frequency is specified by
 
  187\l {QGeoSatelliteInfoSource::}{minimumUpdateInterval()}. If you specify a
 
  188smaller value, it will be ignored. If no value is specified, the default value
 
  189is \c {qMax(100, minimumUpdateInterval())}.
 
  190At runtime \l {QNmeaSatelliteInfoSource::setBackendProperty()} method can be
 
  191used to update this parameter.
 
  195QVariantMap parameters;
 
  196parameters["nmea.source"] = "qrc:///nmealog.txt";
 
  197parameters["nmea.satellite_info_simulation_interval"] = 1000;
 
  198QGeoSatelliteInfoSource *fileSource = QGeoSatelliteInfoSource::createSource("nmea", parameters, this);
 
  201This parameter is not applicable to position source because NMEA protocol
 
  202already has timestamps in position messages. These timestamps are used to
 
  203simulate the correct message rate while using \l QGeoPositionInfoSource with
 
  204file as a data source.
 
  206\note Once a \l QGeoSatelliteInfoSource is created, it can't be reconfigured to
 
  207use other type of source data.