From 47f5d71a81a528aff225805d28bf181ce4d6f55d Mon Sep 17 00:00:00 2001 From: 陈奇 <1650699704@qq.com> Date: Thu, 15 Nov 2018 13:14:43 +0800 Subject: [PATCH] [*]1.0.3.2版本 --- FastBleLib/src/main/java/com/clj/fastble/conn/BleConnector.java | 36 +++++++++++++++++------------------- 1 files changed, 17 insertions(+), 19 deletions(-) diff --git a/FastBleLib/src/main/java/com/clj/fastble/conn/BleConnector.java b/FastBleLib/src/main/java/com/clj/fastble/conn/BleConnector.java index 33a3d7a..eb8bd2c 100644 --- a/FastBleLib/src/main/java/com/clj/fastble/conn/BleConnector.java +++ b/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,39 +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 Hex ->" + dumpHex(characteristic.getValue())); bleCallback.onSuccess(characteristic); } } - - @Override - public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) { - super.onMtuChanged(gatt, mtu, status); - System.out.println(String.format("onMtuChanged���mtu = %s", mtu)); - } }); - - } + } + + 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(); } /** @@ -390,6 +387,7 @@ @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { + if (!msgRemoved.getAndSet(true)) { handler.removeMessages(MSG_INDICATE_DES, this); } -- Gitblit v1.8.0