nochanges

Dependents:   BLE_Acceleration_Statejudging

Fork of nRF51822 by Nordic Semiconductor

Committer:
MonroeLee
Date:
Thu Jun 09 05:15:47 2016 +0000
Revision:
638:6efcf74f000d
Parent:
37:c29c330d942c
no changes

Who changed what in which revision?

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