iOSのBLEコントローラアプリ「RCBController」と接続し、コントローラの操作を取得するサンプルプログラムです。 mbed HRM1017で動作を確認しています。 2014.08.20時点でのBLEライブラリに対応しました。
Fork of BLE_RCBController by
HRM1017/nordic/nrf-sdk/ble/ble_services/ble_bas.h@4:ebda47d22091, 2014-08-20 (annotated)
- Committer:
- jksoft
- Date:
- Wed Aug 20 13:41:01 2014 +0000
- Revision:
- 4:ebda47d22091
- Parent:
- nRF51822/nordic/nrf-sdk/ble/ble_services/ble_bas.h@1:48f6e08a3ac2
?????????
Who changed what in which revision?
User | Revision | Line number | New 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_bas Battery Service |
jksoft | 1:48f6e08a3ac2 | 16 | * @{ |
jksoft | 1:48f6e08a3ac2 | 17 | * @ingroup ble_sdk_srv |
jksoft | 1:48f6e08a3ac2 | 18 | * @brief Battery Service module. |
jksoft | 1:48f6e08a3ac2 | 19 | * |
jksoft | 1:48f6e08a3ac2 | 20 | * @details This module implements the Battery Service with the Battery Level characteristic. |
jksoft | 1:48f6e08a3ac2 | 21 | * During initialization it adds the Battery Service and Battery Level characteristic |
jksoft | 1:48f6e08a3ac2 | 22 | * to the BLE stack database. Optionally it can also add a Report Reference descriptor |
jksoft | 1:48f6e08a3ac2 | 23 | * to the Battery Level characteristic (used when including the Battery Service in |
jksoft | 1:48f6e08a3ac2 | 24 | * the HID service). |
jksoft | 1:48f6e08a3ac2 | 25 | * |
jksoft | 1:48f6e08a3ac2 | 26 | * If specified, the module will support notification of the Battery Level characteristic |
jksoft | 1:48f6e08a3ac2 | 27 | * through the ble_bas_battery_level_update() function. |
jksoft | 1:48f6e08a3ac2 | 28 | * If an event handler is supplied by the application, the Battery Service will |
jksoft | 1:48f6e08a3ac2 | 29 | * generate Battery Service events to the application. |
jksoft | 1:48f6e08a3ac2 | 30 | * |
jksoft | 1:48f6e08a3ac2 | 31 | * @note The application must propagate BLE stack events to the Battery Service module by calling |
jksoft | 1:48f6e08a3ac2 | 32 | * ble_bas_on_ble_evt() from the from the @ref ble_stack_handler callback. |
jksoft | 1:48f6e08a3ac2 | 33 | * |
jksoft | 1:48f6e08a3ac2 | 34 | * @note Attention! |
jksoft | 1:48f6e08a3ac2 | 35 | * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile |
jksoft | 1:48f6e08a3ac2 | 36 | * qualification listings, this section of source code must not be modified. |
jksoft | 1:48f6e08a3ac2 | 37 | */ |
jksoft | 1:48f6e08a3ac2 | 38 | |
jksoft | 1:48f6e08a3ac2 | 39 | #ifndef BLE_BAS_H__ |
jksoft | 1:48f6e08a3ac2 | 40 | #define BLE_BAS_H__ |
jksoft | 1:48f6e08a3ac2 | 41 | |
jksoft | 1:48f6e08a3ac2 | 42 | #include <stdint.h> |
jksoft | 1:48f6e08a3ac2 | 43 | #include <stdbool.h> |
jksoft | 1:48f6e08a3ac2 | 44 | #include "ble.h" |
jksoft | 1:48f6e08a3ac2 | 45 | #include "ble_srv_common.h" |
jksoft | 1:48f6e08a3ac2 | 46 | |
jksoft | 1:48f6e08a3ac2 | 47 | /**@brief Battery Service event type. */ |
jksoft | 1:48f6e08a3ac2 | 48 | typedef enum |
jksoft | 1:48f6e08a3ac2 | 49 | { |
jksoft | 1:48f6e08a3ac2 | 50 | BLE_BAS_EVT_NOTIFICATION_ENABLED, /**< Battery value notification enabled event. */ |
jksoft | 1:48f6e08a3ac2 | 51 | BLE_BAS_EVT_NOTIFICATION_DISABLED /**< Battery value notification disabled event. */ |
jksoft | 1:48f6e08a3ac2 | 52 | } ble_bas_evt_type_t; |
jksoft | 1:48f6e08a3ac2 | 53 | |
jksoft | 1:48f6e08a3ac2 | 54 | /**@brief Battery Service event. */ |
jksoft | 1:48f6e08a3ac2 | 55 | typedef struct |
jksoft | 1:48f6e08a3ac2 | 56 | { |
jksoft | 1:48f6e08a3ac2 | 57 | ble_bas_evt_type_t evt_type; /**< Type of event. */ |
jksoft | 1:48f6e08a3ac2 | 58 | } ble_bas_evt_t; |
jksoft | 1:48f6e08a3ac2 | 59 | |
jksoft | 1:48f6e08a3ac2 | 60 | // Forward declaration of the ble_bas_t type. |
jksoft | 1:48f6e08a3ac2 | 61 | typedef struct ble_bas_s ble_bas_t; |
jksoft | 1:48f6e08a3ac2 | 62 | |
jksoft | 1:48f6e08a3ac2 | 63 | /**@brief Battery Service event handler type. */ |
jksoft | 1:48f6e08a3ac2 | 64 | typedef void (*ble_bas_evt_handler_t) (ble_bas_t * p_bas, ble_bas_evt_t * p_evt); |
jksoft | 1:48f6e08a3ac2 | 65 | |
jksoft | 1:48f6e08a3ac2 | 66 | /**@brief Battery Service init structure. This contains all options and data needed for |
jksoft | 1:48f6e08a3ac2 | 67 | * initialization of the service.*/ |
jksoft | 1:48f6e08a3ac2 | 68 | typedef struct |
jksoft | 1:48f6e08a3ac2 | 69 | { |
jksoft | 1:48f6e08a3ac2 | 70 | ble_bas_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Battery Service. */ |
jksoft | 1:48f6e08a3ac2 | 71 | bool support_notification; /**< TRUE if notification of Battery Level measurement is supported. */ |
jksoft | 1:48f6e08a3ac2 | 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 | 1:48f6e08a3ac2 | 73 | uint8_t initial_batt_level; /**< Initial battery level */ |
jksoft | 1:48f6e08a3ac2 | 74 | ble_srv_cccd_security_mode_t battery_level_char_attr_md; /**< Initial security level for battery characteristics attribute */ |
jksoft | 1:48f6e08a3ac2 | 75 | ble_gap_conn_sec_mode_t battery_level_report_read_perm; /**< Initial security level for battery report read attribute */ |
jksoft | 1:48f6e08a3ac2 | 76 | } ble_bas_init_t; |
jksoft | 1:48f6e08a3ac2 | 77 | |
jksoft | 1:48f6e08a3ac2 | 78 | /**@brief Battery Service structure. This contains various status information for the service. */ |
jksoft | 1:48f6e08a3ac2 | 79 | typedef struct ble_bas_s |
jksoft | 1:48f6e08a3ac2 | 80 | { |
jksoft | 1:48f6e08a3ac2 | 81 | ble_bas_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Battery Service. */ |
jksoft | 1:48f6e08a3ac2 | 82 | uint16_t service_handle; /**< Handle of Battery Service (as provided by the BLE stack). */ |
jksoft | 1:48f6e08a3ac2 | 83 | ble_gatts_char_handles_t battery_level_handles; /**< Handles related to the Battery Level characteristic. */ |
jksoft | 1:48f6e08a3ac2 | 84 | uint16_t report_ref_handle; /**< Handle of the Report Reference descriptor. */ |
jksoft | 1:48f6e08a3ac2 | 85 | uint8_t battery_level_last; /**< Last Battery Level measurement passed to the Battery Service. */ |
jksoft | 1:48f6e08a3ac2 | 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 | 1:48f6e08a3ac2 | 87 | bool is_notification_supported; /**< TRUE if notification of Battery Level is supported. */ |
jksoft | 1:48f6e08a3ac2 | 88 | } ble_bas_t; |
jksoft | 1:48f6e08a3ac2 | 89 | |
jksoft | 1:48f6e08a3ac2 | 90 | /**@brief Function for initializing the Battery Service. |
jksoft | 1:48f6e08a3ac2 | 91 | * |
jksoft | 1:48f6e08a3ac2 | 92 | * @param[out] p_bas Battery Service structure. This structure will have to be supplied by |
jksoft | 1:48f6e08a3ac2 | 93 | * the application. It will be initialized by this function, and will later |
jksoft | 1:48f6e08a3ac2 | 94 | * be used to identify this particular service instance. |
jksoft | 1:48f6e08a3ac2 | 95 | * @param[in] p_bas_init Information needed to initialize the service. |
jksoft | 1:48f6e08a3ac2 | 96 | * |
jksoft | 1:48f6e08a3ac2 | 97 | * @return NRF_SUCCESS on successful initialization of service, otherwise an error code. |
jksoft | 1:48f6e08a3ac2 | 98 | */ |
jksoft | 1:48f6e08a3ac2 | 99 | uint32_t ble_bas_init(ble_bas_t * p_bas, const ble_bas_init_t * p_bas_init); |
jksoft | 1:48f6e08a3ac2 | 100 | |
jksoft | 1:48f6e08a3ac2 | 101 | /**@brief Function for handling the Application's BLE Stack events. |
jksoft | 1:48f6e08a3ac2 | 102 | * |
jksoft | 1:48f6e08a3ac2 | 103 | * @details Handles all events from the BLE stack of interest to the Battery Service. |
jksoft | 1:48f6e08a3ac2 | 104 | * |
jksoft | 1:48f6e08a3ac2 | 105 | * @note For the requirements in the BAS specification to be fulfilled, |
jksoft | 1:48f6e08a3ac2 | 106 | * ble_bas_battery_level_update() must be called upon reconnection if the |
jksoft | 1:48f6e08a3ac2 | 107 | * battery level has changed while the service has been disconnected from a bonded |
jksoft | 1:48f6e08a3ac2 | 108 | * client. |
jksoft | 1:48f6e08a3ac2 | 109 | * |
jksoft | 1:48f6e08a3ac2 | 110 | * @param[in] p_bas Battery Service structure. |
jksoft | 1:48f6e08a3ac2 | 111 | * @param[in] p_ble_evt Event received from the BLE stack. |
jksoft | 1:48f6e08a3ac2 | 112 | */ |
jksoft | 1:48f6e08a3ac2 | 113 | void ble_bas_on_ble_evt(ble_bas_t * p_bas, ble_evt_t * p_ble_evt); |
jksoft | 1:48f6e08a3ac2 | 114 | |
jksoft | 1:48f6e08a3ac2 | 115 | /**@brief Function for updating the battery level. |
jksoft | 1:48f6e08a3ac2 | 116 | * |
jksoft | 1:48f6e08a3ac2 | 117 | * @details The application calls this function after having performed a battery measurement. If |
jksoft | 1:48f6e08a3ac2 | 118 | * notification has been enabled, the battery level characteristic is sent to the client. |
jksoft | 1:48f6e08a3ac2 | 119 | * |
jksoft | 1:48f6e08a3ac2 | 120 | * @note For the requirements in the BAS specification to be fulfilled, |
jksoft | 1:48f6e08a3ac2 | 121 | * this function must be called upon reconnection if the battery level has changed |
jksoft | 1:48f6e08a3ac2 | 122 | * while the service has been disconnected from a bonded client. |
jksoft | 1:48f6e08a3ac2 | 123 | * |
jksoft | 1:48f6e08a3ac2 | 124 | * @param[in] p_bas Battery Service structure. |
jksoft | 1:48f6e08a3ac2 | 125 | * @param[in] battery_level New battery measurement value (in percent of full capacity). |
jksoft | 1:48f6e08a3ac2 | 126 | * |
jksoft | 1:48f6e08a3ac2 | 127 | * @return NRF_SUCCESS on success, otherwise an error code. |
jksoft | 1:48f6e08a3ac2 | 128 | */ |
jksoft | 1:48f6e08a3ac2 | 129 | uint32_t ble_bas_battery_level_update(ble_bas_t * p_bas, uint8_t battery_level); |
jksoft | 1:48f6e08a3ac2 | 130 | |
jksoft | 1:48f6e08a3ac2 | 131 | #endif // BLE_BAS_H__ |
jksoft | 1:48f6e08a3ac2 | 132 | |
jksoft | 1:48f6e08a3ac2 | 133 | /** @} */ |