[蓝牙] 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 ...
随机推荐
- fname
from lxml import etreeimport requestsdef getHtml(html): novelcontent = requests.get(html).content re ...
- win64
修改IIS应用程序池,启用支持32位 未能写入输出文件“c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary AS
- ZooKeeper事务日志记录器SyncRequestProcessor
SyncRequestProcessor作为一个ZooKeeper中的一个关键线程(ZooKeeperCriticalThread),是ZooKeeper请求处理链中的事务日志记录处理器,其主要用来将 ...
- Jquery打造的类似新浪微博@提醒功能
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- html 页面内锚点定位及跳转方法总结
第一种方法,也是最简单的方法是锚点用<a>标签,在href属性中写入DIV的id.如下: <!DOCTYPE html><html><head> < ...
- php代码优化系列 -- array_walk 和 foreach, for 的效率的比较
实验是我学习计算机科学的一个重要方法,计算机科学不是简单的智力游戏,它本质上来说不是一门科学,而是一个改造世界的工具.数学方法和实验方法是计算机研究的基本方法,也是我们学习的基本方法,数学锻炼我们的思 ...
- OpenResty(nginx_lua_module)做ES代理以及备份ES数据
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...
- command not found,系统很多命令都用不了 ,修改环境变量
bash: ***: command not found,系统很多命令都用不了,均提示没有此命令. 突然之间linux很多命令都用不了,均提示没有此命令. 这应该是系统环境变量出现了问题导致的. 解决 ...
- JS无刷新分页插件
本文介绍一个本人自己写的一JS分页插件 <script src="/Js/smart.page.min.js" type="text/javascript" ...
- ArcGIS10.1 api for Flex开发用于ArcGIS 9.3时QueryTask 'Error #2032'错误的解决方案
因客户GIS软件需求,将应用降级到低版本ArcGIS9.3,不仅数据有些样式.配色.字符有些问题,API也要相应“降级”,解决如下: 利用9.3+flex做QueryTask时候出现了[RPC Fau ...