diff options
author | JF <jf@codingfield.com> | 2020-10-29 16:06:01 +0100 |
---|---|---|
committer | JF <jf@codingfield.com> | 2020-10-29 16:06:01 +0100 |
commit | 29f8074fcb844cf9668a5bf071e9cffa47299c99 (patch) | |
tree | 9b410aee92af82099619c56a4d25c9c6b7c99e68 /src/components/ble/ServiceDiscovery.cpp | |
parent | f90f2254f55086589d1d378d35a54085e2620cb6 (diff) |
Refactoring of BLE service discovery : it is now implemented into the classes of the services.
Diffstat (limited to 'src/components/ble/ServiceDiscovery.cpp')
-rw-r--r-- | src/components/ble/ServiceDiscovery.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/components/ble/ServiceDiscovery.cpp b/src/components/ble/ServiceDiscovery.cpp new file mode 100644 index 00000000..4b29d89c --- /dev/null +++ b/src/components/ble/ServiceDiscovery.cpp @@ -0,0 +1,31 @@ +#include <libraries/log/nrf_log.h> +#include "ServiceDiscovery.h" +using namespace Pinetime::Controllers; + +ServiceDiscovery::ServiceDiscovery(std::array<BleClient*, 2>&& clients) : clients{clients} { + +} + +void ServiceDiscovery::StartDiscovery(uint16_t connectionHandle) { + NRF_LOG_INFO("[Discovery] Starting discovery"); + clientIterator = clients.begin(); + DiscoverNextService(connectionHandle); +} + +void ServiceDiscovery::OnServiceDiscovered(uint16_t connectionHandle) { + clientIterator++; + if(clientIterator != clients.end()) { + DiscoverNextService(connectionHandle); + } else { + NRF_LOG_INFO("End of service discovery"); + } +} + +void ServiceDiscovery::DiscoverNextService(uint16_t connectionHandle) { + NRF_LOG_INFO("[Discovery] Discover next service"); + + auto discoverNextService = [this](uint16_t connectionHandle){ + this->OnServiceDiscovered(connectionHandle); + }; + (*clientIterator)->Discover(connectionHandle, discoverNextService); +}
\ No newline at end of file |