InfiniTime/src/components/ble/ServiceDiscovery.cpp

33 lines
977 B
C++
Raw Normal View History

#include "ServiceDiscovery.h"
2020-11-15 14:05:51 +00:00
#include <libraries/log/nrf_log.h>
#include "BleClient.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);
}