@Override public void accept(RxBleDeviceServices rxBleDeviceServices) throws Exception { bleServicesLogger.log(rxBleDeviceServices, bluetoothGatt.getDevice()); } });
private boolean isDisconnected(BluetoothGatt bluetoothGatt) { return bluetoothManager.getConnectionState(bluetoothGatt.getDevice(), BluetoothProfile.GATT) == BluetoothProfile.STATE_DISCONNECTED; }
@Override protected BleException provideException(DeadObjectException deadObjectException) { return new BleDisconnectedException(deadObjectException, bluetoothGatt.getDevice().getAddress(), BleDisconnectedException.UNKNOWN_STATUS); }
@Override protected BleException provideException(DeadObjectException deadObjectException) { return new BleDisconnectedException(deadObjectException, bluetoothGatt.getDevice().getAddress(), BleDisconnectedException.UNKNOWN_STATUS); }
@Override protected BleException provideException(DeadObjectException deadObjectException) { return new BleDisconnectedException(deadObjectException, bluetoothGatt.getDevice().getAddress(), BleDisconnectedException.UNKNOWN_STATUS); } }
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { RxBleLog.d("onConnectionStateChange newState=%d status=%d", newState, status); nativeCallbackDispatcher.notifyNativeConnectionStateCallback(gatt, status, newState); super.onConnectionStateChange(gatt, status, newState); bluetoothGattProvider.updateBluetoothGatt(gatt); if (isDisconnectedOrDisconnecting(newState)) { disconnectionRouter.onDisconnectedException(new BleDisconnectedException(gatt.getDevice().getAddress(), status)); } else if (status != BluetoothGatt.GATT_SUCCESS) { disconnectionRouter.onGattConnectionStateException( new BleGattException(gatt, status, BleGattOperationType.CONNECTION_STATE) ); } connectionStatePublishRelay.accept(mapConnectionStateToRxBleConnectionStatus(newState)); }
/** * 获取设备 * * @return */ public BluetoothDevice getDevice() { return this.bluetoothGatt != null ? this.bluetoothGatt.getDevice() : null; }
/** * Gets remote connected device * * @return Connected device or null */ public BluetoothDevice getConnectedDevice() { BluetoothDevice connectedDevice = null; if (mBluetoothGatt != null) { connectedDevice = mBluetoothGatt.getDevice(); } return connectedDevice; }
public BluetoothDevice getDevice() { if (null == gatt) { Log.e(TAG, "실패 getDevice"); return null; } return gatt.getDevice(); }
private BluetoothGatt findBluetoothGatt(BluetoothDevice device) { for (BluetoothGatt d : mGattMap.values()) { if (d.getDevice() == device) { return d; } } return null; }
/** * Returns whether the device is bonded. * @return true if the device is bonded, false if not bonded or in process of bonding. */ protected boolean isBonded() { final BluetoothDevice device = mGatt.getDevice(); return device.getBondState() == BluetoothDevice.BOND_BONDED; }
@Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { UUID uuid = characteristic.getUuid(); String valueStr = new String(characteristic.getValue()); Log.i(TAG, String.format("onCharacteristicRead:%s,%s,%s,%s,%s", gatt.getDevice().getName(), gatt.getDevice().getAddress(), uuid, valueStr, status)); logTv("读取Characteristic[" + uuid + "]:\n" + valueStr); }
@Override public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { UUID uuid = descriptor.getUuid(); String valueStr = Arrays.toString(descriptor.getValue()); Log.i(TAG, String.format("onDescriptorRead:%s,%s,%s,%s,%s", gatt.getDevice().getName(), gatt.getDevice().getAddress(), uuid, valueStr, status)); logTv("读取Descriptor[" + uuid + "]:\n" + valueStr); }
@Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { UUID uuid = characteristic.getUuid(); String valueStr = new String(characteristic.getValue()); Log.i(TAG, String.format("onCharacteristicChanged:%s,%s,%s,%s", gatt.getDevice().getName(), gatt.getDevice().getAddress(), uuid, valueStr)); logTv("通知Characteristic[" + uuid + "]:\n" + valueStr); }
@Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { final AndroidPlatform platform = btleDevices.get(gatt.getDevice()); if (status != 0) { platform.closeGatt(); platform.connectTask.setError(new IllegalStateException(String.format(Locale.US, "Non-zero onServicesDiscovered status (%d)", status))); } else { platform.connectTask.setResult(null); } }
@Override public void onMtuChanged(final BluetoothGatt gatt, final int mtu, final int status) { if (status == BluetoothGatt.GATT_SUCCESS) { mProfile.onMtuChanged(mtu); } else { DebugLogger.e(TAG, "onMtuChanged error: " + status + ", mtu: " + mtu); onError(gatt.getDevice(), ERROR_MTU_REQUEST, status); } mOperationInProgress = false; nextRequest(); }
private synchronized void markDeviceAsSuccessful(BluetoothGatt gatt) { if (!Pref.getStringDefaultBlank("selected_bluetooth_meter_address").equals(mLastConnectedDeviceAddress)) { Pref.setString("selected_bluetooth_meter_address", mLastConnectedDeviceAddress); Pref.setString("selected_bluetooth_meter_info", mLastManufacturer + " " + mLastConnectedDeviceAddress); Pref.setBoolean("bluetooth_meter_enabled", true); // auto-enable the setting JoH.static_toast_long("Success with: " + mLastConnectedDeviceAddress + " Enabling auto-start"); if (gatt != null) sendDeviceUpdate(gatt.getDevice(), true); // force update } }
private synchronized void markDeviceAsSuccessful(BluetoothGatt gatt) { if (!Pref.getStringDefaultBlank("selected_bluetooth_meter_address").equals(mLastConnectedDeviceAddress)) { Pref.setString("selected_bluetooth_meter_address", mLastConnectedDeviceAddress); Pref.setString("selected_bluetooth_meter_info", mLastManufacturer + " " + mLastConnectedDeviceAddress); Pref.setBoolean("bluetooth_meter_enabled", true); // auto-enable the setting JoH.static_toast_long("Success with: " + mLastConnectedDeviceAddress + " Enabling auto-start"); if (gatt != null) sendDeviceUpdate(gatt.getDevice(), true); // force update } }