蓝牙BLE介绍

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mediatec/article/details/88360861

蓝牙BLE介绍


本文主要包括以下内容:

1. 蓝牙定义及版本变化

2. BLE协议栈

3. GATT


1. 蓝牙定义及版本变化

1.1,蓝牙

蓝牙(英语:Bluetooth),一种无线通讯技术标准,用来让固定与移动设备,在短距离间交换数据,以形成个人局域网(PAN)。其使用短波特高頻(UHF)无线电波,经由2.4至2.485 GHz的ISM频段来进行通信。

1.2,蓝牙发布的版本状况大致如下:

蓝牙2.1

  • 使用最广,之前的很多产品都是这个版本,俗称经典蓝牙。

蓝牙3.0

  • 又名为高速蓝牙,在2.1的基础上大大提升了传输速度(24Mbps)。

蓝牙4.0

  • 最重要的特性是支持省电,即引入了低功耗蓝牙。

蓝牙4.1

  • 其目的是为了让 Bluetooth Smart 技术最终成为物联网(Internet of Things)发展的核心动力。

蓝牙5.0

  • 在2016年6月发布。在有效传输距离上将是4.2LE版本的4倍(理论上可达300米),传输速度将是4.2LE版本的2倍(速度上限为24Mbps)。蓝牙5.0还支持室内定位导航功能(结合WiFi可以实现精度小于1米的室内定位),允许无需配对接受信标的数据(比如广告、Beacon、位置信息等,传输率提高了8倍),针对物联网进行了很多底层优化。

1.3,蓝牙BLE与传统蓝牙的比较

BLE,全称为Bluetooth Low Energy,即蓝牙低功耗,较传统蓝牙最大的特点就是低功耗,多应用于对实时性要求较高,但对数据传输速率要求比较低的场景,比如血压计、键鼠等设备,而语音、音乐等对数据量传输比较大的场景依然需要使用传统蓝牙。

2. 协议栈

蓝牙BLE协议栈包含两部分:主机和控制器,如下图所示。

2.1,控制器部分

  • PHY:为Physical的缩写,负责数据的物理传输。
  • LL:为Link Layer的缩写,用于控制设备的射频状态。
  • HCI:为Host Controller interface的缩写,即主机和控制器之间的交互接口。

2.2,主机部分

  • L2CAP:为Logical Link Control and Adaption Protocol的缩写,负责管理逻辑层提供的逻辑链路。
  • SM:为Security Manager的缩写,为蓝牙配对和连接提供安全保证。
  • ATT:为Attributes的缩写,目的是允许设备向另外一个设备展示一块特定的数据,称之为“属性”。展示“属性”的设备称为服务器,与之配对的设备称为客户端。
  • GATT:为Generic Attributes的缩写,由一系列特征(characteristic)组成,这些每个特征又可能依赖不用的profiles。此profile后面会重点介绍。
  • GAP:为General Access Profile的缩写,主要描述了两个蓝牙设备建立通信时必要的基本操作,包括设备的发现、链路的建立和配置以及安全性设置。

2.3,BLE中的四个角色,按照通信之前是否需建立连接划分

不建立连接:

  • 广播者(Braodcaster):广播发送者,是不可连接的设备;
  • 观察者(Observer):扫描广播,不能够启动连接。

建立连接(通过GATT):

  • 中央(Central):扫描广播,启动连接,在单一或多链路层作为主机;
  • 外围(Peripheral):广播发送者,可连接的设备,在单一链路层作为从机。

3. GATT

GATT Profile架构图如下:

容易看出:

  • GATT Profile可由多个Service组成
  • 每个Service由多个Characteristic组成
  • 每个Characteristic由属性(Properties)、value 和 0至多个对此Characteristic的描述(Descriptor)所组成。在BLE设备连接建立成功之后读写,就是对Characteristic的读写。

另外,Service(多个)、Characteristic(多个)和 Descriptor(多个)使用UUID来作为各自的ID。

最后,附上官方对上图的说明:

The top level of the hierarchy is a profile, which is composed of one or more services necessary to fulfill a use case. 
A service is composed of characteristics or references to other services. 
A characteristic consists of a type (represented by a UUID), a value, a set of properties indicating the operations the characteristic supports and a set of permissions relating to security. 
It may also include one or more descriptors—metadata or configuration flags relating to the owning characteristic.

GATT groups these services to encapsulate the behavior of part of a device, and describes a use case, roles and general behaviors based on the GATT functionality. 
This framework defines procedures and formats of services and their characteristics, including discovering, reading, writing, notifying and indicating characteristics, as well as configuring the broadcast of characteristics.
GATT defines client and server roles. 

GATT procedures can be considered to be split into three basic types: 
Discovery procedures, Client-initiated procedures and Server-initiated procedures. 

The GATT server stores the data transported over the ATT and accepts ATT requests, commands and confirmations from the GATT client. 

The GATT server sends responses to requests and sends indications and notifications asynchronously to the GATT client when specified events occur on the GATT server. 
GATT also specifies the format of data contained on the GATT server.

参考如下:

  1. https://zh.wikipedia.org/wiki/%E8%97%8D%E7%89%99#%E8%97%8D%E7%89%99%E5%8D%94%E8%AD%B0%E5%A0%86%E7%96%8A
  2. http://m.elecfans.com/article/578020.html?from=bdhd_site
  3. http://m.elecfans.com/article/705867.html?from=bdhd_site
  4. http://www.mr-wu.cn/ten-important-differences-between-bluetooth-bredr-and-bluetooth-smart/
  5. 蓝牙官方文档

猜你喜欢

转载自blog.csdn.net/mediatec/article/details/88360861