Marcus Chang / nRF51822

Fork of nRF51822 by Nordic Semiconductor

Committer:
marcuschang
Date:
Fri Dec 12 17:12:35 2014 +0000
Revision:
85:17fe69405098
Parent:
65:98215c4f3a25
Write permission was not set for 'write without response' characteristics.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rohit Grover 65:98215c4f3a25 1 /*
Rohit Grover 65:98215c4f3a25 2 * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
Rohit Grover 65:98215c4f3a25 3 *
Rohit Grover 65:98215c4f3a25 4 * The information contained herein is confidential property of Nordic Semiconductor. The use,
Rohit Grover 65:98215c4f3a25 5 * copying, transfer or disclosure of such information is prohibited except by express written
Rohit Grover 65:98215c4f3a25 6 * agreement with Nordic Semiconductor.
Rohit Grover 65:98215c4f3a25 7 *
Rohit Grover 65:98215c4f3a25 8 */
Rohit Grover 65:98215c4f3a25 9
Rohit Grover 65:98215c4f3a25 10 /**@file
Rohit Grover 65:98215c4f3a25 11 *
Rohit Grover 65:98215c4f3a25 12 * @defgroup ble_sdk_srv_hrs_c Heart Rate Service Client
Rohit Grover 65:98215c4f3a25 13 * @{
Rohit Grover 65:98215c4f3a25 14 * @ingroup ble_sdk_srv
Rohit Grover 65:98215c4f3a25 15 * @brief Heart Rate Service Client module.
Rohit Grover 65:98215c4f3a25 16 *
Rohit Grover 65:98215c4f3a25 17 * @details This module contains the APIs and types exposed by the Heart Rate Service Client
Rohit Grover 65:98215c4f3a25 18 * module. These APIs and types can be used by the application to perform discovery of
Rohit Grover 65:98215c4f3a25 19 * Heart Rate Service at the peer and interact with it.
Rohit Grover 65:98215c4f3a25 20 *
Rohit Grover 65:98215c4f3a25 21 * @warning Currently this module only has support for Heart Rate Measurement characteristic. This
Rohit Grover 65:98215c4f3a25 22 * means that it will be able to enable notification of the characteristic at the peer and
Rohit Grover 65:98215c4f3a25 23 * be able to receive Heart Rate Measurement notifications from the peer. It does not
Rohit Grover 65:98215c4f3a25 24 * support the Body Sensor Location and the Heart Rate Control Point characteristics.
Rohit Grover 65:98215c4f3a25 25 * When a Heart Rate Measurement is received, this module will decode only the
Rohit Grover 65:98215c4f3a25 26 * Heart Rate Measurement Value (both 8 bit and 16 bit) field from it and provide it to
Rohit Grover 65:98215c4f3a25 27 * the application.
Rohit Grover 65:98215c4f3a25 28 *
Rohit Grover 65:98215c4f3a25 29 * @note The application must propagate BLE stack events to this module by calling
Rohit Grover 65:98215c4f3a25 30 * ble_hrs_c_on_ble_evt().
Rohit Grover 65:98215c4f3a25 31 *
Rohit Grover 65:98215c4f3a25 32 */
Rohit Grover 65:98215c4f3a25 33
Rohit Grover 65:98215c4f3a25 34 #ifndef BLE_HRS_C_H__
Rohit Grover 65:98215c4f3a25 35 #define BLE_HRS_C_H__
Rohit Grover 65:98215c4f3a25 36
Rohit Grover 65:98215c4f3a25 37 #include <stdint.h>
Rohit Grover 65:98215c4f3a25 38 #include "ble.h"
Rohit Grover 65:98215c4f3a25 39
Rohit Grover 65:98215c4f3a25 40 /**
Rohit Grover 65:98215c4f3a25 41 * @defgroup hrs_c_enums Enumerations
Rohit Grover 65:98215c4f3a25 42 * @{
Rohit Grover 65:98215c4f3a25 43 */
Rohit Grover 65:98215c4f3a25 44
Rohit Grover 65:98215c4f3a25 45 /**@brief HRS Client event type. */
Rohit Grover 65:98215c4f3a25 46 typedef enum
Rohit Grover 65:98215c4f3a25 47 {
Rohit Grover 65:98215c4f3a25 48 BLE_HRS_C_EVT_DISCOVERY_COMPLETE = 1, /**< Event indicating that the Heart Rate Service has been discovered at the peer. */
Rohit Grover 65:98215c4f3a25 49 BLE_HRS_C_EVT_HRM_NOTIFICATION /**< Event indicating that a notification of the Heart Rate Measurement characteristic has been received from the peer. */
Rohit Grover 65:98215c4f3a25 50 } ble_hrs_c_evt_type_t;
Rohit Grover 65:98215c4f3a25 51
Rohit Grover 65:98215c4f3a25 52 /** @} */
Rohit Grover 65:98215c4f3a25 53
Rohit Grover 65:98215c4f3a25 54 /**
Rohit Grover 65:98215c4f3a25 55 * @defgroup hrs_c_structs Structures
Rohit Grover 65:98215c4f3a25 56 * @{
Rohit Grover 65:98215c4f3a25 57 */
Rohit Grover 65:98215c4f3a25 58
Rohit Grover 65:98215c4f3a25 59 /**@brief Structure containing the heart rate measurement received from the peer. */
Rohit Grover 65:98215c4f3a25 60 typedef struct
Rohit Grover 65:98215c4f3a25 61 {
Rohit Grover 65:98215c4f3a25 62 uint16_t hr_value; /**< Heart Rate Value. */
Rohit Grover 65:98215c4f3a25 63 } ble_hrm_t;
Rohit Grover 65:98215c4f3a25 64
Rohit Grover 65:98215c4f3a25 65 /**@brief Heart Rate Event structure. */
Rohit Grover 65:98215c4f3a25 66 typedef struct
Rohit Grover 65:98215c4f3a25 67 {
Rohit Grover 65:98215c4f3a25 68 ble_hrs_c_evt_type_t evt_type; /**< Type of the event. */
Rohit Grover 65:98215c4f3a25 69 union
Rohit Grover 65:98215c4f3a25 70 {
Rohit Grover 65:98215c4f3a25 71 ble_hrm_t hrm; /**< Heart rate measurement received. This will be filled if the evt_type is @ref BLE_HRS_C_EVT_HRM_NOTIFICATION. */
Rohit Grover 65:98215c4f3a25 72 } params;
Rohit Grover 65:98215c4f3a25 73 } ble_hrs_c_evt_t;
Rohit Grover 65:98215c4f3a25 74
Rohit Grover 65:98215c4f3a25 75 /** @} */
Rohit Grover 65:98215c4f3a25 76
Rohit Grover 65:98215c4f3a25 77 /**
Rohit Grover 65:98215c4f3a25 78 * @defgroup hrs_c_types Types
Rohit Grover 65:98215c4f3a25 79 * @{
Rohit Grover 65:98215c4f3a25 80 */
Rohit Grover 65:98215c4f3a25 81
Rohit Grover 65:98215c4f3a25 82 // Forward declaration of the ble_bas_t type.
Rohit Grover 65:98215c4f3a25 83 typedef struct ble_hrs_c_s ble_hrs_c_t;
Rohit Grover 65:98215c4f3a25 84
Rohit Grover 65:98215c4f3a25 85 /**@brief Event handler type.
Rohit Grover 65:98215c4f3a25 86 *
Rohit Grover 65:98215c4f3a25 87 * @details This is the type of the event handler that should be provided by the application
Rohit Grover 65:98215c4f3a25 88 * of this module in order to receive events.
Rohit Grover 65:98215c4f3a25 89 */
Rohit Grover 65:98215c4f3a25 90 typedef void (* ble_hrs_c_evt_handler_t) (ble_hrs_c_t * p_ble_hrs_c, ble_hrs_c_evt_t * p_evt);
Rohit Grover 65:98215c4f3a25 91
Rohit Grover 65:98215c4f3a25 92 /** @} */
Rohit Grover 65:98215c4f3a25 93
Rohit Grover 65:98215c4f3a25 94 /**
Rohit Grover 65:98215c4f3a25 95 * @addtogroup hrs_c_structs
Rohit Grover 65:98215c4f3a25 96 * @{
Rohit Grover 65:98215c4f3a25 97 */
Rohit Grover 65:98215c4f3a25 98
Rohit Grover 65:98215c4f3a25 99 /**@brief Heart Rate Client structure.
Rohit Grover 65:98215c4f3a25 100 */
Rohit Grover 65:98215c4f3a25 101 typedef struct ble_hrs_c_s
Rohit Grover 65:98215c4f3a25 102 {
Rohit Grover 65:98215c4f3a25 103 uint16_t conn_handle; /**< Connection handle as provided by the SoftDevice. */
Rohit Grover 65:98215c4f3a25 104 uint16_t hrm_cccd_handle; /**< Handle of the CCCD of the Heart Rate Measurement characteristic. */
Rohit Grover 65:98215c4f3a25 105 uint16_t hrm_handle; /**< Handle of the Heart Rate Measurement characteristic as provided by the SoftDevice. */
Rohit Grover 65:98215c4f3a25 106 ble_hrs_c_evt_handler_t evt_handler; /**< Application event handler to be called when there is an event related to the heart rate service. */
Rohit Grover 65:98215c4f3a25 107 } ble_hrs_c_t;
Rohit Grover 65:98215c4f3a25 108
Rohit Grover 65:98215c4f3a25 109 /**@brief Heart Rate Client initialization structure.
Rohit Grover 65:98215c4f3a25 110 */
Rohit Grover 65:98215c4f3a25 111 typedef struct
Rohit Grover 65:98215c4f3a25 112 {
Rohit Grover 65:98215c4f3a25 113 ble_hrs_c_evt_handler_t evt_handler; /**< Event handler to be called by the Heart Rate Client module whenever there is an event related to the Heart Rate Service. */
Rohit Grover 65:98215c4f3a25 114 } ble_hrs_c_init_t;
Rohit Grover 65:98215c4f3a25 115
Rohit Grover 65:98215c4f3a25 116 /** @} */
Rohit Grover 65:98215c4f3a25 117
Rohit Grover 65:98215c4f3a25 118 /**
Rohit Grover 65:98215c4f3a25 119 * @defgroup hrs_c_functions Functions
Rohit Grover 65:98215c4f3a25 120 * @{
Rohit Grover 65:98215c4f3a25 121 */
Rohit Grover 65:98215c4f3a25 122
Rohit Grover 65:98215c4f3a25 123 /**@brief Function for initializing the heart rate client module.
Rohit Grover 65:98215c4f3a25 124 *
Rohit Grover 65:98215c4f3a25 125 * @details This function will register with the DB Discovery module. There it
Rohit Grover 65:98215c4f3a25 126 * registers for the Heart Rate Service. Doing so will make the DB Discovery
Rohit Grover 65:98215c4f3a25 127 * module look for the presence of a Heart Rate Service instance at the peer when a
Rohit Grover 65:98215c4f3a25 128 * discovery is started.
Rohit Grover 65:98215c4f3a25 129 *
Rohit Grover 65:98215c4f3a25 130 * @param[in] p_ble_hrs_c Pointer to the heart rate client structure.
Rohit Grover 65:98215c4f3a25 131 * @param[in] p_ble_hrs_c_init Pointer to the heart rate initialization structure containing the
Rohit Grover 65:98215c4f3a25 132 * initialization information.
Rohit Grover 65:98215c4f3a25 133 *
Rohit Grover 65:98215c4f3a25 134 * @retval NRF_SUCCESS On successful initialization. Otherwise an error code. This function
Rohit Grover 65:98215c4f3a25 135 * propagates the error code returned by the Database Discovery module API
Rohit Grover 65:98215c4f3a25 136 * @ref ble_db_discovery_evt_register.
Rohit Grover 65:98215c4f3a25 137 */
Rohit Grover 65:98215c4f3a25 138 uint32_t ble_hrs_c_init(ble_hrs_c_t * p_ble_hrs_c, ble_hrs_c_init_t * p_ble_hrs_c_init);
Rohit Grover 65:98215c4f3a25 139
Rohit Grover 65:98215c4f3a25 140 /**@brief Function for handling BLE events from the SoftDevice.
Rohit Grover 65:98215c4f3a25 141 *
Rohit Grover 65:98215c4f3a25 142 * @details This function will handle the BLE events received from the SoftDevice. If a BLE
Rohit Grover 65:98215c4f3a25 143 * event is relevant to the Heart Rate Client module, then it uses it to update
Rohit Grover 65:98215c4f3a25 144 * interval variables and, if necessary, send events to the application.
Rohit Grover 65:98215c4f3a25 145 *
Rohit Grover 65:98215c4f3a25 146 * @param[in] p_ble_hrs_c Pointer to the heart rate client structure.
Rohit Grover 65:98215c4f3a25 147 * @param[in] p_ble_evt Pointer to the BLE event.
Rohit Grover 65:98215c4f3a25 148 */
Rohit Grover 65:98215c4f3a25 149 void ble_hrs_c_on_ble_evt(ble_hrs_c_t * p_ble_hrs_c, const ble_evt_t * p_ble_evt);
Rohit Grover 65:98215c4f3a25 150
Rohit Grover 65:98215c4f3a25 151
Rohit Grover 65:98215c4f3a25 152 /**@brief Function for requesting the peer to start sending notification of Heart Rate
Rohit Grover 65:98215c4f3a25 153 * Measurement.
Rohit Grover 65:98215c4f3a25 154 *
Rohit Grover 65:98215c4f3a25 155 * @details This function will enable to notification of the Heart Rate Measurement at the peer
Rohit Grover 65:98215c4f3a25 156 * by writing to the CCCD of the Heart Rate Measurement Characteristic.
Rohit Grover 65:98215c4f3a25 157 *
Rohit Grover 65:98215c4f3a25 158 * @param p_ble_hrs_c Pointer to the heart rate client structure.
Rohit Grover 65:98215c4f3a25 159 *
Rohit Grover 65:98215c4f3a25 160 * @retval NRF_SUCCESS If the SoftDevice has been requested to write to the CCCD of the peer.
Rohit Grover 65:98215c4f3a25 161 * Otherwise, an error code. This function propagates the error code returned
Rohit Grover 65:98215c4f3a25 162 * by the SoftDevice API @ref sd_ble_gattc_write.
Rohit Grover 65:98215c4f3a25 163 */
Rohit Grover 65:98215c4f3a25 164 uint32_t ble_hrs_c_hrm_notif_enable(ble_hrs_c_t * p_ble_hrs_c);
Rohit Grover 65:98215c4f3a25 165
Rohit Grover 65:98215c4f3a25 166 /** @} */ // End tag for Function group.
Rohit Grover 65:98215c4f3a25 167
Rohit Grover 65:98215c4f3a25 168 #endif // BLE_HRS_C_H__
Rohit Grover 65:98215c4f3a25 169
Rohit Grover 65:98215c4f3a25 170 /** @} */ // End tag for the file.