Art*_*ert 5 c linux compilation bluetooth-lowenergy bluez
我目前正在使用C 中的api实现一个BLE服务器。我需要使用我自己的具有自定义特征的服务。GATTbluez5
问题是bluez5没有安装GATTapi的所有头文件。libbluetoothwith 中的相同问题不提供所有外部GATTapi。
我使用了错误的 api 吗?编译我的代码的技巧是什么?当前肮脏的解决方案是用我自己的代码替换源代码的btgatt-server.c工具目录中bluez,以便能够实现dev/test我的实现。
编辑:我使用的是最后一个稳定版本bluez:5.32
bluez我需要编译我的代码的头文件:
#include "lib/bluetooth.h"
#include "lib/hci.h"
#include "lib/hci_lib.h"
#include "lib/l2cap.h"
#include "lib/uuid.h"
#include "src/shared/mainloop.h"
#include "src/shared/util.h"
#include "src/shared/att.h"
#include "src/shared/queue.h"
#include "src/shared/timeout.h"
#include "src/shared/gatt-db.h"
#include "src/shared/gatt-server.h"
Run Code Online (Sandbox Code Playgroud)
职能 :
[arthur ] make 2>&1 | grep gatt_ | grep implicit
tools/btgatt-server.c:32:2: error: implicit declaration of function ‘gatt_db_attribute_read_result’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:60:2: error: implicit declaration of function ‘gatt_db_add_service’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:67:2: error: implicit declaration of function ‘gatt_db_service_add_characteristic’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:94:2: error: implicit declaration of function ‘gatt_db_service_set_active’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:110:2: error: implicit declaration of function ‘bt_gatt_server_unref’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:111:2: error: implicit declaration of function ‘gatt_db_unref’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:186:2: error: implicit declaration of function ‘gatt_db_new’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:192:2: error: implicit declaration of function ‘bt_gatt_server_new’ [-Werror=implicit-function-declaration]
tools/btgatt-server.c:202:2: error: implicit declaration of function ‘bt_gatt_server_set_debug’ [-Werror=implicit-function-declaration]
Run Code Online (Sandbox Code Playgroud)
这些包含不是由bluez我系统上的 Makefile 安装的。而且库文件也不包含我需要的功能。
dbus稍后我可能会使用API。但现在我总是使用低c API bluez5(来自bluez5的示例路径:bluez5_utils-5.31/tools/btgatt-server.c)。为了在 bluez5 源目录之外编译此独立代码,我使用了 bluez5 中的一些包含/库:
就我而言,我正在使用 buildroot。所以我在 bluez5 mk 文件中添加一些代码来获取这个缺失的库:
define BLUEZ5_UTILS_EXTERNALIZE_GATT
mkdir -p $(STAGING_DIR)/usr/local/bluez5/gatt
cp $(BLUEZ5_UTILS_SRCDIR)/src/uuid-helper.o $(STAGING_DIR)/usr/local/bluez5/gatt/.
cp $(BLUEZ5_UTILS_SRCDIR)/src/.libs/libshared-mainloop.a $(STAGING_DIR)/usr/local/bluez5/gatt/.
cp $(BLUEZ5_UTILS_SRCDIR)/lib/.libs/libbluetooth-internal.a $(STAGING_DIR)/usr/local/bluez5/gatt/.
$(INSTALL) -D -m 0755 $(@D)/tools/btmgmt $(STAGING_DIR)/usr/bin/btmgmt
$(INSTALL) -D -m 0755 $(@D)/tools/btmgmt $(TARGET_DIR)/usr/bin/btmgmt
endef
Run Code Online (Sandbox Code Playgroud)
然后在我的 Makefile 中,我只需要链接这些库 + 添加 -I 即可找到 bluez5 源目录中缺少的头文件:
# find bluez5 header
HEADER += -I$(BLUEZ_PATH)
# link bluez5 libraries
BLUEZ5_LIB = $(STAGING_DIR)/usr/local/bluez5/gatt/libshared-mainloop.a BLUEZ5_LIB += $(STAGING_DIR)/usr/local/bluez5/gatt/libbluetooth-internal.a
Run Code Online (Sandbox Code Playgroud)
无论如何,这可能不是最好的方法,但效果很好。而且you don't need to do anything if you upgrade your bluez5 version。我找到了一些其他解决方案,例如 fork bluez5 并在 Makefile 中进行了一些修改以构建一个包含我需要的所有内容的静态库。但这个解决方案确实很痛苦,并且您需要在每个新的 bluez5 版本中更新您的工作。