esp-nimble-cpp 2.3.0
Loading...
Searching...
No Matches
NimBLEL2CAPChannel Class Reference

Encapsulates a L2CAP channel. More...

#include <NimBLEL2CAPChannel.h>

Public Member Functions

bool write (const std::vector< uint8_t > &bytes)
 Write data to the channel.
 
bool isConnected () const
 

Static Public Member Functions

static NimBLEL2CAPChannelconnect (NimBLEClient *client, uint16_t psm, uint16_t mtu, NimBLEL2CAPChannelCallbacks *callbacks)
 Open an L2CAP channel via the specified PSM and MTU.
 

Detailed Description

Encapsulates a L2CAP channel.

This class is used to encapsulate a L2CAP connection oriented channel, both from the "server" (which waits for the connection to be opened) and the "client" (which opens the connection) point of view.

Member Function Documentation

◆ connect()

NimBLEL2CAPChannel * NimBLEL2CAPChannel::connect ( NimBLEClient client,
uint16_t  psm,
uint16_t  mtu,
NimBLEL2CAPChannelCallbacks callbacks 
)
static

Open an L2CAP channel via the specified PSM and MTU.

Parameters
[in]psmThe PSM to use.
[in]mtuThe MTU to use. Note that this is the local MTU. Upon opening the channel, the final MTU will be negotiated to be the minimum of local and remote.
[in]callbacksThe callbacks to use. NOTE that these callbacks are called from the context of the NimBLE bluetooth task (nimble_host) and MUST be handled as fast as possible.
Returns
True if the channel was opened successfully, false otherwise.

◆ isConnected()

bool NimBLEL2CAPChannel::isConnected ( ) const
inline
Returns
True, if the channel is connected. False, otherwise.

◆ write()

bool NimBLEL2CAPChannel::write ( const std::vector< uint8_t > &  bytes)

Write data to the channel.

If the size of the data exceeds the MTU, the data will be split into multiple fragments.

Returns
true on success, after the data has been sent.
false, if the data can't be sent.

NOTE: This function will block until the data has been sent or an error occurred.