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