テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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