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/CurrentTimeClient.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/CurrentTimeClient.cpp')
| -rw-r--r-- | src/components/ble/CurrentTimeClient.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/components/ble/CurrentTimeClient.cpp b/src/components/ble/CurrentTimeClient.cpp index 7a225f4..24027e5 100644 --- a/src/components/ble/CurrentTimeClient.cpp +++ b/src/components/ble/CurrentTimeClient.cpp @@ -32,16 +32,17 @@ bool CurrentTimeClient::OnDiscoveryEvent(uint16_t connectionHandle, const ble_ga int CurrentTimeClient::OnCharacteristicDiscoveryEvent(uint16_t conn_handle, const ble_gatt_error *error, const ble_gatt_chr *characteristic) { - if(characteristic == nullptr && error->status == BLE_HS_EDONE) { - NRF_LOG_INFO("CTS Characteristic discovery complete"); - return 0; - } - - if(characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*)¤tTimeCharacteristicUuid), &characteristic->uuid.u) == 0) { - NRF_LOG_INFO("CTS Characteristic discovered : 0x%x", characteristic->val_handle); - currentTimeHandle = characteristic->val_handle; - } + if (characteristic == nullptr && error->status == BLE_HS_EDONE) { + NRF_LOG_INFO("CTS Characteristic discovery complete"); return 0; + } + + if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t *) ¤tTimeCharacteristicUuid), &characteristic->uuid.u) == 0) { + NRF_LOG_INFO("CTS Characteristic discovered : 0x%x", characteristic->val_handle); + isCharacteristicDiscovered = true; + currentTimeHandle = characteristic->val_handle; + } + return 0; } int CurrentTimeClient::OnCurrentTimeReadResult(uint16_t conn_handle, const ble_gatt_error *error, const ble_gatt_attr *attribute) { @@ -74,4 +75,13 @@ uint16_t CurrentTimeClient::EndHandle() const { uint16_t CurrentTimeClient::CurrentTimeHandle() const { return currentTimeHandle; -}
\ No newline at end of file +} + +void CurrentTimeClient::Reset() { + isDiscovered = false; + isCharacteristicDiscovered = false; +} + +bool CurrentTimeClient::IsCharacteristicDiscovered() const { + return isCharacteristicDiscovered; +} |
