QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SerialGPSTransport Class Reference

#include <SerialGPSTransport.h>

Inheritance diagram for SerialGPSTransport:
Collaboration diagram for SerialGPSTransport:

Public Member Functions

 SerialGPSTransport (QString device, GPSCancelToken cancelToken, std::chrono::milliseconds openTimeout=OPEN_TIMEOUT)
 ~SerialGPSTransport () override
GPSOpenResult open () override
bool fatalError () const override
 True once the port hits an error the receive loop should stop retrying past.
bool setBaudrate (unsigned baudrate) override
Public Member Functions inherited from GPSDeviceTransport
GPSReadResult read (std::span< uint8_t > buffer, std::chrono::milliseconds timeout) override
 GPSTransport (GPSCancelToken cancelToken)
Public Member Functions inherited from GPSTransport
 GPSTransport (GPSCancelToken cancelToken)
virtual ~GPSTransport ()
bool isCancelled () const
const GPSCancelToken & cancelToken () const
virtual unsigned fixedBaudrate () const
 Nonzero when the link cannot follow baud-rate changes (for example, a serial bridge).
virtual std::chrono::milliseconds configurationWriteTimeout () const
GPSWriteResult write (QByteArrayView bytes, QDeadlineTimer deadline)

Static Public Attributes

static constexpr std::chrono::milliseconds OPEN_TIMEOUT {30000}
 How long open() keeps retrying a device it is not permitted to open yet.
Static Public Attributes inherited from GPSTransport
static constexpr unsigned BRIDGE_BAUDRATE = 115200
static constexpr qint64 READ_BUFFER_BYTES = 64 * 1024
static constexpr qint64 WRITE_BUFFER_BYTES = 4 * 1024
 Bytes a link queues for writing at once.

Protected Member Functions

QIODevice * device () const override
 The open device, or null before open().
bool readUnavailable () const override
 Whether read() fails without waiting; by default, when there is no device.
bool waitReadable (QDeadlineTimer deadline) override
 Waits until input is buffered. Input reported buffered is delivered even after the link fails.
GPSReadResult readFailure () const override
 Describes a failed link; by default, a closed connection with the device's error.
void waitWritten (QDeadlineTimer &deadline) override
 Waits for queued bytes to drain. May expire deadline to end the write.
qint64 confirmedWritten (int accepted, qint64 drained) override
Protected Member Functions inherited from GPSDeviceTransport
virtual qint64 take (std::span< uint8_t > buffer)
 Takes buffered input.
GPSWriteResult writeData (QByteArrayView bytes, QDeadlineTimer deadline) override
 Receives non-empty bytes and an unexpired, capped deadline that implementations must honor.
virtual void retire ()
 Retires the connection after a failed write that accepted bytes; by default closes the device.
bool waitUntil (const std::function< bool()> &done, QDeadlineTimer deadline)
bool waitForDevice (const std::function< bool()> &ready, QDeadlineTimer deadline)

Detailed Description

GPSTransport backed by a QSerialPort. Owns the port and must be constructed on the thread that pumps the driver — QSerialPort has thread affinity.

Definition at line 15 of file SerialGPSTransport.h.

Constructor & Destructor Documentation

◆ SerialGPSTransport()

SerialGPSTransport::SerialGPSTransport ( QString device,
GPSCancelToken cancelToken,
std::chrono::milliseconds openTimeout = OPEN_TIMEOUT )

Definition at line 46 of file SerialGPSTransport.cc.

References GPSTransport::cancelToken(), and device().

◆ ~SerialGPSTransport()

SerialGPSTransport::~SerialGPSTransport ( )
overridedefault

Member Function Documentation

◆ confirmedWritten()

qint64 SerialGPSTransport::confirmedWritten ( int accepted,
qint64 drained )
overrideprotectedvirtual

Bytes of this write the link confirmed, given accepted bytes accepted and drained bytes reported by the device's bytesWritten() during the write; by default drained.

Reimplemented from GPSDeviceTransport.

Definition at line 159 of file SerialGPSTransport.cc.

References fatalError().

◆ device()

QIODevice * SerialGPSTransport::device ( ) const
overrideprotectedvirtual

The open device, or null before open().

Implements GPSDeviceTransport.

Definition at line 117 of file SerialGPSTransport.cc.

Referenced by SerialGPSTransport().

◆ fatalError()

bool SerialGPSTransport::fatalError ( ) const
overridevirtual

True once the port hits an error the receive loop should stop retrying past.

Implements GPSTransport.

Definition at line 111 of file SerialGPSTransport.cc.

References QSerialPort::NoError, and QSerialPort::TimeoutError.

Referenced by confirmedWritten(), readUnavailable(), setBaudrate(), and waitReadable().

◆ open()

GPSOpenResult SerialGPSTransport::open ( )
overridevirtual

Open the device, retrying briefly while it settles after startup. Aborts the retry promptly once a stop is requested, so a disconnect can't be stalled by it.

Implements GPSTransport.

Definition at line 55 of file SerialGPSTransport.cc.

References QSerialPort::Baud9600, Cancelled, QSerialPort::Data8, Error, GPSTransport::isCancelled(), QSerialPort::NoFlowControl, QSerialPort::NoParity, QSerialPort::OneStop, Opened, QSerialPort::PermissionError, GPSTransport::READ_BUFFER_BYTES, TimedOut, and GPSDeviceTransport::waitUntil().

◆ readFailure()

GPSReadResult SerialGPSTransport::readFailure ( ) const
overrideprotectedvirtual

Describes a failed link; by default, a closed connection with the device's error.

Reimplemented from GPSDeviceTransport.

Definition at line 133 of file SerialGPSTransport.cc.

References Error, and Overflow.

◆ readUnavailable()

bool SerialGPSTransport::readUnavailable ( ) const
overrideprotectedvirtual

Whether read() fails without waiting; by default, when there is no device.

Reimplemented from GPSDeviceTransport.

Definition at line 122 of file SerialGPSTransport.cc.

References fatalError().

◆ setBaudrate()

bool SerialGPSTransport::setBaudrate ( unsigned baudrate)
overridevirtual

Sets the link baud rate. Returns true on success. By default only a healthy link's fixed rate succeeds, as a network bridge cannot change it. A refused rate leaves the link usable unless fatalError() reports otherwise.

Reimplemented from GPSTransport.

Definition at line 170 of file SerialGPSTransport.cc.

References fatalError(), GPSTransport::isCancelled(), and QSerialPort::ResourceError.

◆ waitReadable()

bool SerialGPSTransport::waitReadable ( QDeadlineTimer deadline)
overrideprotectedvirtual

Waits until input is buffered. Input reported buffered is delivered even after the link fails.

Reimplemented from GPSDeviceTransport.

Definition at line 127 of file SerialGPSTransport.cc.

References fatalError(), GPSTransport::isCancelled(), and GPSDeviceTransport::waitReadable().

◆ waitWritten()

void SerialGPSTransport::waitWritten ( QDeadlineTimer & deadline)
overrideprotectedvirtual

Waits for queued bytes to drain. May expire deadline to end the write.

Reimplemented from GPSDeviceTransport.

Definition at line 151 of file SerialGPSTransport.cc.

Member Data Documentation

◆ OPEN_TIMEOUT

std::chrono::milliseconds SerialGPSTransport::OPEN_TIMEOUT {30000}
staticconstexpr

How long open() keeps retrying a device it is not permitted to open yet.

Definition at line 19 of file SerialGPSTransport.h.


The documentation for this class was generated from the following files: