List of usage examples for android.bluetooth BluetoothGattCharacteristic getUuid
public UUID getUuid()
From source file:com.umundus.service.NCallServiceOld.java
public void writePacket(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final byte[] buffer, final int size) { byte[] locBuffer = buffer; if (buffer.length != size) { locBuffer = new byte[size]; System.arraycopy(buffer, 0, locBuffer, 0, size); }// w ww . j a va 2 s .c om characteristic.setValue(locBuffer); gatt.writeCharacteristic(characteristic); Log.i(TAG, "writePacket " + characteristic.getUuid()); }
From source file:br.liveo.ndrawer.ui.activity.MainActivity.java
License:asdf
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic, final int status) { final Intent intent = new Intent(action); intent.putExtra(EXTRA_UUID, characteristic.getUuid().toString()); intent.putExtra(EXTRA_DATA, characteristic.getValue()); intent.putExtra(EXTRA_STATUS, status); sendBroadcast(intent);//from w w w .ja va 2 s . c om }
From source file:com.umundus.service.NCallServiceOld.java
public 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 (BATTERY_CHARACTERISTIC.equals(characteristic.getUuid())) { int battery = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0); Log.d(TAG, String.format("battery value : %d", battery)); intent.putExtra(BATTERY_VALUE, battery); } else if (NCALL_REMOCON_KEY_NOTI_CHARACTERISTIC.equals(characteristic.getUuid())) { int cmd = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0); if (cmd == 0x00) { intent.putExtra(KEY_INPUT_DATA, characteristic.getValue()); } else if (cmd == 0x22) { int status = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 1); Log.d(TAG, String.format("scenario status : %d", status)); intent.putExtra(SCENARIO_STATUS_DATA, status); } else if (cmd == 0x32) { intent.putExtra(LED_INPUT_DATA, characteristic.getValue()); } else if (cmd == 0x42) { intent.putExtra(VERSION_INPUT_DATA, characteristic.getValue()); } else if (cmd == 0x52) { int status = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 1); Log.i(TAG, "RESPONSE_PATRERN_DATA ++"); if (status == RESPONSE_PATRERN_DATA_WRITE_ERROR) { Log.e(TAG, "PATTERN_DATA_WRITE_ERROR"); } else if (status == RESPONSE_PATRERN_DATA_WRITE_START) { Log.i(TAG, "pattern data response ok!!!!!!!!!!!!!!!!!!!!!!!!!!!"); if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "writeRemoconCharacteristic BluetoothAdapter not initialized"); return; }//w w w . j av a 2 s. c o m BluetoothGattService RemoconService = mBluetoothGatt.getService(NCALL_REMOCON_SERVICE); if (RemoconService == null) { showMessage("NCALL_REMOCON_SERVICE = NULL"); return; } BluetoothGattCharacteristic RemoconChar = RemoconService .getCharacteristic(NCALL_REMOCON_SEND_PATTERN_CHARACTERISTIC); if (RemoconChar == null) { showMessage("NCALL_REMOCON_SEND_PATTERN_CHARACTERISTIC = NULL"); return; } try { final byte[] buffer = mBuffer; final int size = mInputStream.read(buffer); writePacket(mBluetoothGatt, RemoconChar, buffer, size); } catch (Exception e) { Log.e(TAG, "" + e); } } else if (status == RESPONSE_PATRERN_DATA_WRITE_END) { try { patternCount++; if (patternCount < 12) { Log.w(TAG, "" + patternCount); PatternTransferStart(patternCount); } else { broadcastUpdate(PROGRESS_SET_INVISIBLE); } } catch (Exception e) { // TODO: handle exception } } Log.i(TAG, "RESPONSE_PATRERN_DATA --"); } else if (cmd == 0x62) { Log.i(TAG, "/ ack:" + characteristic.getValue()); } } else if (MANUFACTURER_NAME_UUID.equals(characteristic.getUuid())) { byte getdata[] = characteristic.getValue(); Log.i(TAG, "Manufacturer Name : " + new String(getdata, 0, getdata.length)); intent.putExtra(MANUFACTURER_NAME, characteristic.getValue()); } else if (MODEL_NAME_UUID.equals(characteristic.getUuid())) { byte getdata[] = characteristic.getValue(); Log.i(TAG, "Model Number : " + new String(getdata, 0, getdata.length)); intent.putExtra(MODEL_NAME, characteristic.getValue()); } else if (FIRMWARE_REVISON_UUID.equals(characteristic.getUuid())) { byte getdata[] = characteristic.getValue(); Log.i(TAG, "firmware vision = " + new String(getdata, 0, getdata.length)); intent.putExtra(FIRMWARE_REVISON, characteristic.getValue()); } else if (HARDWARE_REVISON_UUID.equals(characteristic.getUuid())) { byte getdata[] = characteristic.getValue(); Log.i(TAG, "hardware revision = " + new String(getdata, 0, getdata.length)); intent.putExtra(HARDWARE_REVISON, characteristic.getValue()); } // synchronized (mLock) { // mLock.notifyAll(); // } sendBroadcast(intent); }
From source file:com.nbplus.iotapp.bluetooth.BluetoothLeService.java
/** * Enables or disables notification on a give characteristic. * * @param enabled If true, enable notification. False otherwise. *///from w w w .j a v a 2 s . c o m public boolean setCharacteristicNotification(String address, String serviceUuid, String characteristicUuid, boolean enabled) { Log.d(TAG, "writeRemoteCharacteristic add = " + address + ", svc = " + serviceUuid + ", char = " + characteristicUuid); if (StringUtils.isEmptyString(address) || StringUtils.isEmptyString(serviceUuid) || StringUtils.isEmptyString(characteristicUuid)) { Log.w(TAG, "Unknown parameter"); return false; } BluetoothGatt bluetoothGatt = mConnectedBluetoothGattMap.get(address); if (mBluetoothAdapter == null || bluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return false; } BluetoothGattService service = bluetoothGatt.getService(UUID.fromString(serviceUuid)); if (service == null) { Log.w(TAG, "Service not found."); return false; } BluetoothGattCharacteristic characteristic = service.getCharacteristic(UUID.fromString(characteristicUuid)); if (characteristic == null) { Log.w(TAG, "characteristic not found."); return false; } bluetoothGatt.setCharacteristicNotification(characteristic, enabled); final int charaProp = characteristic.getProperties(); if ((charaProp & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { BluetoothGattDescriptor descriptor = characteristic .getDescriptor(UUID.fromString(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); if (descriptor != null) { Log.d(TAG, ">>>> ENABLE_NOTIFICATION_VALUE : " + characteristic.getUuid().toString()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); bluetoothGatt.writeDescriptor(descriptor); return true; } else { return false; } } else if ((charaProp & BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) { BluetoothGattDescriptor descriptor = characteristic .getDescriptor(UUID.fromString(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); if (descriptor != null) { Log.d(TAG, ">>>> ENABLE_INDICATION_VALUE : " + characteristic.getUuid().toString()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); bluetoothGatt.writeDescriptor(descriptor); return true; } else { return false; } } else { return false; } }
From source file:com.guangyao.bluetoothtest.service.BluetoothLeService.java
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 (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { // int flag = characteristic.getProperties(); // int format = -1; // if ((flag & 0x01) != 0) { // format = BluetoothGattCharacteristic.FORMAT_UINT16; // Log.d(TAG, "Heart rate format UINT16."); // } else { // format = BluetoothGattCharacteristic.FORMAT_UINT8; // Log.d(TAG, "Heart rate format UINT8."); // } // final int heartRate = characteristic.getIntValue(format, 1); // Log.d(TAG, String.format("Received heart rate: %d", heartRate)); // intent.putExtra(EXTRA_DATA, String.valueOf(heartRate)); // } else { // // For all other profiles, writes the data formatted in HEX. // 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()); // } // }//w w w.jav a2 s. com if (TX_CHAR_UUID.equals(characteristic.getUuid())) { byte[] data = characteristic.getValue(); Log.d(TAG, "broadcastUpdate: received from ble:" + DataHandlerUtils.bytesToHexStr(data)); if (ble_status == FREE || ble_status == RECEIVING) { ble_status = RECEIVING; if (data != null) { intent.putExtra(EXTRA_DATA, data); sendBroadcast(intent); } ble_status = FREE; } else if (ble_status == SENDING) { if (final_packet) { final_packet = false; } ble_status = FREE; } } }