Qt定位NMEA插件

Qt Positioning NMEA plugin

Qt定位NMEA插件

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.

Qt Positioning附带了一个位置插件,可以将NMEA句子解析为位置更新。此插件可以使用串行端口、套接字或文件作为源。

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

可以使用提供者名称nmea加载此插件。

Parameters

参数

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

下表列出了可以传递给nmea插件的参数。

ParameterDescription
nmea.source

The source that will be used to get NMEA data.

将用于获取NMEA数据的源。

nmea.baudrate

The 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.

​串行端口连接使用的波特率,用正整数表示。通常,它应该是QSerialPort::BaudRate枚举中的值之一。如果未指定参数或不包含正整数,则使用默认值4800。

nmea.satellite_info_simulation_interval

The 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.

不同的来源需要不同的数据提供方式。下表列出了为套接字、串行端口和文件输入提供nmea.source参数的不同方法。

SchemeExampleDescription
socket://hostname:portsocket://localhost:12345

Use 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.

使用socket:关键字指定要从套接字获取nmea数据。将创建一个TCP套接字,该套接字将尝试使用端口连接到主机主机名。成功连接后,预计将从服务器接收文本NMEA流。

serial:portnameserial:/dev/ttyUSB0

Use 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:关键字指定要从串行端口获取nmea数据。该插件将尝试使用默认波特率=4800 Bd(可以使用nmea.baudrate参数指定波特率值)建立与端口端口名的连接。成功连接后,预计将从串行端口接收文本NMEA流。如果您使用serial:而不使用任何端口名,插件将尝试使用供应商标识符查找一个众所周知的串行设备。但是请注意,这不是使用串行端口连接的推荐方式,因为众所周知的设备列表很小,很可能不包括硬件。

serial:COM1
serial:
filepath/home/user/nmealog.txt

Use file:/// or just full file path to specify a path to a local file.

使用file:///或仅使用完整文件路径指定本地文件的路径。

file:///filepathfile:///home/user/nmealog.txt
qrc:///filepathqrc:///nmealog.txt

Use qrc:/// prefix to specify a path to a file in the application resources.

使用qrc:///前缀指定应用程序资源中文件的路径。

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).

注意:如果未指定nmea.source参数,插件将尝试定位一个众所周知的串行设备(就像指定了nmea.source=serial:一样)。

Position source usage example

位置源使用示例

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

​以下示例显示了如何使用不同的数据源创建nmea PositionSource。

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.


注意:一旦创建了PositionSource,就无法将其重新配置为使用其他类型的源数据。

Satellite information source usage example

卫星信息源使用示例

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

除了位置信息,nmea插件还能够提供卫星信息。

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.

​如果想使用QGeoSatelliteInfoSource读取带有NMEA流的文件,你也可以使用额外的参数“nmea.satellite_info_simulation_interval”。此参数用于指定卫星信息消息的播放速率(以毫秒为单位)。最小允许频率由minimumUpdateInterval()指定。如果指定了一个较小的值,它将被忽略。如果未指定值,则默认值为qMax(100,minimumUpdateInterval())。在运行时,QNmeaSatelliteInfoSource::setBackendProperty()方法可用于更新此参数。

// 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.

​此参数不适用于位置源,因为NMEA协议在位置消息中已经有时间戳。这些时间戳用于在使用QGeoPositionInfoSource和文件作为数据源时模拟正确的消息速率。

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


注意:一旦创建了QGeoSatelliteInfoSource,就无法将其重新配置为使用其他类型的源数据。

Gypsy pluginUpgrading from Qt 5

© 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
QT是一款流行的跨平台开发工具,可以实现各种应用程序的开发。要实现读取NMEA串口数据,需要使用QT的串口通信功能和解析NMEA协议的相关代码。 首先,需要在QT项目中包含串口通信相关的头文件。然后,创建一个QSerialPort对象来打开NMEA串口,并设置相应的参数,如波特率、数据位、校验位等。 接下来,可以使用QT的信号与槽机制来实现数据的读取。可以连接QSerialPort的readyRead()信号到一个槽函数中,该槽函数会在有数据可读时触发。在槽函数中调用QSerialPort的readAll()方法来读取数据,并将其保存到一个缓冲区中。 由于NMEA协议的数据是以行为单位进行传输的,所以还需要对读取的数据进行处理。可以使用QString的split()方法将数据按行分割成一个字符串列表。然后,可以遍历列表中的每一行数据,使用QString的split()方法以逗号为分隔符将行数据分割成带有卫星信息的字段列表。根据NMEA协议的不同,可以从字段列表中提取所需的信息。 解析NMEA协议的核心是对各个字段的意义的理解。可以参考NMEA协议的文档,了解各个字段的含义和解析方法。 最后,可以将解析得到的数据显示在QT的界面上,或者进行进一步的处理和分析。 总结起来,要实现QT读取NMEA串口数据,需要使用QT的串口通信功能和解析NMEA协议的相关代码。通过设置串口参数、连接信号和槽、读取数据,并对数据进行解析和处理,可以获取并利用NMEA协议中的数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值