From 29f8074fcb844cf9668a5bf071e9cffa47299c99 Mon Sep 17 00:00:00 2001 From: JF Date: Thu, 29 Oct 2020 16:06:01 +0100 Subject: Refactoring of BLE service discovery : it is now implemented into the classes of the services. --- src/components/ble/ServiceDiscovery.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/components/ble/ServiceDiscovery.cpp (limited to 'src/components/ble/ServiceDiscovery.cpp') 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 +#include "ServiceDiscovery.h" +using namespace Pinetime::Controllers; + +ServiceDiscovery::ServiceDiscovery(std::array&& 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 -- cgit v1.2.3