使用 C++ 的 BLE GATT 服务器示例

问题描述 投票:0回答:1

我正在尝试使用 C++ 在我的 Raspberry Pi 4 上创建 BLE GATT 服务。搜索了一段时间但找不到有用的提示/示例。

更多详情: 我能够使用命令创建 GATT 服务和特征:

#bluetoothctl
[bluetoothctl] menu gatt
[bluetoothctl] register-service 0xFFFF #
[bluetoothctl] register-characteristic 0xAAAA read,write #
[bluetoothctl] register-application #

我想使用 C++ 代码实现相同的目标。

我在

https://github.com/Vudentz/BlueZ/blob/master/doc/gatt-api.txt
中找到了void RegisterApplication(object application, dict options) 的定义,但它没有提供很多细节。我的问题是: 对于这个 RegisterApplication 函数,我应该为“对象应用程序”和“dic 选项”添加什么?有没有格式的例子

g_dbus_proxy_call(
        Proxy,         
        "RegisterApplication",       
        Params,                       
        G_DBUS_CALL_FLAGS_NONE,      
        -1,                  
        NULL,
                NULL,
                NULL);

显示如何为我的服务和特征(使用命令注册)构建“参数”?

c++ linux bluetooth-lowenergy bluez gatt
1个回答
0
投票

您需要在 D-Bus 中构建 BLE GATT 服务层次结构,然后使用

RegisterApplication
告诉 BlueZ 服务的顶层位于 D-Bus 上的位置。

要使用 D-Bus 的说法,需要使用 D-Bus 对象创建本地 BlueZ 服务,然后发布。它是您创建的已发布本地 BlueZ 服务层次结构的 D-Bus 对象,它是

RegisterApplication

的第一个参数

更多信息请访问: https://github.com/Kistler-Group/sdbus-cpp/blob/master/docs/using-sdbus-c++.md#using-d-bus-connections-on-the-server-side

您可能还想查看以下项目,看看他们是如何做到的: https://github.com/netttlep/gobbledegook

© www.soinside.com 2019 - 2024. All rights reserved.