NDEVR
API Documentation
BluetoothConnection

A ConnectionBackend that provides logic for interfacing with a QBluetooth connection. More...

Inheritance diagram for BluetoothConnection:
[legend]
Collaboration diagram for BluetoothConnection:
[legend]

Public Member Functions

 BluetoothConnection (LogPtr log)
 Constructs a BluetoothConnection with the given log.
 ~BluetoothConnection ()
 Destroys the BluetoothConnection and releases the underlying socket.
virtual uint04 bytesAvailable () const override
 Returns the number of bytes available for reading from the socket.
virtual void close () override
 Closes the Bluetooth connection and releases the socket.
void handleBluetoothError (int error)
 Handles a Bluetooth error by updating the internal error state.
virtual bool isOpen () const override
 Checks whether the Bluetooth socket is currently open and connected.
virtual TranslatedString lastError () const override
 Returns the last error message from this connection.
virtual bool open (const ConnectionInfo &request) override
 Opens a Bluetooth connection using the provided connection info.
virtual bool openInMainThread (const ConnectionInfo &request)
 Opens a Bluetooth connection on the main thread, required for some Qt Bluetooth operations.
virtual uint04 peek (char *s, uint04 size=Constant< uint04 >::Max) const override
 Peeks at incoming data without consuming it from the receive buffer.
virtual uint04 rx (char *s, uint04 size=Constant< uint04 >::Max) override
 Receives data from the Bluetooth socket into the provided buffer.
virtual bool setBluetoothPort (QBluetoothSocket *bluetooth_port, const ConnectionInfo &info)
 Assigns an existing QBluetoothSocket to this connection.
virtual void tx (const StringView &command) override
 Transmits the given command string over the Bluetooth socket.
virtual bool waitForReadyRead (const TimeSpan &span) override
 Blocks until data is ready to read or the timeout expires.
Public Member Functions inherited from ConnectionBackend
 ConnectionBackend (LogPtr log)
 Constructs a ConnectionBackend with the given log.
void connectionStateChangedSignal (ConnectionState state)
 Emitted when the connection state changes.
void dataAvailableSignal ()
 Emitted when data is available to be read from the connection.
virtual String threadID () const
 Returns the thread ID this backend must execute on, if any.

Protected Attributes

TranslatedString m_last_error
 The most recent error message from this connection.
QPointer< QBluetoothSocket > m_socket
 The underlying Qt Bluetooth socket used for communication.
Protected Attributes inherited from ConnectionBackend
LogPtr m_log
 Log for diagnostic messages.

Detailed Description

A ConnectionBackend that provides logic for interfacing with a QBluetooth connection.


See also
Connection, SerialPortConnection, SocketConnection

Definition at line 12 of file BluetoothConnection.h.

Constructor & Destructor Documentation

◆ BluetoothConnection()

BluetoothConnection::BluetoothConnection ( LogPtr log)

Constructs a BluetoothConnection with the given log.

Parameters
[in]logThe log to use for reporting connection events and errors.

Member Function Documentation

◆ bytesAvailable()

virtual uint04 BluetoothConnection::bytesAvailable ( ) const
overridevirtual

Returns the number of bytes available for reading from the socket.

Returns
The number of bytes available in the receive buffer.

Implements ConnectionBackend.

◆ handleBluetoothError()

void BluetoothConnection::handleBluetoothError ( int error)

Handles a Bluetooth error by updating the internal error state.

Parameters
[in]errorThe Bluetooth error code to handle.

◆ isOpen()

virtual bool BluetoothConnection::isOpen ( ) const
overridevirtual

Checks whether the Bluetooth socket is currently open and connected.

Returns
True if the connection is open.

Implements ConnectionBackend.

◆ lastError()

virtual TranslatedString BluetoothConnection::lastError ( ) const
overridevirtual

Returns the last error message from this connection.

Returns
A translated string describing the most recent error.

Implements ConnectionBackend.

◆ open()

virtual bool BluetoothConnection::open ( const ConnectionInfo & request)
overridevirtual

Opens a Bluetooth connection using the provided connection info.

Parameters
[in]requestThe connection parameters specifying the target device.
Returns
True if the connection was successfully opened.

Implements ConnectionBackend.

◆ openInMainThread()

virtual bool BluetoothConnection::openInMainThread ( const ConnectionInfo & request)
virtual

Opens a Bluetooth connection on the main thread, required for some Qt Bluetooth operations.

Parameters
[in]requestThe connection parameters specifying the target device.
Returns
True if the connection was successfully opened.

◆ peek()

virtual uint04 BluetoothConnection::peek ( char * s,
uint04 size = Constantuint04 >::Max ) const
overridevirtual

Peeks at incoming data without consuming it from the receive buffer.

Parameters
[in]sThe buffer to copy peeked data into.
[in]sizeThe maximum number of bytes to peek.
Returns
The number of bytes actually peeked.

Implements ConnectionBackend.

◆ rx()

virtual uint04 BluetoothConnection::rx ( char * s,
uint04 size = Constantuint04 >::Max )
overridevirtual

Receives data from the Bluetooth socket into the provided buffer.

Parameters
[in]sThe buffer to copy received data into.
[in]sizeThe maximum number of bytes to receive.
Returns
The number of bytes actually received.

Implements ConnectionBackend.

◆ setBluetoothPort()

virtual bool BluetoothConnection::setBluetoothPort ( QBluetoothSocket * bluetooth_port,
const ConnectionInfo & info )
virtual

Assigns an existing QBluetoothSocket to this connection.

Parameters
[in]bluetooth_portThe QBluetoothSocket to use for communication.
[in]infoThe connection info associated with this socket.
Returns
True if the port was successfully assigned.

◆ tx()

virtual void BluetoothConnection::tx ( const StringView & command)
overridevirtual

Transmits the given command string over the Bluetooth socket.

Parameters
[in]commandThe string data to send.

Implements ConnectionBackend.

◆ waitForReadyRead()

virtual bool BluetoothConnection::waitForReadyRead ( const TimeSpan & span)
overridevirtual

Blocks until data is ready to read or the timeout expires.

Parameters
[in]spanThe maximum time to wait for incoming data.
Returns
True if data became available before the timeout.

Implements ConnectionBackend.


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