1

我正在尝试创建一个安装在 eurotech 网关(reliagate 10 05)上的 OSGi 包。该捆绑包实质上会将网关连接到 BLE 设备。

为此,我使用了由 eurotech 提供的名为Everyware™ Software Framework (ESF)的框架,它在kura v1.2.0框架之上添加了一个额外的层。

问题是,BLE 设备只接受随机静态地址类型。

我设法使用控制台中的以下命令将网关手动连接到 BLE 设备:

hcitool -i hci0 lecc --random <BD_ADDR>

然后

gatttool -i hci0 -b <BD_ADDR> --interactive

这工作正常。困难的部分是当我尝试使用ESF/kura框架在代码中做同样的事情时。

这是我在此页面上找到的示例中的一个片段

public boolean connect(String adapterName) {
    this.bluetoothGatt = this.device.getBluetoothGatt();
    boolean connected = false;
    try {
          connected = this.bluetoothGatt.connect(adapterName);
    } catch (KuraException e) {
          logger.error(e.toString());
    }
    if (connected) {
        this.bluetoothGatt.setBluetoothLeNotificationListener(this);
        this.isConnected = true;
        return true;
    } else {
       // If connect command is not executed, close gatttool
        this.bluetoothGatt.disconnect();
        this.isConnected = false;
        return false;
    }
}

以下是示例用于扫描和建立连接的一些对象的列表:

org.eclipse.kura.bluetooth.BluetoothAdapter;
org.eclipse.kura.bluetooth.BluetoothDevice;
org.eclipse.kura.bluetooth.BluetoothGattSecurityLevel;
org.eclipse.kura.bluetooth.BluetoothGattService;
org.eclipse.kura.bluetooth.BluetoothLeScanListener;
org.eclipse.kura.bluetooth.BluetoothService;
org.eclipse.kura.bluetooth.BluetoothDevice;
org.eclipse.kura.bluetooth.BluetoothGatt;
org.eclipse.kura.bluetooth.BluetoothGattCharacteristic;
org.eclipse.kura.bluetooth.BluetoothLeNotificationListener;

所以我搜索了 api文档,但没有找到任何东西。

不过,一篇有趣的 SO帖子提到了要发送到设备的命令代码。

我在 kura 框架中找到了一种可能有帮助的方法。这是签名:

void ExecuteCmd(java.lang.String ogf, java.lang.String ocf, java.lang.String parameter)

但我无法在任何文档中找出与操作码命令字段(ocf)相关的操作码组字段(ogf)(我浏览了蓝牙 4.0 核心规范的约 2300 页)。如果有人知道在哪里搜索... :)

最后,问题是:有没有办法使用 kura 框架将地址类型设置为随机(与 hcitool 命令一样)?还是我完全被误导了?:/

无论如何,我对 kura 和 ble 生态系统真的很陌生,所以很抱歉,如果这看起来很明显,但我觉得我的灵感快用完了,完全可以用一只手!

PS:如果你成功了,恭喜你!

4

2 回答 2

1

哈哈真好笑。Kura 似乎只是启动了一个 gatttool 进程,以文本形式发送命令,并将输出解析为它的接口......

这是声明的地方,使用地址作为参数:https ://github.com/eclipse/kura/blob/0339ac787f90debdfc270c1dee0c16de16ea6f7e/kura/org.eclipse.kura.linux.bluetooth/src/main/java/org/eclipse /kura/linux/bluetooth/util/BluetoothUtil.java#L319。不幸的是,Kura 开发人员似乎错过了 BLE 标准中称为随机地址的东西,我不知道如何使用当前的 API 解决这个问题。

于 2017-09-21T23:04:13.633 回答
0

好的,对于那些将来发现自己处于我的位置的人,我刚刚收到了 Eurotech 支持团队的答复。

亲爱的卡内罗先生,

[...]

关于随机 BD_ADDR,这是 BLE 设备的配置。因此,您的 BLE 设备正在广播一个随机类型的地址,而不是公共地址,您应该在连接字符串上指定地址类型,就像您已经做的那样。 不幸的是,当前的 Kura 蓝牙 API 没有提供将地址类型指定到连接字符串中的方法。我们正在为 BLE 开发一组新的 API,将在下一个 Kura/ESF 版本的预览版中提供,但 Reliagate 10-05 尚不支持这些 API。

于 2017-09-22T09:20:12.120 回答