我正在尝试创建一个安装在 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:如果你成功了,恭喜你!