2015-07-28 97 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版本中更新你的工作。