2017-12-19 19 views
0

다른 사람들도 도움을 받기 바랍니다. 블루투스 저에너지 프로토콜에 관한 문제로 상당히 어려움을 겪고 있습니다. 예를 들어 장치에는 서비스가 있고이 서비스에는 설명자가 포함 된 특성이 포함됩니다. 서비스, ​​특성 및 설명자의 UUID는 사전에 알 수 없습니다. 내 질문은이 특정 UUID가 Service/Charactersitic/Descriptor 유형이라는 것을 알 수있는 방식으로 UUID를 가져 오는 방법입니다.BLE (Bluetooth Low Energy) - 서비스, 특성 및 설명자의 UUID를 별도로 얻는 방법

BluetoothGatt.getServices()은 도움이되지 않습니다. 왜냐하면 모든 UUID를 함께 반환하기 때문에 어떤 서비스에 속하는지 알 수 없기 때문입니다. 나는 UUID를 분할하는 방법이 있다고 확신한다. 적어도 nRF Connect 앱 (Play 스토어에서 찾을 수 있음)에서이 작업을 수행 할 수 있습니다.

시간과 노력에 감사드립니다. https://www.bluetooth.com/specifications/gatt/characteristics

지금 당신이 UUID를의 목록을 실행하고 그들과 비교할 수 있습니다 여기에

+0

BluetoothGatt.getServices() 원격 장치에서 제공하는 GATT 서비스 목록을 반환합니다. 그 후에 서비스를 통해 각 서비스의 특성을 파악할 수 있습니다. idk 당신이 잘못하고있는 일. 가능한 경우 일부 코드를 공유하십시오. –

답변

0

당신은 가능한 모든 특성의 목록을 가지고있다. 당신은 GATT 콜백의 특성을받을 때

다음
// All BLE characteristic UUIDs are of the form: 
// 0000XXXX-0000-1000-8000-00805f9b34fb 
// The assigned number for the Heart Rate Measurement characteristic UUID is 
// listed as 0x2A37, which is how the developer of the sample code could arrive at: 
// 00002a37-0000-1000-8000-00805f9b34fb 
public static class Characteristic { 
    final static public UUID HEART_RATE_MEASUREMENT = UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb"); 
    final static public UUID CSC_MEASUREMENT   = UUID.fromString("00002a5b-0000-1000-8000-00805f9b34fb"); 
    final static public UUID MANUFACTURER_STRING  = UUID.fromString("00002a29-0000-1000-8000-00805f9b34fb"); 
    final static public UUID MODEL_NUMBER_STRING  = UUID.fromString("00002a24-0000-1000-8000-00805f9b34fb"); 
    final static public UUID FIRMWARE_REVISION_STRING = UUID.fromString("00002a26-0000-1000-8000-00805f9b34fb"); 
    final static public UUID APPEARANCE    = UUID.fromString("00002a01-0000-1000-8000-00805f9b34fb"); 
    final static public UUID BODY_SENSOR_LOCATION  = UUID.fromString("00002a38-0000-1000-8000-00805f9b34fb"); 
    final static public UUID BATTERY_LEVEL   = UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb"); 
    final static public UUID CLIENT_CHARACTERISTIC_CONFIG = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); 
} 

, (목록에 대해) 확인하려고 그것이 특징 :

private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { 
    ... 
    @Override 
    public void onCharacteristicRead(BluetoothGatt gatt, 
            BluetoothGattCharacteristic characteristic, 
            int status) { 
     if (status == BluetoothGatt.GATT_SUCCESS) { 
      getCharacteristicValue(characteristic); 
     } 
    } 

    @Override 
    public void onCharacteristicChanged(BluetoothGatt gatt, 
             BluetoothGattCharacteristic characteristic) { 
     getCharacteristicValue(characteristic); 
    } 
} 

private void getCharacteristicValue(BluetoothGattCharacteristic characteristic) { 
    if(characteristic.getUuid().equals(Characteristic.HEART_RATE_MEASUREMENT)) { 
     if (mType == Accessory.Type.HRM && mBtLeGattServiceHeartrate != null) { 
      mBtLeGattServiceHeartrate.onCharacteristicChanged(mContext, BtLeDevice.this, characteristic); 
     } 
    } 
} 

희망이 여기에 그 중 일부를 포함하는 클래스입니다 도움이됩니다.

+0

노력해 주셔서 감사합니다. 그러나 도움이되지 않습니다. 나는 UUID를 미리 모른다. 목표는 서비스, 특성 및 설명자를 위해 별도로 찾아내는 것입니다. –

0

문제를 해결할 수있는 유일한 방법은 ScanResult에서 가져온 ScanRecord을 사용하는 것입니다. ScanRecord에는 서비스의 UUID를 포함하여 검색된 각 장치에 대한 정보가 저장됩니다. 따라서

List<UUID> serviceUUIDsList  = new ArrayList<>(); 
List<UUID> characteristicUUIDsList = new ArrayList<>(); 
List<UUID> descriptorUUIDsList  = new ArrayList<>(); 

private void initScanning(BluetoothLeScannerCompat bleScanner) 
{ 
    bleScanner.startScan(getScanCallback()); 
} 

private ScanCallback getScanCallback() 
{ 
    return new ScanCallback() 
    { 
     @Override 
     public void onScanResult(int callbackType, ScanResult scanResult) 
     { 
      super.onScanResult(callbackType, scanResult); 
      serviceUUIDsList = getServiceUUIDsList(scanResult); 
     } 
    }; 
} 

private List<UUID> getServiceUUIDsList(ScanResult scanResult) 
{ 
    List<ParcelUuid> parcelUuids = scanResult.getScanRecord().getServiceUuids(); 

    List<UUID> serviceList = new ArrayList<>(); 

    for (int i = 0; i < parcelUuids.size(); i++) 
    { 
     UUID serviceUUID = parcelUuids.get(i).getUuid(); 

     if (!serviceList.contains(serviceUUID)) 
      serviceList.add(serviceUUID); 
    } 

    return serviceList; 
} 

, 우리는 서비스 UUID를 알고있을 때, 우리는 특성 및 기술자의 UUID를 얻을 수 있습니다 :

private void defineCharAndDescrUUIDs(BluetoothGatt bluetoothGatt) 
{ 
    List<BluetoothGattService> servicesList = bluetoothGatt.getServices(); 

    for (int i = 0; i < servicesList.size(); i++) 
    { 
     BluetoothGattService bluetoothGattService = servicesList.get(i); 

     if (serviceUUIDsList.contains(bluetoothGattService.getUuid())) 
     { 
      List<BluetoothGattCharacteristic> bluetoothGattCharacteristicList = bluetoothGattService.getCharacteristics(); 

      for (BluetoothGattCharacteristic bluetoothGattCharacteristic : bluetoothGattCharacteristicList) 
      { 
       characteristicUUIDsList.add(bluetoothGattCharacteristic.getUuid()); 
       List<BluetoothGattDescriptor> bluetoothGattDescriptorsList = bluetoothGattCharacteristic.getDescriptors(); 

       for (BluetoothGattDescriptor bluetoothGattDescriptor : bluetoothGattDescriptorsList) 
       { 
        descriptorUUIDsList.add(bluetoothGattDescriptor.getUuid()); 
       } 
      } 
     } 
    } 
} 
를 스캔 initScanning() 방법으로 시작 onScanResult()에서 어떤 결과를 반환되면 우리는 ScanRecord 개체에 액세스 할 수 있습니다

나는 비슷한 문제로 어려움을 겪을 다른 사람들을 도울 수 있기를 바랍니다.