gatt协议

GATT协议

  (2013-11-26 10:17:49)
标签: 

gatt

 

att

 

bluetooth

 

attribute

分类: Bluetooth
1.主要用于寻找和配置服务端的属性,其实就是寻找、配置和读写servcice端的各种attribute,使其按需要的方式工作。
它有两个角色:Server和Client,一个实际的例子:
GATT协议

2.概述
GATT使用Attribute Protocol来传输data:
GATT协议
Opcode表示该PDU的类型,包括command, request, response, indication,notification or confirmation这六种。
Logical Attribute Representation: GATT协议
这是service端某个attribute的格式。
      The Attribute Handle is an index corresponding to a specific Attribute. The Attribute Type is a UUID that describes the Attribute Value. The Attribute Value is the data described by the Attribute Type and indexed by the Attribute Handle. The Attributes are ordered by increasing Attribute Handle values.Attribute Permissions is part of the Attribute that cannot be read from or written to using the Attribute Protocol.

3.GATT的层次结构
GATT协议

多个service组成完整的profile,一个service可能包含几个referenced services, 一些mandatory characteristics 和optional characteristics.有两种类型的service:primary service and secondary service。A primary service can be included by another service,A secondary service is a service that is only intended to be referenced from a primary service or another secondary service or other higher layer specification.

4.service的组成
(1)SERVICE DEFINITION
A service definition shall  contain a service declaration and may contain include definitions and characteristic definitions.
组织顺序:service declaration-->include definitions-->characteristic definitions
Service Declaration:
GATT协议

(2)INCLUDE DEFINITION
GATT协议

(3)CHARACTERISTIC DEFINITION
A characteristic definition shall contain a characteristic declaration, a Characteristic Value declaration and may contain characteristic descriptor declarations.
The Characteristic Value declaration shall exist immediately following the characteristic declaration
(3.1) Characteristic Declaration
GATT协议

(3.2)Characteristic Value Declaration
真正的data是保存在这个里面的
GATT协议
(3.3)Characteristic Descriptor Declarations
Used to contain related information about the Characteristic Value.Only one Characteristic Extended Properties.
declaration shall exist in a characteristic definition.
(3.3.1)Characteristic Extended Properties
GATT协议
GATT协议

(3.3.2)Characteristic User Description
GATT协议
(3.3.3)Client Characteristic Configuration
GATT协议
GATT协议

(3.3.4)Server Characteristic Configuration
GATT协议
GATT协议

(3.3.5)Characteristic Presentation Format
GATT协议
GATT协议

(3.3.6)Characteristic Aggregate Format
       Only one Characteristic Aggregate Format declaration shall exist in a characteristic definition.The Characteristic Aggregate Format value is composed of a list of Attribute Handles of Characteristic Presentation Format declarations, where each Attribute. Handle points to a Characteristic Presentation Format declaration.
可以理解为是多个Characteristic Presentation Format的集合,而且可以使用其他characteristic definition的characteristic presentation。
GATT协议

3.4 GATT PROFILE ATTRIBUTE TYPES总结
GATT协议
主要有以上几种GATT Attribute Type。

5.GATT features
主要有以下11种:
GATT协议
5.1  SERVER CONFIGURATION
一个sub-processdure:Exchange MTU
This sub-procedure is used by the client to set the ATT_MTU to the maximum possible value that can be supported by both devices. 

5.2 PRIMARY SERVICE DISCOVERY
两个sub-procedures:Discover All Primary Services and Discover Primary Services by Service UUID
This procedure is used by a client to discover primary services on a server.

5.3 RELATIONSHIP DISCOVERY
一个sub-procedure:Find Included Services.
There is one sub-procedure that can be used for relationship discovery: Find Included Services.

5.4 CHARACTERISTIC DISCOVERY
两个sub-procedures:Discover All Characteristics of a Service and Discover Characteristics by  UUID.
This procedure is used by a client to discover service characteristics on a server.

