我试图创建将安装在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:恭喜你,如果你做到了!
嗨,埃米尔谢谢你的答案! 是的,我看到那个类,我试图导入包org.kura.linux.bluetooth作为捆绑依赖项,以便我可以使用方法 hcitoolCmd(String name,String [] cmd,BluetoothProcessListener listener); 和基本上“重载”startSession()方法。 但是,当我导出捆绑软件包时说我的bluetooth。*软件包的类没有解析* sigh *。 我觉得这是一个有效的途径。 – ChrisCarneiro