陈奇
2018-11-15 47f5d71a81a528aff225805d28bf181ce4d6f55d
FastBleLib/src/main/java/com/clj/fastble/conn/BleConnector.java
@@ -102,7 +102,6 @@
            descriptor = characteristic.getDescriptor(descriptorUUID);
        }
        return this;
    }
@@ -118,7 +117,7 @@
    /*------------------------------- main operation ----------------------------------- */
     /*------------------------------- main operation ----------------------------------- */
    /**
@@ -342,36 +341,37 @@
                                                          final String uuid_notify) {
        if (bleCallback != null) {
//            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//                bluetoothGatt.requestMtu(10);
//            }
            listenAndTimer(bleCallback, MSG_NOTIFY_CHA, uuid_notify, new BluetoothGattCallback() {
                AtomicBoolean msgRemoved = new AtomicBoolean(false);
                @Override
                public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
                    super.onConnectionStateChange(gatt, status, newState);
                }
                @Override
                public void onCharacteristicChanged(BluetoothGatt gatt,
                                                    BluetoothGattCharacteristic characteristic) {
                    if (!msgRemoved.getAndSet(true)) {
                        handler.removeMessages(MSG_NOTIFY_CHA, this);
                    }
                    if (characteristic.getUuid().equals(UUID.fromString(uuid_notify))) {
                        System.out.println("chenqi Notify ->" + characteristic.getValue().length);
                        System.out.println("chenqi Notify Hex ->" + BleBluetooth.dumpHex(characteristic.getValue()));
                        System.out.println("chenqi Hex ->" + dumpHex(characteristic.getValue()));
                        bleCallback.onSuccess(characteristic);
                    }
                }
            });
        }
    }
    public String dumpHex(byte[] src) {
        String num = "0123456789ABCDEF";
        StringBuilder sb = new StringBuilder();
//      sb.append("[ ");
        for (byte aSrc : src) {
            int high = aSrc >> 4 & 0x0f;
            int low = aSrc & 0x0f;
            sb.append(num.charAt(high)).append(num.charAt(low)).append(" ");
        }
//      sb.append(" ]");
        return sb.toString();
    }
    /**
@@ -387,6 +387,7 @@
                @Override
                public void onCharacteristicChanged(BluetoothGatt gatt,
                                                    BluetoothGattCharacteristic characteristic) {
                    if (!msgRemoved.getAndSet(true)) {
                        handler.removeMessages(MSG_INDICATE_DES, this);
                    }