加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

Linux API上的Bluetooth Low-Enery

发布时间:2020-12-13 19:47:24 所属栏目:Linux 来源:网络整理
导读:我有一个设备有一些自定义GATT服务,我想编写一个 Linux程序来与它进行交互.经过一番搜索,我发现Linux正在使用BlueZ来处理蓝牙LE协议.我正在使用UZntu 15.10和BlueZ 5.35,但我无法弄清楚如何在用户空间程序中使用这个BlueZ.我无法在任何地方找到API文档,没有
我有一个设备有一些自定义GATT服务,我想编写一个 Linux程序来与它进行交互.经过一番搜索,我发现Linux正在使用BlueZ来处理蓝牙LE协议.我正在使用UZntu 15.10和BlueZ 5.35,但我无法弄清楚如何在用户空间程序中使用这个BlueZ.我无法在任何地方找到API文档,没有教程,示例,什么都没有.甚至可以使用这个BlueZ堆栈来做除了使用默认服务连接蓝牙设备之外的任何事情吗?如果是这样,文档在哪里? (最好是C/C++ API,但此时一切顺利)

解决方法

看一下bluez来源中的attrib / gatttool.c [1]. Gatttool是一个命令行实用程序,用于使用C“API”连接到BTLE设备.但是,GATT接口不会暴露在libbluetooth中. gatttool的另一个新替代方案是另一个可以学习的例子是btgatt-client,你可以在tools / btgatt-client.c中找到它(为了使用–enable-experimental启用编译配置bluez).除了C接口bluez集成了DBUS接口. bluetoothctl是使用DBUS接口的示例工具. bluetoothctl的代码可以在client / [2]中找到.另一个使用bluez的C接口的示例程序是Anki Drive SDK [3].它将bluez GATT C接口打包在自己的库libbzle [4]中.使用C接口时,必须在建立BTLE连接时连接套接字. gatttool通过GATT接口完成此操作,GATT接口又使用glib iirc.但你也可以使用系统调用(socket,connect,…)来解决这个问题.这里[5].该文件还解释了:

Unfortunately,as of now there is no official API reference to refer to,so more curious readers are advised to download and examine the BlueZ source code.

Gilbert Brault还从bluez [6]中提取了GATT接口,并链接到GATT接口的基本doxygen文档[7],其中包含以下免责声明:

This is a work in progress with the intent of documenting all important functions and data structures

此外,Szymon Janc在2016年嵌入式Linux大会上的演讲“蓝牙现代Linux”中给出了很好的概述[8].在42:00关闭时,他谈到了未曝光的C接口.但总的来说,他似乎推荐使用DBUS API(请参阅45:30的“提示”幻灯片).一些DBUS文档可以在doc / gatt-api.txt [9]中找到,使用DBUS接口的Python示例可以在test /中找到.

希望这可以帮助.

[1] http://git.kernel.org/cgit/bluetooth/bluez.git/tree/attrib/gatttool.c
[2] http://git.kernel.org/cgit/bluetooth/bluez.git/tree/client/
[3] https://github.com/anki/drive-sdk/
[4] https://github.com/anki/drive-sdk/tree/master/deps/bzle/
[5] https://people.csail.mit.edu/albert/bluez-intro/c404.html
[6] https://github.com/gbrault/gattclient
[7] http://gbrault.github.io/gattclient/index.html
[8] https://www.youtube.com/watch?v=tclS9arLFzk
[9] http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/gatt-api.txt

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读