![](/media/cache/profiles/5f14615696649541a025d3d0f8e0447f.jpg.50x50_q85.jpg)
テスト用です。
nRF51822_wallbot/nordic/nrf-sdk/ble/ble_services/ble_bas_c.h@0:8468a4403fea, 2016-10-11 (annotated)
- Committer:
- jksoft
- Date:
- Tue Oct 11 11:09:42 2016 +0000
- Revision:
- 0:8468a4403fea
SB??ver;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:8468a4403fea | 1 | /* |
jksoft | 0:8468a4403fea | 2 | * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. |
jksoft | 0:8468a4403fea | 3 | * |
jksoft | 0:8468a4403fea | 4 | * The information contained herein is confidential property of Nordic Semiconductor. The use, |
jksoft | 0:8468a4403fea | 5 | * copying, transfer or disclosure of such information is prohibited except by express written |
jksoft | 0:8468a4403fea | 6 | * agreement with Nordic Semiconductor. |
jksoft | 0:8468a4403fea | 7 | * |
jksoft | 0:8468a4403fea | 8 | */ |
jksoft | 0:8468a4403fea | 9 | |
jksoft | 0:8468a4403fea | 10 | /**@file |
jksoft | 0:8468a4403fea | 11 | * |
jksoft | 0:8468a4403fea | 12 | * @defgroup ble_sdk_srv_bas_c Battery Service Client |
jksoft | 0:8468a4403fea | 13 | * @{ |
jksoft | 0:8468a4403fea | 14 | * @ingroup ble_sdk_srv |
jksoft | 0:8468a4403fea | 15 | * @brief Battery Service Client module. |
jksoft | 0:8468a4403fea | 16 | * |
jksoft | 0:8468a4403fea | 17 | * @details This module contains APIs to read and interact with the Battery Service of a remote |
jksoft | 0:8468a4403fea | 18 | * device. |
jksoft | 0:8468a4403fea | 19 | * |
jksoft | 0:8468a4403fea | 20 | * @note The application must propagate BLE stack events to this module by calling |
jksoft | 0:8468a4403fea | 21 | * ble_hrs_c_on_ble_evt(). |
jksoft | 0:8468a4403fea | 22 | * |
jksoft | 0:8468a4403fea | 23 | */ |
jksoft | 0:8468a4403fea | 24 | |
jksoft | 0:8468a4403fea | 25 | #ifndef BLE_BAS_C_H__ |
jksoft | 0:8468a4403fea | 26 | #define BLE_BAS_C_H__ |
jksoft | 0:8468a4403fea | 27 | |
jksoft | 0:8468a4403fea | 28 | #include <stdint.h> |
jksoft | 0:8468a4403fea | 29 | #include "ble.h" |
jksoft | 0:8468a4403fea | 30 | |
jksoft | 0:8468a4403fea | 31 | /** |
jksoft | 0:8468a4403fea | 32 | * @defgroup bas_c_enums Enumerations |
jksoft | 0:8468a4403fea | 33 | * @{ |
jksoft | 0:8468a4403fea | 34 | */ |
jksoft | 0:8468a4403fea | 35 | |
jksoft | 0:8468a4403fea | 36 | /**@brief Battery Service Client event type. */ |
jksoft | 0:8468a4403fea | 37 | typedef enum |
jksoft | 0:8468a4403fea | 38 | { |
jksoft | 0:8468a4403fea | 39 | BLE_BAS_C_EVT_DISCOVERY_COMPLETE, /**< Event indicating that the Battery Service has been discovered at the peer. */ |
jksoft | 0:8468a4403fea | 40 | BLE_BAS_C_EVT_BATT_NOTIFICATION, /**< Event indicating that a notification of the Battery Level characteristic has been received from the peer. */ |
jksoft | 0:8468a4403fea | 41 | BLE_BAS_C_EVT_BATT_READ_RESP /**< Event indicating that a read response on Battery Level characteristic has been received from peer. */ |
jksoft | 0:8468a4403fea | 42 | } ble_bas_c_evt_type_t; |
jksoft | 0:8468a4403fea | 43 | |
jksoft | 0:8468a4403fea | 44 | /** @} */ |
jksoft | 0:8468a4403fea | 45 | |
jksoft | 0:8468a4403fea | 46 | /** |
jksoft | 0:8468a4403fea | 47 | * @defgroup bas_c_structs Structures |
jksoft | 0:8468a4403fea | 48 | * @{ |
jksoft | 0:8468a4403fea | 49 | */ |
jksoft | 0:8468a4403fea | 50 | |
jksoft | 0:8468a4403fea | 51 | /**@brief Battery Service Client Event structure. */ |
jksoft | 0:8468a4403fea | 52 | typedef struct |
jksoft | 0:8468a4403fea | 53 | { |
jksoft | 0:8468a4403fea | 54 | ble_bas_c_evt_type_t evt_type; /**< Event Type. */ |
jksoft | 0:8468a4403fea | 55 | union |
jksoft | 0:8468a4403fea | 56 | { |
jksoft | 0:8468a4403fea | 57 | uint8_t battery_level; /**< Battery level received from peer. This field will be used for the events @ref BLE_BAS_C_EVT_BATT_NOTIFICATION and @ref BLE_BAS_C_EVT_BATT_READ_RESP.*/ |
jksoft | 0:8468a4403fea | 58 | } params; |
jksoft | 0:8468a4403fea | 59 | } ble_bas_c_evt_t; |
jksoft | 0:8468a4403fea | 60 | |
jksoft | 0:8468a4403fea | 61 | /** @} */ |
jksoft | 0:8468a4403fea | 62 | |
jksoft | 0:8468a4403fea | 63 | /** |
jksoft | 0:8468a4403fea | 64 | * @defgroup bas_c_types Types |
jksoft | 0:8468a4403fea | 65 | * @{ |
jksoft | 0:8468a4403fea | 66 | */ |
jksoft | 0:8468a4403fea | 67 | |
jksoft | 0:8468a4403fea | 68 | // Forward declaration of the ble_bas_t type. |
jksoft | 0:8468a4403fea | 69 | typedef struct ble_bas_c_s ble_bas_c_t; |
jksoft | 0:8468a4403fea | 70 | |
jksoft | 0:8468a4403fea | 71 | /**@brief Event handler type. |
jksoft | 0:8468a4403fea | 72 | * |
jksoft | 0:8468a4403fea | 73 | * @details This is the type of the event handler that should be provided by the application |
jksoft | 0:8468a4403fea | 74 | * of this module in order to receive events. |
jksoft | 0:8468a4403fea | 75 | */ |
jksoft | 0:8468a4403fea | 76 | typedef void (* ble_bas_c_evt_handler_t) (ble_bas_c_t * p_bas_bas_c, ble_bas_c_evt_t * p_evt); |
jksoft | 0:8468a4403fea | 77 | |
jksoft | 0:8468a4403fea | 78 | /** @} */ |
jksoft | 0:8468a4403fea | 79 | |
jksoft | 0:8468a4403fea | 80 | /** |
jksoft | 0:8468a4403fea | 81 | * @addtogroup bas_c_structs |
jksoft | 0:8468a4403fea | 82 | * @{ |
jksoft | 0:8468a4403fea | 83 | */ |
jksoft | 0:8468a4403fea | 84 | |
jksoft | 0:8468a4403fea | 85 | /**@brief Battery Service Client structure. |
jksoft | 0:8468a4403fea | 86 | |
jksoft | 0:8468a4403fea | 87 | */ |
jksoft | 0:8468a4403fea | 88 | typedef struct ble_bas_c_s |
jksoft | 0:8468a4403fea | 89 | { |
jksoft | 0:8468a4403fea | 90 | uint16_t conn_handle; /**< Connection handle as provided by the SoftDevice. */ |
jksoft | 0:8468a4403fea | 91 | uint16_t bl_cccd_handle; /**< Handle of the CCCD of the Battery Level characteristic. */ |
jksoft | 0:8468a4403fea | 92 | uint16_t bl_handle; /**< Handle of the Battery Level characteristic as provided by the SoftDevice. */ |
jksoft | 0:8468a4403fea | 93 | ble_bas_c_evt_handler_t evt_handler; /**< Application event handler to be called when there is an event related to the Battery service. */ |
jksoft | 0:8468a4403fea | 94 | } ble_bas_c_t; |
jksoft | 0:8468a4403fea | 95 | |
jksoft | 0:8468a4403fea | 96 | /**@brief Battery Service Client initialization structure. |
jksoft | 0:8468a4403fea | 97 | */ |
jksoft | 0:8468a4403fea | 98 | typedef struct |
jksoft | 0:8468a4403fea | 99 | { |
jksoft | 0:8468a4403fea | 100 | ble_bas_c_evt_handler_t evt_handler; /**< Event handler to be called by the Battery Service Client module whenever there is an event related to the Battery Service. */ |
jksoft | 0:8468a4403fea | 101 | } ble_bas_c_init_t; |
jksoft | 0:8468a4403fea | 102 | |
jksoft | 0:8468a4403fea | 103 | /** @} */ |
jksoft | 0:8468a4403fea | 104 | |
jksoft | 0:8468a4403fea | 105 | /** |
jksoft | 0:8468a4403fea | 106 | * @defgroup bas_c_functions Functions |
jksoft | 0:8468a4403fea | 107 | * @{ |
jksoft | 0:8468a4403fea | 108 | */ |
jksoft | 0:8468a4403fea | 109 | |
jksoft | 0:8468a4403fea | 110 | /**@brief Function for initializing the Battery Service Client module. |
jksoft | 0:8468a4403fea | 111 | * |
jksoft | 0:8468a4403fea | 112 | * @details This function will initialize the module and set up Database Discovery to discover |
jksoft | 0:8468a4403fea | 113 | * the Battery Service. After calling this function, call @ref ble_db_discovery_start |
jksoft | 0:8468a4403fea | 114 | * to start discovery. |
jksoft | 0:8468a4403fea | 115 | * |
jksoft | 0:8468a4403fea | 116 | * @param[out] p_ble_bas_c Pointer to the Battery Service client structure. |
jksoft | 0:8468a4403fea | 117 | * @param[in] p_ble_bas_c_init Pointer to the Battery Service initialization structure containing |
jksoft | 0:8468a4403fea | 118 | * the initialization information. |
jksoft | 0:8468a4403fea | 119 | * |
jksoft | 0:8468a4403fea | 120 | * @retval NRF_SUCCESS Operation success. |
jksoft | 0:8468a4403fea | 121 | * @retval NRF_ERROR_NULL A parameter is NULL. |
jksoft | 0:8468a4403fea | 122 | * Otherwise, an error code returned by @ref ble_db_discovery_register. |
jksoft | 0:8468a4403fea | 123 | */ |
jksoft | 0:8468a4403fea | 124 | uint32_t ble_bas_c_init(ble_bas_c_t * p_ble_bas_c, ble_bas_c_init_t * p_ble_bas_c_init); |
jksoft | 0:8468a4403fea | 125 | |
jksoft | 0:8468a4403fea | 126 | |
jksoft | 0:8468a4403fea | 127 | /**@brief Function for handling BLE events from the SoftDevice. |
jksoft | 0:8468a4403fea | 128 | * |
jksoft | 0:8468a4403fea | 129 | * @details This function will handle the BLE events received from the SoftDevice. If the BLE |
jksoft | 0:8468a4403fea | 130 | * event is relevant for the Battery Service Client module, then it is used to update |
jksoft | 0:8468a4403fea | 131 | * interval variables and, if necessary, send events to the application. |
jksoft | 0:8468a4403fea | 132 | * |
jksoft | 0:8468a4403fea | 133 | * @note This function must be called by the application. |
jksoft | 0:8468a4403fea | 134 | * |
jksoft | 0:8468a4403fea | 135 | * @param[in] p_ble_bas_c Pointer to the Battery Service client structure. |
jksoft | 0:8468a4403fea | 136 | * @param[in] p_ble_evt Pointer to the BLE event. |
jksoft | 0:8468a4403fea | 137 | */ |
jksoft | 0:8468a4403fea | 138 | void ble_bas_c_on_ble_evt(ble_bas_c_t * p_ble_bas_c, const ble_evt_t * p_ble_evt); |
jksoft | 0:8468a4403fea | 139 | |
jksoft | 0:8468a4403fea | 140 | |
jksoft | 0:8468a4403fea | 141 | /**@brief Function for enabling notifications on the Battery Level characteristic. |
jksoft | 0:8468a4403fea | 142 | * |
jksoft | 0:8468a4403fea | 143 | * @details This function will enable to notification of the Battery Level characteristic at the |
jksoft | 0:8468a4403fea | 144 | * peer by writing to the CCCD of the Battery Level Characteristic. |
jksoft | 0:8468a4403fea | 145 | * |
jksoft | 0:8468a4403fea | 146 | * @param p_ble_bas_c Pointer to the Battery Service client structure. |
jksoft | 0:8468a4403fea | 147 | * |
jksoft | 0:8468a4403fea | 148 | * @retval NRF_SUCCESS If the SoftDevice has been requested to write to the CCCD of the peer. |
jksoft | 0:8468a4403fea | 149 | * NRF_ERROR_NULL Parameter is NULL. |
jksoft | 0:8468a4403fea | 150 | * Otherwise, an error code returned by the SoftDevice API @ref |
jksoft | 0:8468a4403fea | 151 | * sd_ble_gattc_write. |
jksoft | 0:8468a4403fea | 152 | */ |
jksoft | 0:8468a4403fea | 153 | uint32_t ble_bas_c_bl_notif_enable(ble_bas_c_t * p_ble_bas_c); |
jksoft | 0:8468a4403fea | 154 | |
jksoft | 0:8468a4403fea | 155 | |
jksoft | 0:8468a4403fea | 156 | /**@brief Function for reading the Battery Level characteristic. |
jksoft | 0:8468a4403fea | 157 | * |
jksoft | 0:8468a4403fea | 158 | * @param p_ble_bas_c Pointer to the Battery Service client structure. |
jksoft | 0:8468a4403fea | 159 | * |
jksoft | 0:8468a4403fea | 160 | * @retval NRF_SUCCESS If the read request was successfully queued to be sent to peer. |
jksoft | 0:8468a4403fea | 161 | */ |
jksoft | 0:8468a4403fea | 162 | uint32_t ble_bas_c_bl_read(ble_bas_c_t * p_ble_bas_c); |
jksoft | 0:8468a4403fea | 163 | |
jksoft | 0:8468a4403fea | 164 | |
jksoft | 0:8468a4403fea | 165 | /** @} */ // End tag for Function group. |
jksoft | 0:8468a4403fea | 166 | |
jksoft | 0:8468a4403fea | 167 | #endif // BLE_BAS_C_H__ |
jksoft | 0:8468a4403fea | 168 | |
jksoft | 0:8468a4403fea | 169 | /** @} */ // End tag for the file. |