テスト用です。

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