Pigweed
 
Loading...
Searching...
No Matches
pw::bluetooth::low_energy::Central2 Class Referenceabstract

Represents the LE central role. Used to scan and connect to peripherals. More...

#include <central2.h>

Inheritance diagram for pw::bluetooth::low_energy::Central2:
pw::bluetooth_sapphire::Central

Classes

struct  ScanFilter
 
class  ScanHandle
 Represents an ongoing LE scan. More...
 
struct  ScanOptions
 Parameters used during a scan. More...
 
struct  ScanResult
 

Public Types

enum class  ScanType : uint8_t { kPassive , kActiveUsePublicAddress , kActiveUseRandomAddress , kActiveUseResolvablePrivateAddress }
 
enum class  ConnectError : uint8_t { kUnknownPeer , kInvalidOptions , kAlreadyExists , kCouldNotBeEstablished }
 Possible errors returned by Connect. More...
 
enum class  StartScanError : uint8_t { kScanInProgress , kInvalidParameters , kInternal }
 
using ConnectResult = pw::expected< Connection2::Ptr, ConnectError >
 The result type returned by Connect().
 
using ScanStartResult = pw::expected< ScanHandle::Ptr, StartScanError >
 The result type returned by Scan().
 

Public Member Functions

virtual async2::OnceReceiver< ConnectResultConnect (PeerId peer_id, Connection2::ConnectionOptions options)=0
 
virtual async2::OnceReceiver< ScanStartResultScan (const ScanOptions &options)=0
 

Detailed Description

Represents the LE central role. Used to scan and connect to peripherals.

Member Enumeration Documentation

◆ ConnectError

Possible errors returned by Connect.

Enumerator
kUnknownPeer 

The peer ID is unknown.

kInvalidOptions 

The ConnectionOptions were invalid.

kAlreadyExists 

A connection to the peer already exists.

kCouldNotBeEstablished 

The connection procedure failed at the link layer or timed out immediately after being established. A "could not be established" error was reported by the controller. This may be due to interference.

◆ ScanType

enum class pw::bluetooth::low_energy::Central2::ScanType : uint8_t
strong
Enumerator
kActiveUsePublicAddress 

Send scanning PDUs with the public address.

kActiveUseRandomAddress 

Send scanning PDUs with the random address.

kActiveUseResolvablePrivateAddress 

Send scanning PDUs with a generated Resolvable Private Address.

◆ StartScanError

Enumerator
kScanInProgress 

A scan is already in progress. Only 1 scan may be active at a time.

kInvalidParameters 

Some of the scan options are invalid.

kInternal 

An internal error occurred and a scan could not be started.

Member Function Documentation

◆ Connect()

virtual async2::OnceReceiver< ConnectResult > pw::bluetooth::low_energy::Central2::Connect ( PeerId  peer_id,
Connection2::ConnectionOptions  options 
)
pure virtual

Connect to the peer with the given identifier.

The returned Connection2 represents the client's interest in the LE connection to the peer. Destroying all Connection2 instances for a peer will disconnect from the peer.

The Connection will be closed by the system if the connection to the peer is lost or an error occurs, as indicated by Connection.OnError.

Parameters
peer_idIdentifier of the peer to initiate a connection to.
optionsOptions used to configure the connection.
Returns
Returns a result when a connection is successfully established, or an error occurs.

Possible errors are documented in ConnectError.

◆ Scan()

virtual async2::OnceReceiver< ScanStartResult > pw::bluetooth::low_energy::Central2::Scan ( const ScanOptions options)
pure virtual

Scans for nearby LE peripherals and broadcasters. The lifetime of the scan session is tied to the returned ScanHandle object in ScanStartResult. Once a scan is started, ScanHandle::PendResult can be called to get scan results. Only 1 scan may be active at a time.

Parameters
optionsOptions used to configure the scan session. These options are suggestions only, and the implementation may use different parameters to meet power or radio requirements.
Returns
Returns a ScanHandle object if the scan successfully starts, or a ScanError otherwise. ScanHandle::PendResult can be called to get ScanResults for LE peers that satisfy the filters indicated in options. The initial results may report recently discovered peers. Subsequent results will be reported only when peers have been scanned or updated since the last call.

Implemented in pw::bluetooth_sapphire::Central.


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