2016-06-07 116 views
0

我正在尝试从蓝牙LE设备发送给我的数组中读取数据。从UUID读取蓝牙LE数组?

该数据流应为18个字节,并且,作为一个数组观察时,我需要字节5,图6和7

我对servicecharacteristic正确的UUID。但是,我不知道如何从characteristic获得数组。

现在我只是试图获取我认识的数据。但是,下面的日志语句会生成我无法理解或与数据匹配的随机字符。

这个函数中唯一真正重要的行是与characteristic.getValue()的日志,但我想我会包括整个事情的一些上下文。

@Override 
     public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { 
      Log.d(TAG, "characteristic read: "+characteristic.getValue()); 
      gatt.setCharacteristicNotification(characteristic, true); 
      gatt.readRemoteRssi(); 
      runOnUiThread(update_UI); 

      try { 
       Thread.sleep(500); 
      } catch(InterruptedException ex) { 
       Thread.currentThread().interrupt(); 
      } 

      gatt.discoverServices(); 
     } 

回答

0

在阵列末尾加上我想要的字节的括号给了我想要的数据。

Log.d(TAG, "characteristic read: "+characteristic.getValue()[4]);会给我第四个字节。