Skip to content
Permalink
Browse files

[gps] Allow GPS serial port connection properties to be specified in …

…QSettings

Instead of hardcoding these values, allow them to be customised by changing
settings in QSettings (either via the settings ini file or through the
advanced settings editor), as some serial GPS devices require non-default
settings for the connection to work correctly.

(cherry picked from commit bb1c504)
  • Loading branch information
nyalldawson committed Jan 7, 2020
1 parent 88e34d7 commit 2f1bcd8432087f140140e11811bdabc6d9c91c4b
Showing with 38 additions and 11 deletions.
  1. +28 −0 resources/qgis_global_settings.ini
  2. +10 −11 src/core/gps/qgsgpsdetector.cpp
@@ -78,6 +78,34 @@ projections\newProjectCrsBehavior=UseCrsOfFirstLayerAdded
projections\unknownCrsBehavior=NoAction

[core]

# Desired flow control mode for serial port GPS connections
# "NoFlowControl" - no flow control
# "HardwareControl" - hardware flow control (RTS/CTS)
# "SoftwareControl" - software flow control (XON/XOFF)
gps\flow_control=NoFlowControl

# Desired parity checking mode for serial port GPS connections
# "NoParity" - No parity bit it sent. This is the most common parity setting. Error detection is handled by the communication protocol.
# "EvenParity" - The number of 1 bits in each character, including the parity bit, is always even.
# "OddParity" - The number of 1 bits in each character, including the parity bit, is always odd. It ensures that at least one state transition occurs in each character.
# "SpaceParity" - Space parity. The parity bit is sent in the space signal condition. It does not provide error detection information.
# "MarkParity" - Mark parity. The parity bit is always set to the mark signal condition (logical 1). It does not provide error detection information.
gps\parity=NoParity

# Desired data bits in a frame for serial port GPS connections
# "Data5" - The number of data bits in each character is 5. It is used for Baudot code. It generally only makes sense with older equipment such as teleprinters.
# "Data6" - The number of data bits in each character is 6. It is rarely used.
# "Data7" - The number of data bits in each character is 7. It is used for true ASCII. It generally only makes sense with older equipment such as teleprinters.
# "Data8" - The number of data bits in each character is 8. It is used for most kinds of data, as this size matches the size of a byte. It is almost universally used in newer applications.
gps\data_bits=Data8

# Desired number of stop bits in a frame for serial port GPS connections
# "OneStop" - 1 stop bit.
# "OneAndHalfStop" - 1.5 stop bits. This is only for the Windows platform.
# "TwoStop" - 2 stop bits.
gps\stop_bits=OneStop

# Whether or not to anonymize newly created projects
# If set to 1, then project metadata items like AUTHOR and CREATION DATE
# will not be automatically populated when a new project is created.
@@ -20,7 +20,7 @@
#include "qgsgpsconnection.h"
#include "qgsnmeaconnection.h"
#include "qgsgpsdconnection.h"

#include "qgssettings.h"

#if defined(HAVE_QT_MOBILITY_LOCATION ) || defined(QT_POSITIONING_LIB)
#include "qgsqtlocationconnection.h"
@@ -80,6 +80,8 @@ void QgsGpsDetector::advance()
{
mConn.reset();

QgsSettings settings;

while ( !mConn )
{
mBaudIndex++;
@@ -117,21 +119,18 @@ void QgsGpsDetector::advance()
else
{
#if defined( HAVE_QT5SERIALPORT )
QSerialPort *serial = new QSerialPort( mPortList.at( mPortIndex ).first );
std::unique_ptr< QSerialPort > serial = qgis::make_unique< QSerialPort >( mPortList.at( mPortIndex ).first );

serial->setBaudRate( mBaudList[ mBaudIndex ] );
serial->setFlowControl( QSerialPort::NoFlowControl );
serial->setParity( QSerialPort::NoParity );
serial->setDataBits( QSerialPort::Data8 );
serial->setStopBits( QSerialPort::OneStop );

serial->setFlowControl( settings.enumValue( QStringLiteral( "gps/flow_control" ), QSerialPort::NoFlowControl, QgsSettings::Core ) );
serial->setParity( settings.enumValue( QStringLiteral( "gps/parity" ), QSerialPort::NoParity, QgsSettings::Core ) );
serial->setDataBits( settings.enumValue( QStringLiteral( "gps/data_bits" ), QSerialPort::Data8, QgsSettings::Core ) );
serial->setStopBits( settings.enumValue( QStringLiteral( "gps/stop_bits" ), QSerialPort::OneStop, QgsSettings::Core ) );

if ( serial->open( QIODevice::ReadOnly ) )
{
mConn = qgis::make_unique< QgsNmeaConnection >( serial );
}
else
{
delete serial;
mConn = qgis::make_unique< QgsNmeaConnection >( serial.release() );
}
#else
qWarning( "QT5SERIALPORT not found and mPortList matches serial port, this should never happen" );

0 comments on commit 2f1bcd8

Please sign in to comment.
You can’t perform that action at this time.