Refactoring of BLE service discovery : it is now implemented into the classes of the services.

This commit is contained in:
JF
2020-10-29 16:06:01 +01:00
parent f90f2254f5
commit 29f8074fcb
10 changed files with 254 additions and 227 deletions

View File

@@ -0,0 +1,31 @@
#include <libraries/log/nrf_log.h>
#include "ServiceDiscovery.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);
}