SDK  23.9.2
For IoT System Software Development
Public Member Functions | Public Attributes | List of all members
BLEClient Class Reference

A model of a BLE client. More...

#include <BLEClient.hpp>

Public Member Functions

bool connect (BLEAdvertisedDevice *device)
 
bool connect (BLEAddress address, BLEAddress::Type_t type=BLEAddress::TYPE_PUBLIC)
 
void disconnect ()
 
BLEAddress getPeerAddress ()
 Retrieve the address of the peer. More...
 
int getRssi ()
 
std::map< std::string, BLERemoteService * > * getServices ()
 
BLERemoteServicegetService (const char *uuid)
 Get the service BLE Remote Service instance corresponding to the uuid. More...
 
BLERemoteServicegetService (BLEUUID uuid)
 Get the service object corresponding to the uuid. More...
 
std::string getValue (BLEUUID serviceUUID, BLEUUID characteristicUUID)
 
void handleGAPEvent (void *info)
 
bool isConnected ()
 Are we connected to a partner? More...
 
void setClientCallbacks (BLEClientCallbacks *pClientCallbacks, bool deleteCallbacks=true)
 Set the callbacks that will be invoked.
 
void setValue (BLEUUID serviceUUID, BLEUUID characteristicUUID, std::string value)
 Set the value of a specific characteristic associated with a specific service. More...
 
std::string toString ()
 
uint16_t getConnId ()
 
void * getGattcIf ()
 
uint16_t getMTU ()
 

Public Attributes

uint16_t m_appId
 

Detailed Description

A model of a BLE client.

Member Function Documentation

◆ connect()

bool BLEClient::connect ( BLEAdvertisedDevice device)

Add overloaded function to ease connect to peer device with not public address

75  {
76  BLEAddress address = device->getAddress();
77  BLEAddress::Type_t type = device->getAddressType();
78  return connect(address, type);
79 }

◆ getPeerAddress()

BLEAddress BLEClient::getPeerAddress ( )

Retrieve the address of the peer.

Returns the Bluetooth device address of the BLE peer to which this client is connected.

87  {
88  return m_peerAddress;
89 } // getAddress

◆ getService() [1/2]

BLERemoteService * BLEClient::getService ( BLEUUID  uuid)

Get the service object corresponding to the uuid.

Parameters
[in]uuidThe UUID of the service being sought.
Returns
A reference to the Service or nullptr if don't know about it.
Exceptions
BLEUuidNotFound
109  {
110  _debug_print_s(TAG, ">> getService: uuid", uuid.toString().c_str());
111 // Design
112 // ------
113 // We wish to retrieve the service given its UUID. It is possible that we have not yet asked the
114 // device what services it has in which case we have nothing to match against. If we have not
115 // asked the device about its services, then we do that now. Once we get the results we can then
116 // examine the services map to see if it has the service we are looking for.
117  if (!m_haveServices) {
118  getServices();
119  }
120  std::string uuidStr = uuid.toString();
121  for (auto &myPair : m_servicesMap) {
122  if (myPair.first == uuidStr) {
123  _debug_print_s(TAG, "<< getService: found the service with uuid", uuid.toString().c_str());
124  return myPair.second;
125  }
126  } // End of each of the services.
127  _debug_print(TAG, "<< getService: not found");
128  return nullptr;
129 } // getService

◆ getService() [2/2]

BLERemoteService * BLEClient::getService ( const char *  uuid)

Get the service BLE Remote Service instance corresponding to the uuid.

Parameters
[in]uuidThe UUID of the service being sought.
Returns
A reference to the Service or nullptr if don't know about it.
98  {
99  return getService(BLEUUID(uuid));
100 } // getService

◆ isConnected()

bool BLEClient::isConnected ( )

Are we connected to a partner?

Returns
True if we are connected and false if we are not connected.
147  {
148  return m_isConnected;
149 } // isConnected

◆ setValue()

void BLEClient::setValue ( BLEUUID  serviceUUID,
BLEUUID  characteristicUUID,
std::string  value 
)

Set the value of a specific characteristic associated with a specific service.

Parameters
[in]serviceUUIDThe service that owns the characteristic.
[in]characteristicUUIDThe characteristic whose value we wish to write.
Exceptions
BLEUuidNotFound
169  {
170  void *logCtx __attribute__((unused)) = nullptr;
171  _debug_print_s(TAG, ">> setValue: serviceUUID", serviceUUID.toString().c_str());
172  _debug_print_s(TAG, ", characteristicUUID", characteristicUUID.toString().c_str());
173  getService(serviceUUID)->getCharacteristic(characteristicUUID)->writeValue(value);
174  _debug_print(TAG, "<< setValue");
175 } // setValue

The documentation for this class was generated from the following files:
BLEUUID::toString
std::string toString()
Get a string representation of the UUID.
Definition: BLEUUID.cpp:317
BLEUUID
A model of a BLE UUID.
Definition: BLEUUID.hpp:41
BLEAdvertisedDevice::getAddress
BLEAddress getAddress()
Get the address.
Definition: BLEAdvertisedDevice.cpp:66
BLEClient::getService
BLERemoteService * getService(const char *uuid)
Get the service BLE Remote Service instance corresponding to the uuid.
Definition: BLEClient.cpp:98
BLEAddress
A BLE device address.
Definition: BLEAddress.hpp:43
BLERemoteService::getCharacteristic
BLERemoteCharacteristic * getCharacteristic(const char *uuid)
Get the remote characteristic object for the characteristic UUID.
Definition: BLERemoteService.cpp:54
BLEClient::connect
bool connect(BLEAdvertisedDevice *device)
Definition: BLEClient.cpp:75