ESP32  1.0.4
BLEServer クラス

The model of a BLE server. [詳解]

#include <BLEServer.h>

公開メンバ関数

uint32_t getConnectedCount ()
 Return the number of connected clients. [詳解]
 
BLEServicecreateService (const char *uuid)
 Create a BLE Service. [詳解]
 
BLEServicecreateService (BLEUUID uuid, uint32_t numHandles=15, uint8_t inst_id=0)
 Create a BLE Service. [詳解]
 
BLEAdvertisinggetAdvertising ()
 Retrieve the advertising object that can be used to advertise the existence of the server. [詳解]
 
void setCallbacks (BLEServerCallbacks *pCallbacks)
 Set the server callbacks. [詳解]
 
void startAdvertising ()
 Start advertising. [詳解]
 
void removeService (BLEService *service)
 
BLEServicegetServiceByUUID (const char *uuid)
 Get a BLE Service by its UUID [詳解]
 
BLEServicegetServiceByUUID (BLEUUID uuid)
 Get a BLE Service by its UUID [詳解]
 
bool connect (BLEAddress address)
 
void disconnect (uint16_t connId)
 
void updateConnParams (esp_bd_addr_t remote_bda, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout)
 
std::map< uint16_t, conn_status_tgetPeerDevices (bool client)
 
void addPeerDevice (void *peer, bool is_client, uint16_t conn_id)
 
void removePeerDevice (uint16_t conn_id, bool client)
 
BLEServergetServerByConnId (uint16_t conn_id)
 
void updatePeerMTU (uint16_t connId, uint16_t mtu)
 
uint16_t getPeerMTU (uint16_t conn_id)
 
uint16_t getConnId ()
 

公開変数類

uint16_t m_appId
 

フレンド

class BLEService
 
class BLECharacteristic
 
class BLEDevice
 

詳解

The model of a BLE server.

BLEServer.h63 行目に定義があります。

関数詳解

◆ addPeerDevice()

void BLEServer::addPeerDevice ( void *  peer,
bool  is_client,
uint16_t  conn_id 
)

BLEServer.cpp388 行目に定義があります。

388  {
390  .peer_device = peer,
391  .connected = true,
392  .mtu = 23
393  };
394 
395  m_connectedServersMap.insert(std::pair<uint16_t, conn_status_t>(conn_id, status));
396 }
def status(msg)

◆ connect()

bool BLEServer::connect ( BLEAddress  address)

Allow to connect GATT server to peer device Probably can be used in ANCS for iPhone

BLEServer.cpp327 行目に定義があります。

327  {
329  memcpy(&addr, address.getNative(), 6);
330  // Perform the open connection request against the target BLE Server.
331  m_semaphoreOpenEvt.take("connect");
333  getGattsIf(),
334  addr, // address
335  1 // direct connection
336  );
337  if (errRc != ESP_OK) {
338  log_e("esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
339  return false;
340  }
341 
342  uint32_t rc = m_semaphoreOpenEvt.wait("connect"); // Wait for the connection to complete.
343  log_v("<< connect(), rc=%d", rc==ESP_GATT_OK);
344  return rc == ESP_GATT_OK;
345 } // connect
#define ESP_OK
Definition: esp_err.h:27
__uint32_t uint32_t
Definition: stdint.h:45
static const char * errorToString(esp_err_t errCode)
Convert an ESP error code to a string.
uint32_t wait(std::string owner="<Unknown>")
Wait for a semaphore to be released by trying to take it and then releasing it again.
Definition: FreeRTOS.cpp:62
#define log_e(format,...)
esp_bd_addr_t * getNative()
Return the native representation of the address.
Definition: BLEAddress.cpp:70
uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN]
Bluetooth device address
Definition: esp_bt_defs.h:105
int32_t esp_err_t
Definition: esp_err.h:24
endr Lperloop blti Lstart_memw memw movi Lperloop *linesize bltu Lstart_cachex endif endm macro cache_hit_region addr
Definition: cacheasm.h:208
#define log_v(format,...)
Definition: esp32-hal-log.h:84
bool take(std::string owner="<Unknown>")
Take a semaphore. Take a semaphore and wait indefinitely.
Definition: FreeRTOS.cpp:188
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda, bool is_direct)
Open a direct open connection or add a background auto connection

◆ createService() [1/2]

BLEService * BLEServer::createService ( const char *  uuid)

Create a BLE Service.

With a BLE server, we can host one or more services. Invoking this function causes the creation of a definition of a new service. Every service must have a unique UUID.

引数
[in]uuidThe UUID of the new service.
戻り値
A reference to the new service object.

