From 17d97f58265510ceda0b38959a90424ee07b6910 Mon Sep 17 00:00:00 2001 From: 陈奇 <1650699704@qq.com> Date: Tue, 13 Nov 2018 11:42:07 +0800 Subject: [PATCH] 1.0.3-1测试版本 [*]修改重新连接的方式 [*]修改商城连接 [*]修改心跳机制 [*]主要针对oppo和vivo机型添加开启定位服务 --- FastBleLib/src/main/java/com/clj/fastble/conn/BleConnector.java | 35 +++++++++++++++++++---------------- 1 files changed, 19 insertions(+), 16 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 0707b79..e97e782 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 ----------------------------------- */ /** @@ -129,8 +128,6 @@ if (getCharacteristic() != null && (getCharacteristic().getProperties() | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { BleLog.w(TAG, "characteristic.getProperties():" + getCharacteristic().getProperties()); - - System.out.println("chenqi enableCharacteristicNotify =>" + uuid_notify); handleCharacteristicNotificationCallback(bleCallback, uuid_notify); @@ -346,23 +343,34 @@ listenAndTimer(bleCallback, MSG_NOTIFY_CHA, uuid_notify, new BluetoothGattCallback() { AtomicBoolean msgRemoved = new AtomicBoolean(false); + @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { + if (!msgRemoved.getAndSet(true)) { handler.removeMessages(MSG_NOTIFY_CHA, this); } - - System.out.println("chenqi Notify Hex ->" + BleBluetooth.dumpHex(characteristic.getValue())); - if (characteristic.getUuid().equals(UUID.fromString(uuid_notify))) { + 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(); } /** @@ -378,7 +386,7 @@ @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { - System.out.println("chenqi Notify Hex indicate->" + BleBluetooth.dumpHex(characteristic.getValue())); + if (!msgRemoved.getAndSet(true)) { handler.removeMessages(MSG_INDICATE_DES, this); } @@ -402,8 +410,6 @@ public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { handler.removeMessages(MSG_WRITE_CHA, this); - System.out.println("chenqi Notify Hex write->" + BleBluetooth.dumpHex(characteristic.getValue())); - if (status == BluetoothGatt.GATT_SUCCESS) { if (characteristic.getUuid().equals(UUID.fromString(uuid_write))) { @@ -429,8 +435,6 @@ @Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { - System.out.println("chenqi Notify Hex indicate read->" + BleBluetooth.dumpHex(characteristic.getValue())); - if (!msgRemoved.getAndSet(true)) { handler.removeMessages(MSG_READ_CHA, this); } @@ -456,8 +460,6 @@ @Override public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { handler.removeMessages(MSG_READ_RSSI, this); - System.out.println("chenqi Notify Hex rssi->" + BleBluetooth.dumpHex(characteristic.getValue())); - if (status == BluetoothGatt.GATT_SUCCESS) { bleCallback.onSuccess(rssi); } else { @@ -485,6 +487,7 @@ private void listenAndTimer(BleCallback bleCallback, int what, String uuid, BluetoothGattCallback callback) { bleCallback.setBluetoothGattCallback(callback); bleBluetooth.addGattCallback(uuid, callback); + Message msg = handler.obtainMessage(what, bleCallback); handler.sendMessageDelayed(msg, timeOutMillis); } -- Gitblit v1.8.0