MyoLinux
Public Member Functions | List of all members
Client Class Reference

Class for communication using the GATT protocol. More...

#include <gattclient.h>

Public Member Functions

 Client (const bled112::Client &)
 Creates from an instance of lower level protocol client. More...
 
void discover (std::function< bool(std::int8_t, Address, Buffer)>)
 Discover the devices supporting the GATT protocol. More...
 
Characteristics characteristics ()
 Discover the characteristics of the device. More...
 
void connect (const Address &)
 Connect to the device with the specified address. More...
 
void connect (const std::string &)
 Connect to the device with the specified address in string form. More...
 
bool connected ()
 Checks whether the client is connected. More...
 
Address address ()
 Returns the address of the connected device. More...
 
void disconnect ()
 Disconnect the client.
 
void disconnectAll ()
 Disconnect all devices connected to the dongle. More...
 
void writeAttribute (const std::uint16_t, const Buffer &)
 Write GATT attribute. More...
 
Buffer readAttribute (const std::uint16_t)
 Read GATT attribute. More...
 
void listen (const std::function< void(std::uint16_t, Buffer)> &)
 Listen to GATT notifications. More...
 

Detailed Description

Class for communication using the GATT protocol.

Constructor & Destructor Documentation

§ Client()

Client ( const bled112::Client client)

Creates from an instance of lower level protocol client.

Parameters
clientinstance of the bled112::Client

Member Function Documentation

§ address()

auto address ( )

Returns the address of the connected device.

If the client is not connected an exception is thrown.

Returns
the address of the device

§ characteristics()

auto characteristics ( )

Discover the characteristics of the device.

Returns
a dictionary of characteristics
See also
Characteristics

§ connect() [1/2]

void connect ( const Address address)

Connect to the device with the specified address.

Parameters
addressaddress of the device

§ connect() [2/2]

void connect ( const std::string &  str)

Connect to the device with the specified address in string form.

The address is represented as six hexadecimal digis separated with colons. This is also the format used by the bluetoothctl tool.

Example: 01:23:E2:D4:4D:66

Parameters
strstring form of the address

§ connected()

bool connected ( )

Checks whether the client is connected.

Returns
is the client connected

§ disconnectAll()

void disconnectAll ( )

Disconnect all devices connected to the dongle.

The supplied dongle supports only three.

§ discover()

void discover ( std::function< bool(std::int8_t, Address, Buffer)>  callback)

Discover the devices supporting the GATT protocol.

The callback is called for each found device. As long as it returns true the scanning continues, otherwise the function returns.

Parameters
callbackthe callback called for each device, the parameters are: RSSI, the address and the device specific data included in the advertisment.

§ listen()

void listen ( const std::function< void(std::uint16_t, Buffer)> &  callback)

Listen to GATT notifications.

Parameters
callbackcallback to call when an notification arrives
Exceptions
DisconnectedException

§ readAttribute()

Buffer readAttribute ( const std::uint16_t  handle)

Read GATT attribute.

Parameters
handlehandle of the attribute
Returns
the recieved payload

§ writeAttribute()

void writeAttribute ( const std::uint16_t  handle,
const Buffer payload 
)

Write GATT attribute.

Parameters
handlehandle of the attribute
payloadpayload to send

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