Bizan Nishimura / Mbed 2 deprecated MiniSteer3

Dependencies:   BLE_API mbed

Committer:
lipoyang
Date:
Sat Mar 14 12:02:48 2015 +0000
Revision:
5:7f89fca19a9e
-convert nRF51822 library to a folder

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lipoyang 5:7f89fca19a9e 1 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
lipoyang 5:7f89fca19a9e 2 *
lipoyang 5:7f89fca19a9e 3 * The information contained herein is property of Nordic Semiconductor ASA.
lipoyang 5:7f89fca19a9e 4 * Terms and conditions of usage are described in detail in NORDIC
lipoyang 5:7f89fca19a9e 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
lipoyang 5:7f89fca19a9e 6 *
lipoyang 5:7f89fca19a9e 7 * Licensees are granted free, non-transferable use of the information. NO
lipoyang 5:7f89fca19a9e 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
lipoyang 5:7f89fca19a9e 9 * the file.
lipoyang 5:7f89fca19a9e 10 */
lipoyang 5:7f89fca19a9e 11
lipoyang 5:7f89fca19a9e 12
lipoyang 5:7f89fca19a9e 13 /**@file
lipoyang 5:7f89fca19a9e 14 *
lipoyang 5:7f89fca19a9e 15 * @defgroup ble_sdk_lib_db_discovery Database Discovery
lipoyang 5:7f89fca19a9e 16 * @{
lipoyang 5:7f89fca19a9e 17 * @ingroup nrf51_sdk_api
lipoyang 5:7f89fca19a9e 18 * @brief Database discovery module.
lipoyang 5:7f89fca19a9e 19 *
lipoyang 5:7f89fca19a9e 20 * @details This module contains the APIs and types exposed by the DB Discovery module. These APIs
lipoyang 5:7f89fca19a9e 21 * and types can be used by the application to perform discovery of a service and its
lipoyang 5:7f89fca19a9e 22 * characteristics at the peer server. This module can also be used to discover the
lipoyang 5:7f89fca19a9e 23 * desired services in multiple remote devices.
lipoyang 5:7f89fca19a9e 24 * A typical use of this library is described in the figure below.
lipoyang 5:7f89fca19a9e 25 * @image html db_discovery.jpg
lipoyang 5:7f89fca19a9e 26 *
lipoyang 5:7f89fca19a9e 27 * @warning The maximum number of characteristics per service that can be discovered by this module
lipoyang 5:7f89fca19a9e 28 * is indicated by the value of @ref BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV. If the peer
lipoyang 5:7f89fca19a9e 29 * has more than the supported number of characteristics, then the first found will be
lipoyang 5:7f89fca19a9e 30 * discovered and any further characteristics will be ignored. No descriptors other
lipoyang 5:7f89fca19a9e 31 * than Client Characteristic Configuration Descriptors will be searched for at the peer.
lipoyang 5:7f89fca19a9e 32 *
lipoyang 5:7f89fca19a9e 33 * @note Presently only one instance of a Primary Service can be discovered by this module. If
lipoyang 5:7f89fca19a9e 34 * there are multiple instances of the service at the peer, only the first instance
lipoyang 5:7f89fca19a9e 35 * of it at the peer is fetched and returned to the application.
lipoyang 5:7f89fca19a9e 36 *
lipoyang 5:7f89fca19a9e 37 * @note The application must propagate BLE stack events to this module by calling
lipoyang 5:7f89fca19a9e 38 * ble_db_discovery_on_ble_evt().
lipoyang 5:7f89fca19a9e 39 *
lipoyang 5:7f89fca19a9e 40 */
lipoyang 5:7f89fca19a9e 41
lipoyang 5:7f89fca19a9e 42 #ifndef BLE_DB_DISCOVERY_H__
lipoyang 5:7f89fca19a9e 43 #define BLE_DB_DISCOVERY_H__
lipoyang 5:7f89fca19a9e 44
lipoyang 5:7f89fca19a9e 45 #include <stdint.h>
lipoyang 5:7f89fca19a9e 46 #include "ble_gattc.h"
lipoyang 5:7f89fca19a9e 47 #include "ble.h"
lipoyang 5:7f89fca19a9e 48 #include "nrf_error.h"
lipoyang 5:7f89fca19a9e 49 #include "ble_srv_common.h"
lipoyang 5:7f89fca19a9e 50
lipoyang 5:7f89fca19a9e 51 /**
lipoyang 5:7f89fca19a9e 52 * @defgroup db_disc_defines Defines
lipoyang 5:7f89fca19a9e 53 * @{
lipoyang 5:7f89fca19a9e 54 */
lipoyang 5:7f89fca19a9e 55
lipoyang 5:7f89fca19a9e 56 #define BLE_DB_DISCOVERY_MAX_SRV 2 /**< 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). */
lipoyang 5:7f89fca19a9e 57 #define BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV 3 /**< Maximum number of characteristics per service supported by this module. */
lipoyang 5:7f89fca19a9e 58
lipoyang 5:7f89fca19a9e 59 /** @} */
lipoyang 5:7f89fca19a9e 60
lipoyang 5:7f89fca19a9e 61 /**
lipoyang 5:7f89fca19a9e 62 * @defgroup db_disc_enums Enumerations
lipoyang 5:7f89fca19a9e 63 * @{
lipoyang 5:7f89fca19a9e 64 */
lipoyang 5:7f89fca19a9e 65
lipoyang 5:7f89fca19a9e 66 /**@brief Type of the DB Discovery event.
lipoyang 5:7f89fca19a9e 67 */
lipoyang 5:7f89fca19a9e 68 typedef enum
lipoyang 5:7f89fca19a9e 69 {
lipoyang 5:7f89fca19a9e 70 BLE_DB_DISCOVERY_COMPLETE, /**< Event indicating that the GATT Database discovery is complete. */
lipoyang 5:7f89fca19a9e 71 BLE_DB_DISCOVERY_ERROR, /**< Event indicating that an internal error has occurred in the DB Discovery module. This could typically be because of the SoftDevice API returning an error code during the DB discover.*/
lipoyang 5:7f89fca19a9e 72 BLE_DB_DISCOVERY_SRV_NOT_FOUND /**< Event indicating that the service was not found at the peer.*/
lipoyang 5:7f89fca19a9e 73 } ble_db_discovery_evt_type_t;
lipoyang 5:7f89fca19a9e 74
lipoyang 5:7f89fca19a9e 75 /** @} */
lipoyang 5:7f89fca19a9e 76
lipoyang 5:7f89fca19a9e 77 /**
lipoyang 5:7f89fca19a9e 78 * @defgroup db_disc_structs Structures
lipoyang 5:7f89fca19a9e 79 * @{
lipoyang 5:7f89fca19a9e 80 */
lipoyang 5:7f89fca19a9e 81
lipoyang 5:7f89fca19a9e 82 /**@brief Structure for holding the characteristic and the handle of its CCCD found during the
lipoyang 5:7f89fca19a9e 83 * discovery process.
lipoyang 5:7f89fca19a9e 84 */
lipoyang 5:7f89fca19a9e 85 typedef struct
lipoyang 5:7f89fca19a9e 86 {
lipoyang 5:7f89fca19a9e 87 ble_gattc_char_t characteristic; /**< Structure containing information about the characteristic. */
lipoyang 5:7f89fca19a9e 88 uint16_t cccd_handle; /**< CCCD Handle value for this characteristic. This will be set to BLE_GATT_HANDLE_INVALID if a CCCD is not present at the server. */
lipoyang 5:7f89fca19a9e 89 } ble_db_discovery_char_t;
lipoyang 5:7f89fca19a9e 90
lipoyang 5:7f89fca19a9e 91 /**@brief Structure for holding information about the service and the characteristics found during
lipoyang 5:7f89fca19a9e 92 * the discovery process.
lipoyang 5:7f89fca19a9e 93 */
lipoyang 5:7f89fca19a9e 94 typedef struct
lipoyang 5:7f89fca19a9e 95 {
lipoyang 5:7f89fca19a9e 96 ble_uuid_t srv_uuid; /**< UUID of the service. */
lipoyang 5:7f89fca19a9e 97 uint8_t char_count; /**< Number of characteristics present in the service. */
lipoyang 5:7f89fca19a9e 98 ble_db_discovery_char_t charateristics[BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV]; /**< Array of information related to the characteristics present in the service. */
lipoyang 5:7f89fca19a9e 99 ble_gattc_handle_range_t handle_range; /**< Service Handle Range. */
lipoyang 5:7f89fca19a9e 100 } ble_db_discovery_srv_t;
lipoyang 5:7f89fca19a9e 101
lipoyang 5:7f89fca19a9e 102 /**@brief Structure for holding the information related to the GATT database at the server.
lipoyang 5:7f89fca19a9e 103 *
lipoyang 5:7f89fca19a9e 104 * @details This module identifies a remote database. Use one instance of this structure per
lipoyang 5:7f89fca19a9e 105 * connection.
lipoyang 5:7f89fca19a9e 106 *
lipoyang 5:7f89fca19a9e 107 * @warning This structure must be zero-initialized.
lipoyang 5:7f89fca19a9e 108 */
lipoyang 5:7f89fca19a9e 109 typedef struct
lipoyang 5:7f89fca19a9e 110 {
lipoyang 5:7f89fca19a9e 111 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.*/
lipoyang 5:7f89fca19a9e 112 uint16_t conn_handle; /**< Connection handle as provided by the SoftDevice. */
lipoyang 5:7f89fca19a9e 113 uint8_t srv_count; /**< Number of services at the peers GATT database.*/
lipoyang 5:7f89fca19a9e 114 uint8_t curr_char_ind; /**< Index of the current characteristic being discovered. This is intended for internal use during service discovery.*/
lipoyang 5:7f89fca19a9e 115 uint8_t curr_srv_ind; /**< Index of the current service being discovered. This is intended for internal use during service discovery.*/
lipoyang 5:7f89fca19a9e 116 bool discovery_in_progress; /**< Variable to indicate if there is a service discovery in progress. */
lipoyang 5:7f89fca19a9e 117 } ble_db_discovery_t;
lipoyang 5:7f89fca19a9e 118
lipoyang 5:7f89fca19a9e 119
lipoyang 5:7f89fca19a9e 120 /**@brief Structure containing the event from the DB discovery module to the application.
lipoyang 5:7f89fca19a9e 121 */
lipoyang 5:7f89fca19a9e 122 typedef struct
lipoyang 5:7f89fca19a9e 123 {
lipoyang 5:7f89fca19a9e 124 ble_db_discovery_evt_type_t evt_type; /**< Type of event. */
lipoyang 5:7f89fca19a9e 125 uint16_t conn_handle; /**< Handle of the connection for which this event has occurred. */
lipoyang 5:7f89fca19a9e 126 union
lipoyang 5:7f89fca19a9e 127 {
lipoyang 5:7f89fca19a9e 128 ble_db_discovery_srv_t discovered_db; /**< Structure containing the information about the GATT Database at the server. This will be filled when the event type is @ref BLE_DB_DISCOVERY_COMPLETE.*/
lipoyang 5:7f89fca19a9e 129 uint32_t err_code; /**< nRF Error code indicating the type of error which occurred in the DB Discovery module. This will be filled when the event type is @ref BLE_DB_DISCOVERY_ERROR. */
lipoyang 5:7f89fca19a9e 130 } params;
lipoyang 5:7f89fca19a9e 131 } ble_db_discovery_evt_t;
lipoyang 5:7f89fca19a9e 132
lipoyang 5:7f89fca19a9e 133 /** @} */
lipoyang 5:7f89fca19a9e 134
lipoyang 5:7f89fca19a9e 135 /**
lipoyang 5:7f89fca19a9e 136 * @defgroup db_disc_types Types
lipoyang 5:7f89fca19a9e 137 * @{
lipoyang 5:7f89fca19a9e 138 */
lipoyang 5:7f89fca19a9e 139
lipoyang 5:7f89fca19a9e 140 /**@brief DB Discovery event handler type. */
lipoyang 5:7f89fca19a9e 141 typedef void (* ble_db_discovery_evt_handler_t)(ble_db_discovery_evt_t * p_evt);
lipoyang 5:7f89fca19a9e 142
lipoyang 5:7f89fca19a9e 143 /** @} */
lipoyang 5:7f89fca19a9e 144
lipoyang 5:7f89fca19a9e 145 /**
lipoyang 5:7f89fca19a9e 146 * @addtogroup db_disc_structs
lipoyang 5:7f89fca19a9e 147 * @{
lipoyang 5:7f89fca19a9e 148 */
lipoyang 5:7f89fca19a9e 149
lipoyang 5:7f89fca19a9e 150 /** @} */
lipoyang 5:7f89fca19a9e 151
lipoyang 5:7f89fca19a9e 152 /**
lipoyang 5:7f89fca19a9e 153 * @defgroup db_disc_functions Functions
lipoyang 5:7f89fca19a9e 154 * @{
lipoyang 5:7f89fca19a9e 155 */
lipoyang 5:7f89fca19a9e 156
lipoyang 5:7f89fca19a9e 157 /**@brief Function for initializing the DB Discovery module.
lipoyang 5:7f89fca19a9e 158 *
lipoyang 5:7f89fca19a9e 159 * @retval NRF_SUCCESS on successful initialization.
lipoyang 5:7f89fca19a9e 160 */
lipoyang 5:7f89fca19a9e 161 uint32_t ble_db_discovery_init(void);
lipoyang 5:7f89fca19a9e 162
lipoyang 5:7f89fca19a9e 163
lipoyang 5:7f89fca19a9e 164 /**@brief Function for closing the DB Discovery module.
lipoyang 5:7f89fca19a9e 165 *
lipoyang 5:7f89fca19a9e 166 * @details This function will clear up any internal variables and states maintained by the
lipoyang 5:7f89fca19a9e 167 * module. To re-use the module after calling this function, the function @ref
lipoyang 5:7f89fca19a9e 168 * ble_db_discovery_init must be called again.
lipoyang 5:7f89fca19a9e 169 *
lipoyang 5:7f89fca19a9e 170 * @retval NRF_SUCCESS Operation success.
lipoyang 5:7f89fca19a9e 171 */
lipoyang 5:7f89fca19a9e 172 uint32_t ble_db_discovery_close(void);
lipoyang 5:7f89fca19a9e 173
lipoyang 5:7f89fca19a9e 174
lipoyang 5:7f89fca19a9e 175 /**@brief Function for registering with the DB Discovery module.
lipoyang 5:7f89fca19a9e 176 *
lipoyang 5:7f89fca19a9e 177 * @details The application can use this function to inform which service it is interested in
lipoyang 5:7f89fca19a9e 178 * discovering at the server.
lipoyang 5:7f89fca19a9e 179 *
lipoyang 5:7f89fca19a9e 180 * @param[in] p_uuid Pointer to the UUID of the service to be discovered at the server.
lipoyang 5:7f89fca19a9e 181 * @param[in] evt_handler Event handler to be called by the DB discovery module when any event
lipoyang 5:7f89fca19a9e 182 * related to discovery of the registered service occurs.
lipoyang 5:7f89fca19a9e 183 *
lipoyang 5:7f89fca19a9e 184 * @note The total number of services that can be discovered by this module is @ref
lipoyang 5:7f89fca19a9e 185 * BLE_DB_DISCOVERY_MAX_SRV. This effectively means that the maximum number of
lipoyang 5:7f89fca19a9e 186 * registrations possible is equal to the @ref BLE_DB_DISCOVERY_MAX_SRV.
lipoyang 5:7f89fca19a9e 187 *
lipoyang 5:7f89fca19a9e 188 * @retval NRF_SUCCESS Operation success.
lipoyang 5:7f89fca19a9e 189 * @retval NRF_ERROR_NULL When a NULL pointer is passed as input.
lipoyang 5:7f89fca19a9e 190 * @retval NRF_ERROR_INVALID_STATE If this function is called without calling the
lipoyang 5:7f89fca19a9e 191 * @ref ble_db_discovery_init.
lipoyang 5:7f89fca19a9e 192 * @retval NRF_ERROR_NOT_SUPPORTED The maximum number of registrations allowed by this module
lipoyang 5:7f89fca19a9e 193 * has been reached.
lipoyang 5:7f89fca19a9e 194 */
lipoyang 5:7f89fca19a9e 195 uint32_t ble_db_discovery_evt_register(const ble_uuid_t * const p_uuid,
lipoyang 5:7f89fca19a9e 196 const ble_db_discovery_evt_handler_t evt_handler);
lipoyang 5:7f89fca19a9e 197
lipoyang 5:7f89fca19a9e 198
lipoyang 5:7f89fca19a9e 199 /**@brief Function for starting the discovery of the GATT database at the server.
lipoyang 5:7f89fca19a9e 200 *
lipoyang 5:7f89fca19a9e 201 * @warning p_db_discovery structure must be zero-initialized.
lipoyang 5:7f89fca19a9e 202 *
lipoyang 5:7f89fca19a9e 203 * @param[out] p_db_discovery Pointer to the DB Discovery structure.
lipoyang 5:7f89fca19a9e 204 * @param[in] conn_handle The handle of the connection for which the discovery should be
lipoyang 5:7f89fca19a9e 205 * started.
lipoyang 5:7f89fca19a9e 206 *
lipoyang 5:7f89fca19a9e 207 * @retval NRF_SUCCESS Operation success.
lipoyang 5:7f89fca19a9e 208 * @retval NRF_ERROR_NULL When a NULL pointer is passed as input.
lipoyang 5:7f89fca19a9e 209 * @retval NRF_ERROR_INVALID_STATE If this function is called without calling the
lipoyang 5:7f89fca19a9e 210 * @ref ble_db_discovery_init, or without calling
lipoyang 5:7f89fca19a9e 211 * @ref ble_db_discovery_evt_register.
lipoyang 5:7f89fca19a9e 212 * @retval NRF_ERROR_BUSY If a discovery is already in progress for the current
lipoyang 5:7f89fca19a9e 213 * connection.
lipoyang 5:7f89fca19a9e 214 *
lipoyang 5:7f89fca19a9e 215 * @return This API propagates the error code returned by the
lipoyang 5:7f89fca19a9e 216 * SoftDevice API @ref sd_ble_gattc_primary_services_discover.
lipoyang 5:7f89fca19a9e 217 */
lipoyang 5:7f89fca19a9e 218 uint32_t ble_db_discovery_start(ble_db_discovery_t * const p_db_discovery,
lipoyang 5:7f89fca19a9e 219 uint16_t conn_handle);
lipoyang 5:7f89fca19a9e 220
lipoyang 5:7f89fca19a9e 221
lipoyang 5:7f89fca19a9e 222 /**@brief Function for handling the Application's BLE Stack events.
lipoyang 5:7f89fca19a9e 223 *
lipoyang 5:7f89fca19a9e 224 * @param[in,out] p_db_discovery Pointer to the DB Discovery structure.
lipoyang 5:7f89fca19a9e 225 * @param[in] p_ble_evt Pointer to the BLE event received.
lipoyang 5:7f89fca19a9e 226 */
lipoyang 5:7f89fca19a9e 227 void ble_db_discovery_on_ble_evt(ble_db_discovery_t * const p_db_discovery,
lipoyang 5:7f89fca19a9e 228 const ble_evt_t * const p_ble_evt);
lipoyang 5:7f89fca19a9e 229
lipoyang 5:7f89fca19a9e 230 /** @} */
lipoyang 5:7f89fca19a9e 231
lipoyang 5:7f89fca19a9e 232 #endif // BLE_DB_DISCOVERY_H__
lipoyang 5:7f89fca19a9e 233
lipoyang 5:7f89fca19a9e 234 /** @} */