@Override public byte[] apply(BluetoothGattCharacteristic bluetoothGattCharacteristic) throws Exception { return bluetoothGattCharacteristic.getValue(); } });
@Override public Single<byte[]> readCharacteristic(@NonNull BluetoothGattCharacteristic characteristic) { return Single.just(characteristic.getValue()); }
public BluetoothGattCharacteristicAssert hasValue(byte[] value) { isNotNull(); byte[] actualValue = actual.getValue(); assertThat(actualValue) // .overridingErrorMessage("Expected value <%s> but was <%s>.", Arrays.toString(value), Arrays.toString(actualValue)) // .isEqualTo(value); return this; }
@Override public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { ... if(characteristic.getValue() != value) { gatt.abortReliableWrite(); } else { gatt.executeReliableWrite(); } ... }
@Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { RxBleLog.d("onCharacteristicRead characteristic=%s status=%d", characteristic.getUuid(), status); nativeCallbackDispatcher.notifyNativeReadCallback(gatt, characteristic, status); super.onCharacteristicRead(gatt, characteristic, status); if (readCharacteristicOutput.hasObservers() && !propagateErrorIfOccurred( readCharacteristicOutput, gatt, characteristic, status, BleGattOperationType.CHARACTERISTIC_READ )) { readCharacteristicOutput.valueRelay.accept(new ByteAssociation<>(characteristic.getUuid(), characteristic.getValue())); } }
@Override public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { RxBleLog.d("onCharacteristicWrite characteristic=%s status=%d", characteristic.getUuid(), status); nativeCallbackDispatcher.notifyNativeWriteCallback(gatt, characteristic, status); super.onCharacteristicWrite(gatt, characteristic, status); if (writeCharacteristicOutput.hasObservers() && !propagateErrorIfOccurred( writeCharacteristicOutput, gatt, characteristic, status, BleGattOperationType.CHARACTERISTIC_WRITE )) { writeCharacteristicOutput.valueRelay.accept(new ByteAssociation<>(characteristic.getUuid(), characteristic.getValue())); } }
@Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { RxBleLog.d("onCharacteristicChanged characteristic=%s", characteristic.getUuid()); nativeCallbackDispatcher.notifyNativeChangedCallback(gatt, characteristic); super.onCharacteristicChanged(gatt, characteristic); /* * It is important to call changedCharacteristicSerializedPublishRelay as soon as possible because a quick changing * characteristic could lead to out-of-order execution since onCharacteristicChanged may be called on arbitrary * threads. */ if (changedCharacteristicSerializedPublishRelay.hasObservers()) { changedCharacteristicSerializedPublishRelay.accept( new CharacteristicChangedEvent( characteristic.getUuid(), characteristic.getInstanceId(), characteristic.getValue() ) ); } }
public static Integer twentyFourBitUnsignedAtOffset(BluetoothGattCharacteristic c, int offset) { byte[] value = c.getValue(); Integer lowerByte = (int) value[offset] & 0xFF; Integer mediumByte = (int) value[offset + 1] & 0xFF; Integer upperByte = (int) value[offset + 2] & 0xFF; return (upperByte << 16) + (mediumByte << 8) + lowerByte; }
@Override public void onSuccess(Object data, int status) { int level = ((BluetoothGattCharacteristic) data).getValue()[0]; callback.onSuccess(level, MibandCallback.STATUS_GET_BATTERY); }
@Override public void onSuccess(Object data, int status) { byte[] ab = ((BluetoothGattCharacteristic) data).getValue(); if (ab.length == 4) { int steps = ab[3] << 24 | (ab[2] & 0xFF) << 16 | (ab[1] & 0xFF) << 8 | (ab[0] & 0xFF); callback.onSuccess((int) steps, MibandCallback.STATUS_GET_ACTIVITY_DATA); } }
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); intent.putExtra(EXTRA_UUID_CHAR, characteristic.getUuid().toString()); // Always try to add the RAW value final byte[] data = characteristic.getValue(); if (data != null && data.length > 0) { intent.putExtra(EXTRA_DATA_RAW, data); } sendBroadcast(intent); }
/** * 发送通知 * * @param action 广播Action * @param characteristic 数据 */ private void sendBleBroadcast(String action, BluetoothGattCharacteristic characteristic) { Intent intent = new Intent(action); if (CHARACTERISTIC_READ_UUID.equals(characteristic.getUuid())) { intent.putExtra(EXTRA_DATA, characteristic.getValue()); } sendBroadcast(intent); }
@Override public void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) { Log.d(TAG, "callback characteristic change in thread " + Thread.currentThread()); if (mOnDataAvailableListener != null) { mOnDataAvailableListener.onCharacteristicChange( characteristic.getUuid(), characteristic.getValue()); } }
@Override public void onSuccess(BluetoothGattCharacteristic characteristic) { if (characteristic.getUuid().equals(BluetoothUUID.BATTERY_NOTIFICATION)) { setTitle("使用示例" + " 电量:" + characteristic.getValue()[0] + "%"); } }
@Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { super.onCharacteristicChanged(gatt, characteristic); if (this.notifyListeners.containsKey(characteristic.getUuid())) { this.notifyListeners.get(characteristic.getUuid()).onNotify(characteristic.getValue()); } }
@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 onCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) { super.onCharacteristicWriteRequest(device, requestId, characteristic, preparedWrite, responseNeeded, offset, value); int status = mEddystoneGattService.writeCharacteristic(device, characteristic, value); if (responseNeeded) { mGattServer.sendResponse(device, requestId, status, offset, status == BluetoothGatt.GATT_SUCCESS ? characteristic.getValue() : null); } }
protected void handleNotification(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) { mService.sendLogBroadcast(DfuBaseService.LOG_LEVEL_INFO, "Notification received from " + characteristic.getUuid() + ", value (0x): " + parse(characteristic)); mReceivedData = characteristic.getValue(); mFirmwareUploadInProgress = false; } }