2020-10-29 15:06:01 +00:00
|
|
|
#include "ServiceDiscovery.h"
|
2020-11-15 14:05:51 +00:00
|
|
|
#include <libraries/log/nrf_log.h>
|
|
|
|
#include "BleClient.h"
|
|
|
|
|
2020-10-29 15:06:01 +00:00
|
|
|
using namespace Pinetime::Controllers;
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
ServiceDiscovery::ServiceDiscovery(std::array<BleClient*, 2>&& clients) : clients {clients} {
|
2020-10-29 15:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ServiceDiscovery::StartDiscovery(uint16_t connectionHandle) {
|
|
|
|
NRF_LOG_INFO("[Discovery] Starting discovery");
|
|
|
|
clientIterator = clients.begin();
|
|
|
|
DiscoverNextService(connectionHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServiceDiscovery::OnServiceDiscovered(uint16_t connectionHandle) {
|
|
|
|
clientIterator++;
|
2021-04-18 17:28:14 +00:00
|
|
|
if (clientIterator != clients.end()) {
|
2020-10-29 15:06:01 +00:00
|
|
|
DiscoverNextService(connectionHandle);
|
|
|
|
} else {
|
|
|
|
NRF_LOG_INFO("End of service discovery");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServiceDiscovery::DiscoverNextService(uint16_t connectionHandle) {
|
|
|
|
NRF_LOG_INFO("[Discovery] Discover next service");
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
auto discoverNextService = [this](uint16_t connectionHandle) {
|
2020-10-29 15:06:01 +00:00
|
|
|
this->OnServiceDiscovered(connectionHandle);
|
|
|
|
};
|
|
|
|
(*clientIterator)->Discover(connectionHandle, discoverNextService);
|
|
|
|
}
|