При подключении к устройству OBD, setCharacteristicNotification и writeCharacteristic, onCharacteristicChanges получено 3E 00 00 3F уведомление - PullRequest
0 голосов
/ 20 сентября 2018

При подключении к устройству OBD установитеCharacteristicNotification и writeCharacteristic.Уведомление было получено на характерное изменение.Но уведомление показало 3E 00 00 3F, те же условия для многих запросов на запись.Ожидается, что он вернет информацию об устройстве.

Коды следующие:

public void writeCharacteristic(String commnd, BluetoothGattCharacteristic characteristic, boolean enabled) {
    int commandLength = commnd.length(); // length of the string used for the loop

    byte[] bytes = new byte[commnd.length()];
    for(int i = 0; i < commandLength ; i++){   // while counting characters if less than the length add one
        char character = commnd.charAt(i); // start on the first character
        int ascii = (int) character; //convert the first character
        bytes[i] = (byte) Integer.parseInt(String.valueOf(ascii));
        Log.w(TAG, "byte index:"+i+", ascii:"+ascii+", bytes i:"+bytes[i]);
    }

    characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
    characteristic.setValue(bytes);//ch);//messageBytes);
    boolean success = mBluetoothGatt.writeCharacteristic(characteristic);
    Log.w("Gatt", "write result:"+success);

    Log.w(TAG, "set characteric notification, enabled?"+enabled);
    setCharacteristicNotificationWithDescriptor(characteristic, true);
}

protected static final UUID CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");

public boolean setCharacteristicNotificationWithDescriptor(BluetoothGattCharacteristic characteristic, boolean enable) {
    Log.w(TAG, "setCharacteristicNotification(UUID=" + characteristic.getUuid().toString() + ", enable=" + enable + " )");
    mBluetoothGatt.setCharacteristicNotification(characteristic, enable);
    Log.w(TAG, "descriptor:"+CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID);
    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID);
    descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 });
    Log.w(TAG, "notification value:"+BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE+", false:"+new byte[] { 0x00, 0x00 }.toString());
    boolean status = mBluetoothGatt.writeDescriptor(descriptor); //descriptor write operation successfully started?
    Log.w(TAG, "write descriptor:"+status);
    return status;
}

Не знаете, как получить правильный ответ?Я отправил команду AT с 0D.Спасибо.

...