低功耗蓝牙4.0BLE编程-nrf51822开发(6)-Battery Service
来源:互联网 发布:数据集成平台软件 编辑:程序博客网 时间:2024/05/18 01:39
Battery Service是有关电池特性方面的服务,如果需要它,在初始化时将它加入到蓝牙协议栈。
如果通过ble_bas_battery_level_update(),电池电量将会通知,Battery Service将发送事件到应用程序。
(1)Battery Service事件类型
- /**@brief Battery Service event type. */
- typedef enum
- {
- BLE_BAS_EVT_NOTIFICATION_ENABLED, /**< Battery value notification enabled event. */
- BLE_BAS_EVT_NOTIFICATION_DISABLED /**< Battery value notification disabled event. */
- } ble_bas_evt_type_t;
- /**@brief Battery Service event. */
- typedef struct
- {
- // Forward declaration of the ble_bas_t type.
- typedef struct ble_bas_s ble_bas_t;
- /**@brief Battery Service event handler type. */
- typedef void (*ble_bas_evt_handler_t) (ble_bas_t * p_bas, ble_bas_evt_t * p_evt);
- /**@brief Battery Service init structure. This contains all options and data needed for
- * initialization of the service.*/
- typedef struct
- {
- ble_bas_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Battery Service. */
- bool support_notification; /**< TRUE if notification of Battery Level measurement is supported. */
- 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 */
- uint8_t initial_batt_level; /**< Initial battery level */
- ble_srv_cccd_security_mode_t battery_level_char_attr_md; /**< Initial security level for battery characteristics attribute */
- ble_gap_conn_sec_mode_t battery_level_report_read_perm; /**< Initial security level for battery report read attribute */
- } ble_bas_in
- /**@brief Battery Service structure. This contains various status information for the service. */
- typedef struct ble_bas_s
- {
- ble_bas_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Battery Service. */
- uint16_t service_handle; /**< Handle of Battery Service (as provided by the BLE stack). */
- ble_gatts_char_handles_t battery_level_handles; /**< Handles related to the Battery Level characteristic. */
- uint16_t report_ref_handle; /**< Handle of the Report Reference descriptor. */
- uint8_t battery_level_last; /**< Last Battery Level measurement passed to the Battery Service. */
- 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). */
- bool is_notification_supported; /**< TRUE if notification of Battery Level is supported. */
- } ble_bas_t;
- uint32_t ble_bas_init (ble_bas_t *p_bas, const ble_bas_init_t *p_bas_init) //服务初始化
- void ble_bas_on_ble_evt (ble_bas_t *p_bas, ble_evt_t *p_ble_evt) //处理协议栈事件的回调函数
- uint32_t ble_bas
- // Here the sec level for the Battery Service can be changed/increased.
- BLE_GAP_CONN_SEC_MODE_SET_OPEN(&bas_init.battery_level_char_attr_md.cccd_write_perm);
- BLE_GAP_CONN_SEC_MODE_SET_OPEN(&bas_init.battery_level_char_attr_md.read_perm);
- BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&bas_init.battery_level_char_attr_md.write_perm);
- BLE_GAP_CONN_SEC_MODE_SET_OPEN(&bas_init.battery_level_report_read_perm);
- bas_init.evt_handler = NULL;
- bas_init.support_notification = true;
- bas_init.p_report_ref = NULL;
- bas_init.initial_batt_level = 100;
- err_code = ble_bas_init(&bas, &bas_init);
- APP_ERROR_CHECK(err_code);
0 0
- 低功耗蓝牙4.0BLE编程-nrf51822开发(6)-Battery Service
- 低功耗蓝牙4.0BLE编程-nrf51822开发(6)-Battery Service
- 低功耗蓝牙4.0BLE编程-nrf51822开发(6)-Battery Service
- 低功耗蓝牙4.0BLE编程-nrf51822开发(1)
- 低功耗蓝牙4.0BLE编程-nrf51822开发(2)
- 低功耗蓝牙4.0BLE编程-nrf51822开发(3)
- 低功耗蓝牙4.0BLE编程-nrf51822开发(4)
- 低功耗蓝牙4.0BLE编程-nrf51822开发(5)-链路层
- 低功耗蓝牙4.0BLE编程-nrf51822开发(8)-GATT
- 低功耗蓝牙4.0BLE编程-nrf51822开发(9)
- 低功耗蓝牙4.0BLE编程-nrf51822开发(1)
- 低功耗蓝牙4.0BLE编程-nrf51822开发(2)
- 低功耗蓝牙4.0BLE编程-nrf51822开发(3)
- 低功耗蓝牙4.0BLE编程-nrf51822开发(4)
- 低功耗蓝牙4.0BLE编程-nrf51822开发(5)-链路层
- 低功耗蓝牙4.0BLE编程-nrf51822开发(8)-GATT
- 低功耗蓝牙4.0BLE编程-nrf51822开发(9)
- 低功耗蓝牙4.0BLE编程-nrf51822开发(1)
- 如何用IP地址反查域名
- 关于ImportError: xxxx.so: undefined symbol: PyFPE_jbuf的解决方案
- SSL握手通信详解及linux下c/c++ SSL Socket代码举例
- C++指针详解
- Ubuntu命令行连接VPN并自动设置所有流量通过VPN(通过VPN上网)
- 低功耗蓝牙4.0BLE编程-nrf51822开发(6)-Battery Service
- C++各种格式转换
- c++虚函数实现原理
- Android学习笔记-在5.0之前的系统使用Metail Design 的设计风格
- jquery.tagsinput.js 实现记录checkbox勾选的顺序
- 低功耗蓝牙4.0BLE编程-nrf51822开发(7)-SDP服务发现协议
- Gerrit server setup
- android6.0 ble scan android6.0蓝牙扫描
- Apache MINA学习笔记