创建 Gatt 服务器? [英] Creating a Gatt Server?

查看:15
本文介绍了创建 Gatt 服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个更广泛的问题,所以如果有人可以向我指出可以解释这一点的文档或文章,那就足够了.不用说,一天的谷歌搜索让我一无所获,我可以伸出援助之手.

I have a wider range question here, so if someone could point me to a doc or article that could explain this, that would suffice. Needless to say, a days worth of googling has gotten me nowhere, and I could use a helping hand.

我正在使用 BlueZ 5.9 连接到 BeagleBoard,我的目的是:

I am connecting to a BeagleBoard with BlueZ 5.9, and my intent is to:

  1. 创建一个 Gatt 服务器,
  2. 用一些可写的属性加载它,然后
  3. 通知该服务器连接到 Android 设备.

我已经创建了 Android 应用程序,它将作为中心进行连接和操作,渲染 3 基本完成.我不知道命令 - 要键入的字面意思 - 如何在 BeagleBoard 上启动 Gatt 服务器/创建属性.我知道硬件写得很大,所以我的术语可能完全不正确 - 也就是说,完成 1 和 2 的任何帮助都会受到赞赏,即使它只是朝着正确的方向推进.谢谢!

I've created the Android app that will connect and operate as the central, rendering 3 basically complete. I don't know how the commands - the literal things to type - to initiate a Gatt server / create attributes on the BeagleBoard. I am knew to hardware writ large, so it is possible I just have my terminology completely incorrect - that said, any help would be a appreciated in completing 1 and 2, even if it is just a shove in the right direction. Thanks!

推荐答案

你的术语基本正确.

通常,GATT 数据库具有服务 0x1800(通用访问)0x1801(通用属性) 至少.通用访问服务包含两个强制性特征:设备名称外观.通用属性服务应为空.

Typically, a GATT database has the services 0x1800 (Generic Access) and 0x1801 (Generic Attribute) at least. The Generic Access service contains two mandatory characteristics: Device Name and Appearance. The Generic Attribute service should be empty.

因此,最小的 GATT 数据库如下所示:

Therefore, the minimal GATT database looks like this:

Handle  Description
 0000   Service: Generic Access (1800)
 0001   Characteristic: Device Name (2A00, readable)
 0002   Characteristic Value (string)
 0003   Characteristic: Appearance (2A01, readable)
 0004   Characteristic Value (16bit enum)
 0005   Service: Generic Attribute (1801) 

在这两个服务之后,您可以添加自己的服务.就您而言,您似乎没有针对知名服务,因此您将创建自己的服务.

After these two services, you can add your own services. In your case, you don't seem to target a well-known service, so you'll create an own one.

首先,创建一个 128 位 UUID,例如使用 Mac 命令行上的 uuidgen 工具

First, create a 128-bit UUID, for example using the uuidgen tool on your Mac's command line

$ uuidgen
DCDF2725-56C8-4235-A4BC-F7951D5C3762

这将是您的服务 UUID

This will be your service UUID

 0006   Service: Custom defined Service (DCDF2725-56C8-4235-A4BC-F7951D5C3762)

然后,您提到您想要几个可写的特性.因此,让我们为该 UUID 创建另一个 UUID.

Then, you mentioned that you want several writeable characteristics. So, let's create another UUID for that one.

$ uuidgen
4C06C6F4-C90D-4C58-8E31-20C8C74FF832

并为服务添加特征

 0007   Characteristic: Custom Characteristic (4C06C...FF832, writeable)
 0008   Characteristic Value (hex, 20 bytes)

您的特征值不应超过 20 个字节,并且您应该选择写入请求"以确保将写入确认发送到中央.如果您选择写入命令",则写入可能会被手机堆栈或外设丢弃.

Your characteristic value shouldn't exceed 20 bytes, and you should select "Write Request" to ensure that acknowledgments of writes are sent to the central. If you choose "Write Command", writes may be discarded by either your phone's stack or the peripheral.

定义此特性后,您就可以开始编码了.

After you have defined this characteristic, you are ready to start coding.

我不知道 BeagleBoard SDK,但通常情况下,您首先要初始化 GATT 库和其他模块(例如,为了支持写入,您必须初始化库的第二部分).

I don't know the BeagleBoard SDK, but typically, you start by initializing the GATT library and additional modules (for example, to support writes, you have to initialize a second part of the library).

在此初始化之后,您注册 GATT 数据库.如果您没有用于生成二进制数据的好工具,您可能必须自己编写它们.Bluetooth Core Spec V4.0 对此进行了解释.让我们希望您能找到一个 API 来为您进行转换 :-)

After this initialization, you register your GATT database. If you don't have a nice tool for generating the binary data, you may have to write them yourselves. That's explained in the Bluetooth Core Spec V4.0. Let's hope you can find an API that does the transformation for you :-)

注册成功后,您需要设置广告参数,然后才能开始投放广告(请再次查阅您的 SDK 文档和示例).

When the registration is successful, you'll have to set the advertising parameters and can start advertising (consult your SDK's documentation and samples for this, again).

现在发生的是,在某个时候,您将收到一个连接已建立的回调,稍后,您将收到一个给定句柄的属性请求.然后,您只需通过查看句柄、提供的值和操作类型(读/写)来处理请求.不要忘记在响应请求时总是返回成功值或错误代码,否则,您将锁定蓝牙通信.

What happens now, is that at some time, you will get a callback that a connection has been established, and later, you'll get an attribute request for a given handle. Then, you just have to process the request by looking at the handle, the supplied value and the type of the operation (read / write). Don't forget to always return a success value or an error code in response to the request, as otherwise, you'll lock up the Bluetooth communications.

通常情况下,那些蓝牙芯片总是以异步操作工作.您将发送一个请求,然后必须等到请求完成后再发送下一个请求.请记住,在编程时,它可以节省您的时间 :-).

Normally, those Bluetooth chips always work with asynchronous operations. You'll send a request, and then have to wait until the request is completed before sending the next one. Remember that when programming, it saves you time :-).

如果您想先试用 Android,因为它对您更熟悉,您可以尝试使用 Android 4.2 的 Galaxy S 4.它还有一个 LE 外围模式——不过我还没有测试过它的可靠性.目前用作 LE 外围设备的最可靠的智能手机堆栈目前在 iOS 7 中 - 因此,如果可以负担得起,那么购买 iPod touch 可能是值得的.

If you want to try on Android first because it's more familiar for you, you can try the Galaxy S 4 with Android 4.2. It also has an LE peripheral mode - I haven't tested its reliability, though. The most reliable smartphone stack at the moment to act as LE peripheral is currently in iOS 7 - so it may be worth picking up an iPod touch if it's affordable to play around with it.

这篇关于创建 Gatt 服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