2015-07-28 57 views
1

我目前正在实现一个BLE服务器使用GATT api从bluez5 C.我需要使用我自己的服务与自定义特征。使用bluez gatt api编译代码

问题是bluez5没有安装GATT api的所有标头。与libbluetooth相同的问题,并不提供所有外部GATT api。

我使用错误的API吗?什么是编译我的代码的提示? 目前肮脏的解决方案是用我自己的代码替换btgatt-server.c工具目录中的bluez源码,以便能够dev/test我的实现。

编辑: 我使用的bluez最新稳定版本:bluez5.32

头,我需要编译我的代码:

#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" 

功能:

[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] 

这些包括我的系统上没有安装的Makefile的bluez。而库文件不包含我需要的功能。

+0

您使用的是最新版本的Bluez吗?请提供这些信息。你有没有试过http://www.bluez.org/获得帮助? – Neil

+0

也请提供您遇到的错误?我会添加更多信息,这真的有助于那些试图帮助你的人。 – Neil

+0

出于兴趣,你有什么版本的内核 - 它至少是2.4.6版本吗? – Neil

回答

0

我稍后可能会用到dbus API。但是现在我总是使用来自bluez5的低c API(来自bluez5:bluez5_utils-5.31/tools/btgatt-server.c的示例路径)。要编译bluez5源目录之外的这个独立的代码,我使用了一些包括从bluez5 /库:

  • libshared-mainloop.a
  • libbluetooth-internal.a

在我来说,我的工作与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 

然后在我的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 

反正这可能不是做的最好方式,但它是伟大的工作。此外you don't need to do anything if you upgrade your bluez5 version。我找到了一些其他的解决方案,如fork bluez5,并在Makefile中进行了一些修改,以构建一个包含我需要的所有东西的静态库。但是这个解决方案非常痛苦,你需要在每个新的bluez5版本中更新你的工作。