[蓝牙] 2、蓝牙BLE协议及架构浅析&&基于广播超时待机说广播事件









/**@brief Function for initializing the Advertising functionality.
*
* @details Encodes the required advertising data and passes it to the stack.
* Also builds a structure to be passed to the stack when starting advertising.
*/
static void advertising_init(void)
{
uint32_t err_code;
ble_advdata_t advdata;
uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; 12 ble_uuid_t adv_uuids[] =
13 {
14 {BLE_UUID_HEART_RATE_SERVICE, BLE_UUID_TYPE_BLE},
15 {BLE_UUID_BATTERY_SERVICE, BLE_UUID_TYPE_BLE},
16 {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
17 };//广播工程蓝牙3个服务的uuid
// Build and set advertising data
memset(&advdata, , sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME;
advdata.include_appearance = true;
advdata.flags.size = sizeof(flags);
advdata.flags.p_data = &flags;
advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[]);
advdata.uuids_complete.p_uuids = adv_uuids; err_code = ble_advdata_set(&advdata, NULL);
APP_ERROR_CHECK(err_code); // Initialize advertising parameters (used when starting advertising)
memset(&m_adv_params, , sizeof(m_adv_params)); m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND;
m_adv_params.p_peer_addr = NULL; // Undirected advertisement
m_adv_params.fp = BLE_GAP_ADV_FP_ANY;
m_adv_params.interval = APP_ADV_INTERVAL;
m_adv_params.timeout = APP_ADV_TIMEOUT_IN_SECONDS;
}
/*****************************************************************************
* Static Event Handling Functions
*****************************************************************************/ /**@brief Function for handling the Application's BLE Stack events.
*
* @param[in] p_ble_evt Bluetooth stack event.
*/
static void on_ble_evt(ble_evt_t *p_ble_evt)
{
uint32_t err_code;
static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
led_stop(); m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; // Initialize the current heart rate to the average of max and min values. So that
// everytime a new connection is made, the heart rate starts from the same value.
// m_cur_heart_rate = 0;//(MAX_HEART_RATE + MIN_HEART_RATE) / 2;
// Start timers used to generate battery and HR measurements.
application_timers_start(); // Start handling button presses
err_code = app_button_enable();
APP_ERROR_CHECK(err_code);
break; case BLE_GAP_EVT_DISCONNECTED:
// Since we are not in a connection and have not started advertising, store bonds
err_code = ble_bondmngr_bonded_centrals_store();
APP_ERROR_CHECK(err_code); // @note Flash access may not be complete on return of this API. System attributes are now
// stored to flash when they are updated to ensure flash access on disconnect does not
// result in system powering off before data was successfully written. // Go to system-off mode, should not return from this function, wakeup will trigger
// a reset.
//system_off_mode_enter();
app_button_disable();
DispColor(BLACK);
//re-enter advertising model if disconnected advertising_init();
// Start advertising
advertising_start();
break; case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
err_code = sd_ble_gap_sec_params_reply(m_conn_handle,
BLE_GAP_SEC_STATUS_SUCCESS,
&m_sec_params);
APP_ERROR_CHECK(err_code);
break; case BLE_GAP_EVT_TIMEOUT:
if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT)
{
led_stop(); nrf_gpio_cfg_sense_input(SENSOR_BUTTON_PIN_RIGHT,
BUTTON_PULL,
NRF_GPIO_PIN_SENSE_LOW); nrf_gpio_cfg_sense_input(SENSOR_BUTTON_PIN_LEFT,
BUTTON_PULL,
NRF_GPIO_PIN_SENSE_LOW);
#if defined(ENABLE_UP)
nrf_gpio_cfg_sense_input(SENSOR_BUTTON_PIN_UP,
BUTTON_PULL,
NRF_GPIO_PIN_SENSE_LOW); nrf_gpio_cfg_sense_input(SENSOR_BUTTON_PIN_DOWN,
BUTTON_PULL,
NRF_GPIO_PIN_SENSE_LOW);
#endif system_off_mode_enter();
}
break;
default:
// No implementation needed.
break;
}
}
More:[蓝牙] 1、蓝牙核心技术了解(蓝牙协议、架构、硬件和软件笔记)
@beautifulzzzz 2015-12-11 continue~
[蓝牙] 2、蓝牙BLE协议及架构浅析&&基于广播超时待机说广播事件的更多相关文章
- 蓝牙 BLE 协议学习: 001-BLE协议栈整体架构
背景 在深入BLE协议帧之前,我们先看一下BLE协议栈整体架构. 转载自:<深入浅出低功耗蓝牙(BLE)协议栈> 架构 如上图所述,要实现一个BLE应用,首先需要一个支持BLE射频的芯片, ...
- 蓝牙 BLE 协议学习: 3种蓝牙架构实现方案(蓝牙协议栈方案)
导言 不同的蓝牙架构可以用在不同的场景中.从而协议帧的架构方案也会不同. 转载自:<三种蓝牙架构实现方案(蓝牙协议栈方案)> 蓝牙架构实现方案有哪几种?我们一般把整个蓝牙实现方案叫做蓝牙协 ...
- 蓝牙 BLE 协议学习: 000-有关概念介绍
背景 在学校内就用过蓝牙技术参加过比赛(并拿了奖):而蓝牙作为物联网中比较常见的协议,有必要进行深入的学习.此后的文章会以 ble(v4.0) 进行学习. 介绍 蓝牙技术最初由电信巨头爱立信公司于 1 ...
- IOS学习之蓝牙4.0 BLE
IOS学习也一段时间了,该上点干货了.前段时间研究了一下IOS蓝牙通讯相关的东西,把研究的一个成果给大家分享一下. 一 项目背景 简单介绍一下做的东西,设备是一个金融刷卡器,通过蓝牙与iphone手机 ...
- 蓝牙4.0 BLE入门
在BLE协议中有两个角色,一个是周边(Periphery),另外一个是中央(Central).一个中央可以同时连接多个周边,但一个周边某一时刻只能连接一个中央.但是不管periphery还是centr ...
- Android低功耗蓝牙(蓝牙4.0)——BLE开发(上)
段时间,公司项目用到了手机APP和蓝牙设备的通讯开发,这里也正好对低功耗蓝牙(蓝牙4.0及以后标准)的开发,做一个总结. 蓝牙技术联盟在2010年6月30号公布了蓝牙4.0标准,4.0标准在蓝牙3.0 ...
- 蓝牙BLE: 蓝牙4.0 BLE广播数据解析(转)
BLE 设备工作的第一步就是向外广播数据.广播数据中带有设备相关的信息.本文主要说一下 BLE 的广播中的数据的规范以及广播包的解析. 1. 广播模式 BLE 中有两种角色 Central 和 Per ...
- [IOT] 自制蓝牙工牌办公室定位系统 (二)—— 基于ESP32的蓝牙信号扫描系统
前面章节: 自制蓝牙工牌办公室定位系统 (一)-- 阿里物联网平台概览及打通端到云(硬核·干货) 目录: 1.蓝牙广播简介 2.蓝牙扫描简介 3.基于蓝牙广播和蓝牙扫描常见应用 4.ESP32 ...
- 第13节-BLE协议L2CAP层
学习资料:官方手册 Vol 3: Core System Package [Host volume] Part A: Logical Link Control and Adaptation Proto ...
随机推荐
- vim c++补全
弄了个vim对c++的补全,主要参考自: http://vim.wikia.com/wiki/C%2B%2B_code_completion 首先确定vim编辑.cc或者.cpp文件时当前自动补全 ...
- 在ASP.NET MVC中使用Juqery实现页面局部刷新
自己做的一个实验,留作备忘,此实例包括扩一下几个文件: 1.MyMovieController.cs 2.Index.aspx 3.ViewUserControl1.ascx 4.movie类 其中M ...
- action func用法记记
public partial class Form1 : Form { public Form1() { InitializeComponent(); } public delegate void s ...
- ubuntu安装goldendict以及添加本地词典和在线词典
软件在ubuntu软件中心安装就可以了, 关于网络词典, 推荐有道在线词典,网址http://dict.youdao.com/search?q=%GDWORD%&ue=utf8 添加方法:编辑 ...
- group_concat函数详解
来自: http://hchmsguo.iteye.com/blog/555543 MySQL中group_concat函数 完整的语法如下: group_concat([DISTINCT] 要连接的 ...
- Java程序员从笨鸟到菜鸟之(一百零一)sql注入攻击详解(二)sql注入过程详解
在上篇博客中我们分析了sql注入的原理,今天我们就来看一下sql注入的整体过程,也就是说如何进行sql注入,由于本人数据库和网络方面知识有限,此文章是对网上大量同类文章的分析与总结,其中有不少直接引用 ...
- C.C++把整个文件内容读进一个buffer中
原创文章,未经本人允许禁止转载. //C方式, 调用的函数繁多 //fopen,fseek,ftell,fseek,malloc,fread,fclose,free. void foo() { FIL ...
- 将excel数据导入到mysql的方法
文本框被键盘遮挡到了,不会再获取焦点的时候被顶到键盘顶部.解决方案:设置A的Position为绝对定位absolute即可,其他几种定位方式未测试,但是不能是fixed ,正是因为这种定位方式,导致它 ...
- 响应式web设计之CSS3 Media Queries
开始研究响应式web设计,CSS3 Media Queries是入门. Media Queries,其作用就是允许添加表达式用以确定媒体的环境情况,以此来应用不同的样式表.换句话说,其允许我们在不改变 ...
- 如何用70行Java代码实现深度神经网络算法(转)
对于现在流行的深度学习,保持学习精神是必要的——程序员尤其是架构师永远都要对核心技术和关键算法保持关注和敏感,必要时要动手写一写掌握下来,先不用关心什么时候用到——用不用是政治问题,会不会写是技术问题 ...