テスト用です。

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_bas Battery Service
jksoft 0:8468a4403fea 16 * @{
jksoft 0:8468a4403fea 17 * @ingroup ble_sdk_srv
jksoft 0:8468a4403fea 18 * @brief Battery Service module.
jksoft 0:8468a4403fea 19 *
jksoft 0:8468a4403fea 20 * @details This module implements the Battery Service with the Battery Level characteristic.
jksoft 0:8468a4403fea 21 * During initialization it adds the Battery Service and Battery Level characteristic
jksoft 0:8468a4403fea 22 * to the BLE stack database. Optionally it can also add a Report Reference descriptor
jksoft 0:8468a4403fea 23 * to the Battery Level characteristic (used when including the Battery Service in
jksoft 0:8468a4403fea 24 * the HID service).
jksoft 0:8468a4403fea 25 *
jksoft 0:8468a4403fea 26 * If specified, the module will support notification of the Battery Level characteristic
jksoft 0:8468a4403fea 27 * through the ble_bas_battery_level_update() function.
jksoft 0:8468a4403fea 28 * If an event handler is supplied by the application, the Battery Service will
jksoft 0:8468a4403fea 29 * generate Battery Service events to the application.
jksoft 0:8468a4403fea 30 *
jksoft 0:8468a4403fea 31 * @note The application must propagate BLE stack events to the Battery Service module by calling
jksoft 0:8468a4403fea 32 * ble_bas_on_ble_evt() from the from the @ref ble_stack_handler callback.
jksoft 0:8468a4403fea 33 *
jksoft 0:8468a4403fea 34 * @note Attention!
jksoft 0:8468a4403fea 35 * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile
jksoft 0:8468a4403fea 36 * qualification listings, this section of source code must not be modified.
jksoft 0:8468a4403fea 37 */
jksoft 0:8468a4403fea 38
jksoft 0:8468a4403fea 39 #ifndef BLE_BAS_H__
jksoft 0:8468a4403fea 40 #define BLE_BAS_H__
jksoft 0:8468a4403fea 41
jksoft 0:8468a4403fea 42 #include <stdint.h>
jksoft 0:8468a4403fea 43 #include <stdbool.h>
jksoft 0:8468a4403fea 44 #include "ble.h"
jksoft 0:8468a4403fea 45 #include "ble_srv_common.h"
jksoft 0:8468a4403fea 46
jksoft 0:8468a4403fea 47 /**@brief Battery Service event type. */
jksoft 0:8468a4403fea 48 typedef enum
jksoft 0:8468a4403fea 49 {
jksoft 0:8468a4403fea 50 BLE_BAS_EVT_NOTIFICATION_ENABLED, /**< Battery value notification enabled event. */
jksoft 0:8468a4403fea 51 BLE_BAS_EVT_NOTIFICATION_DISABLED /**< Battery value notification disabled event. */
jksoft 0:8468a4403fea 52 } ble_bas_evt_type_t;
jksoft 0:8468a4403fea 53
jksoft 0:8468a4403fea 54 /**@brief Battery Service event. */
jksoft 0:8468a4403fea 55 typedef struct
jksoft 0:8468a4403fea 56 {
jksoft 0:8468a4403fea 57 ble_bas_evt_type_t evt_type; /**< Type of event. */
jksoft 0:8468a4403fea 58 } ble_bas_evt_t;
jksoft 0:8468a4403fea 59
jksoft 0:8468a4403fea 60 // Forward declaration of the ble_bas_t type.
jksoft 0:8468a4403fea 61 typedef struct ble_bas_s ble_bas_t;
jksoft 0:8468a4403fea 62
jksoft 0:8468a4403fea 63 /**@brief Battery Service event handler type. */
jksoft 0:8468a4403fea 64 typedef void (*ble_bas_evt_handler_t) (ble_bas_t * p_bas, ble_bas_evt_t * p_evt);
jksoft 0:8468a4403fea 65
jksoft 0:8468a4403fea 66 /**@brief Battery Service init structure. This contains all options and data needed for
jksoft 0:8468a4403fea 67 * initialization of the service.*/
jksoft 0:8468a4403fea 68 typedef struct
jksoft 0:8468a4403fea 69 {
jksoft 0:8468a4403fea 70 ble_bas_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Battery Service. */
jksoft 0:8468a4403fea 71 bool support_notification; /**< TRUE if notification of Battery Level measurement is supported. */
jksoft 0:8468a4403fea 72 ble_srv_report_ref_t * p_report_ref; /**< If not NULL, a Report Reference descriptor with the specified value will be added to the Battery Level characteristic */
jksoft 0:8468a4403fea 73 uint8_t initial_batt_level; /**< Initial battery level */
jksoft 0:8468a4403fea 74 ble_srv_cccd_security_mode_t battery_level_char_attr_md; /**< Initial security level for battery characteristics attribute */
jksoft 0:8468a4403fea 75 ble_gap_conn_sec_mode_t battery_level_report_read_perm; /**< Initial security level for battery report read attribute */
jksoft 0:8468a4403fea 76 } ble_bas_init_t;
jksoft 0:8468a4403fea 77
jksoft 0:8468a4403fea 78 /**@brief Battery Service structure. This contains various status information for the service. */
jksoft 0:8468a4403fea 79 typedef struct ble_bas_s
jksoft 0:8468a4403fea 80 {
jksoft 0:8468a4403fea 81 ble_bas_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Battery Service. */
jksoft 0:8468a4403fea 82 uint16_t service_handle; /**< Handle of Battery Service (as provided by the BLE stack). */
jksoft 0:8468a4403fea 83 ble_gatts_char_handles_t battery_level_handles; /**< Handles related to the Battery Level characteristic. */
jksoft 0:8468a4403fea 84 uint16_t report_ref_handle; /**< Handle of the Report Reference descriptor. */
jksoft 0:8468a4403fea 85 uint8_t battery_level_last; /**< Last Battery Level measurement passed to the Battery Service. */
jksoft 0:8468a4403fea 86 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 87 bool is_notification_supported; /**< TRUE if notification of Battery Level is supported. */
jksoft 0:8468a4403fea 88 } ble_bas_t;
jksoft 0:8468a4403fea 89
jksoft 0:8468a4403fea 90 /**@brief Function for initializing the Battery Service.
jksoft 0:8468a4403fea 91 *
jksoft 0:8468a4403fea 92 * @param[out] p_bas Battery Service structure. This structure will have to be supplied by
jksoft 0:8468a4403fea 93 * the application. It will be initialized by this function, and will later
jksoft 0:8468a4403fea 94 * be used to identify this particular service instance.
jksoft 0:8468a4403fea 95 * @param[in] p_bas_init Information needed to initialize the service.
jksoft 0:8468a4403fea 96 *
jksoft 0:8468a4403fea 97 * @return NRF_SUCCESS on successful initialization of service, otherwise an error code.
jksoft 0:8468a4403fea 98 */
jksoft 0:8468a4403fea 99 uint32_t ble_bas_init(ble_bas_t * p_bas, const ble_bas_init_t * p_bas_init);
jksoft 0:8468a4403fea 100
jksoft 0:8468a4403fea 101 /**@brief Function for handling the Application's BLE Stack events.
jksoft 0:8468a4403fea 102 *
jksoft 0:8468a4403fea 103 * @details Handles all events from the BLE stack of interest to the Battery Service.
jksoft 0:8468a4403fea 104 *
jksoft 0:8468a4403fea 105 * @note For the requirements in the BAS specification to be fulfilled,
jksoft 0:8468a4403fea 106 * ble_bas_battery_level_update() must be called upon reconnection if the
jksoft 0:8468a4403fea 107 * battery level has changed while the service has been disconnected from a bonded
jksoft 0:8468a4403fea 108 * client.
jksoft 0:8468a4403fea 109 *
jksoft 0:8468a4403fea 110 * @param[in] p_bas Battery Service structure.
jksoft 0:8468a4403fea 111 * @param[in] p_ble_evt Event received from the BLE stack.
jksoft 0:8468a4403fea 112 */
jksoft 0:8468a4403fea 113 void ble_bas_on_ble_evt(ble_bas_t * p_bas, ble_evt_t * p_ble_evt);
jksoft 0:8468a4403fea 114
jksoft 0:8468a4403fea 115 /**@brief Function for updating the battery level.
jksoft 0:8468a4403fea 116 *
jksoft 0:8468a4403fea 117 * @details The application calls this function after having performed a battery measurement. If
jksoft 0:8468a4403fea 118 * notification has been enabled, the battery level characteristic is sent to the client.
jksoft 0:8468a4403fea 119 *
jksoft 0:8468a4403fea 120 * @note For the requirements in the BAS specification to be fulfilled,
jksoft 0:8468a4403fea 121 * this function must be called upon reconnection if the battery level has changed
jksoft 0:8468a4403fea 122 * while the service has been disconnected from a bonded client.
jksoft 0:8468a4403fea 123 *
jksoft 0:8468a4403fea 124 * @param[in] p_bas Battery Service structure.
jksoft 0:8468a4403fea 125 * @param[in] battery_level New battery measurement value (in percent of full capacity).
jksoft 0:8468a4403fea 126 *
jksoft 0:8468a4403fea 127 * @return NRF_SUCCESS on success, otherwise an error code.
jksoft 0:8468a4403fea 128 */
jksoft 0:8468a4403fea 129 uint32_t ble_bas_battery_level_update(ble_bas_t * p_bas, uint8_t battery_level);
jksoft 0:8468a4403fea 130
jksoft 0:8468a4403fea 131 #endif // BLE_BAS_H__
jksoft 0:8468a4403fea 132
jksoft 0:8468a4403fea 133 /** @} */