initial working service discovery (with a lot of debugging printfs)
This commit is contained in:
parent
f135020de9
commit
1ffbf3e2eb
1 changed files with 59 additions and 16 deletions
|
@ -144,8 +144,56 @@ 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: {
|
||||
// printf("count of characteristics: %u\r\n", p_ble_evt->evt.gattc_evt.params.char_disc_rsp.count);
|
||||
discoveryStatus.currCharInd = 0;
|
||||
discoveryStatus.charCount = p_ble_evt->evt.gattc_evt.params.char_disc_rsp.count;
|
||||
|
||||
unsigned charIndex = 0;
|
||||
for (; charIndex < discoveryStatus.charCount; charIndex++) {
|
||||
// printf("<service index %u>[%u %u]\r\n", discoveryStatus.currSrvInd,
|
||||
// discoveryStatus.services[discoveryStatus.currSrvInd].startHandle, discoveryStatus.services[discoveryStatus.currSrvInd].endHandle);
|
||||
printf("%x [%u]\r\n", p_ble_evt->evt.gattc_evt.params.char_disc_rsp.chars[charIndex].uuid.uuid,
|
||||
p_ble_evt->evt.gattc_evt.params.char_disc_rsp.chars[charIndex].handle_value);
|
||||
// discoveryStatus.characteristics[charIndex].
|
||||
// setup(p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[charIndex].uuid.uuid,
|
||||
// p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[charIndex].handle_range.start_handle,
|
||||
// p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[charIndex].handle_range.end_handle);
|
||||
}
|
||||
|
||||
Gap::Handle_t startHandle = p_ble_evt->evt.gattc_evt.params.char_disc_rsp.chars[charIndex - 1].handle_value + 1;
|
||||
Gap::Handle_t endHandle = discoveryStatus.services[discoveryStatus.currSrvInd].endHandle;
|
||||
|
||||
if (startHandle < endHandle) {
|
||||
ble_gattc_handle_range_t handleRange = {
|
||||
.start_handle = startHandle,
|
||||
.end_handle = endHandle
|
||||
};
|
||||
printf("restarting char discovery from %u to %u\r\n", handleRange.start_handle, handleRange.end_handle);
|
||||
printf("char discovery returned %u\r\n", sd_ble_gattc_characteristics_discover(p_ble_evt->evt.gattc_evt.conn_handle, &handleRange));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* NOTE: fallthrough */
|
||||
|
||||
case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: {
|
||||
discoveryStatus.characteristicDiscoveryInProgress = false;
|
||||
discoveryStatus.serviceDiscoveryInProgress = true;
|
||||
discoveryStatus.currSrvInd++;
|
||||
// if (discoveryStatus.currSrvInd < discoveryStatus.srvCount) {
|
||||
// printf("end of characteristic discovery for this service; moving to service index %u [%u %u]\r\n",
|
||||
// discoveryStatus.currSrvInd,
|
||||
// discoveryStatus.services[discoveryStatus.currSrvInd].startHandle,
|
||||
// discoveryStatus.services[discoveryStatus.currSrvInd].endHandle);
|
||||
// } else {
|
||||
// printf("end of characteristic discovery for this service\r\n");
|
||||
// }
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
printf("gatt failure status: %u\r\n", p_ble_evt->evt.gattc_evt.gatt_status);
|
||||
printf("char response: gatt failure status: %u\r\n", p_ble_evt->evt.gattc_evt.gatt_status);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -154,23 +202,18 @@ void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|||
|
||||
while (discoveryStatus.serviceDiscoveryInProgress && (discoveryStatus.currSrvInd < discoveryStatus.srvCount)) {
|
||||
printf("%x [%u %u]\r\n",
|
||||
p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[discoveryStatus.currSrvInd].uuid.uuid,
|
||||
p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[discoveryStatus.currSrvInd].handle_range.start_handle,
|
||||
p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[discoveryStatus.currSrvInd].handle_range.end_handle);
|
||||
discoveryStatus.services[discoveryStatus.currSrvInd].uuid,
|
||||
discoveryStatus.services[discoveryStatus.currSrvInd].startHandle,
|
||||
discoveryStatus.services[discoveryStatus.currSrvInd].endHandle);
|
||||
|
||||
// ble_gattc_handle_range_t handleRange = {
|
||||
// .start_handle = p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[discoveryStatus.currSrvInd].handle_range.start_handle,
|
||||
// .end_handle = p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[discoveryStatus.currSrvInd].handle_range.end_handle
|
||||
// };
|
||||
// printf("characteristics_discover returned %u\r\n",
|
||||
// sd_ble_gattc_characteristics_discover(p_ble_evt->evt.gattc_evt.conn_handle, &handleRange));
|
||||
|
||||
discoveryStatus.currSrvInd++;
|
||||
launchCharacteristicDiscovery(discoveryStatus.connHandle,
|
||||
discoveryStatus.services[discoveryStatus.currSrvInd].startHandle,
|
||||
discoveryStatus.services[discoveryStatus.currSrvInd].endHandle);
|
||||
}
|
||||
if (discoveryStatus.serviceDiscoveryInProgress && (discoveryStatus.srvCount > 0)) {
|
||||
if (discoveryStatus.serviceDiscoveryInProgress && (discoveryStatus.srvCount > 0) && (discoveryStatus.currSrvInd > 0)) {
|
||||
Gap::Handle_t endHandle = discoveryStatus.services[discoveryStatus.currSrvInd - 1].endHandle;
|
||||
memset(discoveryStatus.services, 0, sizeof(DiscoveredService) * BLE_DB_DISCOVERY_MAX_SRV);
|
||||
printf("services discover returned %u\r\n",
|
||||
sd_ble_gattc_primary_services_discover(p_ble_evt->evt.gattc_evt.conn_handle,
|
||||
p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[discoveryStatus.currSrvInd -1].handle_range.end_handle,
|
||||
NULL));
|
||||
sd_ble_gattc_primary_services_discover(discoveryStatus.connHandle, endHandle, NULL));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue