Skip to content

Commit

Permalink
add onMtuChanged to BLEServerCallbacks (#5222)
Browse files Browse the repository at this point in the history
* add onMtuChanged to BLEServerCallbacks

Add method onMtuChanged to the BLEServerCallbacks so the application can be notified if the MTU size changes.

* Correct missing semicolon and misspelled method.

Correct missing semicolon and misspelled method.
  • Loading branch information
davidlehrian committed Jun 9, 2021
1 parent 39155e7 commit 67de199
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libraries/BLE/src/BLEServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t

case ESP_GATTS_MTU_EVT:
updatePeerMTU(param->mtu.conn_id, param->mtu.mtu);
m_pServerCallbacks->onMtuChanged(this, param);
break;

// ESP_GATTS_CONNECT_EVT
Expand Down Expand Up @@ -371,6 +372,12 @@ void BLEServerCallbacks::onDisconnect(BLEServer* pServer) {
log_d("BLEServerCallbacks", "<< onDisconnect()");
} // onDisconnect

void BLEServerCallbacks::onMtuChanged(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) {
log_d("BLEServerCallbacks", ">> onMtuChanged(): Default");
log_d("BLEServerCallbacks", "Device: %s MTU: %d", BLEDevice::toString().c_str(), param->mtu.mtu);
log_d("BLEServerCallbacks", "<< onMtuChanged()");
} // onMtuChanged

/* multi connect support */
/* TODO do some more tweaks */
void BLEServer::updatePeerMTU(uint16_t conn_id, uint16_t mtu) {
Expand Down
10 changes: 10 additions & 0 deletions libraries/BLE/src/BLEServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ class BLEServerCallbacks {
* @param [in] pServer A reference to the %BLE server that received the existing client disconnection.
*/
virtual void onDisconnect(BLEServer* pServer);

/**
* @brief Handle a new client connection.
*
* When the MTU changes this method is invoked.
*
* @param [in] pServer A reference to the %BLE server that received the client connection.
* @param [in] param A reference to esp_ble_gatts_cb_param_t.
*/
virtual void onMtuChanged(BLEServer* pServer, esp_ble_gatts_cb_param_t* param);
}; // BLEServerCallbacks


Expand Down

0 comments on commit 67de199

Please sign in to comment.