add class NordicServiceDiscovery
parent
50a110cd42
commit
11d76136a8
|
@ -5,12 +5,6 @@
|
|||
#include "btle_discovery.h"
|
||||
#include "ble_err.h"
|
||||
|
||||
ServiceDiscovery *ServiceDiscovery::getSingleton(void) {
|
||||
static ServiceDiscovery discoverySingleton;
|
||||
|
||||
return &discoverySingleton;
|
||||
}
|
||||
|
||||
ble_error_t
|
||||
ServiceDiscovery::launch(Gap::Handle_t connectionHandle, ServiceCallback_t sc, CharacteristicCallback_t cc)
|
||||
{
|
||||
|
@ -62,7 +56,7 @@ ble_error_t ServiceDiscovery::launchCharacteristicDiscovery(Gap::Handle_t connec
|
|||
}
|
||||
|
||||
void
|
||||
ServiceDiscovery::setupDiscoveredServices(const ble_gattc_evt_prim_srvc_disc_rsp_t *response)
|
||||
NordicServiceDiscovery::setupDiscoveredServices(const ble_gattc_evt_prim_srvc_disc_rsp_t *response)
|
||||
{
|
||||
currSrvInd = 0;
|
||||
srvCount = response->count;
|
||||
|
@ -80,7 +74,7 @@ ServiceDiscovery::setupDiscoveredServices(const ble_gattc_evt_prim_srvc_disc_rsp
|
|||
}
|
||||
|
||||
void
|
||||
ServiceDiscovery::setupDiscoveredCharacteristics(const ble_gattc_evt_char_disc_rsp_t *response)
|
||||
NordicServiceDiscovery::setupDiscoveredCharacteristics(const ble_gattc_evt_char_disc_rsp_t *response)
|
||||
{
|
||||
currCharInd = 0;
|
||||
charCount = response->count;
|
||||
|
|
|
@ -137,9 +137,6 @@ public:
|
|||
memset(characteristics, 0, sizeof(DiscoveredCharacteristic) * BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV);
|
||||
}
|
||||
|
||||
void setupDiscoveredServices(const ble_gattc_evt_prim_srvc_disc_rsp_t *response);
|
||||
void setupDiscoveredCharacteristics(const ble_gattc_evt_char_disc_rsp_t *response);
|
||||
|
||||
void progressCharacteristicDiscovery() {
|
||||
while (characteristicDiscoveryInProgress && (currCharInd < charCount)) {
|
||||
/* THIS IS WHERE THE CALLBACK WILL GO */
|
||||
|
@ -199,7 +196,7 @@ private:
|
|||
serviceDiscoveryInProgress = false;
|
||||
}
|
||||
|
||||
private:
|
||||
protected:
|
||||
ServiceDiscovery() {
|
||||
/* empty */
|
||||
}
|
||||
|
@ -220,4 +217,10 @@ public:
|
|||
bool characteristicDiscoveryInProgress;
|
||||
};
|
||||
|
||||
class NordicServiceDiscovery : public ServiceDiscovery {
|
||||
public:
|
||||
void setupDiscoveredServices(const ble_gattc_evt_prim_srvc_disc_rsp_t *response);
|
||||
void setupDiscoveredCharacteristics(const ble_gattc_evt_char_disc_rsp_t *response);
|
||||
};
|
||||
|
||||
#endif /*_BTLE_DISCOVERY_H_*/
|
||||
|
|
|
@ -18,20 +18,23 @@
|
|||
#include "UUID.h"
|
||||
#include "btle_discovery.h"
|
||||
|
||||
static NordicServiceDiscovery discoverySingleton;
|
||||
ServiceDiscovery *ServiceDiscovery::getSingleton(void) {
|
||||
return &discoverySingleton;
|
||||
}
|
||||
|
||||
void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
||||
{
|
||||
ServiceDiscovery *singleton = ServiceDiscovery::getSingleton();
|
||||
|
||||
switch (p_ble_evt->header.evt_id) {
|
||||
case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
|
||||
switch (p_ble_evt->evt.gattc_evt.gatt_status) {
|
||||
case BLE_GATT_STATUS_SUCCESS:
|
||||
singleton->setupDiscoveredServices(&p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp);
|
||||
discoverySingleton.setupDiscoveredServices(&p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp);
|
||||
break;
|
||||
|
||||
case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
|
||||
default:
|
||||
singleton->terminate();
|
||||
discoverySingleton.terminate();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -39,17 +42,17 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
case BLE_GATTC_EVT_CHAR_DISC_RSP:
|
||||
switch (p_ble_evt->evt.gattc_evt.gatt_status) {
|
||||
case BLE_GATT_STATUS_SUCCESS:
|
||||
singleton->setupDiscoveredCharacteristics(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp);
|
||||
discoverySingleton.setupDiscoveredCharacteristics(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp);
|
||||
break;
|
||||
|
||||
case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
|
||||
default:
|
||||
singleton->terminateCharacteristicDiscovery();
|
||||
discoverySingleton.terminateCharacteristicDiscovery();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
singleton->progressCharacteristicDiscovery();
|
||||
singleton->progressServiceDiscovery();
|
||||
discoverySingleton.progressCharacteristicDiscovery();
|
||||
discoverySingleton.progressServiceDiscovery();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue