使用kura框架时,如何在连接到BLE设备时指定地址类型为“随机静态”
我试图创建将安装在eurotech网关(reliagate 10 05)上的OSGi捆绑包。 该捆绑包实质上将网关连接到BLE设备。使用kura框架时,如何在连接到BLE设备时指定地址类型为“随机静态”
要做到这一点,我用的Eurotech提供了一个框架称为Everyware™软件框架(ESF),关于库拉V1.2.0框架的顶部增加了一个额外的层。
问题是,BLE设备只接受随机静态地址类型。
我设法在控制台中使用以下命令手动连接的门户BLE装置:
hcitool -i hci0 lecc --random <BD_ADDR>
然后
gatttool -i hci0 -b <BD_ADDR> --interactive
这工作得很好。困难的部分是当我尝试使用框架在代码中做同样的事情时。
下面是从样本的片断我用我这个page
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 doc搜索,但没有找到任何东西。
虽然有一个有趣的SO post提到了一个命令代码发送到设备。
我在库拉框架中找到了一种方法,可能有所帮助。 这里的签名:
void ExecuteCmd(java.lang.String ogf, java.lang.String ocf, java.lang.String parameter)
,但我无法弄清楚操作码组字段(OGF)的任何文档相关联的操作码命令字段(OCF)(我脱脂蓝牙4.0核心的〜2300页规格)。如果有人知道在哪里搜索... :)
最后,问题是:有没有办法将地址类型设置为随机(与hcitool命令一样)与库拉框架? 还是我完全误导了? :/
无论如何,我真的对库拉和布莱克生态系统很陌生,所以,抱歉,如果它看起来像一个明显的事情,但我觉得我用尽灵感,可以完全用一只手!
PS:恭喜你,如果你做到了!
对于那些在未来发现自己处于我的位置的人来说,我刚刚收到了Eurotech支持团队的答复。
亲爱卡内罗先生,
[...]
关于随机BD_ADDR,这是BLE设备的配置。 因此,您的BLE设备正在广告一个随机类型的地址,而不是公共地址,并且您应该在连接字符串上指定地址类型,就像您已经做的那样。 不幸的是,目前的库拉蓝牙API没有提供一种方法来指定连接字符串中的地址类型。我们正在为BLE开发一套新的API,将在下一个Kura/ESF版本上预览,但Reliagate 10-05目前还不支持这些API。
哈哈大声笑。 Kura似乎只是启动了一个gattool进程,以文本形式发送命令,并将输出解析为其接口...
以下是它的使用地址作为参数: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。不幸的是,库拉开发人员似乎错过了BLE标准中存在的所谓随机地址,我不明白如何使用当前的API。
嗨,埃米尔谢谢你的答案! 是的,我看到那个类,我试图导入包org.kura.linux.bluetooth作为捆绑依赖项,以便我可以使用方法 hcitoolCmd(String name,String [] cmd,BluetoothProcessListener listener); 和基本上“重载”startSession()方法。 但是,当我导出捆绑软件包时说我的bluetooth。*软件包的类没有解析* sigh *。 我觉得这是一个有效的途径。 – ChrisCarneiro