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
Revision 194:c99fc3160091, committed 2015-06-19
- Comitter:
- rgrover1
- Date:
- Fri Jun 19 15:55:15 2015 +0100
- Parent:
- 193:29ed6ba3e53f
- Child:
- 195:061ed80ffbcf
- Commit message:
- Synchronized with git rev 5f5027e2
Author: Rohit Grover
separate out gatt-client functionality into btle_gattc.cpp
presently have event handler and lauchServiceDiscovery()
Changed in this revision
--- a/btle/btle.cpp Fri Jun 19 15:55:15 2015 +0100
+++ b/btle/btle.cpp Fri Jun 19 15:55:15 2015 +0100
@@ -24,6 +24,7 @@
#include "ble_conn_params.h"
#include "btle_gap.h"
+#include "btle_gattc.h"
#include "btle_advertising.h"
#include "custom/custom_helper.h"
@@ -104,6 +105,8 @@
dm_ble_evt_handler(p_ble_evt);
+ bleGattcEventHandler(p_ble_evt);
+
/* Custom event handler */
switch (p_ble_evt->header.evt_id) {
case BLE_GAP_EVT_CONNECTED: {
@@ -174,52 +177,6 @@
break;
}
- case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
- switch (p_ble_evt->evt.gattc_evt.gatt_status) {
- case BLE_GATT_STATUS_SUCCESS: {
- printf("count of primary services: %u; status code %u\r\n",
- p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.count, p_ble_evt->evt.gattc_evt.gatt_status);
-
- unsigned index;
- for (index = 0; index < p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.count; index++) {
- printf("%x [%u %u]\r\n",
- p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[index].uuid.uuid,
- p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[index].handle_range.start_handle,
- p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[index].handle_range.end_handle);
-
- ble_gattc_handle_range_t handleRange = {
- .start_handle = p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[index].handle_range.start_handle,
- .end_handle = p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[index].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));
- }
- 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[index -1].handle_range.end_handle,
- NULL));
- break;
- }
- case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: {
- printf("end of service discovery\r\n");
- break;
- }
- default: {
- printf("gatt failure status: %u\r\n", p_ble_evt->evt.gattc_evt.gatt_status);
- break;
- }
- }
- break;
-
- case BLE_GATTC_EVT_CHAR_DISC_RSP: {
- switch (p_ble_evt->evt.gattc_evt.gatt_status) {
- default:
- printf("gatt failure status: %u\r\n", p_ble_evt->evt.gattc_evt.gatt_status);
- break;
- }
- break;
- }
-
default:
break;
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/btle/btle_gattc.cpp Fri Jun 19 15:55:15 2015 +0100
@@ -0,0 +1,100 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "btle_gattc.h"
+
+#define BLE_DB_DISCOVERY_MAX_SRV 4 /**< Maximum number of services supported by this module. This also indicates the maximum number of users allowed to be registered to this module. (one user per service). */
+#define BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV 4 /**< Maximum number of characteristics per service supported by this module. */
+
+#define SRV_DISC_START_HANDLE 0x0001 /**< The start handle value used during service discovery. */
+
+
+/**@brief Structure for holding information about the service and the characteristics found during
+ * the discovery process.
+ */
+typedef struct
+{
+ ble_uuid_t srvUUID; /**< UUID of the service. */
+ // uint8_t char_count; /**< Number of characteristics present in the service. */
+ // ble_db_discovery_char_t charateristics[BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV]; /**< Array of information related to the characteristics present in the service. */
+ ble_gattc_handle_range_t handleRange; /**< Service Handle Range. */
+} ble_db_discovery_srv_t;
+
+typedef struct
+{
+ ble_db_discovery_srv_t services[BLE_DB_DISCOVERY_MAX_SRV]; /**< Information related to the current service being discovered. This is intended for internal use during service discovery.*/
+ uint16_t connHandle; /**< Connection handle as provided by the SoftDevice. */
+ uint8_t srvCount; /**< Number of services at the peers GATT database.*/
+ // uint8_t currCharInd; /**< Index of the current characteristic being discovered. This is intended for internal use during service discovery.*/
+ uint8_t currSrvInd; /**< Index of the current service being discovered. This is intended for internal use during service discovery.*/
+ // bool discoveryInProgress; /**< Variable to indicate if there is a service discovery in progress. */
+} ble_db_discovery_t;
+
+void launchServiceDiscovery(Gap::Handle_t connectionHandle)
+{
+ // printf("connectionHandle %u\r\n", connectionHandle);
+ printf("launch service discovery returned %u\r\n", sd_ble_gattc_primary_services_discover(connectionHandle, SRV_DISC_START_HANDLE, NULL));
+}
+
+void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
+{
+ 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: {
+ printf("count of primary services: %u\r\n", p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.count);
+
+ unsigned index;
+ for (index = 0; index < p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.count; index++) {
+ printf("%x [%u %u]\r\n",
+ p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[index].uuid.uuid,
+ p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[index].handle_range.start_handle,
+ p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[index].handle_range.end_handle);
+
+ ble_gattc_handle_range_t handleRange = {
+ .start_handle = p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[index].handle_range.start_handle,
+ .end_handle = p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[index].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));
+ }
+ 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[index -1].handle_range.end_handle,
+ NULL));
+ break;
+ }
+ case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: {
+ printf("end of service discovery\r\n");
+ break;
+ }
+ default: {
+ printf("gatt failure status: %u\r\n", p_ble_evt->evt.gattc_evt.gatt_status);
+ break;
+ }
+ }
+ break;
+
+ case BLE_GATTC_EVT_CHAR_DISC_RSP: {
+ switch (p_ble_evt->evt.gattc_evt.gatt_status) {
+ default:
+ printf("gatt failure status: %u\r\n", p_ble_evt->evt.gattc_evt.gatt_status);
+ break;
+ }
+ break;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/btle/btle_gattc.h Fri Jun 19 15:55:15 2015 +0100 @@ -0,0 +1,26 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _BTLE_GATTC_H_ +#define _BTLE_GATTC_H_ + +#include "btle.h" +#include "Gap.h" + +void launchServiceDiscovery(Gap::Handle_t connectionHandle); +void bleGattcEventHandler(const ble_evt_t *p_ble_evt); + +#endif // ifndef _BTLE_GATTC_H_ \ No newline at end of file
