我試圖創建將安裝在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