1. Introduction

1.1。在你开始之前

在您开始之前需要:

  • 安装最新的SmartSnippets Studio
  • 下载DA1469X平台的最新SDK

这se can be downloaded from theDA1469X产品页面

此外,对于本教程aPro开发套件is required.

本教程的关键目标是提供:

  • 对通用ATT配置文件的基本了解
  • 一种basic understanding of Dialog Bluetooth framework architecture
  • 对蓝牙数据库创建过程的基本了解
  • 一个完整的示例项目,演示了创建自定义蓝牙服务

1.2。属性协议(ATT)

这attribute protocol provides mechanisms for discovering attributes of a remote device, as well as reading and writing attributes. The attribute protocol follows a client-server model. The server exposes a set of attributes to the client. The client can discover, read, and write those attributes. The server can also send notifications or indications to the client about any of the attributes. A device can implement a client, a server, or both client and server roles. At any given time, only one server can be active on a device.

1.2.1。客户端 - 服务器架构

Servers have data, this is known as theperipheral在通用访问协议(间隙)中。

Clients request data to/from servers, this is known as中央在差距中。

服务器使用属性公开数据。

Client Server Architecture

图。1客户端 - 服务器架构

1.3。属性定义

一种n attribute is something that represents data. It could be thought of as any data, at any given time, when the device is in any given state. ATT is designed to push or pull that data to or from a remote device. ATT also supports setting notifications and indications, so that the remote device can be alerted when the data changes. As well as containing the value of the data, an attribute has three properties associated with it:

  1. 属性类型
  2. 属性句柄
  3. 一种ccess Permissions

1.3.1。属性值

一个属性值是一个数组,其中包含结构the actual value of the attribute. The length of the attribute can be either fixed or variable:

  • 固定长度:长度可以是一个,两个或四个八位字节。
  • Variable length:该属性可以是可变长度的字符串。

为了简化事物,ATT不允许在单个PDU中传输多个属性值。PDU仅包含一个属性值,如果属性值太长以在单个PDU中传输,则可以跨多个PDU拆分。例如,当客户端请求要读取的多个属性并且属性具有固定长度时,存在一些例外,则响应可以包含多个属性。

1.3.2。属性类型

属性类型指定特定属性所代表的内容。这允许客户理解属性的含义。属性类型由普遍唯一的标识符(UUID)标识。UUID是一个128位值,被认为是空间和时间唯一的。实现可以使用预定义的UUID集或定义自己的UUID。通常,使用更短的UUID形式。这个较短的形式是16位。16位UUID由蓝牙SIG分配,并在蓝牙SIG网站上的蓝牙分配的数字页面上发布。

1.3。3. Attribute Handle

一种ll attributes on the server are assigned a unique non-zero attribute handle. This handle is used by the client in all operations with the server to identify the attribute. It is allowed to dynamically add or remove attributes on the server as long as the new attributes are not assigned a handle which has already been used by any other attribute in the past (even if that attribute has been deleted). This ensures that clients always get a unique attribute handle. Once an attribute has been assigned an attribute handle, it should not change over time. This ensures that clients can keep accessing that attribute with the same handle. The attributes on the server are ordered by the attribute handle. The attribute handle of 0x0000 is reserved and the attribute handle of 0xFFFF is known as the maximum attribute handle.

1.3.4。属性权限

每个属性都有一个关联的一组权限,它决定了该特定属性允许的访问级别。服务器使用属性权限来确定是否允许客户端读取或写入属性值,以及是否需要身份验证或授权来访问该特定属性。属性权限是以下三个权限的组合:

  1. 一种ccess Permission:这可以是:
    • 可读取的
    • 可写的
    • 可读取的and Writeable
  2. 身份验证权限:当客户端尝试访问该属性或者服务器必须向客户端发送通知或指示时,服务器使用该服务器以确定是否需要验证的物理链路。这可以设置为:
    • 需要身份验证
    • No Authentication Required
  3. 授权许可:这是服务器使用,以确定是否需要在访问属性值之前授权客户端。这可以设置为:
    • 需要授权
    • 不需要授权

If client does not have sufficient permissions an error is returned.


1.4. BLE Service Structure

本节介绍ATT轮廓的内部结构。它包含构成配置文件的属性的简要说明,然后解释对话框BLE框架体系结构。

1.4.1。服务声明

一种service is grouped using a服务声明。This is an attribute with an attribute type of either主要服务or二次服务。一种ll attributes that follow this Service Declaration and occur before the next Service Declaration are considered grouped with this service; they belong to this service. A Primary Service is one that encapsulates what the device does. A Secondary Service is one that helps the Primary Service to achieve its behavior. All Secondary Services are referenced from a Primary Service. The service declaration’s value is aService UUID。这是一个16位蓝牙uuid或128位自定义uuid。任何设备都无法理解的服务可以安全地忽略。为了帮助解决此问题,属性协议允许进一步处理要发现的服务的属性处理范围,并且仅处理已知服务。

'Primary and Secondary Service Declaration'

图2初级和二级服务声明

1.4.2. Include Declaration

二次服务s must be discovered separately. To do this, each service can have zero or moreInclude属性。包含声明始终立即遵循服务声明并在服务的任何其他属性之前。该包含定义还包括引用服务的手柄范围,以及所包含的服务的服务UUID。这允许非常快速发现引用的服务,其分组属性和服务的类型。如果此引用的服务是主服务或辅助服务,则不会陈述,因为这不相关。

