| | |
| | | descriptor = characteristic.getDescriptor(descriptorUUID); |
| | | } |
| | | |
| | | |
| | | return this; |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | |
| | | /*------------------------------- main operation ----------------------------------- */ |
| | | /*------------------------------- main operation ----------------------------------- */ |
| | | |
| | | |
| | | /** |
| | |
| | | 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(); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public void onCharacteristicChanged(BluetoothGatt gatt, |
| | | BluetoothGattCharacteristic characteristic) { |
| | | |
| | | if (!msgRemoved.getAndSet(true)) { |
| | | handler.removeMessages(MSG_INDICATE_DES, this); |
| | | } |