diff options
| author | JF <jf@codingfield.com> | 2020-10-28 17:23:09 (GMT) |
|---|---|---|
| committer | JF <jf@codingfield.com> | 2020-10-28 17:23:09 (GMT) |
| commit | f90f2254f55086589d1d378d35a54085e2620cb6 (patch) | |
| tree | d74081d6331b36ebdbe0138a45e2a96eca481968 /src/components/ble/NimbleController.cpp | |
| parent | cb9e8815d8bc6ce71fd8e97f3e3dae402658ce1f (diff) | |
Reset BLE services on disconnect, do not start advertising if a connection is already established.
Diffstat (limited to 'src/components/ble/NimbleController.cpp')
| -rw-r--r-- | src/components/ble/NimbleController.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index 022cc51..577c897 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -108,7 +108,7 @@ void NimbleController::Init() { } void NimbleController::StartAdvertising() { - if(ble_gap_adv_active()) return; + if(bleController.IsConnected() || ble_gap_conn_active() || ble_gap_adv_active()) return; ble_svc_gap_device_name_set(deviceName); @@ -197,6 +197,8 @@ int NimbleController::OnGAPEvent(ble_gap_event *event) { NRF_LOG_INFO("disconnect; reason=%d", event->disconnect.reason); /* Connection terminated; resume advertising. */ + currentTimeClient.Reset(); + alertNotificationClient.Reset(); connectionHandle = BLE_HS_CONN_HANDLE_NONE; bleController.Disconnect(); StartAdvertising(); @@ -289,10 +291,10 @@ int NimbleController::OnDiscoveryEvent(uint16_t i, const ble_gatt_error *error, int NimbleController::OnCTSCharacteristicDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error, const ble_gatt_chr *characteristic) { - if(characteristic == nullptr && error->status == BLE_HS_EDONE) { + if(characteristic == nullptr && error->status == BLE_HS_EDONE && currentTimeClient.IsCharacteristicDiscovered()) { NRF_LOG_INFO("CTS characteristic Discovery complete"); - ble_gattc_read(connectionHandle, currentTimeClient.CurrentTimeHandle(), CurrentTimeReadCallback, this); - return 0; + auto res = ble_gattc_read(connectionHandle, currentTimeClient.CurrentTimeHandle(), CurrentTimeReadCallback, this); + return res; } return currentTimeClient.OnCharacteristicDiscoveryEvent(connectionHandle, error, characteristic); } |
