Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nRF51822 by
btle_discovery.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "nRF5xServiceDiscovery.h" 00018 #include "nRF5xCharacteristicDescriptorDiscoverer.h" 00019 #include "nRF5xGattClient.h" 00020 #include "nRF5xn.h" 00021 00022 #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110) 00023 void bleGattcEventHandler(const ble_evt_t *p_ble_evt) 00024 { 00025 nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE); 00026 nRF5xGap &gap = (nRF5xGap &) ble.getGap(); 00027 nRF5xGattClient &gattClient = (nRF5xGattClient &) ble.getGattClient(); 00028 nRF5xServiceDiscovery &sdSingleton = gattClient.discovery(); 00029 nRF5xCharacteristicDescriptorDiscoverer &characteristicDescriptorDiscoverer = 00030 gattClient.characteristicDescriptorDiscoverer(); 00031 00032 switch (p_ble_evt->header.evt_id) { 00033 case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: 00034 switch (p_ble_evt->evt.gattc_evt.gatt_status) { 00035 case BLE_GATT_STATUS_SUCCESS: 00036 sdSingleton.setupDiscoveredServices(&p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp); 00037 break; 00038 00039 case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: 00040 default: 00041 sdSingleton.terminate(); 00042 break; 00043 } 00044 break; 00045 00046 case BLE_GATTC_EVT_CHAR_DISC_RSP: 00047 switch (p_ble_evt->evt.gattc_evt.gatt_status) { 00048 case BLE_GATT_STATUS_SUCCESS: 00049 sdSingleton.setupDiscoveredCharacteristics(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp); 00050 break; 00051 00052 case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: 00053 default: 00054 sdSingleton.terminateCharacteristicDiscovery(BLE_ERROR_NONE); 00055 break; 00056 } 00057 break; 00058 00059 case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP: 00060 if (sdSingleton.isActive()) { 00061 sdSingleton.processDiscoverUUIDResponse(&p_ble_evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp); 00062 } 00063 break; 00064 00065 case BLE_GATTC_EVT_READ_RSP: { 00066 GattReadCallbackParams response = { 00067 .connHandle = p_ble_evt->evt.gattc_evt.conn_handle, 00068 .handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle, 00069 .offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset, 00070 .len = p_ble_evt->evt.gattc_evt.params.read_rsp.len, 00071 .data = p_ble_evt->evt.gattc_evt.params.read_rsp.data, 00072 }; 00073 gattClient.processReadResponse(&response); 00074 } 00075 break; 00076 00077 case BLE_GATTC_EVT_WRITE_RSP: { 00078 GattWriteCallbackParams response = { 00079 .connHandle = p_ble_evt->evt.gattc_evt.conn_handle, 00080 .handle = p_ble_evt->evt.gattc_evt.params.write_rsp.handle, 00081 .writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op), 00082 .offset = p_ble_evt->evt.gattc_evt.params.write_rsp.offset, 00083 .len = p_ble_evt->evt.gattc_evt.params.write_rsp.len, 00084 .data = p_ble_evt->evt.gattc_evt.params.write_rsp.data, 00085 }; 00086 gattClient.processWriteResponse(&response); 00087 } 00088 break; 00089 00090 case BLE_GATTC_EVT_HVX: { 00091 GattHVXCallbackParams params; 00092 params.connHandle = p_ble_evt->evt.gattc_evt.conn_handle; 00093 params.handle = p_ble_evt->evt.gattc_evt.params.hvx.handle; 00094 params.type = static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type); 00095 params.len = p_ble_evt->evt.gattc_evt.params.hvx.len; 00096 params.data = p_ble_evt->evt.gattc_evt.params.hvx.data; 00097 00098 gattClient.processHVXEvent(¶ms); 00099 } 00100 break; 00101 00102 case BLE_GATTC_EVT_DESC_DISC_RSP: { 00103 uint16_t conn_handle = p_ble_evt->evt.gattc_evt.conn_handle; 00104 uint16_t status = p_ble_evt->evt.gattc_evt.gatt_status; 00105 const ble_gattc_evt_desc_disc_rsp_t& discovered_descriptors = p_ble_evt->evt.gattc_evt.params.desc_disc_rsp; 00106 00107 switch(status) { 00108 case BLE_GATT_STATUS_SUCCESS: 00109 characteristicDescriptorDiscoverer.process( 00110 conn_handle, 00111 discovered_descriptors 00112 ); 00113 break; 00114 case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: 00115 // end of discovery 00116 characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_NONE); 00117 break; 00118 default: 00119 characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_UNSPECIFIED); 00120 break; 00121 } 00122 } break; 00123 } 00124 00125 sdSingleton.progressCharacteristicDiscovery(); 00126 sdSingleton.progressServiceDiscovery(); 00127 } 00128 #endif
Generated on Fri Jul 15 2022 12:51:28 by
