BLE-NRF51822教程19-Battery Service
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
{
ble_bas_evt_type_t evt_type; /**< Type of event. */
} ble_bas_evt_t;
(2)Battery Service事件处理函数
// 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);
(3)ble_bas_init_t:初始化用到的结构体
/**@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_init_t;
(4)包含可变状态信息的结构体ble_bas_t:
/**@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;
(5)几个函数说明:
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_battery_level_update (ble_bas_t *p_bas, uint8_t battery_level) //更新电池电量时调用
(6)初始化操作
// 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 = ; err_code = ble_bas_init(&bas, &bas_init); APP_ERROR_CHECK(err_code);
BLE-NRF51822教程19-Battery Service的更多相关文章
- 低功耗蓝牙4.0BLE编程-nrf51822开发(6)-Battery Service
Battery Service是有关电池特性方面的服务,如果需要它,在初始化时将它加入到蓝牙协议栈. 如果通过ble_bas_battery_level_update(),电池电量将会通知,Batte ...
- 蓝牙BLE实用教程
蓝牙BLE实用教程 Bluetooth BLE 欢迎使用 小书匠(xiaoshujiang)编辑器,您可以通过 设置 里的修改模板来改变新建文章的内容. 1.蓝牙BLE常见问答 Q: Smart Re ...
- [蓝牙] 5、Battery Service module
Detailed Description This module implements the Battery Service with the Battery Level characteristi ...
- node-webkit教程(11)Platform Service之shell
node-webkit教程(11)Platform Service之shell 文/玄魂 目录 node-webkit教程(10)Platform Service之shell 前言 11.1 She ...
- node-webkit教程(10)Platform Service之File dialogs
node-webkit教程(10)Platform Service之File dialogs 文/玄魂 目录 node-webkit教程(10)Platform Service之File dialog ...
- node-webkit教程(8)Platform Service之Clipboard
node-webkit教程(8)Platform Service之Clipboard 文/玄魂 目录 node-webkit教程(8)Platform Service之Clipboard 前言 8.1 ...
- node-webkit教程(7)Platform Service之APP
node-webkit教程(7)Platform Service之APP 文/玄魂 前言 几个月前,要开发一个简易的展示应用,要求支持离线播放(桌面应用)和在线播放(web应用). 当时第一想到的是f ...
- [译]Vulkan教程(19)渲染和呈现
[译]Vulkan教程(19)渲染和呈现 Rendering and presentation 渲染和呈现 Setup 设置 This is the chapter where everything ...
- Directx11教程(19) 画一个简单的地形
原文:Directx11教程(19) 画一个简单的地形 通常我们在xz平面定义一个二维的网格,然后y的值根据一定的函数计算得到,比如正弦.余弦函数的组合等等,可以得到一个看似不错的地形或者 ...
- 蓝牙BLE实用教程(转载)
欢迎使用 小书匠(xiaoshujiang)编辑器,您可以通过 设置 里的修改模板来改变新建文章的内容. 1.蓝牙BLE常见问答 Q: Smart Ready 和 Smart 以及传统蓝牙之间是什么关 ...
随机推荐
- js执行顺序
我们知道有个全局的 window对象,js的一切皆window上的属性和方法.window上有个window.document属性,记录了整个html的dom树,document是顶层. body 和 ...
- asp.net控件开发基础(1)(转)原文更多内容
asp.net本身提供了很多控件,提供给我们这些比较懒惰的人使用,我认为控件的作用就在此,因为我们不想重复工作,所以要创建它,这个本身便是一个需求的关系,所以学习控件开发很有意思. wrox网站上有本 ...
- js:数据结构笔记9--二叉树
树:以分层的方式存储数据:节点:根节点,子节点,父节点,叶子节点(没有任何子节点的节点):层:根节点开始0层: 二叉树:每个节点子节点不超过两个:查找快(比链表),添加,删除快(比数组): BST:二 ...
- QUnit使用笔记-5简化编写
在测试中,如果用到了大量相同的方法返回判断结果,可以将他们简化; 使用push(): push( result/*boolean,result of assert*/, actual, /*objec ...
- 简单几何(凸包) POJ 2187 Beauty Contest
题目传送门 题意:求两点的距离平方的最大值 分析:凸包模板题 /************************************************ * Author :Running_T ...
- Codeforces Round #208 (Div. 2) B Dima and Text Messages
#include <iostream> #include <algorithm> #include <string> using namespace std; in ...
- object-c 协议和委托
协议相当于接口 委托相当于帮助实现其它类的功能 object-c提供的协议机制,一个类可以实现多个协议,从而感觉上像多继承一样
- 【POJ】3261 Milk Patterns
http://poj.org/problem?id=3261 题意:一个长度为n的串,要求最长的子串的长度且这个子串的出现次数不少于k次.(1<=n<=20000, 2<=k< ...
- python 操作execl文件
http://www.jb51.net/article/60510.htm import xlrdimport xlwt # 打开文件 workbook = xlrd.open_workbook( ...
- CentOS下搭建使用gitlab 和tortoiseGit使用
gitlab和github 一样很爽的一个东西 关于gitlab在CentOS下的安装方法地址参考: https://github.com/gitlabhq/gitlab-recipes/tree/m ...