简体   繁体   English

Dbus和Bluez编程语言

[英]Dbus & Bluez programming language

For a project I am doing I have to connect my Linux PC to a Bluetooth LE device. 对于我正在做的项目,我必须将我的Linux PC连接到蓝牙LE设备。 The application I design will be deployed on an ARM embedded system when it is complete. 我设计的应用程序将在ARM嵌入式系统完成后部署。 Searching for documentation online hints that the preferred programming language for these kind of applications is Python. 在线搜索文档提示这些应用程序的首选编程语言是Python。 All the Bluez /test examples are written in Python and there are quite a few sources of information regarding creating BLE applications in Python. 所有Bluez /测试示例都是用Python编写的,有很多关于在Python中创建BLE应用程序的信息来源。 Not so much in C. 在C.中没有那么多

My superior and I had an arguement about whether I should use Python or C. One of his arguments was that there was unacceptable overhead when using Python for setting up Bluetooth LE connections and that Bluetooth LE had to be very timely in order to function properly. 我和我的上司争论我是否应该使用Python或C.他的一个论点是,当使用Python设置蓝牙LE连接时,存在不可接受的开销,并且蓝牙LE必须非常及时才能正常运行。 My argument was that the overhead would not matter as much, since there were no time constraints regarding bluetooth LE connections; 我的论点是,开销并不重要,因为蓝牙LE连接没有时间限制; The application will find devices, connect to a specific one and read a few attributes, which it saves to a file. 应用程序将查找设备,连接到特定设备并读取一些属性,并将其保存到文件中。

My question is; 我的问题是; is there any reason to prefer the low-level C approach over using a high-level Python implementation for a basic application that reads GATT services and their characteristics? 是否有理由更倾向于使用低级C方法而不是将高级Python实现用于读取GATT服务及其特性的基本应用程序? What would the implications be for an embedded device? 对嵌入式设备有什么影响?

This is quite an open question as there are so many things to consider when making this decision. 这是一个非常开放的问题,因为在做出这个决定时需要考虑很多事情。 So the best "answer" might rather be an attempt to narrow down the discussion: 因此,最好的“答案”可能是尝试缩小讨论范围:

Based on the question, I'm making the assumption that the system you are targeting has D-Bus and Python available with all needed dependencies. 基于这个问题,我假设您所针对的系统具有所有必需的依赖关系的D-Bus和Python。

I'd try to narrow down the discussion by first deciding on what BlueZ API to use. 我首先尝试通过决定使用什么BlueZ API来缩小讨论范围。 If you are planning on using the D-Bus API rather than the libbluetooth C library API, then there is already some overhead introduced by that and I don't believe Python in itself would be the major factor. 如果您计划使用D-Bus API而不是libbluetooth C库API,那么已经引入了一些开销,我不相信Python本身就是主要因素。 That should of course be measured/evaluated to know for sure, but ruling out Python while still using D-Bus might be a premature optimization without much impact in practice. 当然,这应该被测量/评估以确定,但是在仍然使用D-Bus的情况下排除Python可能是一个不成熟的优化,在实践中没有太大影响。

If the C library API is to be used in order to avoid D-Bus overhead then I think you should go with C for the client throughout. 如果要使用C库API以避免D-Bus开销,那么我认为你应该在整个客户端使用C语言。

If the "timely manner" factor is very important I believe you will eventually need to have ways to measure performance anyway. 如果“及时”因素非常重要,我相信你最终还是需要有办法衡量绩效。 Then perhaps a proof of concept of both design options might be the best way to really decide. 那么也许两种设计方案的概念证明可能是真正决定的最佳方式。

If the timing constraints turn out to be a moot question in practice, other aspects should weigh in more, eg ease of development (documentation and examples available), testability, and so on. 如果时间限制在实践中成为一个没有实际意义的问题,那么其他方面应该更加重要,例如易于开发(可用的文档和示例),可测试性等等。

Something more to consider: 还需要考虑的事情:

  1. the latest BlueZ (eg. 5.36+), BLE should work fine and has been very stable for me - and remember to add "experimental" when building it and "-E" as a service parameter to get manufacturerData (and other experimental features) 最新的BlueZ(例如5.36+),BLE应该可以正常工作并且对我来说非常稳定 - 并且记住在构建它时添加“experimental”和“-E”作为服务参数以获得manufacturerData(和其他实验性功能)

  2. Using the C API, I think your code must be GPL (not 100% sure tho). 使用C API,我认为您的代码必须是GPL(不是100%肯定)。 The DBus interface allows you to make closed source code (if it's for a company) DBus接口允许您制作封闭的源代码(如果是公司的话)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM