List of usage examples for android.bluetooth BluetoothGatt GATT_SUCCESS
int GATT_SUCCESS
To view the source code for android.bluetooth BluetoothGatt GATT_SUCCESS.
Click Source Link
From source file:org.bcsphere.bluetooth.BluetoothG43plus.java
private void readValueManage(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { String deviceAddress = getDeviceAddress(gatt); JSONObject obj = new JSONObject(); if (readValueCC.get(deviceAddress) != null) { if (status == BluetoothGatt.GATT_SUCCESS) { Tools.addProperty(obj, Tools.DEVICE_ADDRESS, deviceAddress); Tools.addProperty(obj, Tools.VALUE, Tools.encodeBase64(characteristic.getValue())); Tools.addProperty(obj, Tools.DATE, Tools.getDateString()); readValueCC.get(deviceAddress).success(obj); readValueCC.remove(deviceAddress); } else {/* w w w.j a v a 2s . c o m*/ Tools.sendErrorMsg(readValueCC.get(deviceAddress)); readValueCC.remove(deviceAddress); } } }
From source file:is.hello.buruberi.bluetooth.stacks.android.NativeGattPeripheral.java
@NonNull @Override// w w w .ja v a2s . c o m @RequiresPermission(Manifest.permission.BLUETOOTH) public Observable<Map<UUID, ? extends GattService>> discoverServices(final @NonNull OperationTimeout timeout) { final ConnectedOnSubscribe<Map<UUID, ? extends GattService>> onSubscribe = new ConnectedOnSubscribe<Map<UUID, ? extends GattService>>( this) { @Override public void onSubscribe(@NonNull BluetoothGatt gatt, @NonNull final Subscriber<? super Map<UUID, ? extends GattService>> subscriber) { final Runnable onDisconnect = addTimeoutDisconnectListener(subscriber, timeout); setupTimeout(Operation.DISCOVER_SERVICES, timeout, subscriber, onDisconnect); gattDispatcher.servicesDiscovered = new ServicesDiscoveredListener() { @Override public void onServicesDiscovered(@NonNull BluetoothGatt gatt, int status) { timeout.unschedule(); removeDisconnectListener(onDisconnect); if (status == BluetoothGatt.GATT_SUCCESS) { NativeGattPeripheral.this.services = NativeGattService.wrap(gatt.getServices(), NativeGattPeripheral.this); subscriber.onNext(services); subscriber.onCompleted(); gattDispatcher.servicesDiscovered = null; } else { logger.error(LOG_TAG, "Could not discover services. " + GattException.statusToString(status), null); NativeGattPeripheral.this.services = Collections.emptyMap(); subscriber.onError(new GattException(status, Operation.DISCOVER_SERVICES)); gattDispatcher.servicesDiscovered = null; } } }; if (gatt.discoverServices()) { timeout.schedule(); } else { gattDispatcher.servicesDiscovered = null; removeDisconnectListener(onDisconnect); subscriber.onError(new ServiceDiscoveryException()); } } }; // See <https://code.google.com/p/android/issues/detail?id=58381> return createObservable(onSubscribe).delay(SERVICES_DELAY_S, TimeUnit.SECONDS, stack.getScheduler()); }
From source file:org.bcsphere.bluetooth.BluetoothG43plus.java
private void readValueManage(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { String deviceAddress = getDeviceAddress(gatt); JSONObject obj = new JSONObject(); if (readValueCC.get(deviceAddress) != null) { if (status == BluetoothGatt.GATT_SUCCESS) { Tools.addProperty(obj, Tools.DEVICE_ADDRESS, deviceAddress); Tools.addProperty(obj, Tools.VALUE, Tools.encodeBase64(descriptor.getValue())); Tools.addProperty(obj, Tools.DATE, Tools.getDateString()); readValueCC.get(deviceAddress).success(obj); readValueCC.remove(deviceAddress); } else {//from w w w .j av a2 s .c o m Tools.sendErrorMsg(readValueCC.get(deviceAddress)); readValueCC.remove(deviceAddress); } } }
From source file:org.bcsphere.bluetooth.BluetoothG43plus.java
private void getDeviceAllDataManage(BluetoothGatt gatt, int status) { String deviceAddress = getDeviceAddress(gatt); if (getDeviceAllDataCC.get(deviceAddress) != null) { if (status == BluetoothGatt.GATT_SUCCESS) { JSONObject obj = new JSONObject(); JSONArray servicesInfo = new JSONArray(); List<BluetoothGattService> services = gatt.getServices(); for (int i = 0; i < services.size(); i++) { JSONObject serviceInfo = new JSONObject(); Tools.addProperty(serviceInfo, Tools.SERVICE_INDEX, i); Tools.addProperty(serviceInfo, Tools.SERVICE_UUID, services.get(i).getUuid()); Tools.addProperty(serviceInfo, Tools.SERVICE_NAME, Tools.lookup(services.get(i).getUuid())); List<BluetoothGattCharacteristic> characteristics = services.get(i).getCharacteristics(); JSONArray characteristicsInfo = new JSONArray(); for (int j = 0; j < characteristics.size(); j++) { JSONObject characteristicInfo = new JSONObject(); Tools.addProperty(characteristicInfo, Tools.CHARACTERISTIC_INDEX, j); Tools.addProperty(characteristicInfo, Tools.CHARACTERISTIC_UUID, characteristics.get(j).getUuid()); Tools.addProperty(characteristicInfo, Tools.CHARACTERISTIC_NAME, Tools.lookup(characteristics.get(j).getUuid())); Tools.addProperty(characteristicInfo, Tools.CHARACTERISTIC_PROPERTY, Tools.decodeProperty(characteristics.get(j).getProperties())); List<BluetoothGattDescriptor> descriptors = new ArrayList<BluetoothGattDescriptor>(); JSONArray descriptorsInfo = new JSONArray(); for (int k = 0; k < descriptors.size(); k++) { JSONObject descriptorInfo = new JSONObject(); Tools.addProperty(descriptorInfo, Tools.DESCRIPTOR_INDEX, k); Tools.addProperty(descriptorInfo, Tools.DESCRIPTOR_UUID, descriptors.get(k).getUuid()); Tools.addProperty(descriptorInfo, Tools.DESCRIPTOR_NAME, Tools.lookup(descriptors.get(k).getUuid())); descriptorsInfo.put(descriptorInfo); }// w w w . j a va 2 s . c o m Tools.addProperty(characteristicInfo, Tools.DESCRIPTORS, descriptorsInfo); characteristicsInfo.put(characteristicInfo); } Tools.addProperty(serviceInfo, Tools.CHARACTERISTICS, characteristicsInfo); servicesInfo.put(serviceInfo); } Tools.addProperty(obj, Tools.DEVICE_ADDRESS, deviceAddress); Tools.addProperty(obj, Tools.SERVICES, servicesInfo); getDeviceAllDataCC.get(deviceAddress).success(obj); getDeviceAllDataCC.remove(deviceAddress); deviceServices.put(deviceAddress, services); } else { Tools.sendErrorMsg(getDeviceAllDataCC.get(deviceAddress)); getDeviceAllDataCC.remove(deviceAddress); } } }
From source file:com.android.dragonkeyboardfirmwareupdater.KeyboardFirmwareUpdateService.java
private boolean connectToKeyboard() { if (!isBluetoothEnabled() || !isUpdateServiceInUse()) { Log.w(TAG, "connectToKeyboard: Bluetooth connectivity not enabled or associated keyboard not found."); return false; }/* w w w . j a v a 2 s . c o m*/ final BluetoothDevice keyboard = mBluetoothAdapter.getRemoteDevice(mKeyboardAddress); if (keyboard == null) { Log.w(TAG, "connectToKeyboard: " + getKeyboardString() + " not found. Unable to connect."); return false; } Log.d(TAG, "connectToKeyboard: Trying to create a new connection to " + getKeyboardString()); mBluetoothGattClient = keyboard.connectGatt(this, false, mGattCallback); changeGattState(GATT_STATE_CONNECTING); mGattOperationStatus = BluetoothGatt.GATT_SUCCESS; return true; }
From source file:org.bcsphere.bluetooth.BluetoothG43plus.java
private void addServiceManage(int status) { if (addServiceCC != null) { if (status == BluetoothGatt.GATT_SUCCESS) { gattServerSum = gattServerSum - 1; if (gattServerSum == 0) { Tools.sendSuccessMsg(addServiceCC); addServiceCC = null;//from www . j av a2s . c o m } } else { gattServerSum = 0; Tools.sendErrorMsg(addServiceCC); addServiceCC = null; } } }
From source file:com.android.dragonkeyboardfirmwareupdater.KeyboardFirmwareUpdateService.java
private void disconnectFromKeyboard() { if (mGattConnectionState == GATT_STATE_DISCONNECTED) return;//from w w w. j av a 2 s.c om if (!isUpdateServiceInUse() || !isBluetoothEnabled() || mDfuStatus == DFU_STATE_NOT_STARTED) { Log.i(TAG, "disconnectFromKeyboard: Bluetooth connectivity not enabled"); return; } Log.d(TAG, "disconnectFromKeyboard: " + getKeyboardString()); mBluetoothGattClient.disconnect(); changeGattState(GATT_STATE_DISCONNECTING); mGattOperationStatus = BluetoothGatt.GATT_SUCCESS; }
From source file:org.bcsphere.bluetooth.BluetoothG43plus.java
private void getRSSIManage(BluetoothGatt gatt, int rssi, int status) { String deviceAddress = getDeviceAddress(gatt); if (getRSSICC.get(deviceAddress) != null) { if (status == BluetoothGatt.GATT_SUCCESS) { JSONObject obj = new JSONObject(); Tools.addProperty(obj, Tools.DEVICE_ADDRESS, deviceAddress); Tools.addProperty(obj, Tools.RSSI, rssi); getRSSICC.get(deviceAddress).success(obj); getRSSICC.remove(deviceAddress); } else {/*from ww w .j ava 2 s . c om*/ Tools.sendErrorMsg(getRSSICC.get(deviceAddress)); getRSSICC.remove(deviceAddress); } } }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support.java
@Override public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { super.onCharacteristicChanged(gatt, characteristic); UUID characteristicUUID = characteristic.getUuid(); if (MiBand2Service.UUID_CHARACTERISTIC_6_BATTERY_INFO.equals(characteristicUUID)) { handleBatteryInfo(characteristic.getValue(), BluetoothGatt.GATT_SUCCESS); return true; } else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) { handleRealtimeSteps(characteristic.getValue()); return true; } else if (GattCharacteristic.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) { handleHeartrate(characteristic.getValue()); return true; } else if (MiBand2Service.UUID_CHARACTERISTIC_AUTH.equals(characteristicUUID)) { LOG.info("AUTHENTICATION?? " + characteristicUUID); logMessageContent(characteristic.getValue()); return true; } else if (MiBand2Service.UUID_CHARACTERISTIC_10_BUTTON.equals(characteristicUUID)) { handleButtonPressed(characteristic.getValue()); return true; } else if (MiBand2Service.UUID_CHARACTERISTIC_7_REALTIME_STEPS.equals(characteristicUUID)) { handleRealtimeSteps(characteristic.getValue()); return true; } else {/* w w w. j a v a 2 s . c o m*/ LOG.info("Unhandled characteristic changed: " + characteristicUUID); logMessageContent(characteristic.getValue()); } return false; }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support.java
public void logHeartrate(byte[] value, int status) { if (status == BluetoothGatt.GATT_SUCCESS && value != null) { LOG.info("Got heartrate:"); if (value.length == 2 && value[0] == 0) { int hrValue = (value[1] & 0xff); GB.toast(getContext(), "Heart Rate measured: " + hrValue, Toast.LENGTH_LONG, GB.INFO); }//from w w w. ja v a 2 s. c o m return; } logMessageContent(value); }