2021-10-13 22:08:35 +02:00
|
|
|
#include "components/ble/ServiceDiscovery.h"
|
2020-11-15 15:05:51 +01:00
|
|
|
#include <libraries/log/nrf_log.h>
|
2021-10-13 22:08:35 +02:00
|
|
|
#include "components/ble/BleClient.h"
|
2020-11-15 15:05:51 +01:00
|
|
|
|
2020-10-29 16:06:01 +01:00
|
|
|
using namespace Pinetime::Controllers;
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
ServiceDiscovery::ServiceDiscovery(std::array<BleClient*, 2>&& clients) : clients {clients} {
|
2020-10-29 16:06:01 +01: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 19:28:14 +02:00
|
|
|
if (clientIterator != clients.end()) {
|
2020-10-29 16:06:01 +01: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 19:28:14 +02:00
|
|
|
auto discoverNextService = [this](uint16_t connectionHandle) {
|
2020-10-29 16:06:01 +01:00
|
|
|
this->OnServiceDiscovered(connectionHandle);
|
|
|
|
};
|
|
|
|
(*clientIterator)->Discover(connectionHandle, discoverNextService);
|
|
|
|
}
|