5.5  CHARACTERISTIC DESCRIPTOR DISCOVERY
一个sub-procedure:Discover All Characteristic Descriptors.
This procedure is used by a client to discover characteristic descriptors of a characteristic.

5.6 CHARACTERISTIC VALUE READ
四个sub-procedures:Read Characteristic Value, Read Using Characteristic UUID, Read Long CharacteristicValues, and Read Multiple Characteristic Values.
This procedure is used to read a Characteristic Value from a server.

5.7 CHARACTERISTIC VALUE WRITE
5个sub-procedures: Write Without Response, Signed Write Without Response, Write Characteristic
Value, Write Long Characteristic Values and Reliable Writes.
This procedure is used to write a Characteristic Value to a server.

5.8 CHARACTERISTIC VALUE NOTIFICATION
1个sub-procedure:Notifications.
This procedure is used to notify a client of the value of a Characteristic Value from a server.

5.9  CHARACTERISTIC VALUE INDICATIONS
1个sub-procedure:Indications
This procedure is used to indicate the Characteristic Value from a server to a client.

5.10  CHARACTERISTIC DESCRIPTORS
两个sub-procedures:  Read Characteristic Descriptors and Write Characteristic Descriptors.
This procedure is used to read and write characteristic descriptors on a server.

下图是GATT和ATT的相关processdure的mapping图:
GATT协议
GATT协议

6.其他
SERVICE CHANGED:一个重要的characteristic,be used to indicate to connected devices that services have changed。
GATT协议
GATT协议
There is only one instance of the Service Changed characteristic within the GATT service definition.
GATT over BR/EDR:
GATT协议
### RTOS环境下GATT协议的相关信息 在实时操作系统(RTOS)环境中实现GATT协议通常涉及配置BLE堆栈并管理服务和特征的注册与交互。以下是有关如何在RTOS下实现GATT协议的一些关键点: #### 1. GATT协议基础 GATT(Generic Attribute Profile)基于ATT(Attribute Protocol),用于定义两个BLE设备之间的数据交换方式。GATT通过Service和Characteristic来组织数据[^1]。每个Service可以包含多个Characteristics,而这些Characteristics则存储具体的数据。 #### 2. 查找表结构 ATT协议维护了一个查找表,其中包含了所有的Services、Characteristics及其关联的数据。该查找表中的每一项都由一个唯一的16位ID索引来标识。这种设计使得客户端能够高效地访问服务器上的资源。 #### 3. 配置GATT Server 为了实现在RTOS环境下的GATT功能,开发者需要完成以下工作: - **初始化BLE控制器**:启动硬件模块并与主机建立连接。 - **创建GATT数据库**:定义所需的Services和Characteristics,并将其添加到ATT查找表中。 - **处理事件回调**:当有来自远程设备的操作请求时,调用相应的函数响应读写操作或其他动作。 下面是一个简单的伪代码示例展示如何设置基本的服务和特性: ```c #include "ble_gatt.h" // 定义UUIDs (这里简化为常量字符串表示) #define SERVICE_UUID "0000180F" #define CHARACTERISTIC_UUID "00002A19" void setup_gatt_server(void){ uint16_t service_handle; ble_gatts_add_service(SERVICE_UUID, &service_handle); // 添加服务 ble_gatts_add_characteristic(service_handle, CHARACTERISTIC_UUID, BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE); } ``` 此片段展示了向系统增加一个新的自定义服务以及其内的单一可读写的属性的过程。 #### 4. RFCOMM与其他高层应用的关系 值得注意的是,在某些情况下,如果应用程序涉及到更复杂的通信需求,则可能还会依赖其他类型的协议如RFCOMM来进行串口模拟传输等功能支持[^2]。不过这通常是针对经典蓝牙而非低功耗蓝牙而言的情况。 #### 5. NimBLE移植至ESP32平台说明 对于特定芯片组比如Espressif Systems推出的ESP32系列微控制器来说,官方提供了详细的文档指导用户如何将Mynewt项目里的NimBLE组件成功迁移到目标平台上运行[^3]。这对于希望利用开源解决方案快速构建产品的工程师们非常有用。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值