BLEServer.cpp51 行目に定義があります。

51  {
52  return createService(BLEUUID(uuid));
53 }
A model of a BLE UUID.
Definition: BLEUUID.h:18
BLEService * createService(const char *uuid)
Create a BLE Service.
Definition: BLEServer.cpp:51

◆ createService() [2/2]

BLEService * BLEServer::createService ( BLEUUID  uuid,
uint32_t  numHandles = 15,
uint8_t  inst_id = 0 
)

Create a BLE Service.

With a BLE server, we can host one or more services. Invoking this function causes the creation of a definition of a new service. Every service must have a unique UUID.

引数
[in]uuidThe UUID of the new service.
[in]numHandlesThe maximum number of handles associated with this service.
[in]inst_idWith multiple services with the same UUID we need to provide inst_id value different for each service.
戻り値
A reference to the new service object.

BLEServer.cpp66 行目に定義があります。

66  {
67  log_v(">> createService - %s", uuid.toString().c_str());
68  m_semaphoreCreateEvt.take("createService");
69 
70  // Check that a service with the supplied UUID does not already exist.
71  if (m_serviceMap.getByUUID(uuid) != nullptr) {
72  log_w("<< Attempt to create a new service with uuid %s but a service with that UUID already exists.",
73  uuid.toString().c_str());
74  }
75 
76  BLEService* pService = new BLEService(uuid, numHandles);
77  pService->m_instId = inst_id;
78  m_serviceMap.setByUUID(uuid, pService); // Save a reference to this service being on this server.
79  pService->executeCreate(this); // Perform the API calls to actually create the service.
80 
81  m_semaphoreCreateEvt.wait("createService");
82 
83  log_v("<< createService");
84  return pService;
85 } // createService
BLEService * getByUUID(const char *uuid)
Return the service by UUID.
void setByUUID(const char *uuid, BLEService *service)
#define log_w(format,...)
The model of a BLE service.
Definition: BLEService.h:49
uint32_t wait(std::string owner="<Unknown>")
Wait for a semaphore to be released by trying to take it and then releasing it again.
Definition: FreeRTOS.cpp:62
void executeCreate(BLEServer *pServer)
Create the service. Create the service.
Definition: BLEService.cpp:59
friend class BLEService
Definition: BLEServer.h:91
std::string toString()
Get a string representation of the UUID.
Definition: BLEUUID.cpp:350
#define log_v(format,...)
Definition: esp32-hal-log.h:84
uint8_t m_instId
Definition: BLEService.h:65
bool take(std::string owner="<Unknown>")
Take a semaphore. Take a semaphore and wait indefinitely.
Definition: FreeRTOS.cpp:188

◆ disconnect()

void BLEServer::disconnect ( uint16_t  connId)

BLEServer.cpp416 行目に定義があります。

416  {
417  esp_ble_gatts_close(m_gatts_if, connId);
418 }
esp_err_t esp_ble_gatts_close(esp_gatt_if_t gatts_if, uint16_t conn_id)
Close a connection a remote device.

◆ getAdvertising()

BLEAdvertising * BLEServer::getAdvertising ( )

Retrieve the advertising object that can be used to advertise the existence of the server.

戻り値
An advertising object.

BLEServer.cpp111 行目に定義があります。

111  {
112  return BLEDevice::getAdvertising();
113 }
static BLEAdvertising * getAdvertising()
Definition: BLEDevice.cpp:551

◆ getConnectedCount()

uint32_t BLEServer::getConnectedCount ( )

Return the number of connected clients.

戻り値
The number of connected clients.

BLEServer.cpp124 行目に定義があります。

124  {
125  return m_connectedCount;
126 } // getConnectedCount

◆ getConnId()

uint16_t BLEServer::getConnId ( )

BLEServer.cpp115 行目に定義があります。

115  {
116  return m_connId;
117 }

◆ getPeerDevices()

std::map< uint16_t, conn_status_t > BLEServer::getPeerDevices ( bool  client)

BLEServer.cpp379 行目に定義があります。

379  {
380  return m_connectedServersMap;
381 }

◆ getPeerMTU()

uint16_t BLEServer::getPeerMTU ( uint16_t  conn_id)

BLEServer.cpp384 行目に定義があります。

384  {
385  return m_connectedServersMap.find(conn_id)->second.mtu;
386 }

◆ getServerByConnId()

BLEServer* BLEServer::getServerByConnId ( uint16_t  conn_id)

◆ getServiceByUUID() [1/2]

BLEService * BLEServer::getServiceByUUID ( const char *  uuid)

