iOSのBLEコントローラアプリ「RCBController」と接続し、コントローラの操作を取得するサンプルプログラムです。 mbed HRM1017で動作を確認しています。 2014.08.20時点でのBLEライブラリに対応しました。

Dependencies:   BLE_API mbed

Fork of BLE_RCBController by Junichi Katsu

Committer:
jksoft
Date:
Wed Aug 20 13:41:01 2014 +0000
Revision:
4:ebda47d22091
Parent:
nRF51822/nordic/nrf-sdk/ble/ble_services/ble_hrs.h@1:48f6e08a3ac2
?????????

Who changed what in which revision?

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