关于BLE通信中WithoutResponse详细介绍

发布时间:2024年01月10日

什么是WithoutResponse

在蓝牙低功耗(BLE)协议栈中,Characteristic 的写操作具有两种属性,分别为 "write" 和 "writeWithoutResponse"。

  • 使用 "write" 属性发送命令时,需要接收端发送确认(ACK);
  • 而使用 "writeWithoutResponse" 属性发送命令时,则不需要接收端发送确认(ACK)。

为了更灵活地控制写操作的行为,我们的操作系统引入了一个设置参数WithoutResponse。

  • 通过设置 WithoutResponse=true,表示使用 "writeWithoutResponse" 属性进行写操作
  • 通过设置 WithoutResponse=false,表示使用 "write" 属性进行写操作

WithoutResponse在不同的操作系统下的差异

  • 在Windows/安卓系统下,可以在特征没有writeWithoutResponse属性,只有write属性的情况下,发送WithoutResponse=true命令
  • 在macOs/ISO系统下,不可以在特征没有writeWithoutResponse属性,只有write属性的情况下,发送WithoutResponse=true命令

注意:

确切地说,只有在GATT(Generic Attribute Profile)中,特定的Characteristic声明了支持**Write Without Response属性时,才能在写操作中设置WithoutResponse**为true。

在BLE中,GATT表明了设备之间的通信协议,包括服务、特征(Characteristic)以及它们的属性。如果一个Characteristic声明了支持**Write Without Response属性,那么在实际的写操作中,你可以选择设置WithoutResponse**为true,以提高数据传输效率。在这种情况下,接收端不会发送ACK确认,从而加快了数据传输速度。

在WinRT中,特征(Characteristic)是否支持**Write Without Response属性可能受到操作系统或BLE堆栈的一些默认设置或行为影响。有时,操作系统或BLE堆栈可能会允许在特征不显式声明支持Write Without Response的情况下发送WithoutResponse=true的写操作。在实际应用中,这可能是由于操作系统或堆栈的实现选择了一种默认行为,或者可能是特定的BLE堆栈或驱动程序允许这种行为。这种情况可能是特定于操作系统、BLE堆栈版本或硬件平台。虽然某些系统可能允许这样的写入,但为了确保应用程序的可移植性和与规范的一致性,最好还是在进行写操作之前检查Characteristic的属性,以确保它明确支持Write Without Response**

抓包分析WithoutResponse在BLE的ATT协议中的定义

Windows下通过Wireshark抓包分析

  1. WithoutResponse=false

  2. WithoutResponse=true

MacOs下通过PacketLogger抓包分析ATT协议

  1. WithoutResponse=false
  2. WithoutResponse=true
    1. 注意在macOs下如果特征没有writeWithoutResponse属性,发送**WithoutResponse=true命令是无法抓到ATT协议数据的**

文章来源:https://blog.csdn.net/GUMU12345/article/details/135505914
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。