'Including Service Declaration'

图3.包括服务声明

笔记

鉴于属性值字段中的四个八位字节用于处理,完整的128位服务UUID将不适合用于查找附加服务的标准响应数据包。因此,当包含的服务具有128位UUID时,服务UUID不属于值声明的一部分。这意味着需要额外的属性协议读取请求来查找包括的服务类型。

1.4.3。特征

将属性在服务中进行分组,演示了如何组合这些属性以提供对行为块的一致接口。蓝牙低能量架构还使得可以对属性进行组,以允许公开服务的状态和行为。更具体地,特征暴露了值的数据类型,值表示值,是如何读取或写入值的,如何配置要指示,通知或广播的值以及值均值。为此,特征由三个基本元素组成:

  • Declaration
  • Value
  • Descriptor(s)

一种Declarationis the start of a characteristic; it groups all the other attributes for this characteristic. TheValue属性包含此特性的实际值。这描述符hold additional information or configuration for this characteristic.

1.4.3.1。特征宣言

开始一个特征,一个Characteristic使用属性。这包含三个字段,如图所示图4.

  • 特性
  • Value handle
  • 特征Uuid.

More specifically, the characteristic特性确定是否可以在签名的写入中读取,写入,通知,指示,广播或验证是否可以读取特征值属性。特征价值句柄字段是包含特性值的属性的句柄。最后的领域是特征Uuid.which holds the UUID that is used to identify the type of the characteristic value.

'特点宣言'

图4.特征宣言

笔记

价值句柄field allows a very quick search for the characteristic to be performed by a client. It returns only Characteristic Declarations. With this declaration, the attribute that holds the value is immediately available. If this field did not exist, the client would need to perform an additional search for attributes and effectively guess which attribute after the declaration was the value.

1.4.3.2。特征价值

特征价值is an attribute with a type that must match the characteristic declarations’特征Uuid.场地。除此之外,它是一个普通的属性。最大的区别在于可以在此特征值属性上执行的动作类型在特征声明中暴露特性领域和另外可能在特征扩展属性descriptor.

1.4.3.3。特征描述符

在特征上可以有任何数量的描述符。大多数描述符都是可选的,尽管可能需要根据特征声明而需要。服务规范也可能需要一些描述符。以下描述符可以包含在特征中:

特征扩展属性

This is used to capture the additional extended properties, for example the ability to perform reliable writes on the value or to write the Characteristic User Description descriptor.

特征用户描述

使用这个描述符,一个设备可以将text string with a characteristic.

Client Characteristic Configuration

如果要概述或指示特性,则必须存在该描述符。它是一个双比特值,有一位通知,另一个用于指示。通知和迹象是互补的程序,因此不可能同时设置这两位。如何在核心规范中通知或指示所示的值;这由服务规范定义。

服务器特征配置

这与客户端特征配置描述符非常相似,除了它仅具有用于广播的一位。设置该位使设备广播与分组此特征的服务相关联的数据。该广播的时间由服务确定。

特征呈现格式

通用属性配置文件的一个目标之一是启用泛型客户端。通用客户端被定义为可以读取特征值并将其显示给用户的设备,而无需了解它们的意思。特征呈现格式如果可以由通用客户端使用特性。

特征聚合格式

一些特征值比单个值更复杂。为了允许这种复杂的特征值,特征聚合格式描述符允许引用多个特征呈现格式描述符,从而可以示出该值的各个字段。

1.5。BLE框架架构

这Dialog’s BLE framework consists of the following building blocks:

  • BLE服务框架- 提供实施的“开箱即用的BLE服务”
  • 对话框API.- 启动BLE操作或响应BLE事件的一组函数
  • BLE Manager- 为芯片的BLE功能提供接口
  • 适配器- 将接口提供给BLE堆栈,并执行BLE堆栈内部调度程序,BLE中断等。
  • BLE堆栈- 与BLE H / W IP一起,这使得所有额外的BLE堆叠层达到间隙和GATT
BLE框架架构

图5.BLE框架架构

命令执行的典型流程图如下:

  1. 原则上,应用程序应仅使用对话框BLE API库或/和BLE服务框架来接口。
  2. Commands are sent to the BLE Manager over the command queue and application tasks wait for the response on the response queue.
  3. 收到命令后,在响应队列上发送响应消息。
  4. 一种PI call completes and application execution continues.
  5. BLE events are received asynchronously from the BLE event queue.
BLE框架流程图

图6.BLE Framework Flow Chart

1.6。事件处理水平

Several events can occur during the lifetime of the BLE application and these events need to be handled in a specific manner. In all Dialog’s sample projects (found in the SDK) there are three levels of event handling:

  1. Check whether Bluetooth events can be handled by well-defined Bluetooth services
  2. 如果没有,那么主应用程序任务应该处理它们。
  3. If the target application does not exhibit handlers for handling the received Bluetooth events, theble_handle_event_default()routine is invoked.
'事件处理水平'

图7.事件处理水平

1.7。BLE服务框架

提供:

  • 这一种PI to create new services.
  • 在BLE应用中使用“开箱即用”的服务池。

标题文件在:

  • SDK / BLE /服务/包括

用法:

  • 调用简单的初始化函数
  • 定义各种BLE服务事件的回调