Get a BLE Service by its UUID

引数
[in]uuidThe UUID of the new service.
戻り値
A reference to the service object.

BLEServer.cpp93 行目に定義があります。

93  {
94  return m_serviceMap.getByUUID(uuid);
95 }
BLEService * getByUUID(const char *uuid)
Return the service by UUID.

◆ getServiceByUUID() [2/2]

BLEService * BLEServer::getServiceByUUID ( BLEUUID  uuid)

Get a BLE Service by its UUID

引数
[in]uuidThe UUID of the new service.
戻り値
A reference to the service object.

BLEServer.cpp102 行目に定義があります。

102  {
103  return m_serviceMap.getByUUID(uuid);
104 }
BLEService * getByUUID(const char *uuid)
Return the service by UUID.

◆ removePeerDevice()

void BLEServer::removePeerDevice ( uint16_t  conn_id,
bool  client 
)

BLEServer.cpp398 行目に定義があります。

398  {
399  m_connectedServersMap.erase(conn_id);
400 }

◆ removeService()

void BLEServer::removeService ( BLEService service)

BLEServer.cpp305 行目に定義があります。

305  {
306  service->stop();
307  service->executeDelete();
308  m_serviceMap.removeService(service);
309 }
void removeService(BLEService *service)
Removes service from maps.
void stop()
Stop the service.
Definition: BLEService.cpp:166
void executeDelete()
Delete the service. Delete the service.
Definition: BLEService.cpp:86

◆ setCallbacks()

void BLEServer::setCallbacks ( BLEServerCallbacks pCallbacks)

Set the server callbacks.

As a BLE server operates, it will generate server level events such as a new client connecting or a previous client disconnecting. This function can be called to register a callback handler that will be invoked when these events are detected.

引数
[in]pCallbacksThe callbacks to be invoked.

BLEServer.cpp298 行目に定義があります。

298  {
299  m_pServerCallbacks = pCallbacks;
300 } // setCallbacks

◆ startAdvertising()

void BLEServer::startAdvertising ( )

Start advertising.

Start the server advertising its existence. This is a convenience function and is equivalent to retrieving the advertising object and invoking start upon it.

BLEServer.cpp317 行目に定義があります。

317  {
318  log_v(">> startAdvertising");
320  log_v("<< startAdvertising");
321 } // startAdvertising
static void startAdvertising()
Definition: BLEDevice.cpp:560
#define log_v(format,...)
Definition: esp32-hal-log.h:84

◆ updateConnParams()

void BLEServer::updateConnParams ( esp_bd_addr_t  remote_bda,
uint16_t  minInterval,
uint16_t  maxInterval,
uint16_t  latency,
uint16_t  timeout 
)

Update connection parameters can be called only after connection has been established

BLEServer.cpp406 行目に定義があります。

406  {
407  esp_ble_conn_update_params_t conn_params;
408  memcpy(conn_params.bda, remote_bda, sizeof(esp_bd_addr_t));
409  conn_params.latency = latency;
410  conn_params.max_int = maxInterval; // max_int = 0x20*1.25ms = 40ms
411  conn_params.min_int = minInterval; // min_int = 0x10*1.25ms = 20ms
412  conn_params.timeout = timeout; // timeout = 400*10ms = 4000ms
413  esp_ble_gap_update_conn_params(&conn_params);
414 }
esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params)
Update connection parameters, can only be used when connection is up.
Connection update parameters
uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN]
Bluetooth device address
Definition: esp_bt_defs.h:105

◆ updatePeerMTU()

void BLEServer::updatePeerMTU ( uint16_t  connId,
uint16_t  mtu 
)

BLEServer.cpp370 行目に定義があります。

370  {
371  // set mtu in conn_status_t
372  const std::map<uint16_t, conn_status_t>::iterator it = m_connectedServersMap.find(conn_id);
373  if (it != m_connectedServersMap.end()) {
374  it->second.mtu = mtu;
375  std::swap(m_connectedServersMap[conn_id], it->second);
376  }
377 }
u16_t mtu
Definition: netif.h:319

フレンドと関連関数の詳解

◆ BLECharacteristic

friend class BLECharacteristic
friend

BLEServer.h92 行目に定義があります。

◆ BLEDevice

friend class BLEDevice
friend

BLEServer.h93 行目に定義があります。

◆ BLEService

friend class BLEService
friend

BLEServer.h91 行目に定義があります。

メンバ詳解

◆ m_appId

uint16_t BLEServer::m_appId

BLEServer.h76 行目に定義があります。


このクラス詳解は次のファイルから抽出されました: