-
-
Notifications
You must be signed in to change notification settings - Fork 984
/
Copy pathServiceDiscovery.cpp
32 lines (26 loc) · 1009 Bytes
/
ServiceDiscovery.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "components/ble/ServiceDiscovery.h"
#include <libraries/log/nrf_log.h>
#include "components/ble/BleClient.h"
using namespace Pinetime::Controllers;
ServiceDiscovery::ServiceDiscovery(std::array<BleClient*, 3>&& 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);
}