nochanges

Dependents:   BLE_Acceleration_Statejudging

Fork of nRF51822 by Nordic Semiconductor

Committer:
MonroeLee
Date:
Thu Jun 09 05:15:47 2016 +0000
Revision:
638:6efcf74f000d
Parent:
37:c29c330d942c
no changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rohit Grover 37:c29c330d942c 1 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
Rohit Grover 37:c29c330d942c 2 *
Rohit Grover 37:c29c330d942c 3 * The information contained herein is property of Nordic Semiconductor ASA.
Rohit Grover 37:c29c330d942c 4 * Terms and conditions of usage are described in detail in NORDIC
Rohit Grover 37:c29c330d942c 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
Rohit Grover 37:c29c330d942c 6 *
Rohit Grover 37:c29c330d942c 7 * Licensees are granted free, non-transferable use of the information. NO
Rohit Grover 37:c29c330d942c 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
Rohit Grover 37:c29c330d942c 9 * the file.
Rohit Grover 37:c29c330d942c 10 *
Rohit Grover 37:c29c330d942c 11 */
Rohit Grover 37:c29c330d942c 12
Rohit Grover 37:c29c330d942c 13 /** @file
Rohit Grover 37:c29c330d942c 14 *
Rohit Grover 37:c29c330d942c 15 * @defgroup ble_sdk_srv_hrs Heart Rate Service
Rohit Grover 37:c29c330d942c 16 * @{
Rohit Grover 37:c29c330d942c 17 * @ingroup ble_sdk_srv
Rohit Grover 37:c29c330d942c 18 * @brief Heart Rate Service module.
Rohit Grover 37:c29c330d942c 19 *
Rohit Grover 37:c29c330d942c 20 * @details This module implements the Heart Rate Service with the Heart Rate Measurement,
Rohit Grover 37:c29c330d942c 21 * Body Sensor Location and Heart Rate Control Point characteristics.
Rohit Grover 37:c29c330d942c 22 * During initialization it adds the Heart Rate Service and Heart Rate Measurement
Rohit Grover 37:c29c330d942c 23 * characteristic to the BLE stack database. Optionally it also adds the
Rohit Grover 37:c29c330d942c 24 * Body Sensor Location and Heart Rate Control Point characteristics.
Rohit Grover 37:c29c330d942c 25 *
Rohit Grover 37:c29c330d942c 26 * If enabled, notification of the Heart Rate Measurement characteristic is performed
Rohit Grover 37:c29c330d942c 27 * when the application calls ble_hrs_heart_rate_measurement_send().
Rohit Grover 37:c29c330d942c 28 *
Rohit Grover 37:c29c330d942c 29 * The Heart Rate Service also provides a set of functions for manipulating the
Rohit Grover 37:c29c330d942c 30 * various fields in the Heart Rate Measurement characteristic, as well as setting
Rohit Grover 37:c29c330d942c 31 * the Body Sensor Location characteristic value.
Rohit Grover 37:c29c330d942c 32 *
Rohit Grover 37:c29c330d942c 33 * If an event handler is supplied by the application, the Heart Rate Service will
Rohit Grover 37:c29c330d942c 34 * generate Heart Rate Service events to the application.
Rohit Grover 37:c29c330d942c 35 *
Rohit Grover 37:c29c330d942c 36 * @note The application must propagate BLE stack events to the Heart Rate Service module by calling
Rohit Grover 37:c29c330d942c 37 * ble_hrs_on_ble_evt() from the from the @ref ble_stack_handler callback.
Rohit Grover 37:c29c330d942c 38 *
Rohit Grover 37:c29c330d942c 39 * @note Attention!
Rohit Grover 37:c29c330d942c 40 * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile
Rohit Grover 37:c29c330d942c 41 * qualification listings, this section of source code must not be modified.
Rohit Grover 37:c29c330d942c 42 */
Rohit Grover 37:c29c330d942c 43
Rohit Grover 37:c29c330d942c 44 #ifndef BLE_HRS_H__
Rohit Grover 37:c29c330d942c 45 #define BLE_HRS_H__
Rohit Grover 37:c29c330d942c 46
Rohit Grover 37:c29c330d942c 47 #include <stdint.h>
Rohit Grover 37:c29c330d942c 48 #include <stdbool.h>
Rohit Grover 37:c29c330d942c 49 #include "ble.h"
Rohit Grover 37:c29c330d942c 50 #include "ble_srv_common.h"
Rohit Grover 37:c29c330d942c 51
Rohit Grover 37:c29c330d942c 52 // Body Sensor Location values
Rohit Grover 37:c29c330d942c 53 #define BLE_HRS_BODY_SENSOR_LOCATION_OTHER 0
Rohit Grover 37:c29c330d942c 54 #define BLE_HRS_BODY_SENSOR_LOCATION_CHEST 1
Rohit Grover 37:c29c330d942c 55 #define BLE_HRS_BODY_SENSOR_LOCATION_WRIST 2
Rohit Grover 37:c29c330d942c 56 #define BLE_HRS_BODY_SENSOR_LOCATION_FINGER 3
Rohit Grover 37:c29c330d942c 57 #define BLE_HRS_BODY_SENSOR_LOCATION_HAND 4
Rohit Grover 37:c29c330d942c 58 #define BLE_HRS_BODY_SENSOR_LOCATION_EAR_LOBE 5
Rohit Grover 37:c29c330d942c 59 #define BLE_HRS_BODY_SENSOR_LOCATION_FOOT 6
Rohit Grover 37:c29c330d942c 60
Rohit Grover 37:c29c330d942c 61 #define BLE_HRS_MAX_BUFFERED_RR_INTERVALS 20 /**< Size of RR Interval buffer inside service. */
Rohit Grover 37:c29c330d942c 62
Rohit Grover 37:c29c330d942c 63 /**@brief Heart Rate Service event type. */
Rohit Grover 37:c29c330d942c 64 typedef enum
Rohit Grover 37:c29c330d942c 65 {
Rohit Grover 37:c29c330d942c 66 BLE_HRS_EVT_NOTIFICATION_ENABLED, /**< Heart Rate value notification enabled event. */
Rohit Grover 37:c29c330d942c 67 BLE_HRS_EVT_NOTIFICATION_DISABLED /**< Heart Rate value notification disabled event. */
Rohit Grover 37:c29c330d942c 68 } ble_hrs_evt_type_t;
Rohit Grover 37:c29c330d942c 69
Rohit Grover 37:c29c330d942c 70 /**@brief Heart Rate Service event. */
Rohit Grover 37:c29c330d942c 71 typedef struct
Rohit Grover 37:c29c330d942c 72 {
Rohit Grover 37:c29c330d942c 73 ble_hrs_evt_type_t evt_type; /**< Type of event. */
Rohit Grover 37:c29c330d942c 74 } ble_hrs_evt_t;
Rohit Grover 37:c29c330d942c 75
Rohit Grover 37:c29c330d942c 76 // Forward declaration of the ble_hrs_t type.
Rohit Grover 37:c29c330d942c 77 typedef struct ble_hrs_s ble_hrs_t;
Rohit Grover 37:c29c330d942c 78
Rohit Grover 37:c29c330d942c 79 /**@brief Heart Rate Service event handler type. */
Rohit Grover 37:c29c330d942c 80 typedef void (*ble_hrs_evt_handler_t) (ble_hrs_t * p_hrs, ble_hrs_evt_t * p_evt);
Rohit Grover 37:c29c330d942c 81
Rohit Grover 37:c29c330d942c 82 /**@brief Heart Rate Service init structure. This contains all options and data needed for
Rohit Grover 37:c29c330d942c 83 * initialization of the service. */
Rohit Grover 37:c29c330d942c 84 typedef struct
Rohit Grover 37:c29c330d942c 85 {
Rohit Grover 37:c29c330d942c 86 ble_hrs_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Heart Rate Service. */
Rohit Grover 37:c29c330d942c 87 bool is_sensor_contact_supported; /**< Determines if sensor contact detection is to be supported. */
Rohit Grover 37:c29c330d942c 88 uint8_t * p_body_sensor_location; /**< If not NULL, initial value of the Body Sensor Location characteristic. */
Rohit Grover 37:c29c330d942c 89 ble_srv_cccd_security_mode_t hrs_hrm_attr_md; /**< Initial security level for heart rate service measurement attribute */
Rohit Grover 37:c29c330d942c 90 ble_srv_security_mode_t hrs_bsl_attr_md; /**< Initial security level for body sensor location attribute */
Rohit Grover 37:c29c330d942c 91 } ble_hrs_init_t;
Rohit Grover 37:c29c330d942c 92
Rohit Grover 37:c29c330d942c 93 /**@brief Heart Rate Service structure. This contains various status information for the service. */
Rohit Grover 37:c29c330d942c 94 typedef struct ble_hrs_s
Rohit Grover 37:c29c330d942c 95 {
Rohit Grover 37:c29c330d942c 96 ble_hrs_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Heart Rate Service. */
Rohit Grover 37:c29c330d942c 97 bool is_expended_energy_supported; /**< TRUE if Expended Energy measurement is supported. */
Rohit Grover 37:c29c330d942c 98 bool is_sensor_contact_supported; /**< TRUE if sensor contact detection is supported. */
Rohit Grover 37:c29c330d942c 99 uint16_t service_handle; /**< Handle of Heart Rate Service (as provided by the BLE stack). */
Rohit Grover 37:c29c330d942c 100 ble_gatts_char_handles_t hrm_handles; /**< Handles related to the Heart Rate Measurement characteristic. */
Rohit Grover 37:c29c330d942c 101 ble_gatts_char_handles_t bsl_handles; /**< Handles related to the Body Sensor Location characteristic. */
Rohit Grover 37:c29c330d942c 102 ble_gatts_char_handles_t hrcp_handles; /**< Handles related to the Heart Rate Control Point characteristic. */
Rohit Grover 37:c29c330d942c 103 uint16_t conn_handle; /**< Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection). */
Rohit Grover 37:c29c330d942c 104 bool is_sensor_contact_detected; /**< TRUE if sensor contact has been detected. */
Rohit Grover 37:c29c330d942c 105 uint16_t rr_interval[BLE_HRS_MAX_BUFFERED_RR_INTERVALS]; /**< Set of RR Interval measurements since the last Heart Rate Measurement transmission. */
Rohit Grover 37:c29c330d942c 106 uint16_t rr_interval_count; /**< Number of RR Interval measurements since the last Heart Rate Measurement transmission. */
Rohit Grover 37:c29c330d942c 107 } ble_hrs_t;
Rohit Grover 37:c29c330d942c 108
Rohit Grover 37:c29c330d942c 109 /**@brief Function for initializing the Heart Rate Service.
Rohit Grover 37:c29c330d942c 110 *
Rohit Grover 37:c29c330d942c 111 * @param[out] p_hrs Heart Rate Service structure. This structure will have to be supplied by
Rohit Grover 37:c29c330d942c 112 * the application. It will be initialized by this function, and will later
Rohit Grover 37:c29c330d942c 113 * be used to identify this particular service instance.
Rohit Grover 37:c29c330d942c 114 * @param[in] p_hrs_init Information needed to initialize the service.
Rohit Grover 37:c29c330d942c 115 *
Rohit Grover 37:c29c330d942c 116 * @return NRF_SUCCESS on successful initialization of service, otherwise an error code.
Rohit Grover 37:c29c330d942c 117 */
Rohit Grover 37:c29c330d942c 118 uint32_t ble_hrs_init(ble_hrs_t * p_hrs, const ble_hrs_init_t * p_hrs_init);
Rohit Grover 37:c29c330d942c 119
Rohit Grover 37:c29c330d942c 120 /**@brief Function for handling the Application's BLE Stack events.
Rohit Grover 37:c29c330d942c 121 *
Rohit Grover 37:c29c330d942c 122 * @details Handles all events from the BLE stack of interest to the Heart Rate Service.
Rohit Grover 37:c29c330d942c 123 *
Rohit Grover 37:c29c330d942c 124 * @param[in] p_hrs Heart Rate Service structure.
Rohit Grover 37:c29c330d942c 125 * @param[in] p_ble_evt Event received from the BLE stack.
Rohit Grover 37:c29c330d942c 126 */
Rohit Grover 37:c29c330d942c 127 void ble_hrs_on_ble_evt(ble_hrs_t * p_hrs, ble_evt_t * p_ble_evt);
Rohit Grover 37:c29c330d942c 128
Rohit Grover 37:c29c330d942c 129 /**@brief Function for sending heart rate measurement if notification has been enabled.
Rohit Grover 37:c29c330d942c 130 *
Rohit Grover 37:c29c330d942c 131 * @details The application calls this function after having performed a heart rate measurement.
Rohit Grover 37:c29c330d942c 132 * If notification has been enabled, the heart rate measurement data is encoded and sent to
Rohit Grover 37:c29c330d942c 133 * the client.
Rohit Grover 37:c29c330d942c 134 *
Rohit Grover 37:c29c330d942c 135 * @param[in] p_hrs Heart Rate Service structure.
Rohit Grover 37:c29c330d942c 136 * @param[in] heart_rate New heart rate measurement.
Rohit Grover 37:c29c330d942c 137 * @param[in] include_expended_energy Determines if expended energy will be included in the
Rohit Grover 37:c29c330d942c 138 * heart rate measurement data.
Rohit Grover 37:c29c330d942c 139 *
Rohit Grover 37:c29c330d942c 140 * @return NRF_SUCCESS on success, otherwise an error code.
Rohit Grover 37:c29c330d942c 141 */
Rohit Grover 37:c29c330d942c 142 uint32_t ble_hrs_heart_rate_measurement_send(ble_hrs_t * p_hrs, uint16_t heart_rate);
Rohit Grover 37:c29c330d942c 143
Rohit Grover 37:c29c330d942c 144 /**@brief Function for adding a RR Interval measurement to the RR Interval buffer.
Rohit Grover 37:c29c330d942c 145 *
Rohit Grover 37:c29c330d942c 146 * @details All buffered RR Interval measurements will be included in the next heart rate
Rohit Grover 37:c29c330d942c 147 * measurement message, up to the maximum number of measurements that will fit into the
Rohit Grover 37:c29c330d942c 148 * message. If the buffer is full, the oldest measurement in the buffer will be deleted.
Rohit Grover 37:c29c330d942c 149 *
Rohit Grover 37:c29c330d942c 150 * @param[in] p_hrs Heart Rate Service structure.
Rohit Grover 37:c29c330d942c 151 * @param[in] rr_interval New RR Interval measurement (will be buffered until the next
Rohit Grover 37:c29c330d942c 152 * transmission of Heart Rate Measurement).
Rohit Grover 37:c29c330d942c 153 */
Rohit Grover 37:c29c330d942c 154 void ble_hrs_rr_interval_add(ble_hrs_t * p_hrs, uint16_t rr_interval);
Rohit Grover 37:c29c330d942c 155
Rohit Grover 37:c29c330d942c 156 /**@brief Function for checking if RR Interval buffer is full.
Rohit Grover 37:c29c330d942c 157 *
Rohit Grover 37:c29c330d942c 158 * @param[in] p_hrs Heart Rate Service structure.
Rohit Grover 37:c29c330d942c 159 *
Rohit Grover 37:c29c330d942c 160 * @return true if RR Interval buffer is full, false otherwise.
Rohit Grover 37:c29c330d942c 161 */
Rohit Grover 37:c29c330d942c 162 bool ble_hrs_rr_interval_buffer_is_full(ble_hrs_t * p_hrs);
Rohit Grover 37:c29c330d942c 163
Rohit Grover 37:c29c330d942c 164 /**@brief Function for setting the state of the Sensor Contact Supported bit.
Rohit Grover 37:c29c330d942c 165 *
Rohit Grover 37:c29c330d942c 166 * @param[in] p_hrs Heart Rate Service structure.
Rohit Grover 37:c29c330d942c 167 * @param[in] is_sensor_contact_supported New state of the Sensor Contact Supported bit.
Rohit Grover 37:c29c330d942c 168 *
Rohit Grover 37:c29c330d942c 169 * @return NRF_SUCCESS on success, otherwise an error code.
Rohit Grover 37:c29c330d942c 170 */
Rohit Grover 37:c29c330d942c 171 uint32_t ble_hrs_sensor_contact_supported_set(ble_hrs_t * p_hrs, bool is_sensor_contact_supported);
Rohit Grover 37:c29c330d942c 172
Rohit Grover 37:c29c330d942c 173 /**@brief Function for setting the state of the Sensor Contact Detected bit.
Rohit Grover 37:c29c330d942c 174 *
Rohit Grover 37:c29c330d942c 175 * @param[in] p_hrs Heart Rate Service structure.
Rohit Grover 37:c29c330d942c 176 * @param[in] is_sensor_contact_detected TRUE if sensor contact is detected, FALSE otherwise.
Rohit Grover 37:c29c330d942c 177 */
Rohit Grover 37:c29c330d942c 178 void ble_hrs_sensor_contact_detected_update(ble_hrs_t * p_hrs, bool is_sensor_contact_detected);
Rohit Grover 37:c29c330d942c 179
Rohit Grover 37:c29c330d942c 180 /**@brief Function for setting the Body Sensor Location.
Rohit Grover 37:c29c330d942c 181 *
Rohit Grover 37:c29c330d942c 182 * @details Sets a new value of the Body Sensor Location characteristic. The new value will be sent
Rohit Grover 37:c29c330d942c 183 * to the client the next time the client reads the Body Sensor Location characteristic.
Rohit Grover 37:c29c330d942c 184 *
Rohit Grover 37:c29c330d942c 185 * @param[in] p_hrs Heart Rate Service structure.
Rohit Grover 37:c29c330d942c 186 * @param[in] body_sensor_location New Body Sensor Location.
Rohit Grover 37:c29c330d942c 187 *
Rohit Grover 37:c29c330d942c 188 * @return NRF_SUCCESS on success, otherwise an error code.
Rohit Grover 37:c29c330d942c 189 */
Rohit Grover 37:c29c330d942c 190 uint32_t ble_hrs_body_sensor_location_set(ble_hrs_t * p_hrs, uint8_t body_sensor_location);
Rohit Grover 37:c29c330d942c 191
Rohit Grover 37:c29c330d942c 192 #endif // BLE_HRS_H__
Rohit Grover 37:c29c330d942c 193
Rohit Grover 37:c29c330d942c 194 /** @} */