List of usage examples for android.bluetooth BluetoothGattCharacteristic getValue
public byte[] getValue()
From source file:com.sdingba.su.lanya.UartService.java
/** * ??/*from www.ja va2 s. c o m*/ * * @param action */ private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); // This is special handling for the Heart Rate Measurement profile. Data parsing is // carried out as per profile specifications: // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml if (TX_CHAR_UUID.equals(characteristic.getUuid())) { //?TXCC254x???0xfff4notify? Log.d(TAG, String.format("Received TX: %d", characteristic.getValue())); Log.w(TAG, "SDingBaLanYan characteristic.getUuid() = " + characteristic.getUuid()); intent.putExtra(EXTRA_DATA, characteristic.getValue()); } else { } LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }
From source file:is.hello.buruberi.bluetooth.stacks.android.NativeGattPeripheral.java
@Override public void onCharacteristicChanged(@NonNull BluetoothGatt gatt, @NonNull BluetoothGattCharacteristic characteristic) { if (gatt == this.gatt) { final UUID serviceId = characteristic.getService().getUuid(); final NativeGattService gattService = services.get(serviceId); gattService.dispatchNotify(characteristic.getUuid(), characteristic.getValue()); }// ww w . j a va 2s .co m }
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 ww .j a v a 2 s.c o m*/ Tools.sendErrorMsg(readValueCC.get(deviceAddress)); readValueCC.remove(deviceAddress); } } }
From source file:undot.safedrivers.BLE.BluetoothLeService.java
/** * Write information to the device on a given {@code BluetoothGattCharacteristic}. The content string and characteristic is * only pushed into a ring buffer. All the transmission is based on the {@code onCharacteristicWrite} call back function, * which is called directly in this function * * @param characteristic The characteristic to write to. *///from w ww . j a v a 2 s . c om public void writeCharacteristic(BluetoothGattCharacteristic characteristic) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } //The character size of TI CC2540 is limited to 17 bytes, otherwise characteristic can not be sent properly, //so String should be cut to comply this restriction. And something should be done here: String writeCharacteristicString; try { writeCharacteristicString = new String(characteristic.getValue(), "ISO-8859-1"); } catch (UnsupportedEncodingException e) { // this should never happen because "US-ASCII" is hard-coded. throw new IllegalStateException(e); } System.out.println("allwriteCharacteristicString:" + writeCharacteristicString); //As the communication is asynchronous content string and characteristic should be pushed into an ring buffer for further transmission mCharacteristicRingBuffer .push(new BluetoothGattCharacteristicHelper(characteristic, writeCharacteristicString)); System.out.println("mCharacteristicRingBufferlength:" + mCharacteristicRingBuffer.size()); //The progress of onCharacteristicWrite and writeCharacteristic is almost the same. So callback function is called directly here //for details see the onCharacteristicWrite function mGattCallback.onCharacteristicWrite(mBluetoothGatt, characteristic, WRITE_NEW_CHARACTERISTIC); }
From source file:org.bcsphere.bluetooth.BluetoothG43plus.java
private void setNotificationManage(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { String deviceAddress = getDeviceAddress(gatt); if (setNotificationCC.get(characteristic) != null) { JSONObject obj = new JSONObject(); Tools.addProperty(obj, Tools.DEVICE_ADDRESS, deviceAddress); Tools.addProperty(obj, Tools.SERVICE_INDEX, recordServiceIndex.get(characteristic)); Tools.addProperty(obj, Tools.CHARACTERISTIC_INDEX, recordCharacteristicIndex.get(characteristic)); Tools.addProperty(obj, Tools.VALUE, Tools.encodeBase64(characteristic.getValue())); Tools.addProperty(obj, Tools.DATE, Tools.getDateString()); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, obj); pluginResult.setKeepCallback(true); setNotificationCC.get(characteristic).sendPluginResult(pluginResult); }//from ww w . j a v a 2 s .c o m }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support.java
@Override public boolean onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { UUID characteristicUUID = characteristic.getUuid(); if (MiBand2Service.UUID_CHARACTERISTIC_AUTH.equals(characteristicUUID)) { LOG.info("KEY AES SEND"); logMessageContent(characteristic.getValue()); return true; }/*from w w w . j ava 2 s. c o m*/ return false; }
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 {//from ww w. jav a2 s . c om LOG.info("Unhandled characteristic changed: " + characteristicUUID); logMessageContent(characteristic.getValue()); } return false; }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support.java
@Override public boolean onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { super.onCharacteristicRead(gatt, characteristic, status); UUID characteristicUUID = characteristic.getUuid(); if (GattCharacteristic.UUID_CHARACTERISTIC_GAP_DEVICE_NAME.equals(characteristicUUID)) { handleDeviceName(characteristic.getValue(), status); return true; } else if (MiBand2Service.UUID_CHARACTERISTIC_6_BATTERY_INFO.equals(characteristicUUID)) { handleBatteryInfo(characteristic.getValue(), status); return true; } else if (GattCharacteristic.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) { logHeartrate(characteristic.getValue(), status); return true; } else if (MiBand2Service.UUID_CHARACTERISTIC_7_REALTIME_STEPS.equals(characteristicUUID)) { handleRealtimeSteps(characteristic.getValue()); return true; } else if (MiBand2Service.UUID_CHARACTERISTIC_10_BUTTON.equals(characteristicUUID)) { handleButtonPressed(characteristic.getValue()); return true; } else {/*from ww w . j a v a2 s. co m*/ LOG.info("Unhandled characteristic read: " + characteristicUUID); logMessageContent(characteristic.getValue()); } return false; }
From source file:com.lef.ibeacon.service.UpdateService.java
public UUID decodeBeaconUUID(final BluetoothGattCharacteristic characteristic) { final byte[] data = characteristic.getValue(); // logw("Characteristic get value: " + data.length); final long mostSigBits = (unsignedByteToLong(data[0]) << 56) + (unsignedByteToLong(data[1]) << 48) + (unsignedByteToLong(data[2]) << 40) + (unsignedByteToLong(data[3]) << 32) + (unsignedByteToLong(data[4]) << 24) + (unsignedByteToLong(data[5]) << 16) + (unsignedByteToLong(data[6]) << 8) + unsignedByteToLong(data[7]); // logw("mostSigBits value: " + mostSigBits); final long leastSigBits = (unsignedByteToLong(data[8]) << 56) + (unsignedByteToLong(data[9]) << 48) + (unsignedByteToLong(data[10]) << 40) + (unsignedByteToLong(data[11]) << 32) + (unsignedByteToLong(data[12]) << 24) + (unsignedByteToLong(data[13]) << 16) + (unsignedByteToLong(data[14]) << 8) + unsignedByteToLong(data[15]); // logw("leastSigBits value: " + leastSigBits); UUID uuid = new UUID(mostSigBits, leastSigBits); // logw("UUID: " + uuid.toString()); return uuid;//from w ww . ja va 2 s. c om }
From source file:com.ble.BLService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); if (UUID_STM32_ACCELEROMETER_PARAMETER.equals(characteristic.getUuid())) { // una elaborazione dei dati inviati dalla scheda ST32 che invia i dati come un flusso di byte ad otetti //quindi converto in esadecimale e scambio i primi due ottetti per ottrenerli in ordine //0000-0000-0000-0000|acc_x_bit_meno_significativi[8byte]-acc_x_bit_significativi[8byte]|acc_y_meno..-acc_y..|acc_z_meno...-acc_ // in hex ogni 4 byte ho un valore //0-1-2-3|4-5-6-7|8-9-10-11|12-13-14-15 //per acc_x devo avere i blocchi 6-7-4-5 affiancati //per acc_y =10-11-8-9 //per acc_z=14-15-12-13 //acc_x=sb1.append(sb.substring(6, 8)) concatenato con sb1.append(sb.substring(4, 6)); //magari esiste un metodo meno contorto per recuperarli,io purtroppo non l'ho trovato :-( byte[] stream_byte_received = characteristic.getValue(); StringBuilder sb = new StringBuilder(); for (byte b : stream_byte_received) { sb.append(String.format("%02x", b)); }/*from w w w . ja v a 2s . c o m*/ StringBuilder sb1 = new StringBuilder(); sb1.append(sb.substring(6, 8)); sb1.append(sb.substring(4, 6)); String test = sb1.toString(); short acc_x = (short) Integer.parseInt(test, 16); sb1 = new StringBuilder(); sb1.append(sb.substring(10, 12)); sb1.append(sb.substring(8, 10)); test = sb1.toString(); short acc_y = (short) Integer.parseInt(test, 16); sb1 = new StringBuilder(); sb1.append(sb.substring(14, 16)); sb1.append(sb.substring(12, 14)); test = sb1.toString(); short acc_z = (short) Integer.parseInt(test, 16); sb1 = new StringBuilder(); sb1.append(sb.substring(18, 20)); sb1.append(sb.substring(16, 18)); test = sb1.toString(); short temperatura = (short) Integer.parseInt(test, 16); sb1 = new StringBuilder(); sb1.append(sb.substring(22, 24)); sb1.append(sb.substring(20, 22)); test = sb1.toString(); short Humidity = (short) Integer.parseInt(test, 16); //EVENTUALE SENSORE DA CATTURARE ESEMPIO TEMPERATURA,AFFIANCO NEL VETTORE GATT DEL DEVICE ST32 //16-17-18-19 //sbX.append(sb.substring(18));sbX.append(sb.substring(16, 18)); Log.w("ADC3", "StringBuilder " + sb + "************************** " + acc_x + " | " + acc_y + " | " + acc_z + " | "); String accelerometer = "|X:" + acc_x + " |Y: " + acc_y + " |Z: " + acc_z + " | "; String extra_data = "Temp:" + temperatura + "\nHumidity:" + Humidity + "%\nAccelerometer:\t" + accelerometer; intent.putExtra(EXTRA_DATA, extra_data); } else { final byte[] data = characteristic.getValue(); if (data != null && data.length > 0) { final StringBuilder stringBuilder = new StringBuilder(data.length); for (byte byteChar : data) stringBuilder.append(String.format("%02X", byteChar)); intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString()); } } sendBroadcast(intent); }