QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSDeviceTransport Class Referenceabstract

#include <GPSDeviceTransport.h>

Inheritance diagram for GPSDeviceTransport:
Collaboration diagram for GPSDeviceTransport:

Public Member Functions

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 ()
virtual GPSOpenResult open ()=0
virtual bool fatalError () const =0
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)
virtual bool setBaudrate (unsigned baudrate)

Protected Member Functions

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

Additional Inherited Members

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.

Detailed Description

GPSTransport over a QIODevice its subclass owns. Implements the bounded read and write contract once; subclasses adapt it through the protected hooks. Waits dispatch the owner thread's events and wake at once on a stop.

Definition at line 18 of file GPSDeviceTransport.h.

Member Function Documentation

◆ confirmedWritten()

qint64 GPSDeviceTransport::confirmedWritten ( int accepted,
qint64 drained )
protectedvirtual

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 in SerialGPSTransport.

Definition at line 119 of file GPSDeviceTransport.cc.

Referenced by writeData().

◆ device()

virtual QIODevice * GPSDeviceTransport::device ( ) const
protectedpure virtual

◆ GPSTransport()

GPSTransport::GPSTransport ( GPSCancelToken cancelToken)
explicit

Definition at line 78 of file GPSTransport.cc.

◆ read()

GPSReadResult GPSDeviceTransport::read ( std::span< uint8_t > buffer,
std::chrono::milliseconds timeout )
overridevirtual

A nonpositive timeout polls immediately available input. Failures never carry usable stream bytes. An empty buffer reports the failure of a failed link without reading.

Implements GPSTransport.

Definition at line 14 of file GPSDeviceTransport.cc.

References Cancelled, Data, GPSReadResult::detail, Error, GPSTransport::fatalError(), GPSTransport::isCancelled(), readFailure(), readUnavailable(), take(), TimedOut, and waitReadable().

◆ readFailure()

GPSReadResult GPSDeviceTransport::readFailure ( ) const
protectedvirtual

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

Reimplemented in SerialGPSTransport.

Definition at line 58 of file GPSDeviceTransport.cc.

References Closed, and device().

Referenced by read(), and writeData().

◆ readUnavailable()

bool GPSDeviceTransport::readUnavailable ( ) const
protectedvirtual

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

Reimplemented in SerialGPSTransport.

Definition at line 38 of file GPSDeviceTransport.cc.

References device().

Referenced by read().

◆ retire()

void GPSDeviceTransport::retire ( )
protectedvirtual

Retires the connection after a failed write that accepted bytes; by default closes the device.

Reimplemented in TCPGPSTransport.

Definition at line 125 of file GPSDeviceTransport.cc.

References device().

Referenced by writeData().

◆ take()

qint64 GPSDeviceTransport::take ( std::span< uint8_t > buffer)
protectedvirtual

Takes buffered input.

Returns
the bytes taken, or -1 on failure.

Reimplemented in UDPGPSTransport.

Definition at line 53 of file GPSDeviceTransport.cc.

References device().

Referenced by read().

◆ waitForDevice()

bool GPSDeviceTransport::waitForDevice ( const std::function< bool()> & ready,
QDeadlineTimer deadline )
protected

waitUntil() for ready or a failed link. Short waitForConnected() calls would abort DNS and connection progress on timeout.

Returns
whether ready holds on a healthy link.

Definition at line 169 of file GPSDeviceTransport.cc.

References device(), GPSTransport::fatalError(), GPSTransport::isCancelled(), and waitUntil().

Referenced by TCPGPSTransport::open(), waitReadable(), UDPGPSTransport::waitReadable(), and waitWritten().

◆ waitReadable()

bool GPSDeviceTransport::waitReadable ( QDeadlineTimer deadline)
protectedvirtual

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

Reimplemented in SerialGPSTransport, and UDPGPSTransport.

Definition at line 43 of file GPSDeviceTransport.cc.

References device(), GPSTransport::fatalError(), and waitForDevice().

Referenced by read(), and SerialGPSTransport::waitReadable().

◆ waitUntil()

bool GPSDeviceTransport::waitUntil ( const std::function< bool()> & done,
QDeadlineTimer deadline )
protected

Dispatches events until done holds, deadline expires or a stop is requested, also woken by the device's input, output, error and state signals.

Returns
whether done holds and no stop was requested.

Definition at line 130 of file GPSDeviceTransport.cc.

References GPSTransport::cancelToken(), device(), QSerialPort::errorOccurred(), and GPSTransport::isCancelled().

Referenced by SerialGPSTransport::open(), and waitForDevice().

◆ waitWritten()

void GPSDeviceTransport::waitWritten ( QDeadlineTimer & deadline)
protectedvirtual

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

Reimplemented in SerialGPSTransport.

Definition at line 113 of file GPSDeviceTransport.cc.

References device(), and waitForDevice().

Referenced by writeData().

◆ writeData()

GPSWriteResult GPSDeviceTransport::writeData ( QByteArrayView bytes,
QDeadlineTimer deadline )
overrideprotectedvirtual

Receives non-empty bytes and an unexpired, capped deadline that implementations must honor.

Implements GPSTransport.

Reimplemented in UDPGPSTransport.

Definition at line 63 of file GPSDeviceTransport.cc.

References Cancelled, Completed, confirmedWritten(), GPSReadResult::detail, device(), Error, GPSTransport::fatalError(), GPSTransport::isCancelled(), readFailure(), retire(), TimedOut, waitWritten(), and GPSTransport::WRITE_BUFFER_BYTES.


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