Skip to content

Commit

Permalink
fixed conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
wakwak-koba committed Jan 17, 2019
1 parent ea3154a commit e63c941
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
33 changes: 20 additions & 13 deletions cpp_utils/BLEClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,22 @@ void BLEClient::gattClientEventHandler(
// - uint16_t conn_id
// - esp_bd_addr_t remote_bda
case ESP_GATTC_DISCONNECT_EVT: {
// If we receive a disconnect event, set the class flag that indicates that we are
// no longer connected.
m_isConnected = false;
if (m_pClientCallbacks != nullptr) {
m_pClientCallbacks->onDisconnect(this);
}
BLEDevice::removePeerDevice(m_appId, true);
esp_ble_gattc_app_unregister(m_gattc_if);
m_semaphoreRssiCmplEvt.give();
m_semaphoreSearchCmplEvt.give(1);
ESP_LOGE(__func__, "disconnect event, conn_id: %d", evtParam->disconnect.conn_id);
if(getConnId() != evtParam->disconnect.conn_id)
break;
m_semaphoreOpenEvt.give(evtParam->disconnect.reason);
if(!m_isConnected)
break;
// If we receive a disconnect event, set the class flag that indicates that we are
// no longer connected.
esp_ble_gattc_close(m_gattc_if, m_conn_id);
m_isConnected = false;
if (m_pClientCallbacks != nullptr) {
m_pClientCallbacks->onDisconnect(this);
}
break;
} // ESP_GATTC_DISCONNECT_EVT

//
// ESP_GATTC_OPEN_EVT
//
Expand Down Expand Up @@ -224,8 +227,12 @@ void BLEClient::gattClientEventHandler(
// uint16_t app_id
//
case ESP_GATTC_REG_EVT: {
m_gattc_if = gattc_if;
m_semaphoreRegEvt.give();
if(m_appId == evtParam->reg.app_id){
ESP_LOGI(__func__, "register app id: %d, %d, gattc_if: %d", m_appId, evtParam->reg.app_id, gattc_if);
m_gattc_if = gattc_if;
m_appId = evtParam->reg.app_id;
m_semaphoreRegEvt.give();
}
break;
} // ESP_GATTC_REG_EVT

Expand Down
18 changes: 3 additions & 15 deletions cpp_utils/BLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,10 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
break;
} // switch
for(auto &myPair : BLEDevice::getPeerDevices(true)) {
BLEClient* client = (BLEClient*)((conn_status_t)myPair.second).peer_device;
bool raiseEvent = false;
switch(event) {
case ESP_GATTC_REG_EVT:
raiseEvent = (myPair.first == param->reg.app_id);
break;
case ESP_GATTC_DISCONNECT_EVT:
raiseEvent = (client->getConnId() == param->disconnect.conn_id && client->getGattcIf() == gattc_if);
break;
default:
raiseEvent = (client->getGattcIf() == gattc_if || client->getGattcIf() == ESP_GATT_IF_NONE || gattc_if == ESP_GATT_IF_NONE);
break;
conn_status_t conn_status = (conn_status_t)myPair.second;
if(((BLEClient*)conn_status.peer_device)->getGattcIf() == gattc_if || ((BLEClient*)conn_status.peer_device)->getGattcIf() == ESP_GATT_IF_NONE || gattc_if == ESP_GATT_IF_NONE){
((BLEClient*)conn_status.peer_device)->gattClientEventHandler(event, gattc_if, param);
}

if(raiseEvent)
client->gattClientEventHandler(event, gattc_if, param);
}

if(m_customGattcHandler != nullptr) {
Expand Down

0 comments on commit e63c941

Please sign in to comment.