Yutaka Yoshida / Mbed 2 deprecated BLE_WallbotBLE_Challenge_byYUTAKA3

Dependencies:   mbed

Fork of BLE_WallbotBLE_Challenge_byYUTAKA3 by Maiko Matsumoto

Committer:
Dyotty
Date:
Fri Jun 29 04:13:37 2018 +0000
Revision:
15:e98de98d9328
Parent:
0:76dfa9657d9d
6/28 ??????

Who changed what in which revision?

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